The XML parser for consoles sets the 'port=' attribute of '<target' to
be always the index of the console.
Thus when the "really crazy backcompat stuff for consoles" function
modifies the order of consoles by inserting the default one for a serial
port it must re-number the ports to ensure that the value will not
change on subsequent parse.
This luckily didn't cause any visible changes to the VM as the port
number isn't used for anything.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 15 +++++++++++++++
.../console-compat2.x86_64-latest.xml | 2 +-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2283688ba0..5197953c7f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4957,6 +4957,7 @@ virDomainDefHasDeviceAddress(virDomainDef *def,
static int
virDomainDefAddConsoleCompat(virDomainDef *def)
{
+ bool renumber_consoles = false;
size_t i;
/*
@@ -5023,6 +5024,8 @@ virDomainDefAddConsoleCompat(virDomainDef *def)
/* Create an console alias for the serial port */
def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
def->consoles[0]->targetType =
VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
+
+ renumber_consoles = true;
}
} else if (def->os.type == VIR_DOMAIN_OSTYPE_HVM && def->nserials >
0 &&
def->serials[0]->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
@@ -5050,6 +5053,8 @@ virDomainDefAddConsoleCompat(virDomainDef *def)
return -1;
}
+ renumber_consoles = true;
+
def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
def->consoles[0]->targetType =
VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
@@ -5065,6 +5070,16 @@ virDomainDefAddConsoleCompat(virDomainDef *def)
}
}
+ /* When consoles are parsed in 'virDomainDefParseXML' the value of
+ * 'target.port' is overriden by the index of the console in the
+ * 'def->consoles' array. Thus if we are modifying the list here we
+ * must ensure that the numbering will be identical as if we've parsed
+ * this definition */
+ if (renumber_consoles) {
+ for (i = 0; i < def->nconsoles; i++)
+ def->consoles[i]->target.port = i;
+ }
+
return 0;
}
diff --git a/tests/qemuxml2xmloutdata/console-compat2.x86_64-latest.xml
b/tests/qemuxml2xmloutdata/console-compat2.x86_64-latest.xml
index 81bbb554d0..fd29155eae 100644
--- a/tests/qemuxml2xmloutdata/console-compat2.x86_64-latest.xml
+++ b/tests/qemuxml2xmloutdata/console-compat2.x86_64-latest.xml
@@ -42,7 +42,7 @@
<target type='serial' port='0'/>
</console>
<console type='pty'>
- <target type='virtio' port='0'/>
+ <target type='virtio' port='1'/>
</console>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
--
2.43.0