Skip to content

Commit 959e963

Browse files
Umer Saleembehlendorf
authored andcommitted
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 <[email protected]> Reviewed-by: Ameer Hamza <[email protected]> Signed-off-by: Umer Saleem <[email protected]> Closes #16217
1 parent 4e6b3f7 commit 959e963

File tree

9 files changed

+1816
-339
lines changed

9 files changed

+1816
-339
lines changed

cmd/zpool/zpool_main.c

Lines changed: 1488 additions & 304 deletions
Large diffs are not rendered by default.

include/libzfs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ _LIBZFS_H int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
469469
char *altroot);
470470
_LIBZFS_H int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
471471
nvlist_t *, int);
472-
_LIBZFS_H void zpool_print_unsup_feat(nvlist_t *config);
472+
_LIBZFS_H void zpool_collect_unsup_feat(nvlist_t *config, char *buf,
473+
size_t size);
473474

474475
/*
475476
* Miscellaneous pool functions
@@ -500,7 +501,7 @@ _LIBZFS_H void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
500501
size_t);
501502
_LIBZFS_H int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
502503
_LIBZFS_H void zpool_explain_recover(libzfs_handle_t *, const char *, int,
503-
nvlist_t *);
504+
nvlist_t *, char *, size_t);
504505
_LIBZFS_H int zpool_checkpoint(zpool_handle_t *);
505506
_LIBZFS_H int zpool_discard_checkpoint(zpool_handle_t *);
506507
_LIBZFS_H boolean_t zpool_is_draid_spare(const char *);

lib/libspl/include/statcommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@
3939
void print_timestamp(uint_t);
4040
/* Return timestamp in either Unix or standard format in provided buffer */
4141
void get_timestamp(uint_t, char *, int);
42+
/* convert time_t to standard format */
43+
void format_timestamp(time_t, char *, int);
4244

4345
#endif /* _STATCOMMON_H */

lib/libspl/timestamp.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,23 @@ get_timestamp(uint_t timestamp_fmt, char *buf, int len)
8484
strftime(buf, len, fmt, localtime_r(&t, &tm));
8585
}
8686
}
87+
88+
/*
89+
* Format the provided time stamp to human readable format
90+
*/
91+
void
92+
format_timestamp(time_t t, char *buf, int len)
93+
{
94+
struct tm tm;
95+
static const char *fmt = NULL;
96+
97+
if (t == 0) {
98+
snprintf(buf, len, "-");
99+
return;
100+
}
101+
102+
/* We only need to retrieve this once per invocation */
103+
if (fmt == NULL)
104+
fmt = nl_langinfo(_DATE_FMT);
105+
strftime(buf, len, fmt, localtime_r(&t, &tm));
106+
}

lib/libuutil/libuutil.abi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@
143143
<elf-symbol name='avl_update_gt' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
144144
<elf-symbol name='avl_update_lt' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
145145
<elf-symbol name='avl_walk' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
146+
<elf-symbol name='format_timestamp' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
146147
<elf-symbol name='get_system_hostid' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
148+
<elf-symbol name='get_timestamp' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
147149
<elf-symbol name='getexecname' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
148150
<elf-symbol name='getextmntent' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
149151
<elf-symbol name='getmntany' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -1151,6 +1153,18 @@
11511153
<parameter type-id='3502e3ff' name='timestamp_fmt'/>
11521154
<return type-id='48b5725f'/>
11531155
</function-decl>
1156+
<function-decl name='get_timestamp' mangled-name='get_timestamp' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='get_timestamp'>
1157+
<parameter type-id='3502e3ff' name='timestamp_fmt'/>
1158+
<parameter type-id='26a90f95' name='buf'/>
1159+
<parameter type-id='95e97e5e' name='len'/>
1160+
<return type-id='48b5725f'/>
1161+
</function-decl>
1162+
<function-decl name='format_timestamp' mangled-name='format_timestamp' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='format_timestamp'>
1163+
<parameter type-id='c9d12d66' name='t'/>
1164+
<parameter type-id='26a90f95' name='buf'/>
1165+
<parameter type-id='95e97e5e' name='len'/>
1166+
<return type-id='48b5725f'/>
1167+
</function-decl>
11541168
</abi-instr>
11551169
<abi-instr address-size='64' path='lib/libuutil/uu_alloc.c' language='LANG_C99'>
11561170
<type-decl name='char' size-in-bits='8' id='a84c031d'/>

lib/libzfs/libzfs.abi

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,12 @@
179179
<elf-symbol name='fletcher_4_native' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
180180
<elf-symbol name='fletcher_4_native_varsize' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
181181
<elf-symbol name='fletcher_init' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
182+
<elf-symbol name='format_timestamp' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
182183
<elf-symbol name='fsleep' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
183184
<elf-symbol name='get_dataset_depth' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
184185
<elf-symbol name='get_system_hostid' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
185186
<elf-symbol name='getexecname' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
187+
<elf-symbol name='get_timestamp' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
186188
<elf-symbol name='getextmntent' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
187189
<elf-symbol name='getmntany' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
188190
<elf-symbol name='getprop_uint64' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -280,6 +282,7 @@
280282
<elf-symbol name='vdev_prop_to_name' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
281283
<elf-symbol name='vdev_prop_user' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
282284
<elf-symbol name='vdev_prop_values' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
285+
<elf-symbol name='zcmd_print_json' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
283286
<elf-symbol name='zfeature_depends_on' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
284287
<elf-symbol name='zfeature_is_supported' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
285288
<elf-symbol name='zfeature_is_valid_guid' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -452,6 +455,7 @@
452455
<elf-symbol name='zfs_userspace' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
453456
<elf-symbol name='zfs_valid_proplist' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
454457
<elf-symbol name='zfs_version_kernel' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
458+
<elf-symbol name='zfs_version_nvlist' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
455459
<elf-symbol name='zfs_version_print' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
456460
<elf-symbol name='zfs_version_userland' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
457461
<elf-symbol name='zfs_wait_status' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -524,7 +528,7 @@
524528
<elf-symbol name='zpool_prefetch' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
525529
<elf-symbol name='zpool_prepare_and_label_disk' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
526530
<elf-symbol name='zpool_prepare_disk' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
527-
<elf-symbol name='zpool_print_unsup_feat' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
531+
<elf-symbol name='zpool_collect_unsup_feat' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
528532
<elf-symbol name='zpool_prop_align_right' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
529533
<elf-symbol name='zpool_prop_column_name' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
530534
<elf-symbol name='zpool_prop_default_numeric' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -577,12 +581,14 @@
577581
<elf-symbol name='zpool_vdev_split' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
578582
<elf-symbol name='zpool_wait' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
579583
<elf-symbol name='zpool_wait_status' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
584+
<elf-symbol name='zprop_collect_property' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
580585
<elf-symbol name='zprop_free_list' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
581586
<elf-symbol name='zprop_get_list' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
582587
<elf-symbol name='zprop_index_to_string' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
583588
<elf-symbol name='zprop_iter' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
584589
<elf-symbol name='zprop_iter_common' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
585590
<elf-symbol name='zprop_name_to_prop' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
591+
<elf-symbol name='zprop_nvlist_one_property' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
586592
<elf-symbol name='zprop_print_one_property' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
587593
<elf-symbol name='zprop_random_value' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
588594
<elf-symbol name='zprop_register_hidden' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -1284,6 +1290,18 @@
12841290
<parameter type-id='3502e3ff' name='timestamp_fmt'/>
12851291
<return type-id='48b5725f'/>
12861292
</function-decl>
1293+
<function-decl name='get_timestamp' mangled-name='get_timestamp' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='get_timestamp'>
1294+
<parameter type-id='3502e3ff' name='timestamp_fmt'/>
1295+
<parameter type-id='26a90f95' name='buf'/>
1296+
<parameter type-id='95e97e5e' name='len'/>
1297+
<return type-id='48b5725f'/>
1298+
</function-decl>
1299+
<function-decl name='format_timestamp' mangled-name='format_timestamp' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='format_timestamp'>
1300+
<parameter type-id='c9d12d66' name='t'/>
1301+
<parameter type-id='26a90f95' name='buf'/>
1302+
<parameter type-id='95e97e5e' name='len'/>
1303+
<return type-id='48b5725f'/>
1304+
</function-decl>
12871305
</abi-instr>
12881306
<abi-instr address-size='64' path='lib/libtpool/thread_pool.c' language='LANG_C99'>
12891307
<array-type-def dimensions='1' type-id='49ef3ffd' size-in-bits='1024' id='a14403f5'>
@@ -6456,6 +6474,8 @@
64566474
<parameter type-id='80f4b756' name='name'/>
64576475
<parameter type-id='95e97e5e' name='reason'/>
64586476
<parameter type-id='5ce45b60' name='config'/>
6477+
<parameter type-id='26a90f95' name='buf'/>
6478+
<parameter type-id='b59d7dce' name='size'/>
64596479
<return type-id='48b5725f'/>
64606480
</function-decl>
64616481
<function-decl name='zpool_import' mangled-name='zpool_import' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_import'>
@@ -6465,8 +6485,10 @@
64656485
<parameter type-id='26a90f95' name='altroot'/>
64666486
<return type-id='95e97e5e'/>
64676487
</function-decl>
6468-
<function-decl name='zpool_print_unsup_feat' mangled-name='zpool_print_unsup_feat' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_print_unsup_feat'>
6488+
<function-decl name='zpool_collect_unsup_feat' mangled-name='zpool_collect_unsup_feat' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_collect_unsup_feat'>
64696489
<parameter type-id='5ce45b60' name='config'/>
6490+
<parameter type-id='26a90f95' name='buf'/>
6491+
<parameter type-id='b59d7dce' name='size'/>
64706492
<return type-id='48b5725f'/>
64716493
</function-decl>
64726494
<function-decl name='zpool_import_props' mangled-name='zpool_import_props' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_import_props'>
@@ -8194,6 +8216,20 @@
81948216
<parameter type-id='2e45de5d' name='argtype'/>
81958217
<return type-id='9200a744'/>
81968218
</function-decl>
8219+
<function-decl name='zcmd_print_json' mangled-name='zcmd_print_json' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zcmd_print_json'>
8220+
<parameter type-id='5ce45b60' name='nvl'/>
8221+
<return type-id='48b5725f'/>
8222+
</function-decl>
8223+
<function-decl name='zprop_nvlist_one_property' mangled-name='zprop_nvlist_one_property' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zprop_nvlist_one_property'>
8224+
<parameter type-id='80f4b756' name='propname'/>
8225+
<parameter type-id='80f4b756' name='value'/>
8226+
<parameter type-id='a2256d42' name='sourcetype'/>
8227+
<parameter type-id='80f4b756' name='source'/>
8228+
<parameter type-id='80f4b756' name='recvd_value'/>
8229+
<parameter type-id='5ce45b60' name='nvl'/>
8230+
<parameter type-id='c19b74c3' name='as_int'/>
8231+
<return type-id='95e97e5e'/>
8232+
</function-decl>
81978233
<function-decl name='zprop_print_one_property' mangled-name='zprop_print_one_property' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zprop_print_one_property'>
81988234
<parameter type-id='80f4b756' name='name'/>
81998235
<parameter type-id='0d2a0670' name='cbp'/>
@@ -8204,6 +8240,17 @@
82048240
<parameter type-id='80f4b756' name='recvd_value'/>
82058241
<return type-id='48b5725f'/>
82068242
</function-decl>
8243+
<function-decl name='zprop_collect_property' mangled-name='zprop_collect_property' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zprop_collect_property'>
8244+
<parameter type-id='80f4b756' name='name'/>
8245+
<parameter type-id='0d2a0670' name='cbp'/>
8246+
<parameter type-id='80f4b756' name='propname'/>
8247+
<parameter type-id='80f4b756' name='value'/>
8248+
<parameter type-id='a2256d42' name='sourcetype'/>
8249+
<parameter type-id='80f4b756' name='source'/>
8250+
<parameter type-id='80f4b756' name='recvd_value'/>
8251+
<parameter type-id='5ce45b60' name='nvl'/>
8252+
<return type-id='95e97e5e'/>
8253+
</function-decl>
82078254
<function-decl name='zprop_get_list' mangled-name='zprop_get_list' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zprop_get_list'>
82088255
<parameter type-id='b0382bb3' name='hdl'/>
82098256
<parameter type-id='26a90f95' name='props'/>
@@ -8232,6 +8279,9 @@
82328279
<function-decl name='use_color' mangled-name='use_color' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='use_color'>
82338280
<return type-id='95e97e5e'/>
82348281
</function-decl>
8282+
<function-decl name='zfs_version_nvlist' mangled-name='zfs_version_nvlist' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_version_nvlist'>
8283+
<return type-id='5ce45b60'/>
8284+
</function-decl>
82358285
<function-decl name='printf_color' mangled-name='printf_color' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='printf_color'>
82368286
<parameter type-id='80f4b756' name='color'/>
82378287
<parameter type-id='80f4b756' name='format'/>

0 commit comments

Comments
 (0)