Skip to contentSkip to conversation

add libxl_find_terminal

PATCH New Stefano Stabellini 1 participant 1 message Jul 9, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add libxl_find_terminal

Hi all,
this patch implements a new libxl function called libxl_find_terminal that can be used to find the domid and console number to pass to libxl_console_attach to obtain a working terminal.
In particular the function knows how to deal with stubdoms. Xl uses this function by default unless the user manually specifies a console number using the -n command line option to xl console.

With this patch applied xl create -c works with stubdoms too.

---

tools/libxl/libxl.c +11 -0
diff -r a672af698bc3 tools/libxl/libxl.c
@@ -794,6 +794,17 @@
     return (system(cmd) != 0) ? ERROR_FAIL : 0;
 }
 
+int libxl_find_terminal(struct libxl_ctx *ctx, uint32_t *domid, int *cons_num)
+{
+    uint32_t stubdomid = libxl_get_stubdom_id(ctx, *domid);
+    if (stubdomid) {
+        *domid = stubdomid;
+        *cons_num = 1;
+    } else
+        *cons_num = 0;
+    return 0;
+}
+
 static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
                                              libxl_device_model_info *info,
                                              libxl_device_nic *vifs,
tools/libxl/libxl.h +4 -0
diff -r a672af698bc3 tools/libxl/libxl.h
@@ -359,6 +359,10 @@
 int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce);
 
 int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
+/* libxl_find_terminal finds the domid and console number to be used
+ * with libxl_console_attach in order to obtain a working terminal for
+ * the user. */
+int libxl_find_terminal(struct libxl_ctx *ctx, uint32_t *domid, int *cons_num);
 
 int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r,
                       uint32_t domid);
tools/libxl/xl_cmdimpl.c +9 -3
diff -r a672af698bc3 tools/libxl/xl_cmdimpl.c
@@ -1469,8 +1469,14 @@
 
 void console(char *p, int cons_num)
 {
+    uint32_t domidt;
+    int t;
     find_domain(p);
-    libxl_console_attach(&ctx, domid, cons_num);
+    domidt = domid;
+    t = cons_num;
+    if (t < 0)
+        libxl_find_terminal(&ctx, &domidt, &t);
+    libxl_console_attach(&ctx, domidt, t);
 }
 
 void cd_insert(char *dom, char *virtdev, char *phys)
@@ -1569,7 +1575,7 @@
 
 int main_console(int argc, char **argv)
 {
-    int opt = 0, cons_num = 0;
+    int opt = 0, cons_num = -1;
     char *p = NULL;
 
     while ((opt = getopt(argc, argv, "hn:")) != -1) {
@@ -2754,7 +2760,7 @@
 
     if (console_autoconnect) {
         snprintf(dom, sizeof(dom), "%d", rc);
-        console(dom, 0);
+        console(dom, -1);
     }
 
     exit(0);