]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc to apply mount options for bind mounts
authorCiprian Dorin, Craciun <ciprian@volution.ro>
Thu, 24 Jun 2010 07:47:14 +0000 (09:47 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 24 Jun 2010 07:47:14 +0000 (09:47 +0200)
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 <dlezcano@fr.ibm.com>
src/lxc/conf.c

index 66c60a8d7c60b10afb9f7a6f5d1aee02628db70c..3aaf31cbc08ae44446ffb05d9c0dc06e92a93015 100644 (file)
@@ -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);