[lxc-devel] [PATCH 1/1] lxc-start-ephemeral: handle the overlayfs workdir option

Serge Hallyn serge.hallyn at ubuntu.com
Tue Jan 13 00:00:51 UTC 2015


Quoting Stéphane Graber (stgraber at ubuntu.com):
> On Mon, Jan 12, 2015 at 08:41:38PM +0000, Serge Hallyn wrote:
> > We fixed this some time ago for basic lxc-start, but never did
> > lxc-start-ephemeral.
> > 
> > Since the lxc-start patches were pushed, Miklos has given us a
> > way to detect whether we need the workdir= option.  So the
> > bdev.c code could be simplified to check for "overlay\n" in
> > /proc/filesystems just as lxc-start-ephemeral does.  This
> > patch doesn't do that.
> > 
> > Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
> > ---
> >  src/lxc/lxc-start-ephemeral.in | 25 ++++++++++++++++++++++++-
> >  1 file changed, 24 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/lxc/lxc-start-ephemeral.in b/src/lxc/lxc-start-ephemeral.in
> > index c999e74..bf3f121 100644
> > --- a/src/lxc/lxc-start-ephemeral.in
> > +++ b/src/lxc/lxc-start-ephemeral.in
> > @@ -219,6 +219,14 @@ for entry in args.cdir:
> >          dst_path = "%s/rootfs/%s" % (dest_path, src_path)
> >          overlay_dirs += [(src_path, dst_path)]
> >  
> > +# do we have the new overlay fs which requires workdir, or the older
> > +# overlayfs which does not?
> > +have_new_overlay = False
> > +with open("/proc/filesystems", "r") as fd:
> > +    for line in fd.readlines():
> 
> "for line in fd" should be less memory hungry than reading the whole
> file, splitting it and storing the result in a list.
> 
> > +        if line == "nodev\toverlay\n":
> > +            have_new_overlay = True
> 
> Does that mean that we should also be mounting it as "overlay" rather
> than "overlayfs"?

Hm, good point.  'overlayfs' was working for me on ubuntu, but there
I also have two /proc/filesystems entries, one overlay and one overlayfs.
So yeah it should be changed.  That'll need to be fixed in bdev.c too then.

> >  # Generate pre-mount script
> >  with open(os.path.join(dest_path, "pre-mount"), "w+") as fd:
> >      os.fchmod(fd.fileno(), 0o755)
> > @@ -231,16 +239,31 @@ LXC_NAME="%s"
> >      count = 0
> >      for entry in overlay_dirs:
> >          target = "%s/delta%s" % (dest_path, count)
> > +        workdir = "%s/work%s" % (dest_path, count)
> >          fd.write("mkdir -p %s %s\n" % (target, entry[1]))
> > +        if have_new_overlay:
> > +            fd.write("mkdir -p %s\n" % workdir)
> >  
> >          if args.storage_type == "tmpfs":
> >              fd.write("mount -n -t tmpfs -o mode=0755 none %s\n" % (target))
> > +            if have_new_overlay:
> > +                fd.write("mount -n -t tmpfs -o mode=0755 none %s\n" % (workdir))
> >  
> >          fd.write("getfacl -a %s | setfacl --set-file=- %s || true\n" % (entry[0], target))
> >          fd.write("getfacl -a %s | setfacl --set-file=- %s || true\n" % (entry[0], entry[1]))
> > +        if have_new_overlay:
> > +            fd.write("getfacl -a %s | setfacl --set-file=- %s || true\n" % (entry[0], workdir))
> >  
> >          if args.union_type == "overlayfs":
> > -            fd.write("mount -n -t overlayfs"
> > +            if have_new_overlay:
> > +                fd.write("mount -n -t overlayfs"
> > +                     " -oupperdir=%s,lowerdir=%s,workdir=%s none %s\n" % (
> > +                         target,
> > +                         entry[0],
> > +                         workdir,
> > +                         entry[1]))
> > +            else:
> > +                fd.write("mount -n -t overlayfs"
> >                       " -oupperdir=%s,lowerdir=%s none %s\n" % (
> >                           target,
> >                           entry[0],
> > -- 
> > 2.1.0
> > 
> > _______________________________________________
> > lxc-devel mailing list
> > lxc-devel at lists.linuxcontainers.org
> > http://lists.linuxcontainers.org/listinfo/lxc-devel
> 
> -- 
> Stéphane Graber
> Ubuntu developer
> http://www.ubuntu.com



> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel



More information about the lxc-devel mailing list