From: Karel Zak Date: Tue, 20 Jun 2017 10:46:02 +0000 (+0200) Subject: libmount: ignore "bind" from fstab on command line "remount" X-Git-Tag: v2.31-rc1~283 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b76b0e98b7f9e8a7ea1c2b89cf9a73b89fd6bcb;p=thirdparty%2Futil-linux.git libmount: ignore "bind" from fstab on command line "remount" The current code always apply all flags from /etc/fstab on remount. Unfortunately remount+bind has special semantic and it's impossible from command line to avoid interaction with the "bind" from fstab. Example, fstab: /dev/sda1 /bar ext4 defaults 0 1 /bar /foo none bind 0 0 Command line: # mount /foo -o remount,rw produces: mount(... MS_REMOUNT|MS_BIND ) syscall This changes the per-mountpoint (VFS) ro flag to rw, but doesn't change the filesystem itself. This patch forces libmount to ignore "bind" from fstab when "-o remount" specified on command line. If you need remount+bind semantic you have to specify the "bind" flag on command line. This allow to differentiate between # mount /foo -o remount,bind,rw --> mount(MS_REMOUNT|MS_BIND) and # mount /foo -o remount,rw --> mount(MS_REMOUNT) Suggested-by: NeilBrown Signed-off-by: Karel Zak --- diff --git a/libmount/src/context.c b/libmount/src/context.c index fdbb025857..7c34cad953 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -2045,7 +2045,7 @@ static int apply_table(struct libmnt_context *cxt, struct libmnt_table *tb, */ int mnt_context_apply_fstab(struct libmnt_context *cxt) { - int rc = -1, isremount = 0; + int rc = -1, isremount = 0, iscmdbind = 0; struct libmnt_table *tab = NULL; const char *src = NULL, *tgt = NULL; unsigned long mflags = 0; @@ -2070,8 +2070,10 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt) cxt->optsmode &= ~MNT_OMODE_FORCE; } - if (mnt_context_get_mflags(cxt, &mflags) == 0 && mflags & MS_REMOUNT) - isremount = 1; + if (mnt_context_get_mflags(cxt, &mflags) == 0) { + isremount = !!(mflags & MS_REMOUNT); + iscmdbind = !!(mflags & MS_BIND); + } if (cxt->fs) { src = mnt_fs_get_source(cxt->fs); @@ -2138,6 +2140,12 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt) * not found are not so important and may be misinterpreted by * applications... */ rc = -MNT_ERR_NOFSTAB; + + + } else if (isremount && !iscmdbind) { + + /* remove "bind" from fstab (or no-op if not present) */ + mnt_optstr_remove_option(&cxt->fs->optstr, "bind"); } return rc; } diff --git a/sys-utils/mount.8 b/sys-utils/mount.8 index ac410640ed..3bd278e6aa 100644 --- a/sys-utils/mount.8 +++ b/sys-utils/mount.8 @@ -385,6 +385,20 @@ will be read-only. It's also possible to change nosuid, nodev, noexec, noatime, nodiratime and relatime VFS entry flags by "remount,bind" operation. It's impossible to change mount options recursively (for example with \fB-o rbind,ro\fR). + +.BR mount (8) +since v2.31 ignores the \fBbind\fR flag from +.I /etc/fstab +on +.B remount operation +(if "-o remount" specified on command line). This is necessary to fully control +mount options on remount by command line. In the previous versions the bind +flag has been always applied and it was impossible to re-define mount options +without interaction with the bind semantic. This +.BR mount (8) +behavior does not affect situations when "remount,bind" is specified in the +.I /etc/fstab +file. .RE .SS The move operation @@ -1088,6 +1102,10 @@ Attempt to remount an already-mounted filesystem. This is commonly used to change the mount flags for a filesystem, especially to make a readonly filesystem writable. It does not change device or mount point. +The remount operation together with the +.B bind +flag has special semantic. See above, the subsection \fBBind mounts\fR. + The remount functionality follows the standard way the mount command works with options from fstab. This means that \fBmount\fR does not read fstab (or mtab) only when both