aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorUmer Saleem <[email protected]>2024-04-25 17:59:41 +0500
committerBrian Behlendorf <[email protected]>2024-08-06 12:47:04 -0700
commit4e6b3f7e1d424c923041acecfed8f10780766e19 (patch)
tree83c3e77b666514a65e7e0d296a94ae78c5a69a9a /lib
parenteb2b824bdec95377a4f0612e96814383b87414f6 (diff)
JSON output support for zpool list
This commit adds support for zpool list command to output the list of ZFS pools in JSON format using '-j' option.. Information about available pools is collected in nvlist which is later printed to stdout in JSON format. Existing options for zfs list command work with '-j' flag. man page for zpool list is updated accordingly. Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Ameer Hamza <[email protected]> Signed-off-by: Umer Saleem <[email protected]> Closes #16217
Diffstat (limited to 'lib')
-rw-r--r--lib/libspl/include/statcommon.h2
-rw-r--r--lib/libspl/timestamp.c22
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/libspl/include/statcommon.h b/lib/libspl/include/statcommon.h
index 971997a44..d8d8fd684 100644
--- a/lib/libspl/include/statcommon.h
+++ b/lib/libspl/include/statcommon.h
@@ -37,5 +37,7 @@
/* Print a timestamp in either Unix or standard format. */
void print_timestamp(uint_t);
+/* Return timestamp in either Unix or standard format in provided buffer */
+void get_timestamp(uint_t, char *, int);
#endif /* _STATCOMMON_H */
diff --git a/lib/libspl/timestamp.c b/lib/libspl/timestamp.c
index 9b435221f..8ab1a0e26 100644
--- a/lib/libspl/timestamp.c
+++ b/lib/libspl/timestamp.c
@@ -62,3 +62,25 @@ print_timestamp(uint_t timestamp_fmt)
(void) printf("%s\n", dstr);
}
}
+
+/*
+ * Return timestamp as decimal reprentation (in string) of time_t
+ * value (-T u was specified) or in date(1) format (-T d was specified).
+ */
+void
+get_timestamp(uint_t timestamp_fmt, char *buf, int len)
+{
+ time_t t = time(NULL);
+ static const char *fmt = NULL;
+
+ /* We only need to retrieve this once per invocation */
+ if (fmt == NULL)
+ fmt = nl_langinfo(_DATE_FMT);
+
+ if (timestamp_fmt == UDATE) {
+ (void) snprintf(buf, len, "%lld", (longlong_t)t);
+ } else if (timestamp_fmt == DDATE) {
+ struct tm tm;
+ strftime(buf, len, fmt, localtime_r(&t, &tm));
+ }
+}