ia64/xen-unstable

changeset 19750:f07a915ecc17

xenconsole: support for multiple consoles per domain

This patch adds a new command line argument to xenconsole to specify
to which console to connect to in case a domain has more than one.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jun 16 11:24:58 2009 +0100 (2009-06-16)
parents f649dd4454af
children eeb0fce9aeaf
files tools/console/client/main.c tools/python/xen/xm/console.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/console/client/main.c	Tue Jun 16 11:18:32 2009 +0100
     1.2 +++ b/tools/console/client/main.c	Tue Jun 16 11:24:58 2009 +0100
     1.3 @@ -71,6 +71,7 @@ static void usage(const char *program) {
     1.4  	       "Attaches to a virtual domain console\n"
     1.5  	       "\n"
     1.6  	       "  -h, --help       display this help and exit\n"
     1.7 +	       "  -n, --num N      use console number N\n"
     1.8  	       , program);
     1.9  }
    1.10  
    1.11 @@ -255,15 +256,17 @@ int main(int argc, char **argv)
    1.12  {
    1.13  	struct termios attr;
    1.14  	int domid;
    1.15 -	char *sopt = "h";
    1.16 +	char *sopt = "hn:";
    1.17  	int ch;
    1.18 +	unsigned int num = 0;
    1.19  	int opt_ind=0;
    1.20  	struct option lopt[] = {
    1.21 +		{ "num",     1, 0, 'n' },
    1.22  		{ "help",    0, 0, 'h' },
    1.23  		{ 0 },
    1.24  
    1.25  	};
    1.26 -	char *path;
    1.27 +	char *dom_path = NULL, *path = NULL;
    1.28  	int spty, xsfd;
    1.29  	struct xs_handle *xs;
    1.30  	char *end;
    1.31 @@ -274,16 +277,17 @@ int main(int argc, char **argv)
    1.32  			usage(argv[0]);
    1.33  			exit(0);
    1.34  			break;
    1.35 +		case 'n':
    1.36 +			num = atoi(optarg);
    1.37 +			break;
    1.38 +		default:
    1.39 +			fprintf(stderr, "Invalid argument\n");
    1.40 +			fprintf(stderr, "Try `%s --help' for more information.\n", 
    1.41 +					argv[0]);
    1.42 +			exit(EINVAL);
    1.43  		}
    1.44  	}
    1.45  	
    1.46 -	if ((argc - optind) != 1) {
    1.47 -		fprintf(stderr, "Invalid number of arguments\n");
    1.48 -		fprintf(stderr, "Try `%s --help' for more information.\n", 
    1.49 -			argv[0]);
    1.50 -		exit(EINVAL);
    1.51 -	}
    1.52 -	
    1.53  	domid = strtol(argv[optind], &end, 10);
    1.54  	if (end && *end) {
    1.55  		fprintf(stderr, "Invalid DOMID `%s'\n", argv[optind]);
    1.56 @@ -299,13 +303,13 @@ int main(int argc, char **argv)
    1.57  
    1.58  	signal(SIGTERM, sighandler);
    1.59  
    1.60 -	path = xs_get_domain_path(xs, domid);
    1.61 -	if (path == NULL)
    1.62 +	dom_path = xs_get_domain_path(xs, domid);
    1.63 +	if (dom_path == NULL)
    1.64  		err(errno, "xs_get_domain_path()");
    1.65 -	path = realloc(path, strlen(path) + strlen("/console/tty") + 1);
    1.66 +	path = malloc(strlen(dom_path) + strlen("/serial/0/tty") + 3);
    1.67  	if (path == NULL)
    1.68 -		err(ENOMEM, "realloc");
    1.69 -	strcat(path, "/console/tty");
    1.70 +		err(ENOMEM, "malloc");
    1.71 +	snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 2, "%s/serial/%d/tty", dom_path, num);
    1.72  
    1.73  	/* FIXME consoled currently does not assume domain-0 doesn't have a
    1.74  	   console which is good when we break domain-0 up.  To keep us
    1.75 @@ -336,5 +340,6 @@ int main(int argc, char **argv)
    1.76  	restore_term(STDIN_FILENO, &attr);
    1.77  
    1.78  	free(path);
    1.79 +	free(dom_path);
    1.80  	return 0;
    1.81   }
     2.1 --- a/tools/python/xen/xm/console.py	Tue Jun 16 11:18:32 2009 +0100
     2.2 +++ b/tools/python/xen/xm/console.py	Tue Jun 16 11:24:58 2009 +0100
     2.3 @@ -24,8 +24,8 @@ from xen.util import utils
     2.4  
     2.5  XENCONSOLE = "xenconsole"
     2.6  
     2.7 -def execConsole(domid):
     2.8 -    xen.util.auxbin.execute(XENCONSOLE, [str(domid)])
     2.9 +def execConsole(domid, num = 0):
    2.10 +    xen.util.auxbin.execute(XENCONSOLE, [str(domid), "--num", str(num)])
    2.11  
    2.12  
    2.13  class OurXenstoreConnection:
     3.1 --- a/tools/python/xen/xm/main.py	Tue Jun 16 11:18:32 2009 +0100
     3.2 +++ b/tools/python/xen/xm/main.py	Tue Jun 16 11:24:58 2009 +0100
     3.3 @@ -1779,12 +1779,13 @@ def xm_info(args):
     3.4                  print "%-23s:" % x[0], x[1]
     3.5  
     3.6  def xm_console(args):
     3.7 -    arg_check(args, "console", 1, 2)
     3.8 -
     3.9 +    arg_check(args, "console", 1, 3)
    3.10 +
    3.11 +    num = 0
    3.12      quiet = False;
    3.13  
    3.14      try:
    3.15 -        (options, params) = getopt.gnu_getopt(args, 'q', ['quiet'])
    3.16 +        (options, params) = getopt.gnu_getopt(args, 'qn:', ['quiet', 'num'])
    3.17      except getopt.GetoptError, opterr:
    3.18          err(opterr)
    3.19          usage('console')
    3.20 @@ -1792,6 +1793,8 @@ def xm_console(args):
    3.21      for (k, v) in options:
    3.22          if k in ['-q', '--quiet']:
    3.23              quiet = True
    3.24 +	elif k in ['-n', '--num']:
    3.25 +	    num = int(v[0])
    3.26          else:
    3.27              assert False
    3.28  
    3.29 @@ -1819,7 +1822,7 @@ def xm_console(args):
    3.30          else:
    3.31              raise xmlrpclib.Fault(0, "Domain '%s' is not started" % dom)
    3.32  
    3.33 -    console.execConsole(domid)
    3.34 +    console.execConsole(domid, num)
    3.35  
    3.36  
    3.37  def domain_name_to_domid(domain_name):