summaryrefslogtreecommitdiffstats
path: root/libmount/src/context.c
diff options
context:
space:
mode:
authorKarel Zak2017-06-20 12:46:02 +0200
committerKarel Zak2017-06-20 12:46:02 +0200
commit9b76b0e98b7f9e8a7ea1c2b89cf9a73b89fd6bcb (patch)
tree31723bd29fb5946a5b47d2f93df1499b33cbb5a9 /libmount/src/context.c
parentdmesg: fragment concatenation (diff)
downloadkernel-qcow2-util-linux-9b76b0e98b7f9e8a7ea1c2b89cf9a73b89fd6bcb.tar.gz
kernel-qcow2-util-linux-9b76b0e98b7f9e8a7ea1c2b89cf9a73b89fd6bcb.tar.xz
kernel-qcow2-util-linux-9b76b0e98b7f9e8a7ea1c2b89cf9a73b89fd6bcb.zip
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 <neilb@suse.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/context.c')
-rw-r--r--libmount/src/context.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c
index fdbb02585..7c34cad95 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;
}