1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Olaf Faaland <faaland1@llnl.gov>
3 Date: Mon, 20 Aug 2018 10:05:23 -0700
4 Subject: [PATCH] Skip import activity test in more zdb code paths
6 Since zdb opens the pools read-only, it cannot damage the pool in the
7 event the pool is already imported either on the same host or on
10 If the pool vdev structure is changing while zdb is importing the
11 pool, it may cause zdb to crash. However this is unlikely, and in any
12 case it's a user space process and can simply be run again.
14 For this reason, zdb should disable the multihost activity test on
15 import that is normally run.
17 This commit fixes a few zdb code paths where that had been overlooked.
18 It also adds tests to ensure that several common use cases handle this
19 properly in the future.
21 Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
22 Reviewed-by: Gu Zheng <guzheng2331314@163.com>
23 Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
27 cmd/zdb/zdb.c | 39 +++++++-----
28 tests/runfiles/linux.run | 3 +-
29 tests/zfs-tests/tests/functional/mmp/Makefile.am | 1 +
30 .../zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh | 74 ++++++++++++++++++++++
31 4 files changed, 101 insertions(+), 16 deletions(-)
32 create mode 100755 tests/zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh
34 diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c
35 index 17a0ae25..bb9fd3f1 100644
39 * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
40 * Copyright (c) 2014 Integros [integros.com]
41 * Copyright 2016 Nexenta Systems, Inc.
42 - * Copyright (c) 2017 Lawrence Livermore National Security, LLC.
43 + * Copyright (c) 2017, 2018 Lawrence Livermore National Security, LLC.
44 * Copyright (c) 2015, 2017, Intel Corporation.
47 @@ -3660,6 +3660,22 @@ dump_simulated_ddt(spa_t *spa)
51 +zdb_set_skip_mmp(char *target)
56 + * Disable the activity check to allow examination of
59 + mutex_enter(&spa_namespace_lock);
60 + if ((spa = spa_lookup(target)) != NULL) {
61 + spa->spa_import_flags |= ZFS_IMPORT_SKIP_MMP;
63 + mutex_exit(&spa_namespace_lock);
67 dump_zpool(spa_t *spa)
69 dsl_pool_t *dp = spa_get_dsl(spa);
70 @@ -4412,14 +4428,15 @@ main(int argc, char **argv)
71 target, strerror(ENOMEM));
75 - * Disable the activity check to allow examination of
78 if (dump_opt['C'] > 1) {
79 (void) printf("\nConfiguration for import:\n");
84 + * Disable the activity check to allow examination of
87 error = spa_import(target_pool, cfg, NULL,
88 flags | ZFS_IMPORT_SKIP_MMP);
90 @@ -4430,16 +4447,7 @@ main(int argc, char **argv)
93 if (target_is_spa || dump_opt['R']) {
95 - * Disable the activity check to allow examination of
98 - mutex_enter(&spa_namespace_lock);
99 - if ((spa = spa_lookup(target)) != NULL) {
100 - spa->spa_import_flags |= ZFS_IMPORT_SKIP_MMP;
102 - mutex_exit(&spa_namespace_lock);
104 + zdb_set_skip_mmp(target);
105 error = spa_open_rewind(target, &spa, FTAG, policy,
108 @@ -4462,6 +4470,7 @@ main(int argc, char **argv)
112 + zdb_set_skip_mmp(target);
113 error = open_objset(target, DMU_OST_ANY, FTAG, &os);
116 diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
117 index d8fe6f3a..ddf01aaf 100644
118 --- a/tests/runfiles/linux.run
119 +++ b/tests/runfiles/linux.run
120 @@ -499,7 +499,8 @@ tags = ['functional', 'mmap']
121 [tests/functional/mmp]
122 tests = ['mmp_on_thread', 'mmp_on_uberblocks', 'mmp_on_off', 'mmp_interval',
123 'mmp_active_import', 'mmp_inactive_import', 'mmp_exported_import',
124 - 'mmp_write_uberblocks', 'mmp_reset_interval', 'multihost_history']
125 + 'mmp_write_uberblocks', 'mmp_reset_interval', 'multihost_history',
127 tags = ['functional', 'mmp']
129 [tests/functional/mount]
130 diff --git a/tests/zfs-tests/tests/functional/mmp/Makefile.am b/tests/zfs-tests/tests/functional/mmp/Makefile.am
131 index ecf16f80..f2d0ad0e 100644
132 --- a/tests/zfs-tests/tests/functional/mmp/Makefile.am
133 +++ b/tests/zfs-tests/tests/functional/mmp/Makefile.am
134 @@ -10,6 +10,7 @@ dist_pkgdata_SCRIPTS = \
135 mmp_exported_import.ksh \
136 mmp_write_uberblocks.ksh \
137 mmp_reset_interval.ksh \
142 diff --git a/tests/zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh b/tests/zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh
144 index 00000000..b646475a
146 +++ b/tests/zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh
151 +# This file and its contents are supplied under the terms of the
152 +# Common Development and Distribution License ("CDDL"), version 1.0.
153 +# You may only use this file in accordance with the terms of version
156 +# A full copy of the text of the CDDL should have accompanied this
157 +# source. A copy of the CDDL is also available via the Internet at
158 +# http://www.illumos.org/license/CDDL.
162 +# Copyright (c) 2018 Lawrence Livermore National Security, LLC.
163 +# Copyright (c) 2018 by Nutanix. All rights reserved.
166 +. $STF_SUITE/include/libtest.shlib
167 +. $STF_SUITE/tests/functional/mmp/mmp.cfg
168 +. $STF_SUITE/tests/functional/mmp/mmp.kshlib
172 +# zdb will work while multihost is enabled.
176 +# 2. Enable multihost
177 +# 3. Run zdb -d with pool and dataset arguments.
178 +# 4. Create a checkpoint
179 +# 5. Run zdb -kd with pool and dataset arguments.
180 +# 6. Discard the checkpoint
181 +# 7. Export the pool
182 +# 8. Run zdb -ed with pool and dataset arguments.
187 + datasetexists $TESTPOOL && destroy_pool $TESTPOOL
188 + for DISK in $DISKS; do
189 + zpool labelclear -f $DEV_RDSKDIR/$DISK
191 + log_must mmp_clear_hostid
194 +log_assert "Verify zdb -d works while multihost is enabled"
197 +verify_runnable "global"
198 +verify_disk_count "$DISKS" 2
200 +default_mirror_setup_noexit $DISKS
201 +log_must mmp_set_hostid $HOSTID1
202 +log_must zpool set multihost=on $TESTPOOL
203 +log_must zfs snap $TESTPOOL/$TESTFS@snap
205 +log_must zdb -d $TESTPOOL
206 +log_must zdb -d $TESTPOOL/
207 +log_must zdb -d $TESTPOOL/$TESTFS
208 +log_must zdb -d $TESTPOOL/$TESTFS@snap
210 +log_must zpool export $TESTPOOL
212 +log_must zdb -ed $TESTPOOL
213 +log_must zdb -ed $TESTPOOL/
214 +log_must zdb -ed $TESTPOOL/$TESTFS
215 +log_must zdb -ed $TESTPOOL/$TESTFS@snap
217 +log_must zpool import $TESTPOOL
221 +log_pass "zdb -d works while multihost is enabled"