]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/vdev_removal.c
OpenZFS 9102 - zfs should be able to initialize storage devices
[mirror_zfs.git] / module / zfs / vdev_removal.c
index a706bc2a425a186d50dbd3dcc2e6dc9c8f61b3c9..d0824aa843f7891c0d0d9d1a3e4d9cf36357f70b 100644 (file)
@@ -44,6 +44,7 @@
 #include <sys/vdev_indirect_births.h>
 #include <sys/vdev_indirect_mapping.h>
 #include <sys/abd.h>
+#include <sys/vdev_initialize.h>
 #include <sys/trace_vdev.h>
 
 /*
@@ -1186,6 +1187,7 @@ vdev_remove_complete(spa_t *spa)
        txg_wait_synced(spa->spa_dsl_pool, 0);
        txg = spa_vdev_enter(spa);
        vdev_t *vd = vdev_lookup_top(spa, spa->spa_vdev_removal->svr_vdev_id);
+       ASSERT3P(vd->vdev_initialize_thread, ==, NULL);
 
        sysevent_t *ev = spa_event_create(spa, vd, NULL,
            ESC_ZFS_VDEV_REMOVE_DEV);
@@ -1896,6 +1898,9 @@ spa_vdev_remove_log(vdev_t *vd, uint64_t *txg)
 
        spa_vdev_config_exit(spa, NULL, *txg, 0, FTAG);
 
+       /* Stop initializing */
+       (void) vdev_initialize_stop_all(vd, VDEV_INITIALIZE_CANCELED);
+
        *txg = spa_vdev_config_enter(spa);
 
        sysevent_t *ev = spa_event_create(spa, vd, NULL,
@@ -2072,6 +2077,13 @@ spa_vdev_remove_top(vdev_t *vd, uint64_t *txg)
         */
        error = spa_reset_logs(spa);
 
+       /*
+        * We stop any initializing that is currently in progress but leave
+        * the state as "active". This will allow the initializing to resume
+        * if the removal is canceled sometime later.
+        */
+       vdev_initialize_stop_all(vd, VDEV_INITIALIZE_ACTIVE);
+
        *txg = spa_vdev_config_enter(spa);
 
        /*
@@ -2083,6 +2095,7 @@ spa_vdev_remove_top(vdev_t *vd, uint64_t *txg)
 
        if (error != 0) {
                metaslab_group_activate(mg);
+               spa_async_request(spa, SPA_ASYNC_INITIALIZE_RESTART);
                return (error);
        }