[lxc-devel] lxc-clone outputs some logs

KATOH Yasufumi karma at jazz.email.ne.jp
Tue Nov 4 12:03:34 UTC 2014


>>> On Mon, 3 Nov 2014 15:44:32 +0000
    in message   "Re: [lxc-devel] lxc-clone outputs some logs"
                  Serge Hallyn-san wrote:

> Quoting KATOH Yasufumi (karma at jazz.email.ne.jp):
> > Hi,
> > 
> > >>> On Thu, 30 Oct 2014 14:35:16 +0000
> >     in message   "Re: [lxc-devel] lxc-clone outputs some logs"
> >                   Serge Hallyn-san wrote:
> > 
> > > > > > After applying commit edf7734 "overlay and aufs clone_paths: be more
> > > > > > robust", clone was completed successfully but lxc-clone on unpriv env
> > > > > > is now output the following log:
> > > > 
> > > > > >   $ lxc-clone -o ct02 -n test -s -B overlayfs
> > > > > >   lxc_container: conf.c: chown_mapped_root: 3649 Error stat /home/karma/.local/share/lxc/test/delta0
> > > > > >   Created container test as snapshot of ct02
> > > > > >   lxc_container: lxccontainer.c: copy_file: 2303 copy destination /home/karma/.local/share/lxc/test/lxc_rdepends exists
> > > > > >   Created container test as snapshot of ct02
> > > > 
> > > > > ct02 is the cloned container with overlayfs.
> > > > 
> > > > I find out other problem. After applying that patch, in part of the
> > > > beginning of overlayfs_clonepath function, new->dest variable is,
> > > > for example:
> > > >   "overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:/home/karma/.local/share/lxc/ct02/delta0"
> > > > 
> > > > So, as the result, run "mkdir_p(new->dest, 0755)", and create dir in
> > > > current dir.
> > > > 
> > > > $ lxc-clone -o ct02 -n test -s -B overlayfs
> > > > lxc_container: conf.c: chown_mapped_root: 3649 Error stat /home/karma/.local/share/lxc/test/delta0
> > > > Created container test as snapshot of ct02
> > > > lxc_container: lxccontainer.c: copy_file: 2303 copy destination /home/karma/.local/share/lxc/test/lxc_rdepends exists
> > > > Created container test as snapshot of ct02
> > > > $ find overlayfs\:/
> > > > overlayfs:/
> > > > overlayfs:/home
> > > > overlayfs:/home/karma
> > > > overlayfs:/home/karma/.local
> > > > overlayfs:/home/karma/.local/share
> > > > overlayfs:/home/karma/.local/share/lxc
> > > > overlayfs:/home/karma/.local/share/lxc/ct01
> > > > overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:
> > > > overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:/home
> > > > overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:/home/karma
> > > > overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:/home/karma/.local
> > > > overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:/home/karma/.local/share
> > > > overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:/home/karma/.local/share/lxc
> > > > overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:/home/karma/.local/share/lxc/test
> > > > overlayfs:/home/karma/.local/share/lxc/ct01/rootfs:/home/karma/.local/share/lxc/test/delta0
> > 
> > > Sorry, I'm not really following, and I guess I haven't been using overlayfs
> > > clones much lately.  Do you how to fix it, and can you send a patch?
> > 
> > This problem is also caused when clone by aufs. (between aufs/olfs)
> > 
> > This problem is caused by passing invalid argument as bdev *new to
> > (aufs|overlayfs)_clonepath.
> > 
> > I don't understand your patch edf7734 well. But how about revert a
> > part of the commit edf7734? as following:
> > 

> Hm.  I see.  Ok, then we will have to fix the 'dir' case by actually
> creating des if it doesn't exist.  Else in the case of

> lxc-clone -o x1 -n x2

> where x1's config has

> lxc.rootfs = /var/lib/lxc/x1/x

> the clone will fail again, because dir_mount() tries to mount on a
> nonexistant directory.  Can you send the patch to fix that?

Oh! OK, I understand.

How about like this?

---
 src/lxc/bdev.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
index ae5c77c..b303e00 100644
--- a/src/lxc/bdev.c
+++ b/src/lxc/bdev.c
@@ -3328,6 +3328,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
        const char *oldname = c0->name;
        const char *oldpath = c0->config_path;
        struct rsync_data data;
+       char *rootfs;
 
        /* if the container name doesn't show up in the rootfs path, then
         * we don't know how to come up with a new name
@@ -3338,12 +3339,30 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
                return NULL;
        }
 
-       orig = bdev_init(c0->lxc_conf, src, src, NULL);
+       orig = bdev_init(c0->lxc_conf, src, NULL, NULL);
        if (!orig) {
                ERROR("failed to detect blockdev type for %s", src);
                return NULL;
        }
 
+       if (!orig->dest) {
+               int ret;
+               orig->dest = malloc(MAXPATHLEN);
+               if (!orig->dest) {
+                       ERROR("out of memory");
+                       bdev_put(orig);
+                       return NULL;
+               }
+               rootfs = strrchr(orig->src, '/');
+               rootfs++;
+               ret = snprintf(orig->dest, MAXPATHLEN, "%s/%s/%s", oldpath, oldname, rootfs);
+               if (ret < 0 || ret >= MAXPATHLEN) {
+                       ERROR("rootfs path too long");
+                       bdev_put(orig);
+                       return NULL;
+               }
+       }
+
        /*
         * special case for snapshot - if caller requested maybe_snapshot and
         * keepbdevtype and backing store is directory, then proceed with a copy
-- 
2.1.1


More information about the lxc-devel mailing list