]> granicus.if.org Git - zfs/blobdiff - cmd/ztest/ztest.c
ztest: reduce gangblock creation
[zfs] / cmd / ztest / ztest.c
index 40b107175edca47f2b5ba044697e32fe9c646930..1ad87bb30cdf45d26dd9d1af59eeb5cf21cce723 100644 (file)
 #include <sys/zio.h>
 #include <sys/zil.h>
 #include <sys/zil_impl.h>
-#include <sys/zfs_rlock.h>
 #include <sys/vdev_impl.h>
 #include <sys/vdev_file.h>
 #include <sys/spa_impl.h>
 #include <sys/fs/zfs.h>
 #include <zfs_fletcher.h>
 #include <libnvpair.h>
-#include <libzfs.h>
+#include <libzutil.h>
 #include <sys/crypto/icp.h>
 #ifdef __GLIBC__
 #include <execinfo.h> /* for backtrace() */
@@ -179,6 +178,7 @@ typedef struct ztest_shared_opts {
        uint64_t zo_metaslab_force_ganging;
        int zo_mmp_test;
        int zo_special_vdevs;
+       int zo_dump_dbgmsg;
 } ztest_shared_opts_t;
 
 static const ztest_shared_opts_t ztest_opts_defaults = {
@@ -201,7 +201,7 @@ static const ztest_shared_opts_t ztest_opts_defaults = {
        .zo_init = 1,
        .zo_time = 300,                 /* 5 minutes */
        .zo_maxloops = 50,              /* max loops during spa_freeze() */
-       .zo_metaslab_force_ganging = 32 << 10,
+       .zo_metaslab_force_ganging = 64 << 10,
        .zo_special_vdevs = ZTEST_VDEV_CLASS_RND,
 };
 
@@ -258,6 +258,17 @@ typedef struct bufwad {
        uint64_t        bw_data;
 } bufwad_t;
 
+/*
+ * It would be better to use a rangelock_t per object.  Unfortunately
+ * the rangelock_t is not a drop-in replacement for rl_t, because we
+ * still need to map from object ID to rangelock_t.
+ */
+typedef enum {
+       RL_READER,
+       RL_WRITER,
+       RL_APPEND
+} rl_type_t;
+
 typedef struct rll {
        void            *rll_writer;
        int             rll_readers;
@@ -265,10 +276,12 @@ typedef struct rll {
        kcondvar_t      rll_cv;
 } rll_t;
 
-typedef struct zll {
-       list_t z_list;
-       kmutex_t z_lock;
-} zll_t;
+typedef struct rl {
+       uint64_t        rl_object;
+       uint64_t        rl_offset;
+       uint64_t        rl_size;
+       rll_t           *rl_lock;
+} rl_t;
 
 #define        ZTEST_RANGE_LOCKS       64
 #define        ZTEST_OBJECT_LOCKS      64
@@ -301,7 +314,7 @@ typedef struct ztest_ds {
        char            zd_name[ZFS_MAX_DATASET_NAME_LEN];
        kmutex_t        zd_dirobj_lock;
        rll_t           zd_object_lock[ZTEST_OBJECT_LOCKS];
-       zll_t           zd_range_lock[ZTEST_RANGE_LOCKS];
+       rll_t           zd_range_lock[ZTEST_RANGE_LOCKS];
 } ztest_ds_t;
 
 /*
@@ -346,7 +359,6 @@ ztest_func_t ztest_fault_inject;
 ztest_func_t ztest_ddt_repair;
 ztest_func_t ztest_dmu_snapshot_hold;
 ztest_func_t ztest_mmp_enable_disable;
-ztest_func_t ztest_spa_rename;
 ztest_func_t ztest_scrub;
 ztest_func_t ztest_dsl_dataset_promote_busy;
 ztest_func_t ztest_vdev_attach_detach;
@@ -402,7 +414,6 @@ ztest_info_t ztest_info[] = {
        ZTI_INIT(ztest_dmu_snapshot_hold, 1, &zopt_sometimes),
        ZTI_INIT(ztest_mmp_enable_disable, 1, &zopt_sometimes),
        ZTI_INIT(ztest_reguid, 1, &zopt_rarely),
-       ZTI_INIT(ztest_spa_rename, 1, &zopt_rarely),
        ZTI_INIT(ztest_scrub, 1, &zopt_rarely),
        ZTI_INIT(ztest_spa_upgrade, 1, &zopt_rarely),
        ZTI_INIT(ztest_dsl_dataset_promote_busy, 1, &zopt_rarely),
@@ -474,7 +485,6 @@ static kmutex_t ztest_checkpoint_lock;
 static pthread_rwlock_t ztest_name_lock;
 
 static boolean_t ztest_dump_core = B_TRUE;
-static boolean_t ztest_dump_debug_buffer = B_FALSE;
 static boolean_t ztest_exiting;
 
 /* Global commit callback list */
@@ -523,10 +533,16 @@ _umem_logging_init(void)
 static void
 dump_debug_buffer(void)
 {
-       if (!ztest_dump_debug_buffer)
+       ssize_t ret __attribute__((unused));
+
+       if (!ztest_opts.zo_dump_dbgmsg)
                return;
 
-       (void) printf("\n");
+       /*
+        * We use write() instead of printf() so that this function
+        * is safe to call from a signal handler.
+        */
+       ret = write(STDOUT_FILENO, "\n", 1);
        zfs_dbgmsg_print("ztest");
 }
 
@@ -581,10 +597,11 @@ fatal(int do_perror, char *message, ...)
        (void) fprintf(stderr, "%s\n", buf);
        fatal_msg = buf;                        /* to ease debugging */
 
-       dump_debug_buffer();
-
        if (ztest_dump_core)
                abort();
+       else
+               dump_debug_buffer();
+
        exit(3);
 }
 
@@ -856,7 +873,7 @@ process_options(int argc, char **argv)
                                usage(B_FALSE);
                        break;
                case 'G':
-                       ztest_dump_debug_buffer = B_TRUE;
+                       zo->zo_dump_dbgmsg = 1;
                        break;
                case 'h':
                        usage(B_TRUE);
@@ -1318,100 +1335,6 @@ ztest_dmu_objset_own(const char *name, dmu_objset_type_t type,
        return (err);
 }
 
-
-/*
- * Object and range lock mechanics
- */
-typedef struct {
-       list_node_t z_lnode;
-       zfs_refcount_t z_refcnt;
-       uint64_t z_object;
-       zfs_rlock_t z_range_lock;
-} ztest_znode_t;
-
-typedef struct {
-       rl_t *z_rl;
-       ztest_znode_t *z_ztznode;
-} ztest_zrl_t;
-
-static ztest_znode_t *
-ztest_znode_init(uint64_t object)
-{
-       ztest_znode_t *zp = umem_alloc(sizeof (*zp), UMEM_NOFAIL);
-
-       list_link_init(&zp->z_lnode);
-       zfs_refcount_create(&zp->z_refcnt);
-       zp->z_object = object;
-       zfs_rlock_init(&zp->z_range_lock);
-
-       return (zp);
-}
-
-static void
-ztest_znode_fini(ztest_znode_t *zp)
-{
-       ASSERT(zfs_refcount_is_zero(&zp->z_refcnt));
-       zfs_rlock_destroy(&zp->z_range_lock);
-       zp->z_object = 0;
-       zfs_refcount_destroy(&zp->z_refcnt);
-       list_link_init(&zp->z_lnode);
-       umem_free(zp, sizeof (*zp));
-}
-
-static void
-ztest_zll_init(zll_t *zll)
-{
-       mutex_init(&zll->z_lock, NULL, MUTEX_DEFAULT, NULL);
-       list_create(&zll->z_list, sizeof (ztest_znode_t),
-           offsetof(ztest_znode_t, z_lnode));
-}
-
-static void
-ztest_zll_destroy(zll_t *zll)
-{
-       list_destroy(&zll->z_list);
-       mutex_destroy(&zll->z_lock);
-}
-
-#define        RL_TAG "range_lock"
-static ztest_znode_t *
-ztest_znode_get(ztest_ds_t *zd, uint64_t object)
-{
-       zll_t *zll = &zd->zd_range_lock[object & (ZTEST_OBJECT_LOCKS - 1)];
-       ztest_znode_t *zp = NULL;
-       mutex_enter(&zll->z_lock);
-       for (zp = list_head(&zll->z_list); (zp);
-           zp = list_next(&zll->z_list, zp)) {
-               if (zp->z_object == object) {
-                       zfs_refcount_add(&zp->z_refcnt, RL_TAG);
-                       break;
-               }
-       }
-       if (zp == NULL) {
-               zp = ztest_znode_init(object);
-               zfs_refcount_add(&zp->z_refcnt, RL_TAG);
-               list_insert_head(&zll->z_list, zp);
-       }
-       mutex_exit(&zll->z_lock);
-       return (zp);
-}
-
-static void
-ztest_znode_put(ztest_ds_t *zd, ztest_znode_t *zp)
-{
-       zll_t *zll = NULL;
-       ASSERT3U(zp->z_object, !=, 0);
-       zll = &zd->zd_range_lock[zp->z_object & (ZTEST_OBJECT_LOCKS - 1)];
-       mutex_enter(&zll->z_lock);
-       zfs_refcount_remove(&zp->z_refcnt, RL_TAG);
-       if (zfs_refcount_is_zero(&zp->z_refcnt)) {
-               list_remove(&zll->z_list, zp);
-               ztest_znode_fini(zp);
-       }
-       mutex_exit(&zll->z_lock);
-}
-
-
 static void
 ztest_rll_init(rll_t *rll)
 {
@@ -1484,37 +1407,33 @@ ztest_object_unlock(ztest_ds_t *zd, uint64_t object)
        ztest_rll_unlock(rll);
 }
 
-static ztest_zrl_t *
-ztest_zrl_init(rl_t *rl, ztest_znode_t *zp)
-{
-       ztest_zrl_t *zrl = umem_alloc(sizeof (*zrl), UMEM_NOFAIL);
-       zrl->z_rl = rl;
-       zrl->z_ztznode = zp;
-       return (zrl);
-}
-
-static void
-ztest_zrl_fini(ztest_zrl_t *zrl)
-{
-       umem_free(zrl, sizeof (*zrl));
-}
-
-static ztest_zrl_t *
+static rl_t *
 ztest_range_lock(ztest_ds_t *zd, uint64_t object, uint64_t offset,
     uint64_t size, rl_type_t type)
 {
-       ztest_znode_t *zp = ztest_znode_get(zd, object);
-       rl_t *rl = zfs_range_lock(&zp->z_range_lock, offset,
-           size, type);
-       return (ztest_zrl_init(rl, zp));
+       uint64_t hash = object ^ (offset % (ZTEST_RANGE_LOCKS + 1));
+       rll_t *rll = &zd->zd_range_lock[hash & (ZTEST_RANGE_LOCKS - 1)];
+       rl_t *rl;
+
+       rl = umem_alloc(sizeof (*rl), UMEM_NOFAIL);
+       rl->rl_object = object;
+       rl->rl_offset = offset;
+       rl->rl_size = size;
+       rl->rl_lock = rll;
+
+       ztest_rll_lock(rll, type);
+
+       return (rl);
 }
 
 static void
-ztest_range_unlock(ztest_ds_t *zd, ztest_zrl_t *zrl)
+ztest_range_unlock(rl_t *rl)
 {
-       zfs_range_unlock(zrl->z_rl);
-       ztest_znode_put(zd, zrl->z_ztznode);
-       ztest_zrl_fini(zrl);
+       rll_t *rll = rl->rl_lock;
+
+       ztest_rll_unlock(rll);
+
+       umem_free(rl, sizeof (*rl));
 }
 
 static void
@@ -1536,7 +1455,7 @@ ztest_zd_init(ztest_ds_t *zd, ztest_shared_ds_t *szd, objset_t *os)
                ztest_rll_init(&zd->zd_object_lock[l]);
 
        for (l = 0; l < ZTEST_RANGE_LOCKS; l++)
-               ztest_zll_init(&zd->zd_range_lock[l]);
+               ztest_rll_init(&zd->zd_range_lock[l]);
 }
 
 static void
@@ -1551,7 +1470,7 @@ ztest_zd_fini(ztest_ds_t *zd)
                ztest_rll_destroy(&zd->zd_object_lock[l]);
 
        for (l = 0; l < ZTEST_RANGE_LOCKS; l++)
-               ztest_zll_destroy(&zd->zd_range_lock[l]);
+               ztest_rll_destroy(&zd->zd_range_lock[l]);
 }
 
 #define        TXG_MIGHTWAIT   (ztest_random(10) == 0 ? TXG_NOWAIT : TXG_WAIT)
@@ -1967,7 +1886,7 @@ ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap)
        dmu_tx_t *tx;
        dmu_buf_t *db;
        arc_buf_t *abuf = NULL;
-       ztest_zrl_t *rl;
+       rl_t *rl;
 
        if (byteswap)
                byteswap_uint64_array(lr, sizeof (*lr));
@@ -2016,7 +1935,7 @@ ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap)
                if (abuf != NULL)
                        dmu_return_arcbuf(abuf);
                dmu_buf_rele(db, FTAG);
-               ztest_range_unlock(zd, rl);
+               ztest_range_unlock(rl);
                ztest_object_unlock(zd, lr->lr_foid);
                return (ENOSPC);
        }
@@ -2074,7 +1993,7 @@ ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap)
 
        dmu_tx_commit(tx);
 
-       ztest_range_unlock(zd, rl);
+       ztest_range_unlock(rl);
        ztest_object_unlock(zd, lr->lr_foid);
 
        return (0);
@@ -2088,7 +2007,7 @@ ztest_replay_truncate(void *arg1, void *arg2, boolean_t byteswap)
        objset_t *os = zd->zd_os;
        dmu_tx_t *tx;
        uint64_t txg;
-       ztest_zrl_t *rl;
+       rl_t *rl;
 
        if (byteswap)
                byteswap_uint64_array(lr, sizeof (*lr));
@@ -2103,7 +2022,7 @@ ztest_replay_truncate(void *arg1, void *arg2, boolean_t byteswap)
 
        txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
        if (txg == 0) {
-               ztest_range_unlock(zd, rl);
+               ztest_range_unlock(rl);
                ztest_object_unlock(zd, lr->lr_foid);
                return (ENOSPC);
        }
@@ -2115,7 +2034,7 @@ ztest_replay_truncate(void *arg1, void *arg2, boolean_t byteswap)
 
        dmu_tx_commit(tx);
 
-       ztest_range_unlock(zd, rl);
+       ztest_range_unlock(rl);
        ztest_object_unlock(zd, lr->lr_foid);
 
        return (0);
@@ -2222,30 +2141,23 @@ zil_replay_func_t *ztest_replay_vector[TX_MAX_TYPE] = {
 /*
  * ZIL get_data callbacks
  */
-typedef struct ztest_zgd_private {
-       ztest_ds_t *z_zd;
-       ztest_zrl_t *z_rl;
-       uint64_t z_object;
-} ztest_zgd_private_t;
 
 static void
 ztest_get_done(zgd_t *zgd, int error)
 {
-       ztest_zgd_private_t *zzp = zgd->zgd_private;
-       ztest_ds_t *zd = zzp->z_zd;
-       uint64_t object = zzp->z_object;
+       ztest_ds_t *zd = zgd->zgd_private;
+       uint64_t object = ((rl_t *)zgd->zgd_lr)->rl_object;
 
        if (zgd->zgd_db)
                dmu_buf_rele(zgd->zgd_db, zgd);
 
-       ztest_range_unlock(zd, zzp->z_rl);
+       ztest_range_unlock((rl_t *)zgd->zgd_lr);
        ztest_object_unlock(zd, object);
 
        if (error == 0 && zgd->zgd_bp)
                zil_lwb_add_block(zgd->zgd_lwb, zgd->zgd_bp);
 
        umem_free(zgd, sizeof (*zgd));
-       umem_free(zzp, sizeof (*zzp));
 }
 
 static int
@@ -2263,7 +2175,6 @@ ztest_get_data(void *arg, lr_write_t *lr, char *buf, struct lwb *lwb,
        dmu_buf_t *db;
        zgd_t *zgd;
        int error;
-       ztest_zgd_private_t *zgd_private;
 
        ASSERT3P(lwb, !=, NULL);
        ASSERT3P(zio, !=, NULL);
@@ -2290,15 +2201,11 @@ ztest_get_data(void *arg, lr_write_t *lr, char *buf, struct lwb *lwb,
 
        zgd = umem_zalloc(sizeof (*zgd), UMEM_NOFAIL);
        zgd->zgd_lwb = lwb;
-       zgd_private = umem_zalloc(sizeof (ztest_zgd_private_t), UMEM_NOFAIL);
-       zgd_private->z_zd = zd;
-       zgd_private->z_object = object;
-       zgd->zgd_private = zgd_private;
+       zgd->zgd_private = zd;
 
        if (buf != NULL) {      /* immediate write */
-               zgd_private->z_rl = ztest_range_lock(zd, object, offset, size,
-                   RL_READER);
-               zgd->zgd_rl = zgd_private->z_rl->z_rl;
+               zgd->zgd_lr = (struct locked_range *)ztest_range_lock(zd,
+                   object, offset, size, RL_READER);
 
                error = dmu_read(os, object, offset, size, buf,
                    DMU_READ_NO_PREFETCH);
@@ -2312,9 +2219,8 @@ ztest_get_data(void *arg, lr_write_t *lr, char *buf, struct lwb *lwb,
                        offset = 0;
                }
 
-               zgd_private->z_rl = ztest_range_lock(zd, object, offset, size,
-                   RL_READER);
-               zgd->zgd_rl = zgd_private->z_rl->z_rl;
+               zgd->zgd_lr = (struct locked_range *)ztest_range_lock(zd,
+                   object, offset, size, RL_READER);
 
                error = dmu_buf_hold(os, object, offset, zgd, &db,
                    DMU_READ_NO_PREFETCH);
@@ -2560,7 +2466,7 @@ ztest_prealloc(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size)
        objset_t *os = zd->zd_os;
        dmu_tx_t *tx;
        uint64_t txg;
-       ztest_zrl_t *rl;
+       rl_t *rl;
 
        txg_wait_synced(dmu_objset_pool(os), 0);
 
@@ -2581,7 +2487,7 @@ ztest_prealloc(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size)
                (void) dmu_free_long_range(os, object, offset, size);
        }
 
-       ztest_range_unlock(zd, rl);
+       ztest_range_unlock(rl);
        ztest_object_unlock(zd, object);
 }
 
@@ -3643,6 +3549,15 @@ ztest_device_removal(ztest_ds_t *zd, uint64_t id)
                ztest_device_removal_active = B_TRUE;
                mutex_exit(&ztest_vdev_lock);
 
+               /*
+                * spa->spa_vdev_removal is created in a sync task that
+                * is initiated via dsl_sync_task_nowait(). Since the
+                * task may not run before spa_vdev_remove() returns, we
+                * must wait at least 1 txg to ensure that the removal
+                * struct has been created.
+                */
+               txg_wait_synced(spa_get_dsl(spa), 0);
+
                while (spa->spa_vdev_removal != NULL)
                        txg_wait_synced(spa_get_dsl(spa), 0);
        } else {
@@ -6221,62 +6136,6 @@ ztest_reguid(ztest_ds_t *zd, uint64_t id)
        VERIFY3U(load, ==, spa_load_guid(spa));
 }
 
-/*
- * Rename the pool to a different name and then rename it back.
- */
-/* ARGSUSED */
-void
-ztest_spa_rename(ztest_ds_t *zd, uint64_t id)
-{
-       char *oldname, *newname;
-       spa_t *spa;
-
-       if (ztest_opts.zo_mmp_test)
-               return;
-
-       (void) pthread_rwlock_wrlock(&ztest_name_lock);
-
-       oldname = ztest_opts.zo_pool;
-       newname = umem_alloc(strlen(oldname) + 5, UMEM_NOFAIL);
-       (void) strcpy(newname, oldname);
-       (void) strcat(newname, "_tmp");
-
-       /*
-        * Do the rename
-        */
-       VERIFY3U(0, ==, spa_rename(oldname, newname));
-
-       /*
-        * Try to open it under the old name, which shouldn't exist
-        */
-       VERIFY3U(ENOENT, ==, spa_open(oldname, &spa, FTAG));
-
-       /*
-        * Open it under the new name and make sure it's still the same spa_t.
-        */
-       VERIFY3U(0, ==, spa_open(newname, &spa, FTAG));
-
-       ASSERT(spa == ztest_spa);
-       spa_close(spa, FTAG);
-
-       /*
-        * Rename it back to the original
-        */
-       VERIFY3U(0, ==, spa_rename(newname, oldname));
-
-       /*
-        * Make sure it can still be opened
-        */
-       VERIFY3U(0, ==, spa_open(oldname, &spa, FTAG));
-
-       ASSERT(spa == ztest_spa);
-       spa_close(spa, FTAG);
-
-       umem_free(newname, strlen(newname) + 1);
-
-       (void) pthread_rwlock_unlock(&ztest_name_lock);
-}
-
 void
 ztest_fletcher(ztest_ds_t *zd, uint64_t id)
 {
@@ -6652,13 +6511,20 @@ ztest_deadman_thread(void *arg)
 {
        ztest_shared_t *zs = arg;
        spa_t *spa = ztest_spa;
-       hrtime_t delta, overdue, total = 0;
+       hrtime_t delay, overdue, last_run = gethrtime();
 
-       for (;;) {
-               delta = zs->zs_thread_stop - zs->zs_thread_start +
-                   MSEC2NSEC(zfs_deadman_synctime_ms);
+       delay = (zs->zs_thread_stop - zs->zs_thread_start) +
+           MSEC2NSEC(zfs_deadman_synctime_ms);
 
-               (void) poll(NULL, 0, (int)NSEC2MSEC(delta));
+       while (!ztest_exiting) {
+               /*
+                * Wait for the delay timer while checking occasionally
+                * if we should stop.
+                */
+               if (gethrtime() < last_run + delay) {
+                       (void) poll(NULL, 0, 1000);
+                       continue;
+               }
 
                /*
                 * If the pool is suspended then fail immediately. Otherwise,
@@ -6679,15 +6545,20 @@ ztest_deadman_thread(void *arg)
                 * then it may be hung and is terminated.
                 */
                overdue = zs->zs_proc_stop + MSEC2NSEC(zfs_deadman_synctime_ms);
-               total += zfs_deadman_synctime_ms / 1000;
                if (gethrtime() > overdue) {
                        fatal(0, "aborting test after %llu seconds because "
-                           "the process is overdue for termination.", total);
+                           "the process is overdue for termination.",
+                           (gethrtime() - zs->zs_proc_start) / NANOSEC);
                }
 
                (void) printf("ztest has been running for %lld seconds\n",
-                   total);
+                   (gethrtime() - zs->zs_proc_start) / NANOSEC);
+
+               last_run = gethrtime();
+               delay = MSEC2NSEC(zfs_deadman_checktime_ms);
        }
+
+       thread_exit();
 }
 
 static void
@@ -6881,7 +6752,7 @@ ztest_run(ztest_shared_t *zs)
 {
        spa_t *spa;
        objset_t *os;
-       kthread_t *resume_thread;
+       kthread_t *resume_thread, *deadman_thread;
        kthread_t **run_threads;
        uint64_t object;
        int error;
@@ -6939,7 +6810,7 @@ ztest_run(ztest_shared_t *zs)
        /*
         * Create a deadman thread and set to panic if we hang.
         */
-       (void) thread_create(NULL, 0, ztest_deadman_thread,
+       deadman_thread = thread_create(NULL, 0, ztest_deadman_thread,
            zs, 0, NULL, TS_RUN | TS_JOINABLE, defclsyspri);
 
        spa->spa_deadman_failmode = ZIO_FAILURE_MODE_PANIC;
@@ -7006,9 +6877,10 @@ ztest_run(ztest_shared_t *zs)
 
        umem_free(run_threads, ztest_opts.zo_threads * sizeof (kthread_t *));
 
-       /* Kill the resume thread */
+       /* Kill the resume and deadman threads */
        ztest_exiting = B_TRUE;
        VERIFY0(thread_join(resume_thread));
+       VERIFY0(thread_join(deadman_thread));
        ztest_resume(spa);
 
        /*
@@ -7193,7 +7065,6 @@ make_random_props(void)
 static void
 ztest_import(ztest_shared_t *zs)
 {
-       libzfs_handle_t *hdl;
        importargs_t args = { 0 };
        spa_t *spa;
        nvlist_t *cfg = NULL;
@@ -7208,14 +7079,14 @@ ztest_import(ztest_shared_t *zs)
        VERIFY0(pthread_rwlock_init(&ztest_name_lock, NULL));
 
        kernel_init(FREAD | FWRITE);
-       hdl = libzfs_init();
 
        searchdirs[0] = ztest_opts.zo_dir;
        args.paths = nsearch;
        args.path = searchdirs;
        args.can_be_active = B_FALSE;
 
-       error = zpool_tryimport(hdl, name, &cfg, &args);
+       error = zpool_find_config(NULL, name, &cfg, &args,
+           &libzpool_config_ops);
        if (error)
                (void) fatal(0, "No pools found\n");
 
@@ -7225,7 +7096,6 @@ ztest_import(ztest_shared_t *zs)
            1ULL << spa->spa_root_vdev->vdev_child[0]->vdev_ms_shift;
        spa_close(spa, FTAG);
 
-       libzfs_fini(hdl);
        kernel_fini();
 
        if (!ztest_opts.zo_mmp_test) {
@@ -7498,7 +7368,6 @@ main(int argc, char **argv)
        ztest_shared_callstate_t *zc;
        char timebuf[100];
        char numbuf[NN_NUMBUF_SZ];
-       spa_t *spa;
        char *cmd;
        boolean_t hasalt;
        int f;
@@ -7509,6 +7378,7 @@ main(int argc, char **argv)
 
        dprintf_setup(&argc, argv);
        zfs_deadman_synctime_ms = 300000;
+       zfs_deadman_checktime_ms = 30000;
        /*
         * As two-word space map entries may not come up often (especially
         * if pool and vdev sizes are small) we want to force at least some
@@ -7520,8 +7390,13 @@ main(int argc, char **argv)
         * Verify that even extensively damaged split blocks with many
         * segments can be reconstructed in a reasonable amount of time
         * when reconstruction is known to be possible.
+        *
+        * Note: the lower this value is, the more damage we inflict, and
+        * the more time ztest spends in recovering that damage. We chose
+        * to induce damage 1/100th of the time so recovery is tested but
+        * not so frequently that ztest doesn't get to test other code paths.
         */
-       zfs_reconstruct_indirect_damage_fraction = 4;
+       zfs_reconstruct_indirect_damage_fraction = 100;
 
        action.sa_handler = sig_handler;
        sigemptyset(&action.sa_mask);
@@ -7700,24 +7575,6 @@ main(int argc, char **argv)
                        (void) printf("\n");
                }
 
-               /*
-                * It's possible that we killed a child during a rename test,
-                * in which case we'll have a 'ztest_tmp' pool lying around
-                * instead of 'ztest'.  Do a blind rename in case this happened.
-                */
-               kernel_init(FREAD);
-               if (spa_open(ztest_opts.zo_pool, &spa, FTAG) == 0) {
-                       spa_close(spa, FTAG);
-               } else {
-                       char tmpname[ZFS_MAX_DATASET_NAME_LEN];
-                       kernel_fini();
-                       kernel_init(FREAD | FWRITE);
-                       (void) snprintf(tmpname, sizeof (tmpname), "%s_tmp",
-                           ztest_opts.zo_pool);
-                       (void) spa_rename(tmpname, ztest_opts.zo_pool);
-               }
-               kernel_fini();
-
                if (!ztest_opts.zo_mmp_test)
                        ztest_run_zdb(ztest_opts.zo_pool);
        }