linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: fdmanana@kernel.org
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: fix block group remaining RO forever after error during device replace
Date: Mon, 18 Nov 2019 16:23:27 +0100	[thread overview]
Message-ID: <20191118152327.GG3001@twin.jikos.cz> (raw)
In-Reply-To: <20191114180243.10857-1-fdmanana@kernel.org>

On Thu, Nov 14, 2019 at 06:02:43PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> When doing a device replace, while at scrub.c:scrub_enumerate_chunks(), we
> set the block group to RO mode and then wait for any ongoing writes into
> extents of the block group to complete. While doing that wait we overwrite
> the value of the variable 'ret' and can break out of the loop if an error
> happens without turning the block group back into RW mode. So what happens
> is the following:
> 
> 1) btrfs_inc_block_group_ro() returns 0, meaning it set the block group
>    to RO mode (its ->ro field set to 1 or incremented to some value > 1);
> 
> 2) Then btrfs_wait_ordered_roots() returns a value > 0;
> 
> 3) Then if either joinning or committing the transaction fails, we break
>    out of the loop wihtout calling btrfs_dec_block_group_ro(), leaving
>    the block group in RO mode forever.
> 
> To fix this, just remove the code that waits for ongoing writes to extents
> of the block group, since it's not needed because in the initial setup
> phase of a device replace operation, before starting to find all chunks
> and their extents, we set the target device for replace while holding
> fs_info->dev_replace->rwsem, which ensures that after releasing that
> semaphore, any writes into the source device are made to the target device
> as well (__btrfs_map_block() guarantees that). So while at
> scrub_enumerate_chunks() we only need to worry about finding and copying
> extents (from the source device to the target device) that were written
> before we started the device replace operation.
> 
> Fixes: f0e9b7d6401959 ("Btrfs: fix race setting block group readonly during device replace")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Added to misc-next, thanks.

      reply	other threads:[~2019-11-18 15:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-14 18:02 [PATCH] Btrfs: fix block group remaining RO forever after error during device replace fdmanana
2019-11-18 15:23 ` David Sterba [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191118152327.GG3001@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).