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

[Xen-devel] [PATCH 04 of 13 RFC] libxl: wait for devices to initialize upon addition to the domain



# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1326564288 -3600
# Node ID 4ae3d8e89ed8b491d342ebb8877386f9b72e1c06
# Parent  74c7175a9bcfb48e4db3ad9e92bdb5eaf4f05c31
libxl: wait for devices to initialize upon addition to the domain.

Block waiting for devices (with backend PHY or TAP) to initialize
(switch to state 2). This is necessary because we need to call the
hotplug scripts when state is 2, otherwise the execution fails. Make
use of the newly introduced function libxl__wait_for_device_state.

Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>

diff -r 74c7175a9bcf -r 4ae3d8e89ed8 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Sat Jan 14 19:04:48 2012 +0100
+++ b/tools/libxl/libxl.c       Sat Jan 14 19:04:48 2012 +0100
@@ -1013,6 +1013,8 @@ int libxl_device_disk_add(libxl_ctx *ctx
     flexarray_t *front;
     flexarray_t *back;
     char *dev;
+    char *be_path, *state_path, *state;
+    struct timeval tv;
     libxl__device device;
     int major, minor, rc;
 
@@ -1117,6 +1119,27 @@ int libxl_device_disk_add(libxl_ctx *ctx
                              libxl__xs_kvs_of_flexarray(gc, back, back->count),
                              libxl__xs_kvs_of_flexarray(gc, front, 
front->count));
 
+    if (disk->backend == LIBXL_DISK_BACKEND_PHY ||
+        disk->backend == LIBXL_DISK_BACKEND_TAP) {
+        be_path = libxl__device_backend_path(gc, &device);
+        state_path = libxl__sprintf(gc, "%s/state", be_path);
+        state = libxl__xs_read(gc, XBT_NULL, state_path);
+
+        if (atoi(state) != XenbusStateInitWait) {
+            xs_watch(ctx->xsh, state_path, be_path);
+            tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
+            tv.tv_usec = 0;
+            rc = libxl__wait_for_device_state(gc, &tv, XenbusStateInitWait,
+                                              NULL);
+            xs_unwatch(ctx->xsh, state_path, be_path);
+            if (rc < 0) {
+                LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+                           "unable to initialize disk device: %s",
+                           disk->pdev_path);
+                goto out_free;
+            }
+        }
+    }
     rc = 0;
 
 out_free:
@@ -1492,6 +1515,8 @@ int libxl_device_nic_add(libxl_ctx *ctx,
     flexarray_t *back;
     libxl__device device;
     char *dompath, **l;
+    char *be_path, *state_path, *state;
+    struct timeval tv;
     unsigned int nb, rc;
 
     front = flexarray_make(16, 1);
@@ -1566,8 +1591,25 @@ int libxl_device_nic_add(libxl_ctx *ctx,
                              libxl__xs_kvs_of_flexarray(gc, back, back->count),
                              libxl__xs_kvs_of_flexarray(gc, front, 
front->count));
 
-    /* FIXME: wait for plug */
+    be_path = libxl__device_backend_path(gc, &device);
+    state_path = libxl__sprintf(gc, "%s/state", be_path);
+    state = libxl__xs_read(gc, XBT_NULL, state_path);
+
+    if (atoi(state) != XenbusStateInitWait) {
+        xs_watch(ctx->xsh, state_path, be_path);
+        tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
+        tv.tv_usec = 0;
+        rc = libxl__wait_for_device_state(gc, &tv, XenbusStateInitWait, NULL);
+        xs_unwatch(ctx->xsh, state_path, be_path);
+        if (rc < 0) {
+            LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+                       "unable to initialize nic device: %s",
+                       nic->ifname);
+            goto out_free;
+        }
+    }
     rc = 0;
+
 out_free:
     flexarray_free(back);
     flexarray_free(front);

_______________________________________________
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®.