diff options
author | Stanislav Brabec | 2016-04-12 20:23:25 +0200 |
---|---|---|
committer | Karel Zak | 2016-04-22 12:50:14 +0200 |
commit | b2c2c42a8e77a8b2eff2735b03b9a91a19c5e091 (patch) | |
tree | 787e7762c9431bd0f574bb1c3bedac447eaddaf9 /sys-utils/mount.c | |
parent | libmount: reuse existing loop device (diff) | |
download | kernel-qcow2-util-linux-b2c2c42a8e77a8b2eff2735b03b9a91a19c5e091.tar.gz kernel-qcow2-util-linux-b2c2c42a8e77a8b2eff2735b03b9a91a19c5e091.tar.xz kernel-qcow2-util-linux-b2c2c42a8e77a8b2eff2735b03b9a91a19c5e091.zip |
mount: Handle EROFS before calling mount() syscall
If the loop device is already initialized read-only, the new code for loop
device reuse returns -EROFS. There is no solution of this situation. But mount
can behave in the same way, as it does for EROFS returned by mount syscall: Try
again in read-only mode.
Before:
mount: /mnt/2: mount failed: Read-only file system
After:
mount: /btrfs.img is used as read only loop, mounting read-only
Note: It would be nice to mention loop device name in the warning message, but
it is not available in the mount context.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Diffstat (limited to 'sys-utils/mount.c')
-rw-r--r-- | sys-utils/mount.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/sys-utils/mount.c b/sys-utils/mount.c index 64ec0a779..23856c171 100644 --- a/sys-utils/mount.c +++ b/sys-utils/mount.c @@ -402,6 +402,15 @@ try_readonly: case -EBUSY: warnx(_("%s is already mounted"), src); return MOUNT_EX_USAGE; + /* -EROFS before syscall can happen only for loop mount */ + case -EROFS: + warnx(_("%s is used as read only loop, mounting read-only"), src); + mnt_context_reset_status(cxt); + mnt_context_set_mflags(cxt, mflags | MS_RDONLY); + rc = mnt_context_mount(cxt); + if (!rc) + rc = mnt_context_finalize_mount(cxt); + goto try_readonly; case -MNT_ERR_NOFSTAB: if (mnt_context_is_swapmatch(cxt)) { warnx(_("can't find %s in %s"), |