-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
btrfs-progs: remove loopback device resolution #940
base: devel
Are you sure you want to change the base?
Conversation
[BUG] mkfs.btrfs has a built-in loopback device resolution, to avoid the same file being added to the same fs, using loopback device and the file itself. But it has one big bug: - It doesn't detect partition on loopback devices correctly The function is_loop_device() only utilize major number to detect a loopback device. But partitions on loopback devices doesn't use the same major number as the loopback device: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 5G 0 loop |-loop0p1 259:3 0 128M 0 part `-loop0p2 259:4 0 4.9G 0 part Thus `/dev/loop0p1` will not be treated as a loopback device, thus it will not even resolve the source file. And this can not even be fixed, as if we do extra "/dev/loop*" based file lookup, `/dev/loop0p1` and `/dev/loop0p2` will resolve to the same source file, and refuse to mkfs on two different partitions. [FIX] The loopback file detection is the baby sitting that no one asks for. Just as I explained, it only brings new bugs, and we will never fix all ways that an experienced user can come up with. And I didn't see any other mkfs tool doing such baby sitting. So remove the loopback file resolution, just regular is_same_blk_file() is good enough. Signed-off-by: Qu Wenruo <wqu@suse.com>
@adam900710 Same problem it seems:
|
@DaanDeMeyer Mind to share what's needed to reproduce the problem? On my environment (Archlinux) it doesn't seems to fail at all (and created the rootfs using ext4) Is there anyway to force it to use btrfs instead? |
@adam900710 Apologies, a full reproducer can be found in systemd/systemd#36264. Note that this reproduces both btrfs issues we're seeing. You'll first encounter the issue described in https://lore.kernel.org/linux-fsdevel/20250115185608.GA2223535@zen.localdomain/T/#u, and if that one is fixed (or you're not running a kernel with the change that triggers that issue), mkfs.btrfs will start failing after that due to the loopback device error. |
[BUG]
mkfs.btrfs has a built-in loopback device resolution, to avoid the same file being added to the same fs, using loopback device and the file itself.
But it has one big bug:
It doesn't detect partition on loopback devices correctly The function is_loop_device() only utilize major number to detect a loopback device. But partitions on loopback devices doesn't use the same major number as the loopback device:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 5G 0 loop
|-loop0p1 259:3 0 128M 0 part
`-loop0p2 259:4 0 4.9G 0 part
Thus
/dev/loop0p1
will not be treated as a loopback device, thus it will not even resolve the source file.And this can not even be fixed, as if we do extra "/dev/loop*" based file lookup,
/dev/loop0p1
and/dev/loop0p2
will resolve to the same source file, and refuse to mkfs on two different partitions.[FIX]
The loopback file detection is the baby sitting that no one asks for.
Just as I explained, it only brings new bugs, and we will never fix all ways that an experienced user can come up with.
And I didn't see any other mkfs tool doing such baby sitting.
So remove the loopback file resolution, just regular is_same_blk_file() is good enough.