From: Ciprian Dorin, Craciun Date: Thu, 24 Jun 2010 07:47:14 +0000 (+0200) Subject: lxc to apply mount options for bind mounts X-Git-Tag: lxc-0.7.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e76b8764fa0aa1873724a9e4a8a3ca93c0e5cd70;p=thirdparty%2Flxc.git lxc to apply mount options for bind mounts Hello all! This bug stalked me for a while, but only now it bit me quite badly... (Lost about an hour of work...) So the culprit: inside the fstab file for the `lxc.mount` option I can use options like `ro` together with `bind`. Unfortunately the kernel just laughs in my face and ignores any options I've put in there... :) But not any more: I've updated `./src/lxc/conf.c` (`mount_file_entries` function) so that when it encounters a `bind` option it executes it twice (one without any extra options, and a second time with the remount flag set.) I've marginally (as in my particular case) tested it and it works. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 66c60a8d7..3aaf31cbc 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -799,12 +799,28 @@ static int mount_file_entries(FILE *file) } if (mount(mntent->mnt_fsname, mntent->mnt_dir, - mntent->mnt_type, mntflags, mntdata)) { + mntent->mnt_type, mntflags & ~MS_REMOUNT, mntdata)) { SYSERROR("failed to mount '%s' on '%s'", mntent->mnt_fsname, mntent->mnt_dir); goto out; } + if ((mntflags & MS_REMOUNT) == MS_REMOUNT || + ((mntflags & MS_BIND) == MS_BIND)) { + + DEBUG ("remounting %s on %s to respect bind " \ + "or remount options", + mntent->mnt_fsname, mntent->mnt_dir); + + if (mount(mntent->mnt_fsname, mntent->mnt_dir, + mntent->mnt_type, + mntflags | MS_REMOUNT, mntdata)) { + SYSERROR("failed to mount '%s' on '%s'", + mntent->mnt_fsname, mntent->mnt_dir); + goto out; + } + } + DEBUG("mounted %s on %s, type %s", mntent->mnt_fsname, mntent->mnt_dir, mntent->mnt_type);