From 7e36f87e2560ede94f171f14b6be1cfd5498c0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=2E=C3=87a=C4=9Flar=20Onur?= Date: Sat, 24 May 2014 22:19:06 -0400 Subject: [PATCH] destroy the original container after making sure the snapshot exists (fixes #224) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: S.Çağlar Onur Acked-by: Serge E. Hallyn --- src/lxc/lxccontainer.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index fdac43366..8e611c7d3 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -3083,13 +3083,7 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam if (!newname) newname = c->name; - if (strcmp(c->name, newname) == 0) { - if (!lxcapi_destroy(c)) { - ERROR("Could not destroy existing container %s", newname); - bdev_put(bdev); - return false; - } - } + ret = snprintf(clonelxcpath, MAXPATHLEN, "%ssnaps/%s", c->config_path, c->name); if (ret < 0 || ret >= MAXPATHLEN) { bdev_put(bdev); @@ -3105,6 +3099,15 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam return false; } + if (strcmp(c->name, newname) == 0) { + if (!lxcapi_destroy(c)) { + ERROR("Could not destroy existing container %s", newname); + lxc_container_put(snap); + bdev_put(bdev); + return false; + } + } + if (strcmp(bdev->type, "dir") != 0 && strcmp(bdev->type, "loop") != 0) flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT; rest = lxcapi_clone(snap, newname, c->config_path, flags,