diff options
Diffstat (limited to 'tools/console')
-rw-r--r-- | tools/console/client/main.c | 44 | ||||
-rw-r--r-- | tools/console/daemon/io.c | 75 |
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; |