From: Brian Behlendorf Date: Wed, 6 Mar 2019 17:17:53 +0000 (-0800) Subject: Fix race in vdev_initialize_thread X-Git-Tag: zfs-0.8.0-rc4~88 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96ebc5a1a4cc57806882e4e9b38c49ba8a5bdfda;p=zfs Fix race in vdev_initialize_thread 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 Reviewed-by: Richard Elling Reviewed-by: Tim Chase Reviewed-by: George Wilson Signed-off-by: Brian Behlendorf Closes #8461 --- diff --git a/module/zfs/vdev_initialize.c b/module/zfs/vdev_initialize.c index a69eca354..bec89a28e 100644 --- a/module/zfs/vdev_initialize.c +++ b/module/zfs/vdev_initialize.c @@ -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);