]> git.proxmox.com Git - zfsonlinux.git/blob - zfs-patches/0010-Skip-import-activity-test-in-more-zdb-code-paths.patch
update/rebase to zfs-0.7.12 with patches from ZOL
[zfsonlinux.git] / zfs-patches / 0010-Skip-import-activity-test-in-more-zdb-code-paths.patch
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
5
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
8 another one.
9
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.
13
14 For this reason, zdb should disable the multihost activity test on
15 import that is normally run.
16
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.
20
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>
24 Closes #7797
25 Closes #7801
26 ---
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
33
34 diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c
35 index 17a0ae25..bb9fd3f1 100644
36 --- a/cmd/zdb/zdb.c
37 +++ b/cmd/zdb/zdb.c
38 @@ -24,7 +24,7 @@
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.
45 */
46
47 @@ -3660,6 +3660,22 @@ dump_simulated_ddt(spa_t *spa)
48 }
49
50 static void
51 +zdb_set_skip_mmp(char *target)
52 +{
53 + spa_t *spa;
54 +
55 + /*
56 + * Disable the activity check to allow examination of
57 + * active pools.
58 + */
59 + mutex_enter(&spa_namespace_lock);
60 + if ((spa = spa_lookup(target)) != NULL) {
61 + spa->spa_import_flags |= ZFS_IMPORT_SKIP_MMP;
62 + }
63 + mutex_exit(&spa_namespace_lock);
64 +}
65 +
66 +static void
67 dump_zpool(spa_t *spa)
68 {
69 dsl_pool_t *dp = spa_get_dsl(spa);
70 @@ -4412,14 +4428,15 @@ main(int argc, char **argv)
71 target, strerror(ENOMEM));
72 }
73
74 - /*
75 - * Disable the activity check to allow examination of
76 - * active pools.
77 - */
78 if (dump_opt['C'] > 1) {
79 (void) printf("\nConfiguration for import:\n");
80 dump_nvlist(cfg, 8);
81 }
82 +
83 + /*
84 + * Disable the activity check to allow examination of
85 + * active pools.
86 + */
87 error = spa_import(target_pool, cfg, NULL,
88 flags | ZFS_IMPORT_SKIP_MMP);
89 }
90 @@ -4430,16 +4447,7 @@ main(int argc, char **argv)
91
92 if (error == 0) {
93 if (target_is_spa || dump_opt['R']) {
94 - /*
95 - * Disable the activity check to allow examination of
96 - * active pools.
97 - */
98 - mutex_enter(&spa_namespace_lock);
99 - if ((spa = spa_lookup(target)) != NULL) {
100 - spa->spa_import_flags |= ZFS_IMPORT_SKIP_MMP;
101 - }
102 - mutex_exit(&spa_namespace_lock);
103 -
104 + zdb_set_skip_mmp(target);
105 error = spa_open_rewind(target, &spa, FTAG, policy,
106 NULL);
107 if (error) {
108 @@ -4462,6 +4470,7 @@ main(int argc, char **argv)
109 }
110 }
111 } else {
112 + zdb_set_skip_mmp(target);
113 error = open_objset(target, DMU_OST_ANY, FTAG, &os);
114 }
115 }
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',
126 + 'mmp_on_zdb']
127 tags = ['functional', 'mmp']
128
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 \
138 + mmp_on_zdb.ksh \
139 setup.ksh \
140 cleanup.ksh
141
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
143 new file mode 100755
144 index 00000000..b646475a
145 --- /dev/null
146 +++ b/tests/zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh
147 @@ -0,0 +1,74 @@
148 +#!/bin/ksh
149 +
150 +#
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
154 +# 1.0 of the CDDL.
155 +#
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.
159 +#
160 +
161 +#
162 +# Copyright (c) 2018 Lawrence Livermore National Security, LLC.
163 +# Copyright (c) 2018 by Nutanix. All rights reserved.
164 +#
165 +
166 +. $STF_SUITE/include/libtest.shlib
167 +. $STF_SUITE/tests/functional/mmp/mmp.cfg
168 +. $STF_SUITE/tests/functional/mmp/mmp.kshlib
169 +
170 +#
171 +# Description:
172 +# zdb will work while multihost is enabled.
173 +#
174 +# Strategy:
175 +# 1. Create a pool
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.
183 +#
184 +
185 +function cleanup
186 +{
187 + datasetexists $TESTPOOL && destroy_pool $TESTPOOL
188 + for DISK in $DISKS; do
189 + zpool labelclear -f $DEV_RDSKDIR/$DISK
190 + done
191 + log_must mmp_clear_hostid
192 +}
193 +
194 +log_assert "Verify zdb -d works while multihost is enabled"
195 +log_onexit cleanup
196 +
197 +verify_runnable "global"
198 +verify_disk_count "$DISKS" 2
199 +
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
204 +
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
209 +
210 +log_must zpool export $TESTPOOL
211 +
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
216 +
217 +log_must zpool import $TESTPOOL
218 +
219 +cleanup
220 +
221 +log_pass "zdb -d works while multihost is enabled"