]> git.proxmox.com Git - mirror_lxc.git/commitdiff
storage: do not destroy pre-existing rootfs
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 16 Dec 2018 17:40:22 +0000 (18:40 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 16 Dec 2018 17:40:22 +0000 (18:40 +0100)
Closes #2752.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxccontainer.c

index a7f29838aaaea34acd87c1512b51c0317d674a17..334cca9e61ef763df6ba43752145879658b2a1db 100644 (file)
@@ -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);