Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] try to 'remount,ro' once if the kernel ignores the ro request for bind mounts
@ 2011-02-10 18:02 Stefan Tauner
  2011-02-20  2:14 ` Stefan Tauner
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Tauner @ 2011-02-10 18:02 UTC (permalink / raw)
  To: util-linux; +Cc: Stefan Tauner

Hello,

the linux kernel ignores (some?) options when they are used in bind
mounts. Because of this 'mount' issues a warning if bind mounting with
the ro option results in a writable mount (since 2009).
>From my point of view this is an error in the kernel because it does
not report that and should be fixed. Nevertheless since mount already
checks for this failure it is not a big change to just retry with the
MS_REMOUNT flag added, which normally should succeed. If not we can
still warn as before. This would allow using "bind,ro" in /etc/fstab.
The patch below implements that.

(please cc me)

Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
---
 mount/mount.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/mount/mount.c b/mount/mount.c
index f5b3521..28a05f9 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -1655,14 +1655,18 @@ try_mount_one (const char *spec0, const char *node0, const char *types0,
   }
 
   /* Kernel allows to use MS_RDONLY for bind mounts, but the read-only request
-   * could be silently ignored. Check it to avoid 'ro' in mtab and 'rw' in
-   * /proc/mounts.
+   * could be silently ignored. Check that and retry with MS_REMOUNT once. If it
+   * is still rw honor it to avoid 'ro' in mtab and 'rw' in /proc/mounts.
    */
   if (!fake && mnt5_res == 0 &&
       (flags & MS_BIND) && (flags & MS_RDONLY) && !is_readonly(node)) {
-
-      printf(_("mount: warning: %s seems to be mounted read-write.\n"), node);
-      flags &= ~MS_RDONLY;
+      if (!(flags & MS_REMOUNT)) {
+        flags |= MS_REMOUNT;
+        goto mount_retry;
+      } else {
+        printf(_("mount: warning: %s seems to be mounted read-write.\n"), node);
+        flags &= ~MS_RDONLY;
+      }
   }
 
   /* Kernel can silently add MS_RDONLY flag when mounting file system that
-- 
Kind regards/Mit freundlichen Grüßen, Stefan Tauner

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-21  9:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-10 18:02 [PATCH] try to 'remount,ro' once if the kernel ignores the ro request for bind mounts Stefan Tauner
2011-02-20  2:14 ` Stefan Tauner
2011-02-21  9:19   ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox