Signed-off-by: S.Çağlar Onur <cag...@10ur.org>
---
 src/lxc/lxccontainer.c | 32 ++++++++++++++++++++++++++++++++
 src/lxc/lxccontainer.h |  7 +++++++
 2 files changed, 39 insertions(+)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 6f97879..73a71ce 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -2609,6 +2609,37 @@ static bool lxcapi_snapshot_restore(struct lxc_container 
*c, char *snapname, cha
        return b;
 }
 
+static bool lxcapi_snapshot_destroy(struct lxc_container *c, char *snapname)
+{
+       int ret;
+       char clonelxcpath[MAXPATHLEN];
+       struct lxc_container *snap = NULL;
+
+       if (!c || !c->name || !c->config_path)
+               return false;
+
+       ret = snprintf(clonelxcpath, MAXPATHLEN, "%ssnaps/%s", c->config_path, 
c->name);
+       if (ret < 0 || ret >= MAXPATHLEN)
+               goto err;
+
+       snap = lxc_container_new(snapname, clonelxcpath);
+       if (!snap || !lxcapi_is_defined(snap)) {
+               ERROR("Could not find snapshot %s", snapname);
+               goto err;
+       }
+
+       if (!lxcapi_destroy(snap)) {
+               ERROR("Could not destroy snapshot %s", snapname);
+               goto err;
+       }
+
+       return true;
+err:
+       if (snap)
+               lxc_container_put(snap);
+       return false;
+}
+
 static bool lxcapi_may_control(struct lxc_container *c)
 {
        return lxc_try_cmd(c->name, c->config_path) == 0;
@@ -2733,6 +2764,7 @@ struct lxc_container *lxc_container_new(const char *name, 
const char *configpath
        c->snapshot = lxcapi_snapshot;
        c->snapshot_list = lxcapi_snapshot_list;
        c->snapshot_restore = lxcapi_snapshot_restore;
+       c->snapshot_destroy = lxcapi_snapshot_destroy;
        c->may_control = lxcapi_may_control;
 
        /* we'll allow the caller to update these later */
diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
index 5901066..adcac6a 100644
--- a/src/lxc/lxccontainer.h
+++ b/src/lxc/lxccontainer.h
@@ -225,6 +225,13 @@ struct lxc_container {
        bool (*snapshot_restore)(struct lxc_container *c, char *snapname, char 
*newname);
 
        /*
+        * snapshot_destroy() will destroy the given snapshot of c
+        *
+        * Returns true on success, false on failure.
+        */
+       bool (*snapshot_destroy)(struct lxc_container *c, char *snapname);
+
+       /*
         * Return false if there is a control socket for the container monitor,
         * and the caller may not access it.  Return true otherwise.
         */
-- 
1.8.1.2


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to