aboutsummaryrefslogtreecommitdiffstats
path: root/tools/console
diff options
context:
space:
mode:
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>2010-08-16 13:32:04 +0100
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>2010-08-16 13:32:04 +0100
commitce8ffdb5516b77e2ddb7f84aa0b61dc85f8fc2df (patch)
tree681c427fe28e46dfdcf2fcd7a4795d48a803dae0 /tools/console
parent4129c5a320bca20d94a76a99b6f133b384ada46d (diff)
downloadxen-ce8ffdb5516b77e2ddb7f84aa0b61dc85f8fc2df.tar.gz
xen-ce8ffdb5516b77e2ddb7f84aa0b61dc85f8fc2df.tar.bz2
xen-ce8ffdb5516b77e2ddb7f84aa0b61dc85f8fc2df.zip
tools: xenconsole[d] and libxl: multiple console support
This patch implements the new protocol for handling pv consoles and emulated serials as described in the document docs/misc/console.txt. The changes are: - xenconsoled: do not write the pty under serial in xenstore if xenconsoled is handling a consolepath; - xenconsole: implement support for an explicit 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. - xenconsole: use the new xenstore paths; - libxl: rename libxl_console_constype to libxl_console_consback: constype is used to to specify whether qemu or xenconsoled provides the backend, so I renamed it to libxl_console_consback to make it more obvious that we are talking about backends; - libxl: add a new libxl_console_constype to specify if the console is an emulated serial or a pv console; - libxl: support the new xenconsole "type" command line parameter; - libxl: use the "output" node under console in xenstore to tell qemu where do we want the output of this pv console to go; - remove the legacy "serialpath" from xenconsoled altogether Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Also: update the QEMU_TAG to pull in the qemu part of these changes. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/console')
-rw-r--r--tools/console/client/main.c44
-rw-r--r--tools/console/daemon/io.c75
2 files changed, 55 insertions, 64 deletions
diff --git a/tools/console/client/main.c b/tools/console/client/main.c
index 4289d361a6..df3636fc20 100644
--- a/tools/console/client/main.c
+++ b/tools/console/client/main.c
@@ -40,6 +40,7 @@
#endif
#include "xs.h"
+#include "xenctrl.h"
#define ESCAPE_CHARACTER 0x1d
@@ -254,6 +255,12 @@ static int console_loop(int fd, struct xs_handle *xs, char *pty_path)
return 0;
}
+typedef enum {
+ CONSOLE_INVAL,
+ CONSOLE_PV,
+ CONSOLE_SERIAL,
+} console_type;
+
int main(int argc, char **argv)
{
struct termios attr;
@@ -263,6 +270,7 @@ 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 },
@@ -272,6 +280,7 @@ int main(int argc, char **argv)
int spty, xsfd;
struct xs_handle *xs;
char *end;
+ console_type type = CONSOLE_INVAL;
while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
switch(ch) {
@@ -282,6 +291,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 +334,30 @@ 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) {
+ xc_dominfo_t xcinfo;
+ xc_interface *xc_handle = xc_interface_open(0,0,0);
+ if (xc_handle == NULL)
+ err(errno, "Could not open xc interface");
+ xc_domain_getinfo(xc_handle, domid, 1, &xcinfo);
+ /* default to pv console for pv guests and serial for hvm guests */
+ if (xcinfo.hvm)
+ type = CONSOLE_SERIAL;
+ else
+ type = CONSOLE_PV;
+ xc_interface_close(xc_handle);
+ }
+ 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
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 55e8027d43..691b0f2786 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -87,8 +87,6 @@ struct domain {
struct buffer buffer;
struct domain *next;
char *conspath;
- char *serialpath;
- int use_consolepath;
int ring_ref;
evtchn_port_or_error_t local_port;
evtchn_port_or_error_t remote_port;
@@ -440,20 +438,8 @@ static int domain_create_tty(struct domain *dom)
goto out;
}
- if (dom->use_consolepath) {
- success = asprintf(&path, "%s/limit", dom->conspath) !=
- -1;
- if (!success)
- goto out;
- data = xs_read(xs, XBT_NULL, path, &len);
- if (data) {
- dom->buffer.max_capacity = strtoul(data, 0, 0);
- free(data);
- }
- free(path);
- }
-
- success = asprintf(&path, "%s/limit", dom->serialpath) != -1;
+ success = asprintf(&path, "%s/limit", dom->conspath) !=
+ -1;
if (!success)
goto out;
data = xs_read(xs, XBT_NULL, path, &len);
@@ -463,7 +449,7 @@ static int domain_create_tty(struct domain *dom)
}
free(path);
- success = asprintf(&path, "%s/tty", dom->serialpath) != -1;
+ success = (asprintf(&path, "%s/tty", dom->conspath) != -1);
if (!success)
goto out;
success = xs_write(xs, XBT_NULL, path, slave, strlen(slave));
@@ -471,16 +457,6 @@ static int domain_create_tty(struct domain *dom)
if (!success)
goto out;
- if (dom->use_consolepath) {
- success = (asprintf(&path, "%s/tty", dom->conspath) != -1);
- if (!success)
- goto out;
- success = xs_write(xs, XBT_NULL, path, slave, strlen(slave));
- free(path);
- if (!success)
- goto out;
- }
-
if (fcntl(dom->master_fd, F_SETFL, O_NONBLOCK) == -1)
goto out;
@@ -524,29 +500,20 @@ static int xs_gather(struct xs_handle *xs, const char *dir, ...)
va_end(ap);
return ret;
}
-
+
static int domain_create_ring(struct domain *dom)
{
int err, remote_port, ring_ref, rc;
char *type, path[PATH_MAX];
- err = xs_gather(xs, dom->serialpath,
+ err = xs_gather(xs, dom->conspath,
"ring-ref", "%u", &ring_ref,
"port", "%i", &remote_port,
NULL);
- if (err) {
- err = xs_gather(xs, dom->conspath,
- "ring-ref", "%u", &ring_ref,
- "port", "%i", &remote_port,
- NULL);
- if (err)
- goto out;
- dom->use_consolepath = 1;
- } else
- dom->use_consolepath = 0;
+ if (err)
+ goto out;
- snprintf(path, sizeof(path), "%s/type",
- dom->use_consolepath ? dom->conspath: dom->serialpath);
+ snprintf(path, sizeof(path), "%s/type", dom->conspath);
type = xs_read(xs, XBT_NULL, path, NULL);
if (type && strcmp(type, "xenconsoled") != 0) {
free(type);
@@ -628,16 +595,12 @@ static bool watch_domain(struct domain *dom, bool watch)
snprintf(domid_str, sizeof(domid_str), "dom%u", dom->domid);
if (watch) {
- success = xs_watch(xs, dom->serialpath, domid_str);
- if (success) {
- success = xs_watch(xs, dom->conspath, domid_str);
- if (success)
- domain_create_ring(dom);
- else
- xs_unwatch(xs, dom->serialpath, domid_str);
- }
+ success = xs_watch(xs, dom->conspath, domid_str);
+ if (success)
+ domain_create_ring(dom);
+ else
+ xs_unwatch(xs, dom->conspath, domid_str);
} else {
- success = xs_unwatch(xs, dom->serialpath, domid_str);
success = xs_unwatch(xs, dom->conspath, domid_str);
}
@@ -666,14 +629,6 @@ static struct domain *create_domain(int domid)
dom->domid = domid;
- dom->serialpath = xs_get_domain_path(xs, dom->domid);
- s = realloc(dom->serialpath, strlen(dom->serialpath) +
- strlen("/serial/0") + 1);
- if (s == NULL)
- goto out;
- dom->serialpath = s;
- strcat(dom->serialpath, "/serial/0");
-
dom->conspath = xs_get_domain_path(xs, dom->domid);
s = realloc(dom->conspath, strlen(dom->conspath) +
strlen("/console") + 1);
@@ -712,7 +667,6 @@ static struct domain *create_domain(int domid)
return dom;
out:
- free(dom->serialpath);
free(dom->conspath);
free(dom);
return NULL;
@@ -755,9 +709,6 @@ static void cleanup_domain(struct domain *d)
free(d->buffer.data);
d->buffer.data = NULL;
- free(d->serialpath);
- d->serialpath = NULL;
-
free(d->conspath);
d->conspath = NULL;