Skip to content

btrfs-progs: image: make restored image file to be properly enlarged

Qu Wenruo linux-btrfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 2 repliesIn review
  2. v13 patches 7 repliesSuperseded

Changes in v2 from the cover letter

- Comments word change
- Only enlarge the file when the target file is smaller than expected device size
- Change the prefix of the 1st patch
From "btrfs" to "btrfs-progs"

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs-progs: image: remove the dead stat() callimage/main.c+0 -80 replies
2/3btrfs-progs: image: enlarge the output file if no tree modification is needed for restoreimage/main.c+43 -00 replies
3/3btrfs-progs: misc-tests: add test to ensure the restored image can be mountedtests/misc-tests/048-image-restore-mount/test.sh+20 -01 reply

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchSu Yue
1/3R-b
2/3R-b
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] btrfs-progs: image: make restored image file to be properly enlarged

Recent kernel will refuse to mount restored image, even the source fs is empty:

 # mkfs.btrfs -f /dev/test/test
 # btrfs-image /dev/test/test /tmp/dump
 # btrfs-image -r /tmp/dump ~/test.img
 # mount ~/test.img /mnt/btrfs
 mount: /mnt/btrfs: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
 # dmesg -t | tail -n 7
 loop0: detected capacity change from 10592 to 0
 BTRFS info (device loop0): disk space caching is enabled
 BTRFS info (device loop0): has skinny extents
 BTRFS info (device loop0): flagging fs with big metadata feature
 BTRFS error (device loop0): device total_bytes should be at most 5423104 but found 10737418240
 BTRFS error (device loop0): failed to read chunk tree: -22
 BTRFS error (device loop0): open_ctree failed

This is triggered by a recent kernel commit 3a160a933111 ("btrfs: drop never met disk total bytes check in verify_one_dev_extent").

But the root cause is, we didn't enlarge the output file if the source image only contains single device.

This bug won't affect restore to block device, or the destination file is already large enough.

This patchset will fix the problem, and with new test case to detect such problem.

Also remove one dead code exposed during the development.

Changelog:
v2:
- Comments word change
- Only enlarge the file when the target file is smaller than expected device size
- Change the prefix of the 1st patch
From "btrfs" to "btrfs-progs"

Qu Wenruo (3):
btrfs-progs: image: remove the dead stat() call
btrfs-progs: image: enlarge the output file if no tree modification is
needed for restore
btrfs-progs: misc-tests: add test to ensure the restored image can be
mounted

 image/main.c                                  | 51 ++++++++++++++++---
 .../048-image-restore-mount/test.sh           | 20 ++++++++
 2 files changed, 63 insertions(+), 8 deletions(-)
 create mode 100755 tests/misc-tests/048-image-restore-mount/test.sh
Signature · 1 line
2.31.1