]> git.proxmox.com Git - zfsonlinux.git/blame - zfs-patches/0027-Fix-zdb-ed-on-objset-for-exported-pool.patch
update SPL to 0.7.7
[zfsonlinux.git] / zfs-patches / 0027-Fix-zdb-ed-on-objset-for-exported-pool.patch
CommitLineData
75b07eca
FG
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Chunwei Chen <david.chen@nutanix.com>
3Date: Thu, 1 Feb 2018 16:36:40 -0800
4Subject: [PATCH] Fix zdb -ed on objset for exported pool
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9zdb -ed on objset for exported pool would failed with:
10 failed to own dataset 'qq/fs0': No such file or directory
11
12The reason is that zdb pass objset name to spa_import, it uses that
13name to create a spa. Later, when dmu_objset_own tries to lookup the spa
14using real pool name, it can't find one.
15
16We fix this by make sure we pass pool name rather than objset name to
17spa_import.
18
19Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
20Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
21Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
22Closes #7099
23Closes #6464
24(cherry picked from commit 478754a8f5ff0f3b9f6dfe4ce272efc1681d243e)
25Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
26---
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
34
35diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am
36index 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 = \
40 zdb_002_pos.ksh \
41 zdb_003_pos.ksh \
42 zdb_004_pos.ksh \
43- zdb_005_pos.ksh
44+ zdb_005_pos.ksh \
45+ zdb_006_pos.ksh
46diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c
47index 90847d8d9..17a0ae251 100644
48--- a/cmd/zdb/zdb.c
49+++ b/cmd/zdb/zdb.c
50@@ -4177,7 +4177,7 @@ main(int argc, char **argv)
51 int error = 0;
52 char **searchdirs = NULL;
53 int nsearch = 0;
54- char *target;
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)
60 error = 0;
61 target = argv[0];
62
63+ if (strpbrk(target, "/@") != NULL) {
64+ size_t targetlen;
65+
66+ target_pool = strdup(target);
67+ *strpbrk(target_pool, "/@") = '\0';
68+
69+ target_is_spa = B_FALSE;
70+ targetlen = strlen(target);
71+ if (targetlen && target[targetlen - 1] == '/')
72+ target[targetlen - 1] = '\0';
73+ } else {
74+ target_pool = target;
75+ }
76+
77 if (dump_opt['e']) {
78 importargs_t args = { 0 };
79 nvlist_t *cfg = NULL;
80@@ -4388,8 +4402,10 @@ main(int argc, char **argv)
81 args.path = searchdirs;
82 args.can_be_active = B_TRUE;
83
84- error = zpool_tryimport(g_zfs, target, &cfg, &args);
85+ error = zpool_tryimport(g_zfs, target_pool, &cfg, &args);
86+
87 if (error == 0) {
88+
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");
94 dump_nvlist(cfg, 8);
95 }
96- error = spa_import(target, cfg, NULL,
97+ error = spa_import(target_pool, cfg, NULL,
98 flags | ZFS_IMPORT_SKIP_MMP);
99 }
100 }
101
102- if (strpbrk(target, "/@") != NULL) {
103- size_t targetlen;
104-
105- target_is_spa = B_FALSE;
106- targetlen = strlen(target);
107- if (targetlen && target[targetlen - 1] == '/')
108- target[targetlen - 1] = '\0';
109- }
110+ if (target_pool != target)
111+ free(target_pool);
112
113 if (error == 0) {
114 if (target_is_spa || dump_opt['R']) {
115diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
116index 303c27529..ea2dbb282 100644
117--- a/tests/runfiles/linux.run
118+++ b/tests/runfiles/linux.run
119@@ -73,7 +73,7 @@ tags = ['functional', 'clean_mirror']
120
121 [tests/functional/cli_root/zdb]
122 tests = ['zdb_001_neg', 'zdb_002_pos', 'zdb_003_pos', 'zdb_004_pos',
123- 'zdb_005_pos']
124+ 'zdb_005_pos', 'zdb_006_pos']
125 pre =
126 post =
127 tags = ['functional', 'cli_root', 'zdb']
128diff --git a/tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh b/tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh
129index 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
135
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
139 fi
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
143 fi
144 # recreate and destroy a zpool over the disks to restore the partitions to
145diff --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
146new file mode 100755
147index 000000000..97b00e9e1
148--- /dev/null
149+++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh
150@@ -0,0 +1,64 @@
151+#!/bin/ksh
152+
153+#
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
157+# 1.0 of the CDDL.
158+#
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.
162+#
163+
164+#
165+# Copyright (c) 2018 by Nutanix. All rights reserved.
166+#
167+
168+. $STF_SUITE/include/libtest.shlib
169+
170+#
171+# Description:
172+# zdb -d will work on imported/exported pool with pool/dataset argument
173+#
174+# Strategy:
175+# 1. Create a pool
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.
179+#
180+
181+function cleanup
182+{
183+ datasetexists $TESTPOOL && destroy_pool $TESTPOOL
184+ for DISK in $DISKS; do
185+ zpool labelclear -f $DEV_RDSKDIR/$DISK
186+ done
187+}
188+
189+log_assert "Verify zdb -d works on imported/exported pool with pool/dataset argument"
190+log_onexit cleanup
191+
192+verify_runnable "global"
193+verify_disk_count "$DISKS" 2
194+
195+default_mirror_setup_noexit $DISKS
196+log_must zfs snap $TESTPOOL/$TESTFS@snap
197+
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
202+
203+log_must zpool export $TESTPOOL
204+
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
209+
210+log_must zpool import $TESTPOOL
211+
212+cleanup
213+
214+log_pass "zdb -d works on imported/exported pool with pool/dataset argument"
215--
2162.14.2
217