Commit 176d9acb by Serge Hallyn

api_clone: don't remove storage if we haven't created it

In the best case we'll get errors about failing to remove it. In the worst case we'll be trying to delete the original container's rootfs. Reported-by: 's avatarzoolook <nbensa+lxcusers@gmail.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent ae3f8cf9
...@@ -1866,7 +1866,7 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname, ...@@ -1866,7 +1866,7 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
{ {
struct lxc_container *c2 = NULL; struct lxc_container *c2 = NULL;
char newpath[MAXPATHLEN]; char newpath[MAXPATHLEN];
int ret; int ret, storage_copied = 0;
const char *n, *l; const char *n, *l;
FILE *fout; FILE *fout;
...@@ -1948,6 +1948,10 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname, ...@@ -1948,6 +1948,10 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
if (ret < 0) if (ret < 0)
goto out; goto out;
// We've now successfully created c2's storage, so clear it out if we
// fail after this
storage_copied = 1;
if (!c2->save_config(c2, NULL)) if (!c2->save_config(c2, NULL))
goto out; goto out;
...@@ -1961,6 +1965,8 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname, ...@@ -1961,6 +1965,8 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
out: out:
container_mem_unlock(c); container_mem_unlock(c);
if (c2) { if (c2) {
if (!storage_copied)
c2->lxc_conf->rootfs.path = NULL;
c2->destroy(c2); c2->destroy(c2);
lxc_container_put(c2); lxc_container_put(c2);
} }
......
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