diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index a3537b177..347b232a1 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -5083,6 +5083,31 @@ list_callback(zpool_handle_t *zhp, void *data) return (0); } +// this is a slightly modified version of the iostat func get_namewidth +int +get_namewidth_list(zpool_handle_t *zhp, void *data) +{ + list_cbdata_t *cb = data; + nvlist_t *config, *nvroot; + + if ((config = zpool_get_config(zhp, NULL)) != NULL) { + verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, + &nvroot) == 0); + unsigned int poolname_len = strlen(zpool_get_name(zhp)); + if (!cb->cb_verbose) + cb->cb_namewidth = MAX(poolname_len, cb->cb_namewidth); + else + cb->cb_namewidth = MAX(poolname_len, + max_width(zhp, nvroot, 0, cb->cb_namewidth, + cb->cb_name_flags)); + } + + if (cb->cb_namewidth < 10) + cb->cb_namewidth = 10; + + return (0); +} + /* * zpool list [-gHLpP] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]] * @@ -5173,6 +5198,9 @@ zpool_do_list(int argc, char **argv) if (timestamp_fmt != NODATE) print_timestamp(timestamp_fmt); + cb.cb_namewidth = 0; + (void) pool_list_iter(list, B_FALSE, get_namewidth_list, &cb); + if (!cb.cb_scripted && (first || cb.cb_verbose)) { print_header(&cb); first = B_FALSE;