From: Christian Brauner Date: Sun, 16 Dec 2018 17:40:22 +0000 (+0100) Subject: storage: do not destroy pre-existing rootfs X-Git-Tag: lxc-3.2.0~197^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92fa4347d7e13b586e11494201607083751bb6d3;p=thirdparty%2Flxc.git storage: do not destroy pre-existing rootfs Closes #2752. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index a7f29838a..334cca9e6 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -1796,7 +1796,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t, int partial_fd; mode_t mask; pid_t pid; - bool ret = false; + bool ret = false, rootfs_managed = true; char *tpath = NULL; if (!c) @@ -1832,6 +1832,9 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t, if (!create_container_dir(c)) goto free_tpath; + if (c->lxc_conf->rootfs.path) + rootfs_managed = false; + /* 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 is accessible @@ -1938,8 +1941,18 @@ out_unlock: remove_partial(c, partial_fd); 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); + c->lxc_conf->rootfs.managed = reset_managed; + } free_tpath: free(tpath);