From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: Re: [PATCH v3 2/5] libxl: add libxl__xs_path_cleanup Date: Mon, 23 Apr 2012 17:52:25 +0100 Message-ID: <20373.35017.147406.379559@mariner.uk.xensource.com> References: <1334928211-29856-1-git-send-email-roger.pau@citrix.com> <1334928211-29856-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: <1334928211-29856-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 Roger Pau Monne writes ("[Xen-devel] [PATCH v3 2/5] libxl: add libxl__xs_path_cleanup"): > 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; > } > > - Unrelated whitespace change. > +/* > + * 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); I think, following my confusion, that this needs some better documentation comment. > 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, '/')) { If the path is relative, this won't work correctly. Also this whole thing needs to take place in a transaction, or it is racy. Probably a transaction supplied by the caller, in which case you should assert it. > + *last = '\0'; > + if (!libxl__xs_directory(gc, XBT_NULL, path, &nb)) > + continue; If this fails, it should be a fatal error; we should not just blunder on. Ian.