提交 846a1c64 编写于 作者: B Bob Liu 提交者: Jim Fehlig

libxl: support serial list

Add support for multi serial devices, after this patch virsh can be used to
connect different serial devices of running domains. E.g.
vish # console <xxx> --devname serial<xxx>

Note:
This depends on a xen/libxl bug fix to have libxl_console_get_tty(...) correctly
returning the tty path (as opposed to always returning the first one).
[0] https://lists.xen.org/archives/html/xen-devel/2016-08/msg00438.htmlSigned-off-by: NBob Liu <bob.liu@oracle.com>
上级 70f83f9d
...@@ -431,14 +431,31 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, ...@@ -431,14 +431,31 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
} }
if (def->nserials) { if (def->nserials) {
if (def->nserials > 1) { if (def->nserials == 1) {
if (libxlMakeChrdevStr(def->serials[0], &b_info->u.hvm.serial) <
0)
return -1;
} else {
#ifdef LIBXL_HAVE_BUILDINFO_SERIAL_LIST
if (VIR_ALLOC_N(b_info->u.hvm.serial_list, def->nserials + 1) <
0)
return -1;
for (i = 0; i < def->nserials; i++) {
if (libxlMakeChrdevStr(def->serials[i],
&b_info->u.hvm.serial_list[i]) < 0)
{
libxl_string_list_dispose(&b_info->u.hvm.serial_list);
return -1;
}
}
b_info->u.hvm.serial_list[i] = NULL;
#else
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", "%s",
_("Only one serial device is supported by libxl")); _("Only one serial device is supported by libxl"));
return -1; return -1;
#endif
} }
if (libxlMakeChrdevStr(def->serials[0], &b_info->u.hvm.serial) < 0)
return -1;
} }
if (def->nparallels) { if (def->nparallels) {
......
...@@ -983,18 +983,20 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback) ...@@ -983,18 +983,20 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
{ {
virDomainObjPtr vm = for_callback; virDomainObjPtr vm = for_callback;
size_t i; size_t i;
virDomainChrDefPtr chr;
char *console = NULL;
int ret;
virObjectLock(vm); virObjectLock(vm);
for (i = 0; i < vm->def->nconsoles; i++) { for (i = 0; i < vm->def->nconsoles; i++) {
virDomainChrDefPtr chr = vm->def->consoles[i]; chr = vm->def->consoles[i];
if (i == 0 && if (i == 0 &&
chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL) chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL)
chr = vm->def->serials[0]; chr = vm->def->serials[0];
if (chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) { if (chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {
libxl_console_type console_type; libxl_console_type console_type;
char *console = NULL;
int ret;
console_type = console_type =
(chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL ? (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL ?
...@@ -1012,6 +1014,27 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback) ...@@ -1012,6 +1014,27 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
VIR_FREE(console); VIR_FREE(console);
} }
} }
for (i = 0; i < vm->def->nserials; i++) {
chr = vm->def->serials[i];
ignore_value(virAsprintf(&chr->info.alias, "serial%zd", i));
if (chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {
if (chr->source.data.file.path)
continue;
ret = libxl_console_get_tty(ctx, ev->domid,
chr->target.port,
LIBXL_CONSOLE_TYPE_SERIAL,
&console);
if (!ret) {
VIR_FREE(chr->source.data.file.path);
if (console && console[0] != '\0') {
ignore_value(VIR_STRDUP(chr->source.data.file.path,
console));
}
}
VIR_FREE(console);
}
}
virObjectUnlock(vm); virObjectUnlock(vm);
libxl_event_free(ctx, ev); libxl_event_free(ctx, ev);
} }
......
...@@ -4679,13 +4679,6 @@ libxlDomainOpenConsole(virDomainPtr dom, ...@@ -4679,13 +4679,6 @@ libxlDomainOpenConsole(virDomainPtr dom,
virCheckFlags(VIR_DOMAIN_CONSOLE_FORCE, -1); virCheckFlags(VIR_DOMAIN_CONSOLE_FORCE, -1);
if (dev_name) {
/* XXX support device aliases in future */
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Named device aliases are not supported"));
goto cleanup;
}
if (!(vm = libxlDomObjFromDomain(dom))) if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup; goto cleanup;
...@@ -4701,8 +4694,16 @@ libxlDomainOpenConsole(virDomainPtr dom, ...@@ -4701,8 +4694,16 @@ libxlDomainOpenConsole(virDomainPtr dom,
} }
priv = vm->privateData; priv = vm->privateData;
if (dev_name) {
size_t i;
if (vm->def->nconsoles) { for (i = 0; !chr && i < vm->def->nserials; i++) {
if (STREQ(dev_name, vm->def->serials[i]->info.alias)) {
chr = vm->def->serials[i];
break;
}
}
} else if (vm->def->nconsoles) {
chr = vm->def->consoles[0]; chr = vm->def->consoles[0];
if (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL) if (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL)
chr = vm->def->serials[0]; chr = vm->def->serials[0];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册