From 96ebc5a1a4cc57806882e4e9b38c49ba8a5bdfda Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 6 Mar 2019 09:17:53 -0800 Subject: [PATCH] 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 --- module/zfs/vdev_initialize.c | 7 +++++++ 1 file changed, 7 insertions(+) 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); -- 2.39.2