From 55839c154d28ff1b158e5383835e81946fca4064 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 18 Dec 2023 16:41:01 +0100 Subject: [PATCH] virDomainDefAddConsoleCompat: Fix numbering of console targets after modification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The XML parser for consoles sets the 'port=' attribute of ' Reviewed-by: Ján Tomko --- 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 54fd8dbcf0..8bddd2c1db 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4958,6 +4958,7 @@ virDomainDefHasDeviceAddress(virDomainDef *def, static int virDomainDefAddConsoleCompat(virDomainDef *def) { + bool renumber_consoles = false; size_t i; /* @@ -5024,6 +5025,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) { @@ -5051,6 +5054,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; @@ -5066,6 +5071,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 @@ - +