]> granicus.if.org Git - zfs/commitdiff
Fix race in vdev_initialize_thread
authorBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 6 Mar 2019 17:17:53 +0000 (09:17 -0800)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2019 17:17:53 +0000 (09:17 -0800)
Before allowing new allocations to the metaslab we need to ensure
that any issued initializing writes have been synced.  Otherwise,
it's possible for metaslab_block_alloc() to allocate a range which
is about to be overwritten by an initializing IO.

Serapheim Dimitropoulos <serapheim@delphix.com>
Reviewed-by: Richard Elling <Richard.Elling@RichardElling.com>
Reviewed-by: Tim Chase <tim@chase2k.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #8461

module/zfs/vdev_initialize.c

index a69eca354c1078a4bbf185bd8a88cab4d5620400..bec89a28eefb9a6088a078a15d92c6715601e12c 100644 (file)
@@ -628,6 +628,13 @@ vdev_initialize_thread(void *arg)
 
                spa_config_exit(spa, SCL_CONFIG, FTAG);
                error = vdev_initialize_ranges(vd, deadbeef);
+
+               /*
+                * Wait for the outstanding IO to be synced to prevent
+                * newly allocated blocks from being overwritten.
+                */
+               txg_wait_synced(spa_get_dsl(spa), 0);
+
                vdev_initialize_ms_unmark(msp);
                spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);