Skip to content

Commit

Permalink
update json output for zpool status
Browse files Browse the repository at this point in the history
update zfs create for test suite
  • Loading branch information
goulven riou committed Apr 18, 2016
1 parent 7c63fa1 commit ac73eab
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
36 changes: 29 additions & 7 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ zfs_do_create(int argc, char **argv)
nomem();

/* check options */
while ((c = getopt(argc, argv, ":V:b:so:p:Jj")) != -1) {
while ((c = getopt(argc, argv, ":V:b:so:pJj")) != -1) {
switch (c) {
case 'j':
case 'J':
Expand All @@ -895,9 +895,20 @@ zfs_do_create(int argc, char **argv)
type = ZFS_TYPE_VOLUME;
if (zfs_nicestrtonum(&json,
g_zfs, optarg, &intval) != 0) {
(void) fprintf(stderr, gettext("bad volume "
"size '%s': %s\n"), optarg,
libzfs_error_description(g_zfs));
if (!json.json && !json.ld_json) {
(void) fprintf(stderr,
gettext("bad volume "
"size '%s': %s\n"), optarg,
libzfs_error_description(g_zfs));
} else {
(void) snprintf(errbuf,
sizeof (errbuf),
gettext("bad volume "
"size '%s': %s\n"), optarg,
libzfs_error_description(g_zfs));
fnvlist_add_string(json.nv_dict_error,
"error", errbuf);
}
goto error;
}

Expand All @@ -913,9 +924,20 @@ zfs_do_create(int argc, char **argv)
bflag = B_TRUE;
if (zfs_nicestrtonum(&json,
g_zfs, optarg, &intval) != 0) {
(void) fprintf(stderr, gettext("bad volume "
"block size '%s': %s\n"), optarg,
libzfs_error_description(g_zfs));
if (!json.json && !json.ld_json) {
(void) fprintf(stderr,
gettext("bad volume "
"block size '%s': %s\n"), optarg,
libzfs_error_description(g_zfs));
} else {
(void) snprintf(errbuf,
sizeof (errbuf),
gettext("bad volume "
"block size '%s': %s\n"), optarg,
libzfs_error_description(g_zfs));
fnvlist_add_string(json.nv_dict_error,
"error", errbuf);
}
goto error;
}

Expand Down
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 @@ -5184,6 +5220,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 @@ -7264,7 +7301,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 @@ -7978,6 +8015,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

0 comments on commit ac73eab

Please sign in to comment.