xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v4 2/4] libxl: add libxl__xs_path_cleanup
Date: Thu, 10 May 2012 12:28:30 +0100	[thread overview]
Message-ID: <1336649312-11198-3-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1336649312-11198-1-git-send-email-roger.pau@citrix.com>

Add a function which behaves like "xenstore-rm -t", and which will be
used to
clean xenstore after unplug since we will be no longer executing
xen-hotplug-cleanup script, that used to do that for us.

Changes since v3:

 * Better error checking and function description.

Changes since v2:

 * Moved the function to libxl_xshelp.c and added the prototype to
   libxl_internal.h.

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
 tools/libxl/libxl_internal.h |    7 +++++++
 tools/libxl/libxl_xshelp.c   |   30 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 9ab76f8..fc2024d 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -494,6 +494,13 @@ _hidden bool libxl__xs_mkdir(libxl__gc *gc, xs_transaction_t t,
 
 _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid);
 
+/*
+ * This is a recursive delete, from top to bottom. What this function does
+ * is remove empty folders that contained the deleted entry.
+ *
+ * It mimics xenstore-rm -t behaviour.
+ */
+_hidden int libxl__xs_path_cleanup(libxl__gc *gc, char *user_path);
 
 /*
  * Event generation functions provided by the libxl event core to the
diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c
index 3ea8d08..7339236 100644
--- a/tools/libxl/libxl_xshelp.c
+++ b/tools/libxl/libxl_xshelp.c
@@ -135,6 +135,36 @@ char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid)
     return s;
 }
 
+int libxl__xs_path_cleanup(libxl__gc *gc, char *user_path)
+{
+    unsigned int nb = 0;
+    char *path, *last;
+
+    if (!user_path) {
+        LOGE(ERROR, "null path provided");
+        return ERROR_FAIL;
+    }
+
+    path = libxl__strdup(gc, user_path);
+    xs_rm(CTX->xsh, XBT_NULL, path);
+
+    for (last = strrchr(path, '/'); last != NULL; last = strrchr(path, '/')) {
+        *last = '\0';
+
+        if (!strlen(path)) break;
+
+        if (!libxl__xs_directory(gc, XBT_NULL, path, &nb)) {
+            LOG(DEBUG, "failed to read directory contents of %s", path);
+            return ERROR_FAIL;
+        }
+
+        if (nb == 0) {
+            xs_rm(CTX->xsh, XBT_NULL, path);
+        }
+    }
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
-- 
1.7.7.5 (Apple Git-26)

  parent reply	other threads:[~2012-05-10 11:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10 11:28 [PATCH v4 0/4] libxl: call hotplug scripts from libxl Roger Pau Monne
2012-05-10 11:28 ` [PATCH v4 1/4] libxl: pass env vars to libxl__exec Roger Pau Monne
2012-05-10 16:03   ` Ian Jackson
2012-05-10 11:28 ` Roger Pau Monne [this message]
2012-05-10 16:05   ` [PATCH v4 2/4] libxl: add libxl__xs_path_cleanup Ian Jackson
2012-05-10 11:28 ` [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd Roger Pau Monne
2012-05-10 16:30   ` Ian Jackson
2012-05-14 12:38     ` Roger Pau Monne
2012-05-14 12:51       ` Ian Campbell
2012-05-14 13:30         ` Roger Pau Monne
2012-05-14 14:14         ` Ian Jackson
2012-05-14 14:20           ` Roger Pau Monne
2012-05-14 14:12       ` Ian Jackson
2012-05-10 11:28 ` [PATCH v4 4/4] libxl: call hotplug scripts from libxl for vif Roger Pau Monne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336649312-11198-3-git-send-email-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).