[PATCH] try to 'remount,ro' once if the kernel ignores the ro request for bind mounts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxxx>
---
 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
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux