public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Filipe Manana <fdmanana@gmail.com>
Cc: Kyle Ambroff-Kao <kyle@ambroffkao.com>,
	linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 1/1] btrfs: Allow replacing device with a smaller one if possible
Date: Fri, 13 Dec 2019 16:48:45 +0100	[thread overview]
Message-ID: <20191213154845.GY3929@twin.jikos.cz> (raw)
In-Reply-To: <CAL3q7H60gNBC_zzU8gjZ_s=7MnN23yFzQqYxanhvzMO50qtXJg@mail.gmail.com>

On Mon, Dec 09, 2019 at 10:26:52AM +0000, Filipe Manana wrote:
> 2) A simple solution, but often less efficient: before starting the
> actual replace operation, shrink the source device to the size of the
> target device - just use the existing btrfs_shrink_device(), which
> will relocate chunks beyond the new size, and if there's not enough
> space it just returns -ENOSPC.  This means no changes to the actual
> way replace copies data - it does extra IO, due to the relocation but
> keeps things simple, and it should still be significantly more
> efficient then doing a device remove + device add operation, maybe
> except if all or most of the allocated chunks (in the device to be
> replaced) cross or start beyond an offset matching the new device's
> size.
> 
>    Also, since the shrink can take some time due to relocation of
>    chunks, we would need to teach btrfs_shrink_device() to check for
>    device replace cancel requests as well.  And such request is
>    detected, restore the device's size to the original value.

The shrinking can be done completely in userspace, calling one more
ioctl before device replace. Handling the error cases will be simplified
(and not necessarily done in kernel at all).

So something like that:

  $ btrfs device replace 2 /dev/sdx /mnt
  (fail because the device is too small, print a message that the target
  device needs to be shrunk manually or there's an option eg.
  --shrink-target that will do that in one go)

  $ btrfs device replace --shrink-target 2 /dev/sdx /mnt
  Shrink device 2 from 12345678 to 123456 (you can cancel that by 'btrfs resize --cancel)
  Done
  Starting devicr replace

> I think option 2 may actually be acceptable for an initial version. Option 1 is
> complex and increases the risk for data loss. Also, for option 2, there's the
> possible downside of requiring writes to the source device - one might
> be replacing
> it because the device is not healthy, writes into some regions are
> failing, which
> can prevent the shrink/relocation process from suceeding, in that case only
> a device remove followed by a device add operation would work.

That's a good point and giving user more options how to replace the
device sounds a like a better option than implementing all of that in
kernel.

      parent reply	other threads:[~2019-12-13 20:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-08  9:30 [PATCH 0/1] Support replacing a device with smaller one Kyle Ambroff-Kao
2019-12-08  9:30 ` [PATCH 1/1] btrfs: Allow replacing device with a smaller one if possible Kyle Ambroff-Kao
2019-12-09 10:26   ` Filipe Manana
2019-12-09 19:22     ` Kyle Ambroff-Kao
2019-12-13 15:48     ` 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=20191213154845.GY3929@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=fdmanana@gmail.com \
    --cc=kyle@ambroffkao.com \
    --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