JSON output support for zpool status

This commit adds support for zpool status command to displpay status
of ZFS pools in JSON format using '-j' option. Status information is
collected in nvlist which is later dumped on stdout in JSON format.
Existing options for zpool status work with '-j' flag. man page for
zpool status is updated accordingly.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Signed-off-by: Umer Saleem <usaleem@ixsystems.com>
Closes #16217
This commit is contained in:
Umer Saleem
2024-05-09 16:54:47 +05:00
committed by Brian Behlendorf
parent 4e6b3f7e1d
commit 959e963c81
9 changed files with 1928 additions and 451 deletions
+2
View File
@@ -39,5 +39,7 @@
void print_timestamp(uint_t);
/* Return timestamp in either Unix or standard format in provided buffer */
void get_timestamp(uint_t, char *, int);
/* convert time_t to standard format */
void format_timestamp(time_t, char *, int);
#endif /* _STATCOMMON_H */
+20
View File
@@ -84,3 +84,23 @@ get_timestamp(uint_t timestamp_fmt, char *buf, int len)
strftime(buf, len, fmt, localtime_r(&t, &tm));
}
}
/*
* Format the provided time stamp to human readable format
*/
void
format_timestamp(time_t t, char *buf, int len)
{
struct tm tm;
static const char *fmt = NULL;
if (t == 0) {
snprintf(buf, len, "-");
return;
}
/* We only need to retrieve this once per invocation */
if (fmt == NULL)
fmt = nl_langinfo(_DATE_FMT);
strftime(buf, len, fmt, localtime_r(&t, &tm));
}