From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roger Pau Monne Subject: [PATCH v3 2/5] libxl: add libxl__xs_path_cleanup Date: Fri, 20 Apr 2012 14:23:28 +0100 Message-ID: <1334928211-29856-3-git-send-email-roger.pau@citrix.com> References: <1334928211-29856-1-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1334928211-29856-1-git-send-email-roger.pau@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Roger Pau Monne List-Id: xen-devel@lists.xenproject.org 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 v2: * Moved the function to libxl_xshelp.c and added the prototype to libxl_internal.h. Signed-off-by: Roger Pau Monne --- tools/libxl/libxl_device.c | 1 - tools/libxl/libxl_internal.h | 6 ++++++ tools/libxl/libxl_xshelp.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletions(-) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index c7e057d..36d58cd 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -356,7 +356,6 @@ int libxl__device_disk_dev_number(const char *virtpath, int *pdisk, return -1; } - typedef struct { libxl__ao *ao; libxl__ev_devstate ds; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 9e15f95..020810a 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -458,6 +458,12 @@ _hidden bool libxl__xs_mkdir(libxl__gc *gc, xs_transaction_t t, _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid); +/* + * Perfrom recursive cleanup of xenstore path, from top to bottom + * just like xenstore-rm -t + */ +_hidden int libxl__xs_path_cleanup(libxl__gc *gc, char *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..0b1b844 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -135,6 +135,28 @@ char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid) return s; } +int libxl__xs_path_cleanup(libxl__gc *gc, char *path) +{ + libxl_ctx *ctx = libxl__gc_owner(gc); + unsigned int nb = 0; + char *last; + + if (!path) + return 0; + + xs_rm(ctx->xsh, XBT_NULL, path); + + for (last = strrchr(path, '/'); last != NULL; last = strrchr(path, '/')) { + *last = '\0'; + if (!libxl__xs_directory(gc, XBT_NULL, path, &nb)) + continue; + if (nb == 0) { + xs_rm(ctx->xsh, XBT_NULL, path); + } + } + return 0; +} + /* * Local variables: * mode: C -- 1.7.7.5 (Apple Git-26)