[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 06 of 13 RFC] libxl: perform xenstore device cleanup from libxl



# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1326728389 -3600
# Node ID f7b6d7cd98202be1ca642949c4722c5e6da75540
# Parent  0b45289e57b9fbeee3780f24a6398f7911a3320c
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 0b45289e57b9 -r f7b6d7cd9820 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        Mon Jan 16 16:39:49 2012 +0100
@@ -414,6 +414,28 @@ start:
     return rc;
 }
 
+int libxl__device_cleanup(libxl__gc *gc, libxl__device *dev) {
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    char *path = libxl__device_backend_path(gc, dev);
+    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
@@ -421,14 +443,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__device_cleanup(gc, &dev);
     LIBXL__LOG(ctx, LIBXL__LOG_DEBUG,
                "Destroyed device backend at %s",
                l1[XS_WATCH_TOKEN]);
-
-    return 0;
+    rc = 0;
+out:
+    return rc;
 }
 
 /*
@@ -454,7 +488,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__device_cleanup(gc, dev);
         goto out;
     }
 
@@ -495,7 +529,7 @@ int libxl__device_destroy(libxl__gc *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);
+    libxl__device_cleanup(gc, dev);
     xs_rm(ctx->xsh, XBT_NULL, fe_path);
 
     libxl__device_destroy_tapdisk(gc, be_path);
diff -r 0b45289e57b9 -r f7b6d7cd9820 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Sat Jan 14 19:04:48 2012 +0100
+++ b/tools/libxl/libxl_internal.h      Mon Jan 16 16:39:49 2012 +0100
@@ -306,6 +306,11 @@ _hidden int libxl__wait_for_device_state
                                          libxl__device_state_handler handler);
 
 /*
+ * libxl__device_cleanup - clean xenstore entries recursively for a given 
device
+ */
+_hidden int libxl__device_cleanup(libxl__gc *gc, libxl__device *dev);
+
+/*
  * libxl__try_phy_backend - Check if there's support for the passed
  * type of file using the PHY backend
  * st_mode: mode_t of the file, as returned by stat function

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.