Skip to content

Commit

Permalink
update json output for zpool status
Browse files Browse the repository at this point in the history
  • Loading branch information
goulven riou committed Mar 10, 2016
1 parent ed06b93 commit fcb2dd7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
42 changes: 40 additions & 2 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
if (!json || (!json->json && !json->ld_json)) {
(void) printf(" %5s %5s %5s", rbuf, wbuf, cbuf);
} else {
fnvlist_add_string(buffer_t,
fnvlist_add_string(buffer_t,
"NAME", name);
fnvlist_add_string(buffer_t,
"STATE", state);
Expand All @@ -2015,6 +2015,8 @@ print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
if (!json || (!json->json && !json->ld_json))
(void) printf(" was %s", path);
else
fnvlist_add_string(buffer_t, "was", path);
} else if (vs->vs_aux != 0) {
if (!json || (!json->json && !json->ld_json))
(void) printf(" ");
Expand All @@ -2023,27 +2025,42 @@ print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
case VDEV_AUX_OPEN_FAILED:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("cannot open"));
else
fnvlist_add_string(buffer_t,
"reason", "cannot open");
break;

case VDEV_AUX_BAD_GUID_SUM:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("missing device"));
else
fnvlist_add_string(buffer_t,
"reason", "missing device");
break;

case VDEV_AUX_NO_REPLICAS:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("insufficient replicas"));
else
fnvlist_add_string(buffer_t,
"reason", "insufficient replicas");
break;

case VDEV_AUX_VERSION_NEWER:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("newer version"));
else
fnvlist_add_string(buffer_t,
"reason", "newer version");
break;

case VDEV_AUX_UNSUP_FEAT:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext(
"unsupported feature(s)"));
else
fnvlist_add_string(buffer_t,
"reason", "unsupported feature(s)");
break;

case VDEV_AUX_SPARED:
Expand All @@ -2069,32 +2086,50 @@ print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
case VDEV_AUX_ERR_EXCEEDED:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("too many errors"));
else
fnvlist_add_string(buffer_t,
"reason", "too many errors");
break;

case VDEV_AUX_IO_FAILURE:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("experienced I/O "
"failures"));
else
fnvlist_add_string(buffer_t,
"reason", "experienced I/O failures");
break;

case VDEV_AUX_BAD_LOG:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("bad intent log"));
else
fnvlist_add_string(buffer_t,
"reason", "bad intent log");
break;

case VDEV_AUX_EXTERNAL:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("external device fault"));
else
fnvlist_add_string(buffer_t,
"reason", "external device fault");
break;

case VDEV_AUX_SPLIT_POOL:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("split into new pool"));
else
fnvlist_add_string(buffer_t,
"reason", "split into new pool");
break;

default:
if (!json || (!json->json && !json->ld_json))
(void) printf(gettext("corrupted data"));
else
fnvlist_add_string(buffer_t,
"reason", "corrupted data");
break;
}
}
Expand Down Expand Up @@ -2323,6 +2358,7 @@ print_import_config(const char *name, nvlist_t *nv, int namewidth, int depth,
}
}


/*
* Print log vdevs.
* Logs are recorded as top level vdevs in the main pool child array
Expand Down Expand Up @@ -5176,6 +5212,7 @@ zpool_do_list(int argc, char **argv)
switch (c) {
case 'g':
cb.cb_name_flags |= VDEV_NAME_GUID;
break;
case 'j':
if (json.json || json.ld_json)
break;
Expand Down Expand Up @@ -7256,7 +7293,7 @@ status_callback(zpool_handle_t *zhp, void *data, zfs_json_t *json)
break;

case ZPOOL_STATUS_CORRUPT_LABEL_R:
if (!json->json && json->ld_json) {
if (!json->json && !json->ld_json) {
(void) printf(gettext("status:"
" One or more devices could not "
"be used because the label is"
Expand Down Expand Up @@ -7970,6 +8007,7 @@ zpool_do_status(int argc, char **argv)
"error", "");
fnvlist_add_string(json.nv_dict_props,
"schema_version", "1.0");
break;
case 'g':
cb.cb_name_flags |= VDEV_NAME_GUID;
break;
Expand Down
3 changes: 2 additions & 1 deletion lib/libzfs/libzfs_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,8 @@ zpool_find_import_impl(libzfs_handle_t *hdl,
* if an error is encountered when consulted the libblkid cache.
*/
if (dirs == 0) {
if (!iarg->scan && (zpool_find_import_blkid(hdl, &pools, json) == 0))
if (!iarg->scan && (zpool_find_import_blkid(hdl,
&pools, json) == 0))
goto skip_scanning;

dir = zpool_default_import_path;
Expand Down

0 comments on commit fcb2dd7

Please sign in to comment.