]> git.hungrycats.org Git - linux/commitdiff
Btrfs: fix unprotected assignment of the left cursor for device replace
authorFilipe Manana <fdmanana@suse.com>
Sat, 14 May 2016 15:32:35 +0000 (16:32 +0100)
committerZygo Blaxell <zblaxell@waya.furryterror.org>
Wed, 17 Aug 2016 02:39:31 +0000 (22:39 -0400)
We were assigning new values to fields of the device replace object
without holding the respective lock after processing each device extent.
This is important for the left cursor field which can be accessed by a
concurrent task running __btrfs_map_block (which, correctly, takes the
device replace lock).
So change these fields while holding the device replace lock.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
(cherry picked from commit 81e87a736c5581e83f52dc054b368993ec7f16d7)

fs/btrfs/scrub.c

index bf7ba8d318b62b84eadf65ba6352ca4183187fbd..4c46ff69b4278c3281798e30525ddf23f7c5feb0 100644 (file)
@@ -3600,9 +3600,11 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
                        break;
                }
 
+               btrfs_dev_replace_lock(&fs_info->dev_replace, 1);
                dev_replace->cursor_right = found_key.offset + length;
                dev_replace->cursor_left = found_key.offset;
                dev_replace->item_needs_writeback = 1;
+               btrfs_dev_replace_unlock(&fs_info->dev_replace, 1);
                ret = scrub_chunk(sctx, scrub_dev, chunk_offset, length,
                                  found_key.offset, cache, is_dev_replace);
 
@@ -3676,8 +3678,10 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
                        break;
                }
 
+               btrfs_dev_replace_lock(&fs_info->dev_replace, 1);
                dev_replace->cursor_left = dev_replace->cursor_right;
                dev_replace->item_needs_writeback = 1;
+               btrfs_dev_replace_unlock(&fs_info->dev_replace, 1);
 skip:
                key.offset = found_key.offset + length;
                btrfs_release_path(path);