btrfs-progs: remove loopback device resolution #940
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[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.