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-changelog

[Xen-changelog] [xen-unstable] libxl: handle the return value of wait_fo

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: handle the return value of wait_for_dev_destroy select
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Wed, 02 Nov 2011 22:00:18 +0000
Delivery-date: Wed, 02 Nov 2011 15:02:19 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1320253564 0
# Node ID ac47cafe6776a364b92a15432b4016f37fce44ea
# Parent  2d741388060df5bd2545f38a25278fb9a7fbb127
libxl: handle the return value of wait_for_dev_destroy select

Handle the return value of the select call inside wait_for_dev_destroy
properly, and return 0 if a device is removed, or ERROR_* if a timeout
or error happened. Use the return value of wait_for_dev_destroy inside
libxl__device_remove to properly return from that function.

Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r 2d741388060d -r ac47cafe6776 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Nov 02 16:28:57 2011 +0000
+++ b/tools/libxl/libxl.h       Wed Nov 02 17:06:04 2011 +0000
@@ -221,6 +221,7 @@
     ERROR_INVAL = -6,
     ERROR_BADFAIL = -7,
     ERROR_GUEST_TIMEDOUT = -8,
+    ERROR_TIMEDOUT = -9,
 };
 
 #define LIBXL_VERSION 0
diff -r 2d741388060d -r ac47cafe6776 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Wed Nov 02 16:28:57 2011 +0000
+++ b/tools/libxl/libxl_device.c        Wed Nov 02 17:06:04 2011 +0000
@@ -367,6 +367,10 @@
     return -1;
 }
 
+/*
+ * Returns 0 if a device is removed, ERROR_* if an error
+ * or timeout occurred.
+ */
 static int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -375,22 +379,41 @@
     fd_set rfds;
     char **l1 = NULL;
 
+start:
     rc = 1;
     nfds = xs_fileno(ctx->xsh) + 1;
     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(gc, 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]);
-                LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Destroyed device backend at 
%s", l1[XS_WATCH_TOKEN]);
-                rc = 0;
+    switch (select(nfds, &rfds, NULL, NULL, tv)) {
+        case -1:
+            if (errno == EINTR)
+                goto start;
+            rc = ERROR_FAIL;
+            break;
+        case 0:
+            rc = ERROR_TIMEDOUT;
+            break;
+        default:
+            l1 = xs_read_watch(ctx->xsh, &n);
+            if (l1 != NULL) {
+                char *state = libxl__xs_read(gc, 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]);
+                    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG,
+                               "Destroyed device backend at %s",
+                               l1[XS_WATCH_TOKEN]);
+                    rc = 0;
+                } else {
+                    /* State is not "disconnected", continue waiting... */
+                    goto start;
+                }
+                free(l1);
+            } else {
+                rc = ERROR_FAIL;
             }
-            free(l1);
-        }
+            break;
     }
     return rc;
 }
@@ -436,7 +459,9 @@
         struct timeval tv;
         tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
         tv.tv_usec = 0;
-        (void)wait_for_dev_destroy(gc, &tv);
+        rc = wait_for_dev_destroy(gc, &tv);
+        if (rc < 0) /* an error or timeout occurred, clear watches */
+            xs_unwatch(ctx->xsh, state_path, be_path);
         xs_rm(ctx->xsh, XBT_NULL, libxl__device_frontend_path(gc, dev));
     } else {
         rc = 1; /* Caller must wait_for_dev_destroy */
@@ -542,7 +567,8 @@
         tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
         tv.tv_usec = 0;
         while (n_watches > 0) {
-            if (wait_for_dev_destroy(gc, &tv)) {
+            if (wait_for_dev_destroy(gc, &tv) < 0) {
+                /* function returned ERROR_* */
                 break;
             } else {
                 n_watches--;

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl: handle the return value of wait_for_dev_destroy select, Xen patchbot-unstable <=