WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

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

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 2 of 4] xenconsole: add support for a console type parameter
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Mon, 9 Aug 2010 15:01:19 +0100
Delivery-date: Mon, 09 Aug 2010 07:04:39 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
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

<Prev in Thread] Current Thread [Next in Thread>