[libvirt] [PATCH 0/3] Minor chardev fixes

Ján Tomko (3): Remove chardev port calculation from DomainDefParse Move console target port setting to DeviceDefPostParse Create a console stub for the first serial device src/conf/domain_conf.c | 77 ++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 47 deletions(-) -- 1.8.3.2

It's already in DeviceDefPostParse, the only difference is that the removed code only looked at ports of devices before the current one, the new code looks at all of them. --- src/conf/domain_conf.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6c3bdad..46294fa 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12355,15 +12355,6 @@ virDomainDefParseXML(xmlDocPtr xml, if (!chr) goto error; - if (chr->target.port == -1) { - int maxport = -1; - size_t j; - for (j = 0; j < i; j++) { - if (def->parallels[j]->target.port > maxport) - maxport = def->parallels[j]->target.port; - } - chr->target.port = maxport + 1; - } def->parallels[def->nparallels++] = chr; } VIR_FREE(nodes); @@ -12383,15 +12374,6 @@ virDomainDefParseXML(xmlDocPtr xml, if (!chr) goto error; - if (chr->target.port == -1) { - int maxport = -1; - size_t j; - for (j = 0; j < i; j++) { - if (def->serials[j]->target.port > maxport) - maxport = def->serials[j]->target.port; - } - chr->target.port = maxport + 1; - } def->serials[def->nserials++] = chr; } VIR_FREE(nodes); @@ -12439,21 +12421,6 @@ virDomainDefParseXML(xmlDocPtr xml, chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO && chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) chr->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL; - - if (chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL && - chr->info.addr.vioserial.port == 0) { - int maxport = 0; - size_t j; - for (j = 0; j < i; j++) { - virDomainChrDefPtr thischr = def->channels[j]; - if (thischr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL && - thischr->info.addr.vioserial.controller == chr->info.addr.vioserial.controller && - thischr->info.addr.vioserial.bus == chr->info.addr.vioserial.bus && - (int)thischr->info.addr.vioserial.port > maxport) - maxport = thischr->info.addr.vioserial.port; - } - chr->info.addr.vioserial.port = maxport + 1; - } } VIR_FREE(nodes); -- 1.8.3.2

This overrides the port number on hotplug, not just when parsing the domain XML. https://bugzilla.redhat.com/show_bug.cgi?id=1089991 https://bugzilla.redhat.com/show_bug.cgi?id=1089997 --- src/conf/domain_conf.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 46294fa..3c0d2ff 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2993,18 +2993,25 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev, if (dev->type == VIR_DOMAIN_DEVICE_CHR) { virDomainChrDefPtr chr = dev->data.chr; const virDomainChrDef **arrPtr; - size_t i, cnt; + size_t i, cnt, idx; virDomainChrGetDomainPtrs(def, chr->deviceType, &arrPtr, &cnt); + for (idx = 0; idx < cnt; idx++) { + if (arrPtr[idx] == chr) + break; + } + if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE && chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL; + if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE) + chr->target.port = idx; + if (chr->target.port == -1 && (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL || - chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL || - chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE)) { + chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL)) { int maxport = -1; for (i = 0; i < cnt; i++) { @@ -12395,7 +12402,6 @@ virDomainDefParseXML(xmlDocPtr xml, if (!chr) goto error; - chr->target.port = i; def->consoles[def->nconsoles++] = chr; } VIR_FREE(nodes); -- 1.8.3.2

The <console> alias for the first <serial> device was only formatted when there were no consoles. After removing this alias manually, a round-trip via XML would add it again. However this was not the case when it was removed and a virtio console was hotplugged. https://bugzilla.redhat.com/show_bug.cgi?id=1089914 --- src/conf/domain_conf.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3c0d2ff..69106bd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2923,6 +2923,26 @@ virDomainDefPostParseInternal(virDomainDefPtr def, } } + /* Create a stub for the first serial device in consoles if there are none */ + if (STREQ(def->os.type, "hvm") && + def->nconsoles == 0 && + def->nserials > 0) { + + virDomainChrDefPtr chr; + + if (VIR_ALLOC(chr) < 0) + return -1; + + if (VIR_APPEND_ELEMENT(def->consoles, + def->nconsoles, + chr) < 0) { + VIR_FREE(chr); + return -1; + } + def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; + def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL; + } + if (virDomainDefRejectDuplicateControllers(def) < 0) return -1; @@ -17739,16 +17759,6 @@ virDomainDefFormatInternal(virDomainDefPtr def, if (virDomainChrDefFormat(buf, &console, flags) < 0) goto error; } - if (STREQ(def->os.type, "hvm") && - def->nconsoles == 0 && - def->nserials > 0) { - virDomainChrDef console; - memcpy(&console, def->serials[n], sizeof(console)); - console.deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; - console.targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL; - if (virDomainChrDefFormat(buf, &console, flags) < 0) - goto error; - } for (n = 0; n < def->nchannels; n++) if (virDomainChrDefFormat(buf, def->channels[n], flags) < 0) -- 1.8.3.2
participants (1)
-
Ján Tomko