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

* Re: [PATCH] try to 'remount,ro' once if the kernel ignores the ro request for bind mounts
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Tauner @ 2011-02-20  2:14 UTC (permalink / raw)
  To: util-linux; +Cc: Stefan Tauner

Hey there!

i sent the patch below ~10 days ago and did not receive any feedback
whatsoever. if it's wrong or deemed unneeded, i'd really like to hear
your opinion why. thanks!

On Thu, 10 Feb 2011 19:02:05 +0100
Stefan Tauner <stefan.tauner@student.tuwien.ac.at> wrote:

> 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	[flat|nested] 3+ messages in thread

* Re: [PATCH] try to 'remount,ro' once if the kernel ignores the ro request for bind mounts
  2011-02-20  2:14 ` Stefan Tauner
@ 2011-02-21  9:19   ` Karel Zak
  0 siblings, 0 replies; 3+ messages in thread
From: Karel Zak @ 2011-02-21  9:19 UTC (permalink / raw)
  To: Stefan Tauner; +Cc: util-linux

On Sun, Feb 20, 2011 at 03:14:30AM +0100, Stefan Tauner wrote:
> i sent the patch below ~10 days ago and did not receive any feedback
> whatsoever. if it's wrong or deemed unneeded, i'd really like to hear
> your opinion why. thanks!

I'm still not sure if mount(8) is the right place to fix odd kernel
behaviour. Anyway, your patch seems like a usable workaround.

I'll try to apply the patch later (it will necessary to modify
libmount, because the library is not able to add a new entry to mtab
for MS_REMOUNT requests).

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[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