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

[Xen-devel] [RFC 7/7] libxl: Wait for QEMU startup in stubdomain



To ensure the QEMU instance in a stubdomain is running before we unpause
an HVM guest that relies on it for a device model, we do a xenstore wait
on QEMU's indiction that it is running.

Signed-off-by: Eric Shelton <eshelton@xxxxxxxxx>
---
 tools/libxl/libxl_dm.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index d03be4a..ad8d1dc 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -1361,6 +1361,39 @@ out:
     stubdom_pvqemu_cb(egc, &sdss->multidev, rc);
 }
 
+static void stub_dm_watch_event(libxl__egc *egc, libxl__xswait_state *xswa,
+                                int rc, const char *p)
+{
+    EGC_GC;
+    libxl__spawn_state *spawn = CONTAINER_OF(xswa, libxl__spawn_state, xswait);
+    libxl__dm_spawn_state *pvqemu =
+        CONTAINER_OF(spawn, libxl__dm_spawn_state, spawn);
+    libxl__stub_dm_spawn_state *sdss =
+        CONTAINER_OF(pvqemu, libxl__stub_dm_spawn_state, pvqemu);
+    uint32_t dm_domid = sdss->pvqemu.guest_domid;
+
+    if (rc) {
+        if (rc == ERROR_TIMEDOUT)
+           LIBXL__LOG(CTX, XTL_DEBUG, "%s: startup timed out", xswa->what);
+        if (dm_domid) {
+            sdss->dis.ao = sdss->dm.spawn.ao;
+            sdss->dis.domid = dm_domid;
+            sdss->dis.callback = spaw_stubdom_pvqemu_destroy_cb;
+            libxl__destroy_domid(egc, &sdss->dis);
+        }
+       return;
+    }
+
+    if (!p)
+        return;
+
+    if (strcmp(p, "running"))
+        return;
+
+    libxl__xswait_stop(gc, xswa);
+    sdss->callback(egc, &sdss->dm, rc);
+}
+
 static void stubdom_pvqemu_cb(libxl__egc *egc,
                               libxl__multidev *multidev,
                               int rc)
@@ -1368,12 +1401,24 @@ static void stubdom_pvqemu_cb(libxl__egc *egc,
     libxl__stub_dm_spawn_state *sdss = CONTAINER_OF(multidev, *sdss, multidev);
     STATE_AO_GC(sdss->dm.spawn.ao);
     uint32_t dm_domid = sdss->pvqemu.guest_domid;
+    libxl__xswait_state *xswait = &sdss->pvqemu.spawn.xswait;
 
     if (rc) {
         LOGE(ERROR, "error connecting nics devices");
         goto out;
     }
 
+    /* wait for PV stubdom QEMU instance to be ready */
+    libxl__xswait_init(xswait);
+    xswait->ao = sdss->dm.spawn.ao;
+    xswait->what = GCSPRINTF("stub domain %d startup", dm_domid);
+    xswait->path = GCSPRINTF("/local/domain/0/device-model/%d/state",
+                             sdss->dm.guest_domid);
+    xswait->timeout_ms = LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000;
+    xswait->callback = stub_dm_watch_event;
+    rc = libxl__xswait_start(gc, xswait);
+    if (rc) goto out;
+
     rc = libxl_domain_unpause(CTX, dm_domid);
     if (rc) goto out;
 
@@ -1387,7 +1432,6 @@ static void stubdom_pvqemu_cb(libxl__egc *egc,
             return;
         }
     }
-    sdss->callback(egc, &sdss->dm, rc);
 }
 
 static void spawn_stubdom_pvqemu_destroy_cb(libxl__egc *egc,
-- 
1.8.5.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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