]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Skip import activity test in more zdb code paths
authorOlaf Faaland <faaland1@llnl.gov>
Mon, 20 Aug 2018 17:05:23 +0000 (10:05 -0700)
committerTony Hutter <hutter2@llnl.gov>
Thu, 8 Nov 2018 22:38:28 +0000 (14:38 -0800)
Since zdb opens the pools read-only, it cannot damage the pool in the
event the pool is already imported either on the same host or on
another one.

If the pool vdev structure is changing while zdb is importing the
pool, it may cause zdb to crash.  However this is unlikely, and in any
case it's a user space process and can simply be run again.

For this reason, zdb should disable the multihost activity test on
import that is normally run.

This commit fixes a few zdb code paths where that had been overlooked.
It also adds tests to ensure that several common use cases handle this
properly in the future.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Gu Zheng <guzheng2331314@163.com>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #7797
Closes #7801

cmd/zdb/zdb.c
tests/runfiles/linux.run
tests/zfs-tests/tests/functional/mmp/Makefile.am
tests/zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh [new file with mode: 0755]

index 17a0ae2516db713d3748f69c8c4f369f13941d4a..bb9fd3f18f6700e8030c5211763b362a92a561fb 100644 (file)
@@ -24,7 +24,7 @@
  * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
  * Copyright (c) 2014 Integros [integros.com]
  * Copyright 2016 Nexenta Systems, Inc.
- * Copyright (c) 2017 Lawrence Livermore National Security, LLC.
+ * Copyright (c) 2017, 2018 Lawrence Livermore National Security, LLC.
  * Copyright (c) 2015, 2017, Intel Corporation.
  */
 
@@ -3659,6 +3659,22 @@ dump_simulated_ddt(spa_t *spa)
        dump_dedup_ratio(&dds_total);
 }
 
+static void
+zdb_set_skip_mmp(char *target)
+{
+       spa_t *spa;
+
+       /*
+        * Disable the activity check to allow examination of
+        * active pools.
+        */
+       mutex_enter(&spa_namespace_lock);
+       if ((spa = spa_lookup(target)) != NULL) {
+               spa->spa_import_flags |= ZFS_IMPORT_SKIP_MMP;
+       }
+       mutex_exit(&spa_namespace_lock);
+}
+
 static void
 dump_zpool(spa_t *spa)
 {
@@ -4412,14 +4428,15 @@ main(int argc, char **argv)
                                    target, strerror(ENOMEM));
                        }
 
-                       /*
-                        * Disable the activity check to allow examination of
-                        * active pools.
-                        */
                        if (dump_opt['C'] > 1) {
                                (void) printf("\nConfiguration for import:\n");
                                dump_nvlist(cfg, 8);
                        }
+
+                       /*
+                        * Disable the activity check to allow examination of
+                        * active pools.
+                        */
                        error = spa_import(target_pool, cfg, NULL,
                            flags | ZFS_IMPORT_SKIP_MMP);
                }
@@ -4430,16 +4447,7 @@ main(int argc, char **argv)
 
        if (error == 0) {
                if (target_is_spa || dump_opt['R']) {
-                       /*
-                        * Disable the activity check to allow examination of
-                        * active pools.
-                        */
-                       mutex_enter(&spa_namespace_lock);
-                       if ((spa = spa_lookup(target)) != NULL) {
-                               spa->spa_import_flags |= ZFS_IMPORT_SKIP_MMP;
-                       }
-                       mutex_exit(&spa_namespace_lock);
-
+                       zdb_set_skip_mmp(target);
                        error = spa_open_rewind(target, &spa, FTAG, policy,
                            NULL);
                        if (error) {
@@ -4462,6 +4470,7 @@ main(int argc, char **argv)
                                }
                        }
                } else {
+                       zdb_set_skip_mmp(target);
                        error = open_objset(target, DMU_OST_ANY, FTAG, &os);
                }
        }
index d8fe6f3ab0d2b8f1ea52886cf8dc07e862b6910d..ddf01aafe88682946aafdf3cab2365494b9ae700 100644 (file)
@@ -499,7 +499,8 @@ tags = ['functional', 'mmap']
 [tests/functional/mmp]
 tests = ['mmp_on_thread', 'mmp_on_uberblocks', 'mmp_on_off', 'mmp_interval',
     'mmp_active_import', 'mmp_inactive_import', 'mmp_exported_import',
-    'mmp_write_uberblocks', 'mmp_reset_interval', 'multihost_history']
+    'mmp_write_uberblocks', 'mmp_reset_interval', 'multihost_history',
+    'mmp_on_zdb']
 tags = ['functional', 'mmp']
 
 [tests/functional/mount]
index ecf16f806df66a46ba8ec51bd27d366660cb691f..f2d0ad0ea791b6957249fda3017377ae670492e2 100644 (file)
@@ -10,6 +10,7 @@ dist_pkgdata_SCRIPTS = \
        mmp_exported_import.ksh \
        mmp_write_uberblocks.ksh \
        mmp_reset_interval.ksh \
+       mmp_on_zdb.ksh \
        setup.ksh \
        cleanup.ksh
 
diff --git a/tests/zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh b/tests/zfs-tests/tests/functional/mmp/mmp_on_zdb.ksh
new file mode 100755 (executable)
index 0000000..b646475
--- /dev/null
@@ -0,0 +1,74 @@
+#!/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 Lawrence Livermore National Security, LLC.
+# Copyright (c) 2018 by Nutanix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mmp/mmp.cfg
+. $STF_SUITE/tests/functional/mmp/mmp.kshlib
+
+#
+# Description:
+# zdb will work while multihost is enabled.
+#
+# Strategy:
+# 1. Create a pool
+# 2. Enable multihost
+# 3. Run zdb -d with pool and dataset arguments.
+# 4. Create a checkpoint
+# 5. Run zdb -kd with pool and dataset arguments.
+# 6. Discard the checkpoint
+# 7. Export the pool
+# 8. 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_must mmp_clear_hostid
+}
+
+log_assert "Verify zdb -d works while multihost is enabled"
+log_onexit cleanup
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+default_mirror_setup_noexit $DISKS
+log_must mmp_set_hostid $HOSTID1
+log_must zpool set multihost=on $TESTPOOL
+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 while multihost is enabled"