diff options
author | Brian Behlendorf <behlendorf1@llnl.gov> | 2022-09-29 09:25:31 +0200 |
---|---|---|
committer | Patrick Mooney <pmooney@oxide.computer> | 2022-09-29 18:15:23 +0000 |
commit | 609febc9a48c79a089214cb5d882759a72a38513 (patch) | |
tree | e8e55d2f89ec1a2ac691ade2a98be03f94746057 /usr/src/cmd | |
parent | e472a1cd85bffae230f8546d46fa757bade533e9 (diff) | |
download | illumos-gate-609febc9a48c79a089214cb5d882759a72a38513.tar.gz |
13923 zpool list -v output is misaligned
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Patrick Mooney <pmooney@pfmooney.com>
Diffstat (limited to 'usr/src/cmd')
-rw-r--r-- | usr/src/cmd/zpool/zpool_main.c | 77 |
1 files changed, 43 insertions, 34 deletions
diff --git a/usr/src/cmd/zpool/zpool_main.c b/usr/src/cmd/zpool/zpool_main.c index 79febacacb..e8cc7c5209 100644 --- a/usr/src/cmd/zpool/zpool_main.c +++ b/usr/src/cmd/zpool/zpool_main.c @@ -5148,8 +5148,8 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb) } static void -print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted, - boolean_t valid, enum zfs_nicenum_format format) +print_one_column(zpool_prop_t prop, uint64_t value, const char *str, + boolean_t scripted, boolean_t valid, enum zfs_nicenum_format format) { char propval[64]; boolean_t fixed; @@ -5158,6 +5158,7 @@ print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted, switch (prop) { case ZPOOL_PROP_EXPANDSZ: case ZPOOL_PROP_CHECKPOINT: + case ZPOOL_PROP_DEDUPRATIO: if (value == 0) (void) strlcpy(propval, "-", sizeof (propval)); else @@ -5185,6 +5186,10 @@ print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted, value < 1000 ? "%1.2f%%" : value < 10000 ? "%2.1f%%" : "%3.0f%%", value / 100.0); break; + case ZPOOL_PROP_HEALTH: + width = 8; + (void) strlcpy(propval, str, sizeof (propval)); + break; default: zfs_nicenum_format(value, propval, sizeof (propval), format); } @@ -5203,7 +5208,7 @@ print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted, */ void print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv, - list_cbdata_t *cb, int depth) + list_cbdata_t *cb, int depth, boolean_t isspare) { nvlist_t **child; vdev_stat_t *vs; @@ -5211,7 +5216,8 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv, char *vname; boolean_t scripted = cb->cb_scripted; uint64_t islog = B_FALSE; - char *dashes = "%-*s - - - - - -\n"; + char *dashes = " %-*s - - - - " + "- - - - -\n"; verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&vs, &c) == 0); @@ -5220,6 +5226,7 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv, boolean_t toplevel = (vs->vs_space != 0); uint64_t cap; enum zfs_nicenum_format format; + const char *state; if (cb->cb_literal) format = ZFS_NICENUM_RAW; @@ -5243,24 +5250,35 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv, * 'toplevel' boolean value is passed to the print_one_column() * to indicate that the value is valid. */ - print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted, - toplevel, format); - print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, scripted, + print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, NULL, scripted, toplevel, format); - print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc, + print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, NULL, scripted, toplevel, format); + print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc, + NULL, scripted, toplevel, format); print_one_column(ZPOOL_PROP_CHECKPOINT, - vs->vs_checkpoint_space, scripted, toplevel, format); - print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted, - B_TRUE, format); + vs->vs_checkpoint_space, NULL, scripted, toplevel, format); + print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, NULL, + scripted, B_TRUE, format); print_one_column(ZPOOL_PROP_FRAGMENTATION, - vs->vs_fragmentation, scripted, + vs->vs_fragmentation, NULL, scripted, (vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel), format); cap = (vs->vs_space == 0) ? 0 : (vs->vs_alloc * 10000 / vs->vs_space); - print_one_column(ZPOOL_PROP_CAPACITY, cap, scripted, toplevel, - format); + print_one_column(ZPOOL_PROP_CAPACITY, cap, NULL, + scripted, toplevel, format); + print_one_column(ZPOOL_PROP_DEDUPRATIO, 0, NULL, + scripted, toplevel, format); + state = zpool_state_to_name(vs->vs_state, vs->vs_aux); + if (isspare) { + if (vs->vs_aux == VDEV_AUX_SPARED) + state = "INUSE"; + else if (vs->vs_state == VDEV_STATE_HEALTHY) + state = "AVAIL"; + } + print_one_column(ZPOOL_PROP_HEALTH, 0, state, scripted, + B_TRUE, format); (void) printf("\n"); } @@ -5285,7 +5303,7 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv, vname = zpool_vdev_name(g_zfs, zhp, child[c], cb->cb_name_flags); - print_list_stats(zhp, vname, child[c], cb, depth + 2); + print_list_stats(zhp, vname, child[c], cb, depth + 1, B_FALSE); free(vname); } @@ -5312,38 +5330,38 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv, continue; if (!printed) { - /* LINTED E_SEC_PRINTF_VAR_FMT */ (void) printf(dashes, cb->cb_namewidth, class_name[n]); printed = B_TRUE; } vname = zpool_vdev_name(g_zfs, zhp, child[c], cb->cb_name_flags); - print_list_stats(zhp, vname, child[c], cb, depth + 2); + print_list_stats(zhp, vname, child[c], cb, depth + 2, + B_FALSE); free(vname); } } if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE, &child, &children) == 0 && children > 0) { - /* LINTED E_SEC_PRINTF_VAR_FMT */ (void) printf(dashes, cb->cb_namewidth, "cache"); for (c = 0; c < children; c++) { vname = zpool_vdev_name(g_zfs, zhp, child[c], cb->cb_name_flags); - print_list_stats(zhp, vname, child[c], cb, depth + 2); + print_list_stats(zhp, vname, child[c], cb, depth + 2, + B_FALSE); free(vname); } } if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES, &child, &children) == 0 && children > 0) { - /* LINTED E_SEC_PRINTF_VAR_FMT */ (void) printf(dashes, cb->cb_namewidth, "spare"); for (c = 0; c < children; c++) { vname = zpool_vdev_name(g_zfs, zhp, child[c], cb->cb_name_flags); - print_list_stats(zhp, vname, child[c], cb, depth + 2); + print_list_stats(zhp, vname, child[c], cb, depth + 2, + B_TRUE); free(vname); } } @@ -5356,27 +5374,18 @@ int list_callback(zpool_handle_t *zhp, void *data) { list_cbdata_t *cbp = data; - nvlist_t *config; - nvlist_t *nvroot; - config = zpool_get_config(zhp, NULL); + print_pool(zhp, cbp); if (cbp->cb_verbose) { - config = zpool_get_config(zhp, NULL); + nvlist_t *config, *nvroot; + config = zpool_get_config(zhp, NULL); verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); + print_list_stats(zhp, NULL, nvroot, cbp, 0, B_FALSE); } - if (cbp->cb_verbose) - cbp->cb_namewidth = max_width(zhp, nvroot, 0, 0, - cbp->cb_name_flags); - - print_pool(zhp, cbp); - - if (cbp->cb_verbose) - print_list_stats(zhp, NULL, nvroot, cbp, 0); - return (0); } |