Skip to content

Commit 1f3444f

Browse files
authored
zpool: fix special vdev -v -o conflict
Right now, running `zpool list` with -v and -o passed does not work properly for special vdevs. This commit fixes that problem. See the discussion on #17839. Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Shreshth Srivastava <[email protected]> Closes #17932
1 parent 36e4f18 commit 1f3444f

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

cmd/zpool/zpool_main.c

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6747,10 +6747,12 @@ typedef struct list_cbdata {
67476747

67486748

67496749
/*
6750-
* Given a list of columns to display, output appropriate headers for each one.
6750+
* Given a list of columns to display, print an appropriate line. If
6751+
* `vdev_name` is not NULL, we print `vdev_name` followed by a line of dashes.
6752+
* If `vdev_name` is NULL, we print a line of the headers.
67516753
*/
67526754
static void
6753-
print_header(list_cbdata_t *cb)
6755+
print_line(list_cbdata_t *cb, const char *vdev_name)
67546756
{
67556757
zprop_list_t *pl = cb->cb_proplist;
67566758
char headerbuf[ZPOOL_MAXPROPLEN];
@@ -6759,6 +6761,8 @@ print_header(list_cbdata_t *cb)
67596761
boolean_t right_justify;
67606762
size_t width = 0;
67616763

6764+
boolean_t print_header = (vdev_name == NULL);
6765+
67626766
for (; pl != NULL; pl = pl->pl_next) {
67636767
width = pl->pl_width;
67646768
if (first && cb->cb_verbose) {
@@ -6771,20 +6775,36 @@ print_header(list_cbdata_t *cb)
67716775

67726776
if (!first)
67736777
(void) fputs(" ", stdout);
6774-
else
6775-
first = B_FALSE;
67766778

6777-
right_justify = B_FALSE;
6778-
if (pl->pl_prop != ZPROP_USERPROP) {
6779-
header = zpool_prop_column_name(pl->pl_prop);
6780-
right_justify = zpool_prop_align_right(pl->pl_prop);
6781-
} else {
6782-
int i;
6779+
if (print_header) {
6780+
right_justify = B_FALSE;
6781+
if (pl->pl_prop != ZPROP_USERPROP) {
6782+
header = zpool_prop_column_name(pl->pl_prop);
6783+
right_justify = zpool_prop_align_right(
6784+
pl->pl_prop);
6785+
} else {
6786+
int i;
6787+
6788+
for (i = 0; pl->pl_user_prop[i] != '\0'; i++)
6789+
headerbuf[i] = toupper(
6790+
pl->pl_user_prop[i]);
6791+
headerbuf[i] = '\0';
6792+
header = headerbuf;
6793+
}
67836794

6784-
for (i = 0; pl->pl_user_prop[i] != '\0'; i++)
6785-
headerbuf[i] = toupper(pl->pl_user_prop[i]);
6786-
headerbuf[i] = '\0';
6787-
header = headerbuf;
6795+
}
6796+
/*
6797+
* If `print_header` is false, we want to print a line of
6798+
* dashes.
6799+
*/
6800+
else {
6801+
if (first) {
6802+
header = vdev_name;
6803+
right_justify = B_FALSE;
6804+
} else {
6805+
header = "-";
6806+
right_justify = B_TRUE;
6807+
}
67886808
}
67896809

67906810
if (pl->pl_next == NULL && !right_justify)
@@ -6793,6 +6813,9 @@ print_header(list_cbdata_t *cb)
67936813
(void) printf("%*s", (int)width, header);
67946814
else
67956815
(void) printf("%-*s", (int)width, header);
6816+
6817+
if (first)
6818+
first = B_FALSE;
67966819
}
67976820

67986821
(void) fputc('\n', stdout);
@@ -6996,8 +7019,6 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
69967019
uint64_t islog = B_FALSE;
69977020
nvlist_t *props, *ent, *ch, *obj, *l2c, *sp;
69987021
props = ent = ch = obj = sp = l2c = NULL;
6999-
const char *dashes = "%-*s - - - - "
7000-
"- - - - -\n";
70017022

70027023
verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
70037024
(uint64_t **)&vs, &c) == 0);
@@ -7209,9 +7230,7 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
72097230
continue;
72107231

72117232
if (!printed && !cb->cb_json) {
7212-
/* LINTED E_SEC_PRINTF_VAR_FMT */
7213-
(void) printf(dashes, cb->cb_namewidth,
7214-
class_name[n]);
7233+
print_line(cb, class_name[n]);
72157234
printed = B_TRUE;
72167235
}
72177236
vname = zpool_vdev_name(g_zfs, zhp, child[c],
@@ -7232,8 +7251,7 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
72327251
if (cb->cb_json) {
72337252
l2c = fnvlist_alloc();
72347253
} else {
7235-
/* LINTED E_SEC_PRINTF_VAR_FMT */
7236-
(void) printf(dashes, cb->cb_namewidth, "cache");
7254+
print_line(cb, "cache");
72377255
}
72387256
for (c = 0; c < children; c++) {
72397257
vname = zpool_vdev_name(g_zfs, zhp, child[c],
@@ -7254,8 +7272,7 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
72547272
if (cb->cb_json) {
72557273
sp = fnvlist_alloc();
72567274
} else {
7257-
/* LINTED E_SEC_PRINTF_VAR_FMT */
7258-
(void) printf(dashes, cb->cb_namewidth, "spare");
7275+
print_line(cb, "spare");
72597276
}
72607277
for (c = 0; c < children; c++) {
72617278
vname = zpool_vdev_name(g_zfs, zhp, child[c],
@@ -7498,7 +7515,7 @@ zpool_do_list(int argc, char **argv)
74987515

74997516
if (!cb.cb_scripted && (first || cb.cb_verbose) &&
75007517
!cb.cb_json) {
7501-
print_header(&cb);
7518+
print_line(&cb, NULL);
75027519
first = B_FALSE;
75037520
}
75047521
ret = pool_list_iter(list, B_TRUE, list_callback, &cb);

0 commit comments

Comments
 (0)