]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
clone: a few fixes
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 2 May 2013 04:37:05 +0000 (23:37 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 2 May 2013 13:31:07 +0000 (08:31 -0500)
clean up error case in clone, which in particular could cause double
lxc_container_put(c2)

for overlayfs, handle (with error message) all bdev types.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/bdev.c
src/lxc/lxccontainer.c

index 1de302f17362bd490e5dca5ea3552761ec676256..9408918742285de8290675815daa2ed93159dd92 100644 (file)
@@ -1186,11 +1186,6 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
                free(delta);
                if (ret < 0 || ret >= len)
                        return -ENOMEM;
-       } else if (strcmp(orig->type, "lvm") == 0) {
-               ERROR("overlayfs clone of lvm container is not yet supported");
-               // Note, supporting this will require overlayfs_mount supporting
-               // mounting of the underlay.  No big deal, just needs to be done.
-               return -1;
        } else if (strcmp(orig->type, "overlayfs") == 0) {
                // What exactly do we want to do here?
                // I think we want to use the original lowerdir, with a
@@ -1228,6 +1223,12 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
                free(ndelta);
                if (ret < 0 || ret >= len)
                        return -ENOMEM;
+       } else {
+               ERROR("overlayfs clone of %s container is not yet supported",
+                       orig->type);
+               // Note, supporting this will require overlayfs_mount supporting
+               // mounting of the underlay.  No big deal, just needs to be done.
+               return -1;
        }
 
        return 0;
index 10f188ea1621e4f95f08390a7b96f3fb3fc46c86..452323ca1268a345a67cec8008418a88c3018bb7 100644 (file)
@@ -1477,7 +1477,7 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
        }
 
        c2 = lxc_container_new(n, l);
-       if (!c) {
+       if (!c2) {
                ERROR("clone: failed to create new container (%s %s)", n, l);
                goto out;
        }
@@ -1487,16 +1487,12 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
                ret = copyhooks(c, c2);
                if (ret < 0) {
                        ERROR("error copying hooks");
-                       c2->destroy(c2);
-                       lxc_container_put(c2);
                        goto out;
                }
        }
 
        if (copy_fstab(c, c2) < 0) {
                ERROR("error copying fstab");
-               c2->destroy(c2);
-               lxc_container_put(c2);
                goto out;
        }
 
@@ -1506,23 +1502,14 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
 
        // copy/snapshot rootfs's
        ret = copy_storage(c, c2, bdevtype, flags, bdevdata, newsize);
-       if (ret < 0) {
-               c2->destroy(c2);
-               lxc_container_put(c2);
+       if (ret < 0)
                goto out;
-       }
 
-       if (!c2->save_config(c2, NULL)) {
-               c2->destroy(c2);
-               lxc_container_put(c2);
+       if (!c2->save_config(c2, NULL))
                goto out;
-       }
 
-       if (clone_update_rootfs(c2, flags) < 0) {
-               //c2->destroy(c2);
-               lxc_container_put(c2);
+       if (clone_update_rootfs(c2, flags) < 0)
                goto out;
-       }
 
        // TODO: update c's lxc.snapshot = count
        lxcunlock(c->privlock);
@@ -1530,8 +1517,10 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
 
 out:
        lxcunlock(c->privlock);
-       if (c2)
+       if (c2) {
+               c2->destroy(c2);
                lxc_container_put(c2);
+       }
 
        return NULL;
 }