diff options
author | Jeff Mahoney | 2013-04-09 14:32:50 +0200 |
---|---|---|
committer | Karel Zak | 2013-04-09 14:32:50 +0200 |
commit | 293714c0d157ae04d08bb587e800c70f05cc4a29 (patch) | |
tree | e4f7e30892335c340ea5160843074d9176cca6b0 /sys-utils | |
parent | libblkid: export blkid_init_debug() (diff) | |
download | kernel-qcow2-util-linux-293714c0d157ae04d08bb587e800c70f05cc4a29.tar.gz kernel-qcow2-util-linux-293714c0d157ae04d08bb587e800c70f05cc4a29.tar.xz kernel-qcow2-util-linux-293714c0d157ae04d08bb587e800c70f05cc4a29.zip |
loopdev: sync capacity after setting it
I recently tried to mount an hfsplus file system from an image file with
a partition table by using the loop offset and sizelimit options to specify
the location of the file system.
hfsplus stores some metadata at a set offset from the end of the partition,
so it's sensitive to the device size reported by the kernel.
It worked with this:
But failed with this:
/dev/loop0: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000
/dev/loop1: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000
/proc/partitions shows the correct number of blocks to match the sizelimit.
But if I set a breakpoint in mount before the mount syscall, I could see:
102400000
102432768
The kernel loop driver will set the gendisk capacity of the device at
LOOP_SET_STATUS64 but won't sync it to the block device until one of two
conditions are met: All open file descriptors referring to the device are
closed (and it will sync when re-opened) or if the LOOP_SET_CAPACITY ioctl
is called to sync it. Since mount opens the device and passes it directly
to the mount syscall after LOOP_SET_STATUS64 without closing and reopening
it, the sizelimit argument is effectively ignroed. The capacity needs to
be synced immediately for it to work as expected.
This patch adds the LOOP_SET_CAPACITY call to loopctx_setup_device since
the device isn't yet released to the user, so it's safe to sync the capacity
immediately.
[kzak@redhat.com: - port to the current git HEAD,
- use uint64_t]
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
-rw-r--r-- | sys-utils/losetup.c | 19 | ||||
-rw-r--r-- | sys-utils/mount.8 | 16 |
2 files changed, 20 insertions, 15 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 8f3614e1f..ccf120e9f 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -183,20 +183,6 @@ static int show_all_loops(struct loopdev_cxt *lc, const char *file, return 0; } -static int set_capacity(struct loopdev_cxt *lc) -{ - int fd = loopcxt_get_fd(lc); - - if (fd < 0) - warn(_("cannot open %s"), loopcxt_get_device(lc)); - else if (ioctl(fd, LOOP_SET_CAPACITY) != 0) - warnx(_("%s: set capacity failed"), loopcxt_get_device(lc)); - else - return 0; - - return -1; -} - static int delete_loop(struct loopdev_cxt *lc) { if (loopcxt_delete_device(lc)) @@ -685,7 +671,10 @@ int main(int argc, char **argv) warn(_("%s"), loopcxt_get_device(&lc)); break; case A_SET_CAPACITY: - res = set_capacity(&lc); + res = loopcxt_set_capacity(&lc); + if (res) + warn(_("%s: set capacity failed"), + loopcxt_get_device(&lc)); break; default: usage(stderr); diff --git a/sys-utils/mount.8 b/sys-utils/mount.8 index 72f0f0b45..626d86169 100644 --- a/sys-utils/mount.8 +++ b/sys-utils/mount.8 @@ -2976,6 +2976,22 @@ and .BR ioctl families of functions) may lead to inconsistent result due to the lack of consistency check in kernel even if noac is used. +.PP +The +.B loop +option with the +.B offset +or +.B sizelimit +options used may fail when using older kernels if the +.B mount +command can't confirm that the size of the block device has been configured +as requested. This situation can be worked around by using +the +.B losetup +command manually before calling +.B mount +with the configured loop device. .SH HISTORY A .B mount |