Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH 5/6] Btrfs: fix race setting block group back to RW mode during device replace
@ 2016-05-20  4:45 fdmanana
  2016-05-20 15:22 ` Josef Bacik
  0 siblings, 1 reply; 2+ messages in thread
From: fdmanana @ 2016-05-20  4:45 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

After it finishes processing a device extent, the device replace code sets
back the block group to RW mode and then after that it sets the left cursor
to match the logical end address of the block group, so that future writes
into extents belonging to the block group go both the source (old) and
target (new) devices. However from the moment we turn the block group
back to RW mode we have a short time window, that lasts until we update
the left cursor's value, where extents can be allocated from the block
group and written to, in which case they will not be copied/written to
the target (new) device. Fix this by updating the left cursor's value
before turning the block group back to RW mode.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/scrub.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index a58e0ae..c4c09a8 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3680,6 +3680,11 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 
 		scrub_pause_off(fs_info);
 
+		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);
+
 		if (ro_set)
 			btrfs_dec_block_group_ro(root, cache);
 
@@ -3717,11 +3722,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 			ret = -ENOMEM;
 			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);
-- 
2.7.0.rc3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 5/6] Btrfs: fix race setting block group back to RW mode during device replace
  2016-05-20  4:45 [PATCH 5/6] Btrfs: fix race setting block group back to RW mode during device replace fdmanana
@ 2016-05-20 15:22 ` Josef Bacik
  0 siblings, 0 replies; 2+ messages in thread
From: Josef Bacik @ 2016-05-20 15:22 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs@vger.kernel.org

On Fri, May 20, 2016 at 12:45 AM,  <fdmanana@kernel.org> wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> After it finishes processing a device extent, the device replace code sets
> back the block group to RW mode and then after that it sets the left cursor
> to match the logical end address of the block group, so that future writes
> into extents belonging to the block group go both the source (old) and
> target (new) devices. However from the moment we turn the block group
> back to RW mode we have a short time window, that lasts until we update
> the left cursor's value, where extents can be allocated from the block
> group and written to, in which case they will not be copied/written to
> the target (new) device. Fix this by updating the left cursor's value
> before turning the block group back to RW mode.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Josef Bacik <jbacik@fb.com>

Thanks,

Josef

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-20 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-20  4:45 [PATCH 5/6] Btrfs: fix race setting block group back to RW mode during device replace fdmanana
2016-05-20 15:22 ` Josef Bacik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox