From 88f9c9396bcce596db56dc880260f95c49a51d67 Mon Sep 17 00:00:00 2001 From: LOLi Date: Fri, 27 Oct 2017 01:49:33 +0200 Subject: 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 Reviewed-by: Giuseppe Di Natale Signed-off-by: loli10K Closes #3285 Closes #6762 --- cmd/zpool/zpool_main.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'cmd') 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[,...]> ...\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 -- cgit v1.2.3