]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libmount: reuse existing loop device
authorStanislav Brabec <sbrabec@suse.cz>
Tue, 12 Apr 2016 18:22:56 +0000 (20:22 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 22 Apr 2016 10:50:14 +0000 (12:50 +0200)
commitbdf46c4df9aa9201afce6ae29f72268c54293bd7
tree3032bf4e4caba758e27fbd19bc82031a5e7ab9b3
parent6e258026754ff7db97d6ac390e26ad1cc2e866e0
libmount: reuse existing loop device

According to the Al Viro[1], kernel has no way to detect that a single file is
used by multiple loop devices, and multiple mounts of the same file using
different loop devices will result in a data corruption. Exactly this now
happens, if multiple btrfs sub-volumes in one file are mounted with "-oloop".

Make use of multiple -oloop mounting the same file safe: Do a loop devices
lookup, and if a loop device is already initialized, use it.

Hopefully it is possible, as "losetup -d" will return OK, even if the device
itself is in use, and is not released.

Problems:

There is a risk of race condition between the lookup and real mount.

Once loop device is initialized read-only, kernel offers no way to turn it to
read-write. It has to fail.

References:
https://lkml.org/lkml/2016/2/26/897

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
libmount/src/context_loopdev.c