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] libxenlight: use watch and select in libxl_wait_for_

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] libxenlight: use watch and select in libxl_wait_for_device_model
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Wed, 2 Dec 2009 14:55:41 +0000
Delivery-date: Wed, 02 Dec 2009 06:52:20 -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: Alpine 2.00 (DEB 1167 2008-08-23)
Hi all,
this patch reimplements libxl_wait_for_device_model using a xenstore
watch and a select loop.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>

---

diff -r 40077a808001 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Dec 02 12:20:05 2009 +0000
+++ b/tools/libxl/libxl.c       Wed Dec 02 12:20:26 2009 +0000
@@ -888,6 +888,7 @@
         *starting_r = libxl_calloc(ctx, sizeof(libxl_device_model_starting), 
1);
         if (!*starting_r) goto xit;
         p = *starting_r;
+        p->for_spawn = libxl_calloc(ctx, sizeof(struct libxl_spawn_starting), 
1);
     } else {
         p = &buf_starting;
         p->for_spawn = NULL;
diff -r 40077a808001 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Wed Dec 02 12:20:05 2009 +0000
+++ b/tools/libxl/libxl_device.c        Wed Dec 02 12:20:26 2009 +0000
@@ -297,31 +297,47 @@
 {
     char path[50];
     char *p;
-    int watchdog = 100;
     unsigned int len;
     int rc;
+    struct xs_handle *xsh;
+    int nfds;
+    fd_set rfds;
+    struct timeval tv;
+    unsigned int num;
+    char **l = NULL;
 
+    xsh = xs_daemon_open();
     snprintf(path, sizeof(path), "/local/domain/0/device-model/%d/state", 
domid);
-    while (watchdog > 0) {
-        p = xs_read(ctx->xsh, XBT_NULL, path, &len);
-        if (p == NULL) {
-            usleep(100000);
-            watchdog--;
-        } else {
-            if (state == NULL || !strcmp(state, p)) {
+    xs_watch(xsh, path, path);
+    tv.tv_sec = LIBXL_DEVICE_MODEL_START_TIMEOUT;
+    tv.tv_usec = 0;
+    nfds = xs_fileno(xsh) + 1;
+    while (tv.tv_sec > 0) {
+        FD_ZERO(&rfds);
+        FD_SET(xs_fileno(xsh), &rfds);
+        if (select(nfds, &rfds, NULL, NULL, &tv) > 0) {
+            l = xs_read_watch(xsh, &num);
+            if (l != NULL) {
+                free(l);
+                p = xs_read(xsh, XBT_NULL, path, &len);
+                if (!p)
+                    continue;
+                if (!state || !strcmp(state, p)) {
+                    free(p);
+                    xs_unwatch(xsh, path, path);
+                    xs_daemon_close(xsh);
+                    if (check_callback) {
+                        rc = check_callback(ctx, check_callback_userdata);
+                        if (rc) return rc;
+                    }
+                    return 0;
+                }
                 free(p);
-                return 0;
-            } else {
-                free(p);
-                usleep(100000);
-                watchdog--;
             }
         }
-        if (check_callback) {
-            rc = check_callback(ctx, check_callback_userdata);
-            if (rc) return rc;
-        }
     }
+    xs_unwatch(xsh, path, path);
+    xs_daemon_close(xsh);
     XL_LOG(ctx, XL_LOG_ERROR, "Device Model not ready");
     return -1;
 }
diff -r 40077a808001 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Wed Dec 02 12:20:05 2009 +0000
+++ b/tools/libxl/libxl_internal.h      Wed Dec 02 12:20:26 2009 +0000
@@ -28,6 +28,7 @@
 #include "libxl_utils.h"
 
 #define LIBXL_DESTROY_TIMEOUT 10
+#define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
 #define LIBXL_XENCONSOLE_LIMIT 1048576
 #define LIBXL_XENCONSOLE_PROTOCOL "vt100"
 #define QEMU_SIGNATURE "QemuDeviceModelRecord"

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] libxenlight: use watch and select in libxl_wait_for_device_model, Stefano Stabellini <=