Util-Linux package development
 help / color / mirror / Atom feed
From: Stanislav Brabec <sbrabec@suse.cz>
To: util-linux@vger.kernel.org
Subject: [PATCH 3/3] mount: Handle EROFS before calling mount() syscall
Date: Tue, 12 Apr 2016 20:23:25 +0200	[thread overview]
Message-ID: <570D3D1D.1050502@suse.cz> (raw)

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>
---
 sys-utils/mount.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sys-utils/mount.c b/sys-utils/mount.c
index 9c4729e..3e90fcc 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"),
-- 
2.8.1

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@suse.com
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

                 reply	other threads:[~2016-04-12 18:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=570D3D1D.1050502@suse.cz \
    --to=sbrabec@suse.cz \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox