From: Jim Fehlig Date: Wed, 22 Jun 2016 02:25:23 +0000 (-0600) Subject: libxl: use serial device for console when targetType is serial X-Git-Tag: v2.0.0-rc1~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76d58716483c665e927b04063456b58a186a6f6c;p=thirdparty%2Flibvirt.git libxl: use serial device for console when targetType is serial When domXML contains only and no corresponding , the console is "stolen" [1] and used as the first device. When this "stolen" console is accessed from the libxl driver (in libxlConsoleCallback and libxlDomainOpenConsole), check if the targetType is VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL, and use the "stolen" device in def->serials[0] instead. Prior to this change, creating a domain with input XML containing only a device and subsequently attempting to access its console with 'virsh console' would fail error: internal error: character device is not using a PTY [1] See comments associated with virDomainDefAddConsoleCompat() in $LIBVIRT-SRC/src/conf/domain_conf.c: --- diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 221af8754d..6bcb4d93de 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -964,13 +964,17 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback) virObjectLock(vm); for (i = 0; i < vm->def->nconsoles; i++) { virDomainChrDefPtr chr = vm->def->consoles[i]; - if (chr && chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) { + if (i == 0 && + chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL) + chr = vm->def->serials[0]; + + if (chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) { libxl_console_type console_type; char *console = NULL; int ret; console_type = - (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ? + (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL ? LIBXL_CONSOLE_TYPE_SERIAL : LIBXL_CONSOLE_TYPE_PV); ret = libxl_console_get_tty(ctx, ev->domid, chr->target.port, console_type, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index c8c1f074a6..3189f1c598 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -4443,8 +4443,11 @@ libxlDomainOpenConsole(virDomainPtr dom, priv = vm->privateData; - if (vm->def->nconsoles) + if (vm->def->nconsoles) { chr = vm->def->consoles[0]; + if (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL) + chr = vm->def->serials[0]; + } if (!chr) { virReportError(VIR_ERR_INTERNAL_ERROR,