]> granicus.if.org Git - zfs/commitdiff
Fix zdb -ed on objset for exported pool
authorChunwei Chen <david.chen@nutanix.com>
Fri, 2 Feb 2018 00:36:40 +0000 (16:36 -0800)
committerTony Hutter <hutter2@llnl.gov>
Wed, 14 Mar 2018 23:10:37 +0000 (16:10 -0700)
zdb -ed on objset for exported pool would failed with:
  failed to own dataset 'qq/fs0': No such file or directory

The reason is that zdb pass objset name to spa_import, it uses that
name to create a spa. Later, when dmu_objset_own tries to lookup the spa
using real pool name, it can't find one.

We fix this by make sure we pass pool name rather than objset name to
spa_import.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7099
Closes #6464

cmd/zdb/zdb.c
tests/runfiles/linux.run
tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh
tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am
tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh [new file with mode: 0755]

index 90847d8d991c77634b6408fdc8ccb297faf93105..17a0ae2516db713d3748f69c8c4f369f13941d4a 100644 (file)
@@ -4177,7 +4177,7 @@ main(int argc, char **argv)
        int error = 0;
        char **searchdirs = NULL;
        int nsearch = 0;
-       char *target;
+       char *target, *target_pool;
        nvlist_t *policy = NULL;
        uint64_t max_txg = UINT64_MAX;
        int flags = ZFS_IMPORT_MISSING_LOG;
@@ -4380,6 +4380,20 @@ main(int argc, char **argv)
        error = 0;
        target = argv[0];
 
+       if (strpbrk(target, "/@") != NULL) {
+               size_t targetlen;
+
+               target_pool = strdup(target);
+               *strpbrk(target_pool, "/@") = '\0';
+
+               target_is_spa = B_FALSE;
+               targetlen = strlen(target);
+               if (targetlen && target[targetlen - 1] == '/')
+                       target[targetlen - 1] = '\0';
+       } else {
+               target_pool = target;
+       }
+
        if (dump_opt['e']) {
                importargs_t args = { 0 };
                nvlist_t *cfg = NULL;
@@ -4388,8 +4402,10 @@ main(int argc, char **argv)
                args.path = searchdirs;
                args.can_be_active = B_TRUE;
 
-               error = zpool_tryimport(g_zfs, target, &cfg, &args);
+               error = zpool_tryimport(g_zfs, target_pool, &cfg, &args);
+
                if (error == 0) {
+
                        if (nvlist_add_nvlist(cfg,
                            ZPOOL_REWIND_POLICY, policy) != 0) {
                                fatal("can't open '%s': %s",
@@ -4404,19 +4420,13 @@ main(int argc, char **argv)
                                (void) printf("\nConfiguration for import:\n");
                                dump_nvlist(cfg, 8);
                        }
-                       error = spa_import(target, cfg, NULL,
+                       error = spa_import(target_pool, cfg, NULL,
                            flags | ZFS_IMPORT_SKIP_MMP);
                }
        }
 
-       if (strpbrk(target, "/@") != NULL) {
-               size_t targetlen;
-
-               target_is_spa = B_FALSE;
-               targetlen = strlen(target);
-               if (targetlen && target[targetlen - 1] == '/')
-                       target[targetlen - 1] = '\0';
-       }
+       if (target_pool != target)
+               free(target_pool);
 
        if (error == 0) {
                if (target_is_spa || dump_opt['R']) {
index 303c275299d839afc12496f2746f045e88f26b86..ea2dbb2823a94da45234ecf9922e9fcc138f4950 100644 (file)
@@ -73,7 +73,7 @@ tags = ['functional', 'clean_mirror']
 
 [tests/functional/cli_root/zdb]
 tests = ['zdb_001_neg', 'zdb_002_pos', 'zdb_003_pos', 'zdb_004_pos',
-    'zdb_005_pos']
+    'zdb_005_pos', 'zdb_006_pos']
 pre =
 post =
 tags = ['functional', 'cli_root', 'zdb']
index ac3bfbca8940728698eadf39afa18bd24cc38128..fb0db312ebba21c870a9c8bd6d29b46130f9b9d1 100755 (executable)
@@ -38,10 +38,10 @@ df -F zfs -h | grep "$TESTFS " >/dev/null
 [[ $? == 0 ]] && log_must zfs umount -f $TESTDIR
 destroy_pool $TESTPOOL
 
-if is_mpath_device $MIRROR_PRIMARY; then
+if ( is_mpath_device $MIRROR_PRIMARY || is_loop_device $MIRROR_SECONDARY); then
        parted $DEV_DSKDIR/$MIRROR_PRIMARY -s rm 1
 fi
-if is_mpath_device $MIRROR_SECONDARY; then
+if ( is_mpath_device $MIRROR_SECONDARY || is_loop_device $MIRROR_SECONDARY); then
        parted $DEV_DSKDIR/$MIRROR_SECONDARY -s rm 1
 fi
 # recreate and destroy a zpool over the disks to restore the partitions to
index 51170fbc894dd8b8cfc26f863105ddc41889e1fc..d37bcf607f46b348f89e7e2b8d028b9993e5fb28 100644 (file)
@@ -4,4 +4,5 @@ dist_pkgdata_SCRIPTS = \
        zdb_002_pos.ksh \
        zdb_003_pos.ksh \
        zdb_004_pos.ksh \
-       zdb_005_pos.ksh
+       zdb_005_pos.ksh \
+       zdb_006_pos.ksh
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
new file mode 100755 (executable)
index 0000000..97b00e9
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2018 by Nutanix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Description:
+# zdb -d will work on imported/exported pool with pool/dataset argument
+#
+# Strategy:
+# 1. Create a pool
+# 2. Run zdb -d with pool and dataset arguments.
+# 3. Export the pool
+# 4. Run zdb -ed with pool and dataset arguments.
+#
+
+function cleanup
+{
+       datasetexists $TESTPOOL && destroy_pool $TESTPOOL
+       for DISK in $DISKS; do
+               zpool labelclear -f $DEV_RDSKDIR/$DISK
+       done
+}
+
+log_assert "Verify zdb -d works on imported/exported pool with pool/dataset argument"
+log_onexit cleanup
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+default_mirror_setup_noexit $DISKS
+log_must zfs snap $TESTPOOL/$TESTFS@snap
+
+log_must zdb -d $TESTPOOL
+log_must zdb -d $TESTPOOL/
+log_must zdb -d $TESTPOOL/$TESTFS
+log_must zdb -d $TESTPOOL/$TESTFS@snap
+
+log_must zpool export $TESTPOOL
+
+log_must zdb -ed $TESTPOOL
+log_must zdb -ed $TESTPOOL/
+log_must zdb -ed $TESTPOOL/$TESTFS
+log_must zdb -ed $TESTPOOL/$TESTFS@snap
+
+log_must zpool import $TESTPOOL
+
+cleanup
+
+log_pass "zdb -d works on imported/exported pool with pool/dataset argument"