]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Fix clone issues
authorKATOH Yasufumi <karma@jazz.email.ne.jp>
Wed, 5 Nov 2014 07:03:34 +0000 (16:03 +0900)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Wed, 5 Nov 2014 14:37:17 +0000 (15:37 +0100)
This commit fixes two issues at the time of clone:
* unnecessary directory is created when clone between overlayfs/aufs
* clone failed when the end of rootfs path is not "/rootfs"

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/bdev.c

index ae5c77c0755bcef9478080e3a70e546c0551f958..c95f3f06dbeaee041e29edf0c073928074d88aa6 100644 (file)
@@ -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,35 @@ 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, '/');
+               if (!rootfs) {
+                       ERROR("invalid rootfs path");
+                       bdev_put(orig);
+                       return NULL;
+               }
+               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