mbox series

[0/3] btrfs-progs: add check and repair ability for shrunk device item

Message ID cover.1661841983.git.wqu@suse.com (mailing list archive)
Headers show
Series btrfs-progs: add check and repair ability for shrunk device item | expand

Message

Qu Wenruo Aug. 30, 2022, 6:49 a.m. UTC
There is a bug report that, a btrfs with shrunk underlying device will
be rejected by kernel, but btrfs-check will report nothing wrong.

Furthermore for such case, even if there is no dev extent in the shrunk
range, we have no way to fix it.
Kernel will refuse to mount, thus no way to shrink the device using
"btrfs dev resize".

This patch will:

- Add check ability to report such mismatch

- Add rescue ability to reset the total_bytes in dev items
  This can only be done if there is no dev extent in the shrunk range.

- Add a test case for above behavior

Qu Wenruo (3):
  btrfs-progs: check: verify the underlying block device size is valid
  btrfs-progs: fsck-tests: add test case for shrunk device
  btrfs-progs: rescue: allow fix-device-size to shrink device item

 check/main.c                                 |  28 ++++
 check/mode-lowmem.c                          |  22 +++
 kernel-shared/volumes.c                      | 135 +++++++++++++++++--
 tests/fsck-tests/059-shrinked-device/test.sh |  32 +++++
 4 files changed, 208 insertions(+), 9 deletions(-)
 create mode 100755 tests/fsck-tests/059-shrinked-device/test.sh

Comments

David Sterba Aug. 31, 2022, 2:52 p.m. UTC | #1
On Tue, Aug 30, 2022 at 02:49:41PM +0800, Qu Wenruo wrote:
> There is a bug report that, a btrfs with shrunk underlying device will
> be rejected by kernel, but btrfs-check will report nothing wrong.
> 
> Furthermore for such case, even if there is no dev extent in the shrunk
> range, we have no way to fix it.
> Kernel will refuse to mount, thus no way to shrink the device using
> "btrfs dev resize".
> 
> This patch will:
> 
> - Add check ability to report such mismatch
> 
> - Add rescue ability to reset the total_bytes in dev items
>   This can only be done if there is no dev extent in the shrunk range.
> 
> - Add a test case for above behavior
> 
> Qu Wenruo (3):
>   btrfs-progs: check: verify the underlying block device size is valid
>   btrfs-progs: fsck-tests: add test case for shrunk device
>   btrfs-progs: rescue: allow fix-device-size to shrink device item

Added to devel, thanks.