storage: do not destroy pre-existing rootfs

Closes #2752. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 8465a7f4
...@@ -1796,7 +1796,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t, ...@@ -1796,7 +1796,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
int partial_fd; int partial_fd;
mode_t mask; mode_t mask;
pid_t pid; pid_t pid;
bool ret = false; bool ret = false, rootfs_managed = true;
char *tpath = NULL; char *tpath = NULL;
if (!c) if (!c)
...@@ -1832,6 +1832,9 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t, ...@@ -1832,6 +1832,9 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
if (!create_container_dir(c)) if (!create_container_dir(c))
goto free_tpath; goto free_tpath;
if (c->lxc_conf->rootfs.path)
rootfs_managed = false;
/* If both template and rootfs.path are set, template is setup as /* If both template and rootfs.path are set, template is setup as
* rootfs.path. The container is already created if we have a config and * rootfs.path. The container is already created if we have a config and
* rootfs.path is accessible * rootfs.path is accessible
...@@ -1938,8 +1941,18 @@ out_unlock: ...@@ -1938,8 +1941,18 @@ out_unlock:
remove_partial(c, partial_fd); remove_partial(c, partial_fd);
out: out:
if (!ret) if (!ret) {
bool reset_managed = c->lxc_conf->rootfs.managed;
/*
* Ensure that we don't destroy storage we didn't create
* ourselves.
*/
if (!rootfs_managed)
c->lxc_conf->rootfs.managed = false;
container_destroy(c, NULL); container_destroy(c, NULL);
c->lxc_conf->rootfs.managed = reset_managed;
}
free_tpath: free_tpath:
free(tpath); free(tpath);
......
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