From: Ian Campbell Subject: Re: [PATCH v2 2/5] libxl: add libxl__xs_path_cleanup Date: Wed, 18 Apr 2012 09:51:05 +0100 Message-ID: <1334739065.23948.149.camel@zakaz.uk.xensource.com> References: <1334677876-17704-1-git-send-email-roger.pau@citrix.com> <1334677876-17704-3-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: <1334677876-17704-3-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: Roger Pau Monne Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On Tue, 2012-04-17 at 16:51 +0100, Roger Pau Monne wrote: > 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. Can you put this in libxl_xshelp.c and a prototype in libxl_internal.h, please. Also it should include a comment in the header describing the function and what it does. > > Signed-off-by: Roger Pau Monne > --- > tools/libxl/libxl_device.c | 21 +++++++++++++++++++++ > 1 files changed, 21 insertions(+), 0 deletions(-) > > diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c > index c7e057d..fe4bcc6 100644 > --- a/tools/libxl/libxl_device.c > +++ b/tools/libxl/libxl_device.c > @@ -356,6 +356,27 @@ int libxl__device_disk_dev_number(const char *virtpath, int *pdisk, > return -1; > } > > +static 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; > +} > > typedef struct { > libxl__ao *ao;