Skip to content

Commit c4ff96e

Browse files
committed
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 Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
1 parent 70c8a79 commit c4ff96e

File tree

14 files changed

+412
-3
lines changed

14 files changed

+412
-3
lines changed

cmd/zpool/zpool_main.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ get_usage(zpool_help_t idx)
353353
"\tupgrade -v\n"
354354
"\tupgrade [-V version] <-a | pool ...>\n"));
355355
case HELP_EVENTS:
356-
return (gettext("\tevents [-vHfc]\n"));
356+
return (gettext("\tevents [-vHfc] [pool]\n"));
357357
case HELP_GET:
358358
return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
359359
"<\"all\" | property[,...]> <pool> ...\n"));
@@ -7385,6 +7385,7 @@ typedef struct ev_opts {
73857385
int scripted;
73867386
int follow;
73877387
int clear;
7388+
char poolname[ZFS_MAX_DATASET_NAME_LEN];
73887389
} ev_opts_t;
73897390

73907391
static void
@@ -7652,6 +7653,7 @@ zpool_do_events_next(ev_opts_t *opts)
76527653
{
76537654
nvlist_t *nvl;
76547655
int zevent_fd, ret, dropped;
7656+
char *pool;
76557657

76567658
zevent_fd = open(ZFS_DEV, O_RDWR);
76577659
VERIFY(zevent_fd >= 0);
@@ -7668,6 +7670,11 @@ zpool_do_events_next(ev_opts_t *opts)
76687670
if (dropped > 0)
76697671
(void) printf(gettext("dropped %d events\n"), dropped);
76707672

7673+
if (strlen(opts->poolname) > 0 &&
7674+
nvlist_lookup_string(nvl, FM_FMRI_ZFS_POOL, &pool) == 0 &&
7675+
strcmp(opts->poolname, pool) != 0)
7676+
continue;
7677+
76717678
zpool_do_events_short(nvl, opts);
76727679

76737680
if (opts->verbose) {
@@ -7697,7 +7704,7 @@ zpool_do_events_clear(ev_opts_t *opts)
76977704
}
76987705

76997706
/*
7700-
* zpool events [-vfc]
7707+
* zpool events [-vHfc] [pool]
77017708
*
77027709
* Displays events logs by ZFS.
77037710
*/
@@ -7732,6 +7739,18 @@ zpool_do_events(int argc, char **argv)
77327739
argc -= optind;
77337740
argv += optind;
77347741

7742+
if (argc > 1) {
7743+
(void) fprintf(stderr, gettext("too many arguments\n"));
7744+
usage(B_FALSE);
7745+
} else if (argc == 1) {
7746+
(void) strlcpy(opts.poolname, argv[0], sizeof (opts.poolname));
7747+
if (!zfs_name_valid(opts.poolname, ZFS_TYPE_POOL)) {
7748+
(void) fprintf(stderr,
7749+
gettext("invalid pool name '%s'\n"), opts.poolname);
7750+
usage(B_FALSE);
7751+
}
7752+
}
7753+
77357754
if (opts.clear)
77367755
ret = zpool_do_events_clear(&opts);
77377756
else

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ AC_CONFIG_FILES([
214214
tests/zfs-tests/tests/functional/cli_root/zpool_create/Makefile
215215
tests/zfs-tests/tests/functional/cli_root/zpool_destroy/Makefile
216216
tests/zfs-tests/tests/functional/cli_root/zpool_detach/Makefile
217+
tests/zfs-tests/tests/functional/cli_root/zpool_events/Makefile
217218
tests/zfs-tests/tests/functional/cli_root/zpool_expand/Makefile
218219
tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile
219220
tests/zfs-tests/tests/functional/cli_root/zpool_get/Makefile

man/man8/zpool.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ command instead.
10261026
.Nm
10271027
.Cm events
10281028
.Op Fl cfHv
1029-
.Op Ar pool Ns ...
1029+
.Op Ar pool
10301030
.Xc
10311031
Lists all recent events generated by the ZFS kernel modules. These events
10321032
are consumed by the

tests/runfiles/linux.run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ post =
252252
[tests/functional/cli_root/zpool_detach]
253253
tests = ['zpool_detach_001_neg']
254254

255+
[tests/functional/cli_root/zpool_events]
256+
tests = ['zpool_events_clear', 'zpool_events_cliargs', 'zpool_events_follow',
257+
'zpool_events_poolname']
258+
255259
[tests/functional/cli_root/zpool_expand]
256260
tests = ['zpool_expand_001_pos', 'zpool_expand_002_pos',
257261
'zpool_expand_003_neg', 'zpool_expand_004_pos']

tests/zfs-tests/tests/functional/cli_root/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SUBDIRS = \
3737
zpool_create \
3838
zpool_destroy \
3939
zpool_detach \
40+
zpool_events \
4041
zpool_expand \
4142
zpool_export \
4243
zpool_get \
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_events
2+
dist_pkgdata_SCRIPTS = \
3+
setup.ksh \
4+
cleanup.ksh \
5+
zpool_events.cfg \
6+
zpool_events.kshlib \
7+
zpool_events_clear.ksh \
8+
zpool_events_cliargs.ksh \
9+
zpool_events_follow.ksh \
10+
zpool_events_poolname.ksh
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15+
#
16+
17+
. $STF_SUITE/include/libtest.shlib
18+
19+
default_cleanup
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15+
#
16+
17+
. $STF_SUITE/include/libtest.shlib
18+
19+
DISK=${DISKS%% *}
20+
21+
default_volume_setup $DISK
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15+
#
16+
17+
export EVENTS_NUM=42
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15+
#
16+
17+
. $STF_SUITE/include/libtest.shlib
18+
. $STF_SUITE/tests/functional/cli_root/zpool_events/zpool_events.cfg
19+
20+
#
21+
# Wait to allow the kernel module to process ZFS events until we reach $eventnum
22+
# or a timeout of $timeout seconds expire, whichever comes first
23+
#
24+
function zpool_events_settle # <eventnum> [timeout]
25+
{
26+
typeset eventnum="${1:-$EVENTS_NUM}"
27+
typeset timeout="${2:-3}"
28+
typeset -i count
29+
typeset -i i=0
30+
31+
while [[ $i -lt $timeout ]]; do
32+
count=$(zpool events -H | wc -l)
33+
if [[ $count -ge $eventnum ]]; then
34+
break
35+
fi
36+
i=$((i+1))
37+
sleep 1
38+
done
39+
log_note "waited $i seconds"
40+
}

0 commit comments

Comments
 (0)