[lxc-devel] [lxc/master] storage: do not destroy pre-existing rootfs
brauner on Github
lxc-bot at linuxcontainers.org
Sun Dec 16 17:41:37 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 381 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181216/7fd608cb/attachment.bin>
-------------- next part --------------
From 92fa4347d7e13b586e11494201607083751bb6d3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 16 Dec 2018 18:40:22 +0100
Subject: [PATCH] storage: do not destroy pre-existing rootfs
Closes #2752.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/lxccontainer.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
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 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
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);
More information about the lxc-devel
mailing list