aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLOLi <[email protected]>2017-10-27 01:49:33 +0200
committerBrian Behlendorf <[email protected]>2017-10-26 16:49:33 -0700
commit88f9c9396bcce596db56dc880260f95c49a51d67 (patch)
tree5203ec97b33111ff803c5f7ee916175a791efb58 /cmd
parenta032ac4b3819408b2e17085224290b6a762de79a (diff)
Allow 'zpool events' filtering by pool name
Additionally add four new tests: * zpool_events_clear: verify 'zpool events -c' functionality * zpool_events_cliargs: verify command line options and arguments * zpool_events_follow: verify 'zpool events -f' * zpool_events_poolname: verify events filtering by pool name Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Giuseppe Di Natale <[email protected]> Signed-off-by: loli10K <[email protected]> Closes #3285 Closes #6762
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zpool/zpool_main.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index d80cbc6c6..b6b6f0cf4 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -354,7 +354,7 @@ get_usage(zpool_help_t idx)
"\tupgrade -v\n"
"\tupgrade [-V version] <-a | pool ...>\n"));
case HELP_EVENTS:
- return (gettext("\tevents [-vHfc]\n"));
+ return (gettext("\tevents [-vHf [pool] | -c]\n"));
case HELP_GET:
return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
"<\"all\" | property[,...]> <pool> ...\n"));
@@ -7376,6 +7376,7 @@ typedef struct ev_opts {
int scripted;
int follow;
int clear;
+ char poolname[ZFS_MAX_DATASET_NAME_LEN];
} ev_opts_t;
static void
@@ -7643,6 +7644,7 @@ zpool_do_events_next(ev_opts_t *opts)
{
nvlist_t *nvl;
int zevent_fd, ret, dropped;
+ char *pool;
zevent_fd = open(ZFS_DEV, O_RDWR);
VERIFY(zevent_fd >= 0);
@@ -7659,6 +7661,11 @@ zpool_do_events_next(ev_opts_t *opts)
if (dropped > 0)
(void) printf(gettext("dropped %d events\n"), dropped);
+ if (strlen(opts->poolname) > 0 &&
+ nvlist_lookup_string(nvl, FM_FMRI_ZFS_POOL, &pool) == 0 &&
+ strcmp(opts->poolname, pool) != 0)
+ continue;
+
zpool_do_events_short(nvl, opts);
if (opts->verbose) {
@@ -7688,7 +7695,7 @@ zpool_do_events_clear(ev_opts_t *opts)
}
/*
- * zpool events [-vfc]
+ * zpool events [-vHf [pool] | -c]
*
* Displays events logs by ZFS.
*/
@@ -7723,6 +7730,25 @@ zpool_do_events(int argc, char **argv)
argc -= optind;
argv += optind;
+ if (argc > 1) {
+ (void) fprintf(stderr, gettext("too many arguments\n"));
+ usage(B_FALSE);
+ } else if (argc == 1) {
+ (void) strlcpy(opts.poolname, argv[0], sizeof (opts.poolname));
+ if (!zfs_name_valid(opts.poolname, ZFS_TYPE_POOL)) {
+ (void) fprintf(stderr,
+ gettext("invalid pool name '%s'\n"), opts.poolname);
+ usage(B_FALSE);
+ }
+ }
+
+ if ((argc == 1 || opts.verbose || opts.scripted || opts.follow) &&
+ opts.clear) {
+ (void) fprintf(stderr,
+ gettext("invalid options combined with -c\n"));
+ usage(B_FALSE);
+ }
+
if (opts.clear)
ret = zpool_do_events_clear(&opts);
else