[lxc-devel] [PATCH] clone: a few fixes
Serge Hallyn
serge.hallyn at ubuntu.com
Thu May 2 04:37:05 UTC 2013
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 at ubuntu.com>
---
src/lxc/bdev.c | 11 ++++++-----
src/lxc/lxccontainer.c | 25 +++++++------------------
2 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
index 1de302f..9408918 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 10f188e..452323c 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;
}
--
1.7.9.5
More information about the lxc-devel
mailing list