[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 07 of 29 RFC] libxl: perform xenstore device cleanup from libxl
# HG changeset patch # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> # Date 1328176485 -3600 # Node ID 7b7a3fb7c90a2a08da7348075ba4589d4f2cc19b # Parent 2c5bf4967eb769c69de665fc84a4d3c0d87d3440 libxl: perform xenstore device cleanup from libxl Perform cleanup of xenstore device entries in libxl, instead of relying on xen-hotplug-cleanup script. Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> diff -r 2c5bf4967eb7 -r 7b7a3fb7c90a tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Sat Jan 14 19:04:48 2012 +0100 +++ b/tools/libxl/libxl_device.c Thu Feb 02 10:54:45 2012 +0100 @@ -406,6 +406,28 @@ start: return rc; } +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; +} + /* * Handler function for device destruction to be passed to * libxl__wait_for_device_state @@ -413,14 +435,26 @@ start: static int destroy_device(libxl__gc *gc, char **l1, char *state) { libxl_ctx *ctx = libxl__gc_owner(gc); + libxl__device dev; + int rc = -1; xs_unwatch(ctx->xsh, l1[0], l1[1]); - xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]); + + rc = libxl__parse_backend_path(gc, l1[0], &dev); + if (rc < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + "failed to generate device from backend path %s", + l1[0]); + goto out; + } + + libxl__xs_path_cleanup(gc, libxl__device_backend_path(gc, &dev)); LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Destroyed device backend at %s", l1[XS_WATCH_TOKEN]); - - return 0; + rc = 0; +out: + return rc; } /* @@ -446,7 +480,7 @@ retry_transaction: if (atoi(state) != 4) { xs_transaction_end(ctx->xsh, t, 0); libxl__device_destroy_tapdisk(gc, be_path); - xs_rm(ctx->xsh, XBT_NULL, be_path); + libxl__xs_path_cleanup(gc, be_path); goto out; } @@ -483,12 +517,11 @@ out: int libxl__device_destroy(libxl__gc *gc, libxl__device *dev) { - libxl_ctx *ctx = libxl__gc_owner(gc); char *be_path = libxl__device_backend_path(gc, dev); char *fe_path = libxl__device_frontend_path(gc, dev); - xs_rm(ctx->xsh, XBT_NULL, be_path); - xs_rm(ctx->xsh, XBT_NULL, fe_path); + libxl__xs_path_cleanup(gc, be_path); + libxl__xs_path_cleanup(gc, fe_path); libxl__device_destroy_tapdisk(gc, be_path); _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |