[Xen-devel] [XEN PATCH] libxl: wait for console path before firing console_available

Paweł Marczewski posted 1 patch 4 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/xen tags/patchew/7586792df0070ceeba874ba8f430dd7addb53305.1582128348.git.pawel@invisiblethingslab.com
There is a newer version of this series
tools/libxl/libxl_create.c   | 33 ++++++++++++++++++++++++++++++---
tools/libxl/libxl_internal.h |  1 +
2 files changed, 31 insertions(+), 3 deletions(-)
[Xen-devel] [XEN PATCH] libxl: wait for console path before firing console_available
Posted by Paweł Marczewski 4 years, 1 month ago
If we skip the bootloader, the TTY path will be set for xenconsoled.
However, there is no guarantee that this will happen by the time we
want to call the console_available callback, so we have to wait.

Signed-off-by: Paweł Marczewski <pawel@invisiblethingslab.com>
---
 tools/libxl/libxl_create.c   | 33 ++++++++++++++++++++++++++++++---
 tools/libxl/libxl_internal.h |  1 +
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 3a7364e2ac..53f2886544 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1190,6 +1190,21 @@ static void domcreate_console_available(libxl__egc *egc,
                                         dcs->aop_console_how.for_event));
 }
 
+static void console_watch_callback(libxl__egc *egc, libxl__ev_xswatch *watch,
+                                   const char *watch_path,
+                                   const char *event_path) {
+    EGC_GC;
+    libxl__domain_create_state *dcs = CONTAINER_OF(watch, *dcs, console_watch);
+    char *dompath = libxl__xs_get_dompath(gc, dcs->guest_domid);
+    char *tty_path = GCSPRINTF("%s/console/tty", dompath);
+    char *tty = libxl__xs_read(gc, XBT_NULL, tty_path);
+
+    if (tty && tty[0] != '\0') {
+        domcreate_console_available(egc, dcs);
+        domcreate_complete(egc, dcs, 0);
+    }
+}
+
 static void domcreate_bootloader_done(libxl__egc *egc,
                                       libxl__bootloader_state *bl,
                                       int rc)
@@ -1705,6 +1720,8 @@ static void domcreate_attach_devices(libxl__egc *egc,
     int domid = dcs->guest_domid;
     libxl_domain_config *const d_config = dcs->guest_config;
     const libxl__device_type *dt;
+    char *tty_path;
+    int rc;
 
     if (ret) {
         LOGD(ERROR, domid, "unable to add %s devices",
@@ -1728,9 +1745,15 @@ static void domcreate_attach_devices(libxl__egc *egc,
         return;
     }
 
-    domcreate_console_available(egc, dcs);
-
-    domcreate_complete(egc, dcs, 0);
+    tty_path = GCSPRINTF("%s/console/tty", libxl__xs_get_dompath(gc, domid));
+    rc = libxl__ev_xswatch_register(gc, &dcs->console_watch,
+                                    console_watch_callback,
+                                    tty_path);
+    if (rc) {
+        LOG(ERROR, "unable to set up watch for console path: %s",
+            tty_path);
+        goto error_out;
+    }
 
     return;
 
@@ -1747,6 +1770,9 @@ static void domcreate_complete(libxl__egc *egc,
     libxl_domain_config *const d_config = dcs->guest_config;
     libxl_domain_config *d_config_saved = &dcs->guest_config_saved;
 
+    if (libxl__ev_xswatch_isregistered(&dcs->console_watch))
+        libxl__ev_xswatch_deregister(gc, &dcs->console_watch);
+
     libxl__domain_build_state_dispose(&dcs->build_state);
 
     if (!rc && d_config->b_info.exec_ssidref)
@@ -1861,6 +1887,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
 
     libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how);
     cdcs->domid_out = domid;
+    libxl__ev_xswatch_init(&cdcs->dcs.console_watch);
 
     initiate_domain_create(egc, &cdcs->dcs);
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index dd3c08bc14..fa666cbe0c 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -4177,6 +4177,7 @@ struct libxl__domain_create_state {
     /* necessary if the domain creation failed and we have to destroy it */
     libxl__domain_destroy_state dds;
     libxl__multidev multidev;
+    libxl__ev_xswatch console_watch;
 };
 
 _hidden int libxl__device_nic_set_devids(libxl__gc *gc,
-- 
2.21.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel