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

[Xen-devel] [PATCH 2 of 4] xenconsole: add support for a console type parameter



xenconsole: implement support for an explicit console type parameter

This patch adds support to xenconsole for an explicity console "type"
parameter. The parameter can be "pv", to specify that the user wants to
connect to a pv console, or "serial", to specify that the user wants to
connect to an emulated serial.
If the type parameter hasn't been specified be the user, xenconsole
tries to guess which type of console it has to connect to, defaulting to
pv console for pv guests and emulated serial for hvm guests.

This patch also changes the xenstore paths corresponding to pv consoles
to the console prefix, leaving the serial prefix to emulated serials.

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

diff -r 6b28b2dac7dd tools/console/client/main.c
--- a/tools/console/client/main.c       Thu Aug 05 11:36:24 2010 +0100
+++ b/tools/console/client/main.c       Mon Aug 09 14:26:22 2010 +0100
@@ -254,6 +254,12 @@ static int console_loop(int fd, struct x
        return 0;
 }
 
+typedef enum {
+       CONSOLE_INVAL,
+       CONSOLE_PV,
+       CONSOLE_SERIAL,
+} console_type;
+
 int main(int argc, char **argv)
 {
        struct termios attr;
@@ -263,15 +269,19 @@ int main(int argc, char **argv)
        unsigned int num = 0;
        int opt_ind=0;
        struct option lopt[] = {
+               { "type",     1, 0, 't' },
                { "num",     1, 0, 'n' },
                { "help",    0, 0, 'h' },
                { 0 },
 
        };
-       char *dom_path = NULL, *path = NULL;
+       char *dom_path = NULL, *path = NULL, *vm_path = NULL;
+       char *uuid = NULL, ostype_path[55], *ostype = NULL;
        int spty, xsfd;
        struct xs_handle *xs;
        char *end;
+       unsigned int len;
+       console_type type = CONSOLE_INVAL;
 
        while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
                switch(ch) {
@@ -282,6 +292,17 @@ int main(int argc, char **argv)
                case 'n':
                        num = atoi(optarg);
                        break;
+               case 't':
+                       if (!strcmp(optarg, "serial"))
+                               type = CONSOLE_SERIAL;
+                       else if (!strcmp(optarg, "pv"))
+                               type = CONSOLE_PV;
+                       else {
+                               fprintf(stderr, "Invalid type argument\n");
+                               fprintf(stderr, "Console types supported are: 
serial, pv\n");
+                               exit(EINVAL);
+                       }
+                       break;
                default:
                        fprintf(stderr, "Invalid argument\n");
                        fprintf(stderr, "Try `%s --help' for more 
information.\n", 
@@ -314,10 +335,43 @@ int main(int argc, char **argv)
        dom_path = xs_get_domain_path(xs, domid);
        if (dom_path == NULL)
                err(errno, "xs_get_domain_path()");
-       path = malloc(strlen(dom_path) + strlen("/serial/0/tty") + 5);
+       if (type == CONSOLE_INVAL) {
+               /* guess what type of console we have to connect to */
+               vm_path = malloc(strlen(dom_path) + 4);
+               if (vm_path == NULL)
+                       err(ENOMEM, "malloc");
+               snprintf(vm_path, strlen(dom_path) + 4, "%s/vm", dom_path);
+               uuid = xs_read(xs, XBT_NULL, vm_path, &len);
+               if (uuid == NULL) {
+                       fprintf(stderr, "No vm path for domid %d\n", domid);
+                       exit(EINVAL);
+               }
+               snprintf(ostype_path, strlen(ostype_path), "%s/image/ostype", 
uuid);
+               ostype = xs_read(xs, XBT_NULL, ostype_path, &len);
+               if (ostype == NULL) {
+                       fprintf(stderr, "No ostype for domid %d\n", domid);
+                       exit(EINVAL);
+               }
+               /* default to pv console for pv guests and serial for hvm 
guests */
+               if (strcmp(ostype, "hvm"))
+                       type = CONSOLE_PV;
+               else
+                       type = CONSOLE_SERIAL;
+               free(vm_path);
+               free(uuid);
+               free(ostype);
+       }
+       path = malloc(strlen(dom_path) + strlen("/device/console/0/tty") + 5);
        if (path == NULL)
                err(ENOMEM, "malloc");
-       snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 5, 
"%s/serial/%d/tty", dom_path, num);
+       if (type == CONSOLE_SERIAL)
+               snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 5, 
"%s/serial/%d/tty", dom_path, num);
+       else {
+               if (num == 0)
+                       snprintf(path, strlen(dom_path) + 
strlen("/console/tty") + 1, "%s/console/tty", dom_path);
+               else
+                       snprintf(path, strlen(dom_path) + 
strlen("/device/console/%d/tty") + 5, "%s/device/console/%d/tty", dom_path, 
num);
+       }
 
        /* FIXME consoled currently does not assume domain-0 doesn't have a
           console which is good when we break domain-0 up.  To keep us

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