From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roger Pau Monne Subject: Re: [PATCH v3 2/5] libxl: add libxl__xs_path_cleanup Date: Wed, 25 Apr 2012 14:19:45 +0100 Message-ID: <4F97F9F1.4010003@citrix.com> References: <1334928211-29856-1-git-send-email-roger.pau@citrix.com> <1334928211-29856-3-git-send-email-roger.pau@citrix.com> <20373.35017.147406.379559@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20373.35017.147406.379559@mariner.uk.xensource.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: Ian Jackson Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org Ian Jackson escribi=F3: > 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 *virtpa= th, int *pdisk, >> return -1; >> } >> >> - > > Unrelated whitespace change. Done. >> +/* >> + * 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. Ok, I've tried to change to something more self-explaining. >> 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 =3D libxl__gc_owner(gc); >> + unsigned int nb =3D 0; >> + char *last; >> + >> + if (!path) >> + return 0; >> + >> + xs_rm(ctx->xsh, XBT_NULL, path); >> + >> + for (last =3D strrchr(path, '/'); last !=3D NULL; last =3D strrchr(= path, '/')) { > > If the path is relative, this won't work correctly. Are you sure? From what I've tested it seems to work ok. > > 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. Ok, will add another lock. >> + *last =3D '\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.