Skip to content

Commit 88f5dea

Browse files
committed
zpool status: add -E flag for pool exclusion
Adds -E flag to exclude comma-separated pools from zpool status output. Usage: 'zpool status -E tank,backup' shows all pools except tank and backup. Signed-off-by: Ameer Hamza <[email protected]>
1 parent 5d33801 commit 88f5dea

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

cmd/zpool/zpool_main.c

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ get_usage(zpool_help_t idx)
522522
"<-a | <pool> [<device> ...]>\n"));
523523
case HELP_STATUS:
524524
return (gettext("\tstatus [-DdegiLPpstvx] "
525-
"[-c script1[,script2,...]] ...\n"
525+
"[-E pool1[,pool2,...]] [-c script1[,script2,...]] ...\n"
526526
"\t [-j|--json [--json-flat-vdevs] [--json-int] "
527527
"[--json-pool-key-guid]] ...\n"
528528
"\t [-T d|u] [--power] [pool] [interval [count]]\n"));
@@ -2608,6 +2608,8 @@ typedef struct status_cbdata {
26082608
nvlist_t *cb_jsobj;
26092609
boolean_t cb_json_as_int;
26102610
boolean_t cb_json_pool_key_guid;
2611+
char **cb_exclude_pools;
2612+
int cb_exclude_count;
26112613
} status_cbdata_t;
26122614

26132615
/* Return 1 if string is NULL, empty, or whitespace; return 0 otherwise. */
@@ -10813,6 +10815,15 @@ status_callback_json(zpool_handle_t *zhp, void *data)
1081310815
zpool_status_t reason;
1081410816
zpool_errata_t errata;
1081510817
uint_t c;
10818+
10819+
/* Skip excluded pools */
10820+
if (cbp->cb_exclude_pools != NULL && cbp->cb_exclude_count > 0) {
10821+
const char *poolname = zpool_get_name(zhp);
10822+
for (int i = 0; i < cbp->cb_exclude_count; i++) {
10823+
if (strcmp(poolname, cbp->cb_exclude_pools[i]) == 0)
10824+
return (0);
10825+
}
10826+
}
1081610827
vdev_stat_t *vs;
1081710828
nvlist_t *item, *d, *load_info, *vds;
1081810829

@@ -10935,6 +10946,15 @@ status_callback(zpool_handle_t *zhp, void *data)
1093510946
uint_t c;
1093610947
vdev_stat_t *vs;
1093710948

10949+
/* Skip excluded pools */
10950+
if (cbp->cb_exclude_pools != NULL && cbp->cb_exclude_count > 0) {
10951+
const char *poolname = zpool_get_name(zhp);
10952+
for (int i = 0; i < cbp->cb_exclude_count; i++) {
10953+
if (strcmp(poolname, cbp->cb_exclude_pools[i]) == 0)
10954+
return (0);
10955+
}
10956+
}
10957+
1093810958
/* If dedup stats were requested, also fetch dedupcached. */
1093910959
if (cbp->cb_dedup_stats > 1)
1094010960
zpool_add_propname(zhp, ZPOOL_DEDUPCACHED_PROP_NAME);
@@ -11124,6 +11144,7 @@ zpool_do_status(int argc, char **argv)
1112411144
status_cbdata_t cb = { 0 };
1112511145
nvlist_t *data;
1112611146
char *cmd = NULL;
11147+
char *exclude_str = NULL;
1112711148

1112811149
struct option long_options[] = {
1112911150
{"power", no_argument, NULL, ZPOOL_OPTION_POWER},
@@ -11137,7 +11158,7 @@ zpool_do_status(int argc, char **argv)
1113711158
};
1113811159

1113911160
/* check options */
11140-
while ((c = getopt_long(argc, argv, "c:jdDegiLpPstT:vx", long_options,
11161+
while ((c = getopt_long(argc, argv, "c:jdDeE:giLpPstT:vx", long_options,
1114111162
NULL)) != -1) {
1114211163
switch (c) {
1114311164
case 'c':
@@ -11180,6 +11201,32 @@ zpool_do_status(int argc, char **argv)
1118011201
case 'i':
1118111202
cb.cb_print_vdev_init = B_TRUE;
1118211203
break;
11204+
case 'E':
11205+
/* Exclude comma-separated pools from output */
11206+
if (cb.cb_exclude_pools != NULL) {
11207+
(void) fprintf(stderr,
11208+
gettext("Can't set -E flag twice\n"));
11209+
exit(1);
11210+
}
11211+
if (optarg[0] == '-') {
11212+
(void) fprintf(stderr, gettext("-E: invalid "
11213+
"pool name '%s'\n"), optarg);
11214+
usage(B_FALSE);
11215+
}
11216+
int i = 0;
11217+
cb.cb_exclude_count = 1;
11218+
for (char *p = optarg; *p; p++)
11219+
cb.cb_exclude_count += (*p == ',');
11220+
cb.cb_exclude_pools =
11221+
safe_malloc(cb.cb_exclude_count * sizeof (char *));
11222+
exclude_str = strdup(optarg);
11223+
char *arg_ptr = exclude_str;
11224+
for (char *pool; (pool = strsep(&arg_ptr, ",")); ) {
11225+
if (pool[0] != '\0')
11226+
cb.cb_exclude_pools[i++] = pool;
11227+
}
11228+
cb.cb_exclude_count = i;
11229+
break;
1118311230
case 'L':
1118411231
cb.cb_name_flags |= VDEV_NAME_FOLLOW_LINKS;
1118511232
break;
@@ -11224,6 +11271,10 @@ zpool_do_status(int argc, char **argv)
1122411271
if (optopt == 'c') {
1122511272
print_zpool_script_list("status");
1122611273
exit(0);
11274+
} else if (optopt == 'E') {
11275+
(void) fprintf(stderr,
11276+
gettext("-E requires pool names\n"));
11277+
usage(B_FALSE);
1122711278
} else {
1122811279
fprintf(stderr,
1122911280
gettext("invalid option '%c'\n"), optopt);
@@ -11317,8 +11368,13 @@ zpool_do_status(int argc, char **argv)
1131711368
}
1131811369
}
1131911370

11320-
if (ret != 0)
11371+
if (ret != 0) {
11372+
if (exclude_str != NULL)
11373+
free(exclude_str);
11374+
if (cb.cb_exclude_pools != NULL)
11375+
free(cb.cb_exclude_pools);
1132111376
return (ret);
11377+
}
1132211378

1132311379
if (interval == 0)
1132411380
break;
@@ -11330,6 +11386,10 @@ zpool_do_status(int argc, char **argv)
1133011386
(void) fsleep(interval);
1133111387
}
1133211388

11389+
if (exclude_str != NULL)
11390+
free(exclude_str);
11391+
if (cb.cb_exclude_pools != NULL)
11392+
free(cb.cb_exclude_pools);
1133311393
return (0);
1133411394
}
1133511395

man/man8/zpool-status.8

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
.Nm zpool
3939
.Cm status
4040
.Op Fl DdegiLPpstvx
41+
.Op Fl E Ar pool1 Ns Oo , Ns Ar pool2 Ns ,… Oc
4142
.Op Fl c Ar script1 Ns Oo , Ns Ar script2 Ns ,… Oc
4243
.Oo Fl j|--json
4344
.Oo Ns Fl -json-flat-vdevs Oc
@@ -95,6 +96,22 @@ Direct I/O reads checksum verify errors can also occur if the contents of the
9596
buffer are being manipulated after the I/O has been issued and is in flight.
9697
In the case of Direct I/O read checksum verify errors, the I/O will be reissued
9798
through the ARC.
99+
.It Fl E Ar pool Ns Oo , Ns Ar pool Oc Ns ...
100+
Exclude specified pools from output.
101+
Multiple pool names can be specified separated by commas.
102+
.Pp
103+
Examples:
104+
.Bl -bullet -compact
105+
.It
106+
.Ql zpool status -E tank
107+
shows all pools except tank.
108+
.It
109+
.Ql zpool status -E tank,backup
110+
shows all pools except tank and backup.
111+
.It
112+
.Ql zpool status pool1 pool2 -E pool1
113+
shows only pool2 (pool1 is excluded).
114+
.El
98115
.It Fl e
99116
Only show unhealthy vdevs (not-ONLINE or with errors).
100117
.It Fl g

0 commit comments

Comments
 (0)