mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 19:04:45 +03:00
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:
committed by
Brian Behlendorf
parent
4e6b3f7e1d
commit
959e963c81
+52
-2
@@ -179,10 +179,12 @@
|
||||
<elf-symbol name='fletcher_4_native' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='fletcher_4_native_varsize' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='fletcher_init' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='format_timestamp' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='fsleep' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='get_dataset_depth' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='get_system_hostid' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='getexecname' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='get_timestamp' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='getextmntent' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='getmntany' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='getprop_uint64' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
@@ -280,6 +282,7 @@
|
||||
<elf-symbol name='vdev_prop_to_name' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='vdev_prop_user' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='vdev_prop_values' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zcmd_print_json' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfeature_depends_on' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfeature_is_supported' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfeature_is_valid_guid' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
@@ -452,6 +455,7 @@
|
||||
<elf-symbol name='zfs_userspace' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfs_valid_proplist' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfs_version_kernel' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfs_version_nvlist' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfs_version_print' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfs_version_userland' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zfs_wait_status' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
@@ -524,7 +528,7 @@
|
||||
<elf-symbol name='zpool_prefetch' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_prepare_and_label_disk' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_prepare_disk' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_print_unsup_feat' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_collect_unsup_feat' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_prop_align_right' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_prop_column_name' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_prop_default_numeric' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
@@ -577,12 +581,14 @@
|
||||
<elf-symbol name='zpool_vdev_split' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_wait' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_wait_status' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_collect_property' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_free_list' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_get_list' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_index_to_string' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_iter' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_iter_common' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_name_to_prop' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_nvlist_one_property' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_print_one_property' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_random_value' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zprop_register_hidden' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
@@ -1284,6 +1290,18 @@
|
||||
<parameter type-id='3502e3ff' name='timestamp_fmt'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-decl name='get_timestamp' mangled-name='get_timestamp' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='get_timestamp'>
|
||||
<parameter type-id='3502e3ff' name='timestamp_fmt'/>
|
||||
<parameter type-id='26a90f95' name='buf'/>
|
||||
<parameter type-id='95e97e5e' name='len'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-decl name='format_timestamp' mangled-name='format_timestamp' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='format_timestamp'>
|
||||
<parameter type-id='c9d12d66' name='t'/>
|
||||
<parameter type-id='26a90f95' name='buf'/>
|
||||
<parameter type-id='95e97e5e' name='len'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
</abi-instr>
|
||||
<abi-instr address-size='64' path='lib/libtpool/thread_pool.c' language='LANG_C99'>
|
||||
<array-type-def dimensions='1' type-id='49ef3ffd' size-in-bits='1024' id='a14403f5'>
|
||||
@@ -6456,6 +6474,8 @@
|
||||
<parameter type-id='80f4b756' name='name'/>
|
||||
<parameter type-id='95e97e5e' name='reason'/>
|
||||
<parameter type-id='5ce45b60' name='config'/>
|
||||
<parameter type-id='26a90f95' name='buf'/>
|
||||
<parameter type-id='b59d7dce' name='size'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<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 @@
|
||||
<parameter type-id='26a90f95' name='altroot'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<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'>
|
||||
<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'>
|
||||
<parameter type-id='5ce45b60' name='config'/>
|
||||
<parameter type-id='26a90f95' name='buf'/>
|
||||
<parameter type-id='b59d7dce' name='size'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<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 @@
|
||||
<parameter type-id='2e45de5d' name='argtype'/>
|
||||
<return type-id='9200a744'/>
|
||||
</function-decl>
|
||||
<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'>
|
||||
<parameter type-id='5ce45b60' name='nvl'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<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'>
|
||||
<parameter type-id='80f4b756' name='propname'/>
|
||||
<parameter type-id='80f4b756' name='value'/>
|
||||
<parameter type-id='a2256d42' name='sourcetype'/>
|
||||
<parameter type-id='80f4b756' name='source'/>
|
||||
<parameter type-id='80f4b756' name='recvd_value'/>
|
||||
<parameter type-id='5ce45b60' name='nvl'/>
|
||||
<parameter type-id='c19b74c3' name='as_int'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<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'>
|
||||
<parameter type-id='80f4b756' name='name'/>
|
||||
<parameter type-id='0d2a0670' name='cbp'/>
|
||||
@@ -8204,6 +8240,17 @@
|
||||
<parameter type-id='80f4b756' name='recvd_value'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<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'>
|
||||
<parameter type-id='80f4b756' name='name'/>
|
||||
<parameter type-id='0d2a0670' name='cbp'/>
|
||||
<parameter type-id='80f4b756' name='propname'/>
|
||||
<parameter type-id='80f4b756' name='value'/>
|
||||
<parameter type-id='a2256d42' name='sourcetype'/>
|
||||
<parameter type-id='80f4b756' name='source'/>
|
||||
<parameter type-id='80f4b756' name='recvd_value'/>
|
||||
<parameter type-id='5ce45b60' name='nvl'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<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'>
|
||||
<parameter type-id='b0382bb3' name='hdl'/>
|
||||
<parameter type-id='26a90f95' name='props'/>
|
||||
@@ -8232,6 +8279,9 @@
|
||||
<function-decl name='use_color' mangled-name='use_color' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='use_color'>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<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'>
|
||||
<return type-id='5ce45b60'/>
|
||||
</function-decl>
|
||||
<function-decl name='printf_color' mangled-name='printf_color' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='printf_color'>
|
||||
<parameter type-id='80f4b756' name='color'/>
|
||||
<parameter type-id='80f4b756' name='format'/>
|
||||
|
||||
+42
-31
@@ -1990,23 +1990,18 @@ zpool_rewind_exclaim(libzfs_handle_t *hdl, const char *name, boolean_t dryrun,
|
||||
|
||||
void
|
||||
zpool_explain_recover(libzfs_handle_t *hdl, const char *name, int reason,
|
||||
nvlist_t *config)
|
||||
nvlist_t *config, char *buf, size_t size)
|
||||
{
|
||||
nvlist_t *nv = NULL;
|
||||
int64_t loss = -1;
|
||||
uint64_t edata = UINT64_MAX;
|
||||
uint64_t rewindto;
|
||||
struct tm t;
|
||||
char timestr[128];
|
||||
char timestr[128], temp[1024];
|
||||
|
||||
if (!hdl->libzfs_printerr)
|
||||
return;
|
||||
|
||||
if (reason >= 0)
|
||||
(void) printf(dgettext(TEXT_DOMAIN, "action: "));
|
||||
else
|
||||
(void) printf(dgettext(TEXT_DOMAIN, "\t"));
|
||||
|
||||
/* All attempted rewinds failed if ZPOOL_CONFIG_LOAD_TIME missing */
|
||||
if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nv) != 0 ||
|
||||
nvlist_lookup_nvlist(nv, ZPOOL_CONFIG_REWIND_INFO, &nv) != 0 ||
|
||||
@@ -2017,56 +2012,61 @@ zpool_explain_recover(libzfs_handle_t *hdl, const char *name, int reason,
|
||||
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_DATA_ERRORS,
|
||||
&edata);
|
||||
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) snprintf(buf, size, dgettext(TEXT_DOMAIN,
|
||||
"Recovery is possible, but will result in some data loss.\n"));
|
||||
|
||||
if (localtime_r((time_t *)&rewindto, &t) != NULL &&
|
||||
ctime_r((time_t *)&rewindto, timestr) != NULL) {
|
||||
timestr[24] = 0;
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) snprintf(temp, 1024, dgettext(TEXT_DOMAIN,
|
||||
"\tReturning the pool to its state as of %s\n"
|
||||
"\tshould correct the problem. "),
|
||||
timestr);
|
||||
"\tshould correct the problem. "), timestr);
|
||||
(void) strlcat(buf, temp, size);
|
||||
} else {
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) strlcat(buf, dgettext(TEXT_DOMAIN,
|
||||
"\tReverting the pool to an earlier state "
|
||||
"should correct the problem.\n\t"));
|
||||
"should correct the problem.\n\t"), size);
|
||||
}
|
||||
|
||||
if (loss > 120) {
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) snprintf(temp, 1024, dgettext(TEXT_DOMAIN,
|
||||
"Approximately %lld minutes of data\n"
|
||||
"\tmust be discarded, irreversibly. "),
|
||||
((longlong_t)loss + 30) / 60);
|
||||
(void) strlcat(buf, temp, size);
|
||||
} else if (loss > 0) {
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) snprintf(temp, 1024, dgettext(TEXT_DOMAIN,
|
||||
"Approximately %lld seconds of data\n"
|
||||
"\tmust be discarded, irreversibly. "),
|
||||
(longlong_t)loss);
|
||||
(void) strlcat(buf, temp, size);
|
||||
}
|
||||
if (edata != 0 && edata != UINT64_MAX) {
|
||||
if (edata == 1) {
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) strlcat(buf, dgettext(TEXT_DOMAIN,
|
||||
"After rewind, at least\n"
|
||||
"\tone persistent user-data error will remain. "));
|
||||
"\tone persistent user-data error will remain. "),
|
||||
size);
|
||||
} else {
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) strlcat(buf, dgettext(TEXT_DOMAIN,
|
||||
"After rewind, several\n"
|
||||
"\tpersistent user-data errors will remain. "));
|
||||
"\tpersistent user-data errors will remain. "),
|
||||
size);
|
||||
}
|
||||
}
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) snprintf(temp, 1024, dgettext(TEXT_DOMAIN,
|
||||
"Recovery can be attempted\n\tby executing 'zpool %s -F %s'. "),
|
||||
reason >= 0 ? "clear" : "import", name);
|
||||
(void) strlcat(buf, temp, size);
|
||||
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
(void) strlcat(buf, dgettext(TEXT_DOMAIN,
|
||||
"A scrub of the pool\n"
|
||||
"\tis strongly recommended after recovery.\n"));
|
||||
"\tis strongly recommended after recovery.\n"), size);
|
||||
return;
|
||||
|
||||
no_info:
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
"Destroy and re-create the pool from\n\ta backup source.\n"));
|
||||
(void) strlcat(buf, dgettext(TEXT_DOMAIN,
|
||||
"Destroy and re-create the pool from\n\ta backup source.\n"), size);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2135,9 +2135,10 @@ print_vdev_tree(libzfs_handle_t *hdl, const char *name, nvlist_t *nv,
|
||||
}
|
||||
|
||||
void
|
||||
zpool_print_unsup_feat(nvlist_t *config)
|
||||
zpool_collect_unsup_feat(nvlist_t *config, char *buf, size_t size)
|
||||
{
|
||||
nvlist_t *nvinfo, *unsup_feat;
|
||||
char temp[512];
|
||||
|
||||
nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
|
||||
unsup_feat = fnvlist_lookup_nvlist(nvinfo, ZPOOL_CONFIG_UNSUP_FEAT);
|
||||
@@ -2145,10 +2146,14 @@ zpool_print_unsup_feat(nvlist_t *config)
|
||||
for (nvpair_t *nvp = nvlist_next_nvpair(unsup_feat, NULL);
|
||||
nvp != NULL; nvp = nvlist_next_nvpair(unsup_feat, nvp)) {
|
||||
const char *desc = fnvpair_value_string(nvp);
|
||||
if (strlen(desc) > 0)
|
||||
(void) printf("\t%s (%s)\n", nvpair_name(nvp), desc);
|
||||
else
|
||||
(void) printf("\t%s\n", nvpair_name(nvp));
|
||||
if (strlen(desc) > 0) {
|
||||
(void) snprintf(temp, 512, "\t%s (%s)\n",
|
||||
nvpair_name(nvp), desc);
|
||||
(void) strlcat(buf, temp, size);
|
||||
} else {
|
||||
(void) snprintf(temp, 512, "\t%s\n", nvpair_name(nvp));
|
||||
(void) strlcat(buf, temp, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2171,6 +2176,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
|
||||
const char *origname;
|
||||
int ret;
|
||||
int error = 0;
|
||||
char buf[2048];
|
||||
char errbuf[ERRBUFLEN];
|
||||
|
||||
origname = fnvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME);
|
||||
@@ -2253,7 +2259,9 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
|
||||
(void) printf(dgettext(TEXT_DOMAIN, "This "
|
||||
"pool uses the following feature(s) not "
|
||||
"supported by this system:\n"));
|
||||
zpool_print_unsup_feat(nv);
|
||||
memset(buf, 0, 2048);
|
||||
zpool_collect_unsup_feat(nv, buf, 2048);
|
||||
(void) printf("%s", buf);
|
||||
if (nvlist_exists(nvinfo,
|
||||
ZPOOL_CONFIG_CAN_RDONLY)) {
|
||||
(void) printf(dgettext(TEXT_DOMAIN,
|
||||
@@ -2352,8 +2360,11 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
|
||||
break;
|
||||
default:
|
||||
(void) zpool_standard_error(hdl, error, desc);
|
||||
memset(buf, 0, 2048);
|
||||
zpool_explain_recover(hdl,
|
||||
newname ? origname : thename, -error, nv);
|
||||
newname ? origname : thename, -error, nv,
|
||||
buf, 2048);
|
||||
(void) printf("\t%s", buf);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user