[Lxc-users] lxc-clone -s -B lvm, deletes original lv if no space left!

Serge Hallyn serge.hallyn at ubuntu.com
Mon Jun 17 19:43:39 UTC 2013


Quoting zoolook (nbensa+lxcusers at gmail.com):
> Hello,
> 
> this is one is weird. lxc-clone removes the original volume if there's
> no space to create a snapshot for the clone

D'oh, I'd believe it, yeah.  How have I not run into this?

Haven't tested, but the following should fix it:

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 0a3bd65..fe16f9d 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -1865,6 +1865,7 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
        int ret;
        const char *n, *l;
        FILE *fout;
+       int storage_copied = 0;
 
        if (!c || !c->is_defined(c))
                return NULL;
@@ -1944,6 +1945,7 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
        if (ret < 0)
                goto out;
 
+       storage_copied = 1;
        if (!c2->save_config(c2, NULL))
                goto out;
 
@@ -1957,6 +1959,11 @@ struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
 out:
        container_mem_unlock(c);
        if (c2) {
+               if (!storage_copied) {
+                       // Make sure we don't delete the original container's
+                       // rootfs when we abort.
+                       c->lxc_conf->rootfs.path = NULL;
+               }
                c2->destroy(c2);
                lxc_container_put(c2);
        }





More information about the lxc-users mailing list