Fix column alignment with long zpool names
`zpool status` normally aligns NAME/STATE/etc columns: NAME STATE READ WRITE CKSUM dummy ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 /tmp/dummy-long-1.bin ONLINE 0 0 0 /tmp/dummy-long-2.bin ONLINE 0 0 0 mirror-1 ONLINE 0 0 0 /tmp/dummy-long-3.bin ONLINE 0 0 0 /tmp/dummy-long-4.bin ONLINE 0 0 0 However, if the zpool name is longer than the zvol names, alignment issues arise: NAME STATE READ WRITE CKSUM dummy-very-very-long-zpool-name ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 /tmp/dummy-1.bin ONLINE 0 0 0 /tmp/dummy-2.bin ONLINE 0 0 0 mirror-1 ONLINE 0 0 0 /tmp/dummy-3.bin ONLINE 0 0 0 /tmp/dummy-4.bin ONLINE 0 0 0 `zpool iostat` and `zpool import` are also affected: capacity operations bandwidth pool alloc free read write read write ---------- ----- ----- ----- ----- ----- ----- dummy 104K 1.97G 0 0 152 9.84K dummy-very-very-long-zpool-name 152K 1.97G 0 1 144 13.1K ---------- ----- ----- ----- ----- ----- ----- dummy-very-very-long-zpool-name ONLINE mirror-0 ONLINE /tmp/dummy-1.bin ONLINE /tmp/dummy-2.bin ONLINE mirror-1 ONLINE /tmp/dummy-3.bin ONLINE /tmp/dummy-4.bin ONLINE Reviewed-by: George Melikov <mail@gmelikov.ru> Reviewed-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: George Gaydarov <git@gg7.io> Closes #6786
This commit is contained in:
parent
954516cec1
commit
eab4536081
|
@ -2211,7 +2211,8 @@ show_import(nvlist_t *config)
|
||||||
|
|
||||||
(void) printf(gettext(" config:\n\n"));
|
(void) printf(gettext(" config:\n\n"));
|
||||||
|
|
||||||
cb.cb_namewidth = max_width(NULL, nvroot, 0, 0, VDEV_NAME_TYPE_ID);
|
cb.cb_namewidth = max_width(NULL, nvroot, 0, strlen(name),
|
||||||
|
VDEV_NAME_TYPE_ID);
|
||||||
if (cb.cb_namewidth < 10)
|
if (cb.cb_namewidth < 10)
|
||||||
cb.cb_namewidth = 10;
|
cb.cb_namewidth = 10;
|
||||||
|
|
||||||
|
@ -3901,7 +3902,7 @@ get_namewidth(zpool_handle_t *zhp, void *data)
|
||||||
&nvroot) == 0);
|
&nvroot) == 0);
|
||||||
unsigned int poolname_len = strlen(zpool_get_name(zhp));
|
unsigned int poolname_len = strlen(zpool_get_name(zhp));
|
||||||
if (!cb->cb_verbose)
|
if (!cb->cb_verbose)
|
||||||
cb->cb_namewidth = poolname_len;
|
cb->cb_namewidth = MAX(poolname_len, cb->cb_namewidth);
|
||||||
else
|
else
|
||||||
cb->cb_namewidth = MAX(poolname_len,
|
cb->cb_namewidth = MAX(poolname_len,
|
||||||
max_width(zhp, nvroot, 0, cb->cb_namewidth,
|
max_width(zhp, nvroot, 0, cb->cb_namewidth,
|
||||||
|
|
|
@ -3560,6 +3560,14 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
|
||||||
char buf[PATH_BUF_LEN];
|
char buf[PATH_BUF_LEN];
|
||||||
char tmpbuf[PATH_BUF_LEN];
|
char tmpbuf[PATH_BUF_LEN];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vdev_name will be "root"/"root-0" for the root vdev, but it is the
|
||||||
|
* zpool name that will be displayed to the user.
|
||||||
|
*/
|
||||||
|
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
|
||||||
|
if (zhp != NULL && strcmp(type, "root") == 0)
|
||||||
|
return (zfs_strdup(hdl, zpool_get_name(zhp)));
|
||||||
|
|
||||||
env = getenv("ZPOOL_VDEV_NAME_PATH");
|
env = getenv("ZPOOL_VDEV_NAME_PATH");
|
||||||
if (env && (strtoul(env, NULL, 0) > 0 ||
|
if (env && (strtoul(env, NULL, 0) > 0 ||
|
||||||
!strncasecmp(env, "YES", 3) || !strncasecmp(env, "ON", 2)))
|
!strncasecmp(env, "YES", 3) || !strncasecmp(env, "ON", 2)))
|
||||||
|
@ -3641,7 +3649,6 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
|
||||||
/*
|
/*
|
||||||
* For a block device only use the name.
|
* For a block device only use the name.
|
||||||
*/
|
*/
|
||||||
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
|
|
||||||
if ((strcmp(type, VDEV_TYPE_DISK) == 0) &&
|
if ((strcmp(type, VDEV_TYPE_DISK) == 0) &&
|
||||||
!(name_flags & VDEV_NAME_PATH)) {
|
!(name_flags & VDEV_NAME_PATH)) {
|
||||||
path = strrchr(path, '/');
|
path = strrchr(path, '/');
|
||||||
|
@ -3656,7 +3663,7 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
|
||||||
return (zfs_strip_partition(path));
|
return (zfs_strip_partition(path));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &path) == 0);
|
path = type;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If it's a raidz device, we need to stick in the parity level.
|
* If it's a raidz device, we need to stick in the parity level.
|
||||||
|
|
Loading…
Reference in New Issue