From: Serge Hallyn Date: Thu, 2 May 2013 04:37:05 +0000 (-0500) Subject: clone: a few fixes X-Git-Tag: lxc-1.0.0.alpha1~1^2~240 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=375c2258b24b233832c9ec43ab9c7b3f5dce25fb;p=thirdparty%2Flxc.git clone: a few fixes 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 --- diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c index 1de302f17..940891874 100644 --- a/src/lxc/bdev.c +++ b/src/lxc/bdev.c @@ -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; diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 10f188ea1..452323ca1 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -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; }