[lxc-devel] Fixed (hacked) LXC to apply mount options for bind mounts

Daniel Lezcano daniel.lezcano at free.fr
Mon Mar 15 10:24:32 UTC 2010


Ciprian Dorin, Craciun wrote:
> On Mon, Mar 8, 2010 at 11:35 PM, Ciprian Dorin, Craciun
> <ciprian.craciun at gmail.com> wrote:
>   
>>    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.
>>
>>    Any other ideas on how to solve this? Any comments?
>>    Ciprian.
>>
>>    P.S.: One question though (both in the patched and unpatched
>> versions): it seems that if I put two lines inside the fstab, once
>> with only `bind` options, and a second one with `remount,ro` option it
>> doesn't work and I receive the error `No such device - failed to
>> mount`. But this is equivalent with what my patched version is doing
>> (which works)... Strange...
>>
>>
>> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
>> index 26ddd03..f7c5816 100644
>> --- a/src/lxc/conf.c
>> +++ b/src/lxc/conf.c
>> @@ -801,11 +801,20 @@ 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);
>>     
>
>
>     Forgot to montion that my changeset is also available on Gitorious:
>         clone-URL
> git://gitorious.org/~ciprian.craciun/lxc/ciprian-craciun-patches.git
>         branch: patches/bind-remount
>     Or view on-line:
>         http://gitorious.org/~ciprian.craciun/lxc/ciprian-craciun-patches/commits/patches/bind-remount
>   

Thanks Ciprian for the report.






More information about the lxc-devel mailing list