WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 01/14]: libxenlight, refactore device destroy code

To: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 01/14]: libxenlight, refactore device destroy code
From: Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxxxx>
Date: Mon, 30 Nov 2009 14:09:40 -0500
Cc:
Delivery-date: Mon, 30 Nov 2009 11:10:18 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.23 (X11/20090817)
Refactor libxl device destroy code. Abstract function
waiting for the watch on the state node to fire.
Create a generic device delete function.

Signed-off-by: Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxxxx>

# HG changeset patch
# User Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxxxx>
# Date 1259251414 18000
# Node ID 67d997a4d4c87d739b4d29b301a4ba727563ca9e
# Parent  fc28f6d31728477c20d86ae8a43600f8fc0f6d0a
Refactor libxl device destroy code. Abstract function
waiting for the watch on the state node to fire. 
Create a generic device delete function.

Signed-off-by: Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxxxx>

diff -r fc28f6d31728 -r 67d997a4d4c8 libxl_device.c
--- a/libxl_device.c
+++ b/libxl_device.c
@@ -202,14 +202,44 @@ retry_transaction:
         return 0;
 }
 
+int wait_for_dev_destroy(struct libxl_ctx *ctx)
+{
+    int nfds, rc;
+    unsigned int n;
+    fd_set rfds;
+    struct timeval tv;
+    char **l1 = NULL;
+
+    rc = 1;
+    nfds = xs_fileno(ctx->xsh) + 1;
+    /* Linux-ism */
+    tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
+    tv.tv_usec = 0;
+    FD_ZERO(&rfds);
+    FD_SET(xs_fileno(ctx->xsh), &rfds);
+    if (select(nfds, &rfds, NULL, NULL, &tv) > 0) {
+        l1 = xs_read_watch(ctx->xsh, &n);
+        if (l1 != NULL) {
+            char *state = libxl_xs_read(ctx, XBT_NULL, l1[XS_WATCH_PATH]);
+            if (!state || atoi(state) == 6) {
+                xs_unwatch(ctx->xsh, l1[0], l1[1]);
+                xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]);
+                XL_LOG(ctx, XL_LOG_DEBUG, "Destroyed device backend at %s", 
l1[XS_WATCH_TOKEN]);
+                rc = 0;
+            }
+            libxl_free(ctx, state);
+            free(l1);
+        }
+    }
+    return rc;
+}
+
 int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force)
 {
     char *path, *be_path, *fe_path;
     unsigned int num1, num2;
     char **l1 = NULL, **l2 = NULL;
-    int i, j, nfds, n = 0, n_watches = 0;
-    fd_set rfds;
-    struct timeval tv;
+    int i, j, n = 0, n_watches = 0;
     flexarray_t *toremove;
 
     toremove = flexarray_make(16, 1);
@@ -237,27 +267,12 @@ int libxl_devices_destroy(struct libxl_c
         }
     }
     if (!force) {
-        nfds = xs_fileno(ctx->xsh) + 1;
-        /* Linux-ism */
-        tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
-        tv.tv_usec = 0;
-        while (n_watches > 0 && tv.tv_sec > 0) {
-            FD_ZERO(&rfds);
-            FD_SET(xs_fileno(ctx->xsh), &rfds);
-            if (select(nfds, &rfds, NULL, NULL, &tv) > 0) {
-                l1 = xs_read_watch(ctx->xsh, &num1);
-                if (l1 != NULL) {
-                    char *state = libxl_xs_read(ctx, XBT_NULL, l1[0]);
-                    if (!state || atoi(state) == 6) {
-                        xs_unwatch(ctx->xsh, l1[0], l1[1]);
-                        xs_rm(ctx->xsh, XBT_NULL, l1[1]);
-                        XL_LOG(ctx, XL_LOG_DEBUG, "Destroyed device backend at 
%s", l1[1]);
-                        n_watches--;
-                    }
-                    free(l1);
-                }
-            } else
+        while (n_watches > 0) {
+            if (wait_for_dev_destroy(ctx)) {
                 break;
+            } else {
+                n_watches--;
+            }
         }
     }
     for (i = 0; i < n; i++) {
@@ -268,6 +283,38 @@ int libxl_devices_destroy(struct libxl_c
     return 0;
 }
 
+int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait)
+{
+    char *dom_path_backend, *backend_path, *hotplug_path;
+    int rc;
+
+    /* Create strings */
+    dom_path_backend    = libxl_xs_get_dompath(ctx, dev->backend_domid);
+    backend_path        = libxl_sprintf(ctx, "%s/backend/%s/%u/%d",
+                                    dom_path_backend, 
+                                    string_of_kinds[dev->backend_kind], 
+                                    dev->domid, dev->devid);
+    hotplug_path        = libxl_sprintf(ctx, "/xapi/%d/hotplug/%s/%d",
+                                    dev->domid,
+                                    string_of_kinds[dev->kind], 
+                                    dev->devid);
+    libxl_free(ctx, dom_path_backend);
+
+    rc = libxl_device_destroy(ctx, backend_path, !wait);
+    if (rc == -1) {
+        return ERROR_FAIL;
+    }
+
+    if (wait) {
+        (void)wait_for_dev_destroy(ctx);
+    }
+
+    xs_rm(ctx->xsh, XBT_NULL, hotplug_path);
+    libxl_free(ctx, hotplug_path);
+    libxl_free(ctx, backend_path);
+    return 0;
+}
+
 int libxl_device_pci_flr(struct libxl_ctx *ctx, unsigned int domain, unsigned 
int bus,
                          unsigned int dev, unsigned int func)
 {
diff -r fc28f6d31728 -r 67d997a4d4c8 libxl_internal.h
--- a/libxl_internal.h
+++ b/libxl_internal.h
@@ -105,6 +105,7 @@ int device_disk_dev_number(char *virtpat
 
 int libxl_device_generic_add(struct libxl_ctx *ctx, libxl_device *device,
                              char **bents, char **fents);
+int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait);
 int libxl_device_destroy(struct libxl_ctx *ctx, char *be_path, int force);
 int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);
 int libxl_wait_for_device_model(struct libxl_ctx *ctx,
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH 01/14]: libxenlight, refactore device destroy code, Andres Lagar-Cavilla <=