Commit 375c2258 by Serge Hallyn

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: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent e0b0b533
...@@ -1186,11 +1186,6 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char ...@@ -1186,11 +1186,6 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
free(delta); free(delta);
if (ret < 0 || ret >= len) if (ret < 0 || ret >= len)
return -ENOMEM; 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) { } else if (strcmp(orig->type, "overlayfs") == 0) {
// What exactly do we want to do here? // What exactly do we want to do here?
// I think we want to use the original lowerdir, with a // 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 ...@@ -1228,6 +1223,12 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
free(ndelta); free(ndelta);
if (ret < 0 || ret >= len) if (ret < 0 || ret >= len)
return -ENOMEM; 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; return 0;
......
...@@ -1477,7 +1477,7 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname, ...@@ -1477,7 +1477,7 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
} }
c2 = lxc_container_new(n, l); c2 = lxc_container_new(n, l);
if (!c) { if (!c2) {
ERROR("clone: failed to create new container (%s %s)", n, l); ERROR("clone: failed to create new container (%s %s)", n, l);
goto out; goto out;
} }
...@@ -1487,16 +1487,12 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname, ...@@ -1487,16 +1487,12 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
ret = copyhooks(c, c2); ret = copyhooks(c, c2);
if (ret < 0) { if (ret < 0) {
ERROR("error copying hooks"); ERROR("error copying hooks");
c2->destroy(c2);
lxc_container_put(c2);
goto out; goto out;
} }
} }
if (copy_fstab(c, c2) < 0) { if (copy_fstab(c, c2) < 0) {
ERROR("error copying fstab"); ERROR("error copying fstab");
c2->destroy(c2);
lxc_container_put(c2);
goto out; goto out;
} }
...@@ -1506,23 +1502,14 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname, ...@@ -1506,23 +1502,14 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
// copy/snapshot rootfs's // copy/snapshot rootfs's
ret = copy_storage(c, c2, bdevtype, flags, bdevdata, newsize); ret = copy_storage(c, c2, bdevtype, flags, bdevdata, newsize);
if (ret < 0) { if (ret < 0)
c2->destroy(c2);
lxc_container_put(c2);
goto out; goto out;
}
if (!c2->save_config(c2, NULL)) { if (!c2->save_config(c2, NULL))
c2->destroy(c2);
lxc_container_put(c2);
goto out; goto out;
}
if (clone_update_rootfs(c2, flags) < 0) { if (clone_update_rootfs(c2, flags) < 0)
//c2->destroy(c2);
lxc_container_put(c2);
goto out; goto out;
}
// TODO: update c's lxc.snapshot = count // TODO: update c's lxc.snapshot = count
lxcunlock(c->privlock); lxcunlock(c->privlock);
...@@ -1530,8 +1517,10 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname, ...@@ -1530,8 +1517,10 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
out: out:
lxcunlock(c->privlock); lxcunlock(c->privlock);
if (c2) if (c2) {
c2->destroy(c2);
lxc_container_put(c2); lxc_container_put(c2);
}
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment