1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Chunwei Chen <david.chen@nutanix.com>
3 Date: Thu, 1 Feb 2018 16:36:40 -0800
4 Subject: [PATCH] Fix zdb -ed on objset for exported pool
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 zdb -ed on objset for exported pool would failed with:
10 failed to own dataset 'qq/fs0': No such file or directory
12 The reason is that zdb pass objset name to spa_import, it uses that
13 name to create a spa. Later, when dmu_objset_own tries to lookup the spa
14 using real pool name, it can't find one.
16 We fix this by make sure we pass pool name rather than objset name to
19 Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
20 Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
21 Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
24 (cherry picked from commit 478754a8f5ff0f3b9f6dfe4ce272efc1681d243e)
25 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
27 .../tests/functional/cli_root/zdb/Makefile.am | 3 +-
28 cmd/zdb/zdb.c | 32 +++++++----
29 tests/runfiles/linux.run | 2 +-
30 .../tests/functional/clean_mirror/cleanup.ksh | 4 +-
31 .../tests/functional/cli_root/zdb/zdb_006_pos.ksh | 64 ++++++++++++++++++++++
32 5 files changed, 90 insertions(+), 15 deletions(-)
33 create mode 100755 tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh
35 diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am
36 index 51170fbc8..d37bcf607 100644
37 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am
38 +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am
39 @@ -4,4 +4,5 @@ dist_pkgdata_SCRIPTS = \
46 diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c
47 index 90847d8d9..17a0ae251 100644
50 @@ -4177,7 +4177,7 @@ main(int argc, char **argv)
52 char **searchdirs = NULL;
55 + char *target, *target_pool;
56 nvlist_t *policy = NULL;
57 uint64_t max_txg = UINT64_MAX;
58 int flags = ZFS_IMPORT_MISSING_LOG;
59 @@ -4380,6 +4380,20 @@ main(int argc, char **argv)
63 + if (strpbrk(target, "/@") != NULL) {
66 + target_pool = strdup(target);
67 + *strpbrk(target_pool, "/@") = '\0';
69 + target_is_spa = B_FALSE;
70 + targetlen = strlen(target);
71 + if (targetlen && target[targetlen - 1] == '/')
72 + target[targetlen - 1] = '\0';
74 + target_pool = target;
78 importargs_t args = { 0 };
80 @@ -4388,8 +4402,10 @@ main(int argc, char **argv)
81 args.path = searchdirs;
82 args.can_be_active = B_TRUE;
84 - error = zpool_tryimport(g_zfs, target, &cfg, &args);
85 + error = zpool_tryimport(g_zfs, target_pool, &cfg, &args);
89 if (nvlist_add_nvlist(cfg,
90 ZPOOL_REWIND_POLICY, policy) != 0) {
91 fatal("can't open '%s': %s",
92 @@ -4404,19 +4420,13 @@ main(int argc, char **argv)
93 (void) printf("\nConfiguration for import:\n");
96 - error = spa_import(target, cfg, NULL,
97 + error = spa_import(target_pool, cfg, NULL,
98 flags | ZFS_IMPORT_SKIP_MMP);
102 - if (strpbrk(target, "/@") != NULL) {
105 - target_is_spa = B_FALSE;
106 - targetlen = strlen(target);
107 - if (targetlen && target[targetlen - 1] == '/')
108 - target[targetlen - 1] = '\0';
110 + if (target_pool != target)
114 if (target_is_spa || dump_opt['R']) {
115 diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
116 index 303c27529..ea2dbb282 100644
117 --- a/tests/runfiles/linux.run
118 +++ b/tests/runfiles/linux.run
119 @@ -73,7 +73,7 @@ tags = ['functional', 'clean_mirror']
121 [tests/functional/cli_root/zdb]
122 tests = ['zdb_001_neg', 'zdb_002_pos', 'zdb_003_pos', 'zdb_004_pos',
124 + 'zdb_005_pos', 'zdb_006_pos']
127 tags = ['functional', 'cli_root', 'zdb']
128 diff --git a/tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh b/tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh
129 index ac3bfbca8..fb0db312e 100755
130 --- a/tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh
131 +++ b/tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh
132 @@ -38,10 +38,10 @@ df -F zfs -h | grep "$TESTFS " >/dev/null
133 [[ $? == 0 ]] && log_must zfs umount -f $TESTDIR
134 destroy_pool $TESTPOOL
136 -if is_mpath_device $MIRROR_PRIMARY; then
137 +if ( is_mpath_device $MIRROR_PRIMARY || is_loop_device $MIRROR_SECONDARY); then
138 parted $DEV_DSKDIR/$MIRROR_PRIMARY -s rm 1
140 -if is_mpath_device $MIRROR_SECONDARY; then
141 +if ( is_mpath_device $MIRROR_SECONDARY || is_loop_device $MIRROR_SECONDARY); then
142 parted $DEV_DSKDIR/$MIRROR_SECONDARY -s rm 1
144 # recreate and destroy a zpool over the disks to restore the partitions to
145 diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh
147 index 000000000..97b00e9e1
149 +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh
154 +# This file and its contents are supplied under the terms of the
155 +# Common Development and Distribution License ("CDDL"), version 1.0.
156 +# You may only use this file in accordance with the terms of version
159 +# A full copy of the text of the CDDL should have accompanied this
160 +# source. A copy of the CDDL is also available via the Internet at
161 +# http://www.illumos.org/license/CDDL.
165 +# Copyright (c) 2018 by Nutanix. All rights reserved.
168 +. $STF_SUITE/include/libtest.shlib
172 +# zdb -d will work on imported/exported pool with pool/dataset argument
176 +# 2. Run zdb -d with pool and dataset arguments.
177 +# 3. Export the pool
178 +# 4. Run zdb -ed with pool and dataset arguments.
183 + datasetexists $TESTPOOL && destroy_pool $TESTPOOL
184 + for DISK in $DISKS; do
185 + zpool labelclear -f $DEV_RDSKDIR/$DISK
189 +log_assert "Verify zdb -d works on imported/exported pool with pool/dataset argument"
192 +verify_runnable "global"
193 +verify_disk_count "$DISKS" 2
195 +default_mirror_setup_noexit $DISKS
196 +log_must zfs snap $TESTPOOL/$TESTFS@snap
198 +log_must zdb -d $TESTPOOL
199 +log_must zdb -d $TESTPOOL/
200 +log_must zdb -d $TESTPOOL/$TESTFS
201 +log_must zdb -d $TESTPOOL/$TESTFS@snap
203 +log_must zpool export $TESTPOOL
205 +log_must zdb -ed $TESTPOOL
206 +log_must zdb -ed $TESTPOOL/
207 +log_must zdb -ed $TESTPOOL/$TESTFS
208 +log_must zdb -ed $TESTPOOL/$TESTFS@snap
210 +log_must zpool import $TESTPOOL
214 +log_pass "zdb -d works on imported/exported pool with pool/dataset argument"