[PATCH 0/2] qemu: add append mode config for serial file

Serial log file contains lots of useful information for debugging configuration problems. It makes sense to preserve the log in between restarts, so that one can later figure out what was going on. Oleg Vasilev (2): qemu: add append mode config for serial file qemuxml2xmltest: add serial append=on test src/qemu/libvirtd_qemu.aug | 3 + src/qemu/qemu.conf.in | 10 ++++ src/qemu/qemu_conf.c | 4 ++ src/qemu/qemu_conf.h | 2 + src/qemu/qemu_domain.c | 13 +++++ src/qemu/test_libvirtd_qemu.aug.in | 1 + tests/qemuxml2argvdata/serial-append.xml | 56 +++++++++++++++++++ .../serial-append.x86_64-latest.xml | 56 +++++++++++++++++++ tests/qemuxml2xmltest.c | 4 ++ 9 files changed, 149 insertions(+) create mode 100644 tests/qemuxml2argvdata/serial-append.xml create mode 100644 tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml -- 2.38.1

Serial log file contains lots of useful information for debugging configuration problems. It makes sense to preserve the log in between restarts, so that one can later figure out what was going on. Signed-off-by: Oleg Vasilev <oleg.vasilev@virtuozzo.com> --- src/qemu/libvirtd_qemu.aug | 3 +++ src/qemu/qemu.conf.in | 10 ++++++++++ src/qemu/qemu_conf.c | 4 ++++ src/qemu/qemu_conf.h | 2 ++ src/qemu/qemu_domain.c | 13 +++++++++++++ src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 33 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index ed097ea3d9..7f3eec7cfd 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -147,6 +147,8 @@ module Libvirtd_qemu = let capability_filters_entry = str_array_entry "capability_filters" + let serial_file_append_entry = str_entry "serial_file_append" + (* Each entry in the config is one of the following ... *) let entry = default_tls_entry | vnc_entry @@ -171,6 +173,7 @@ module Libvirtd_qemu = | swtpm_entry | capability_filters_entry | obsolete_entry + | serial_file_append_entry let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ] let empty = [ label "#empty" . eol ] diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 3895d42514..6b38bbeca0 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -968,3 +968,13 @@ # "full" - both QEMU and its helper processes are placed into separate # scheduling group #sched_core = "none" + +# Default append mode for writing to serial file. QEMU will set the chosen +# value everytime it processes the config, unless some value is already there. +# +# Possible options are: +# "default" - leave as-is, omit "append=..." from conf, leave for QEMU to decide. +# The default for QEMU is the same as with append="off". +# "on" - set append value to "on", meaning file won't be truncated on restart +# "off" - set append value to "off", file will be cleared on restart +#serial_file_append = "default" diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ae5bbcd138..bfd93a168f 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -288,6 +288,7 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, return NULL; cfg->deprecationBehavior = g_strdup("none"); + cfg->serialFileAppend = g_strdup("default"); return g_steal_pointer(&cfg); } @@ -376,6 +377,7 @@ static void virQEMUDriverConfigDispose(void *obj) g_strfreev(cfg->capabilityfilters); g_free(cfg->deprecationBehavior); + g_free(cfg->serialFileAppend); } @@ -903,6 +905,8 @@ virQEMUDriverConfigLoadDebugEntry(virQEMUDriverConfig *cfg, return -1; if (virConfGetValueString(conf, "deprecation_behavior", &cfg->deprecationBehavior) < 0) return -1; + if (virConfGetValueString(conf, "serial_file_append", &cfg->serialFileAppend) < 0) + return -1; return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8cf2dd2ec5..316200f38d 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -229,6 +229,8 @@ struct _virQEMUDriverConfig { char *deprecationBehavior; virQEMUSchedCore schedCore; + + char *serialFileAppend; }; G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUDriverConfig, virObjectUnref); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8ae458ae45..0d1fe1ffcc 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -37,6 +37,7 @@ #include "qemu_validate.h" #include "qemu_namespace.h" #include "viralloc.h" +#include "virenum.h" #include "virlog.h" #include "virerror.h" #include "viridentity.h" @@ -5357,6 +5358,8 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, virQEMUDriver *driver, unsigned int parseFlags) { + g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); + /* Historically, isa-serial and the default matched, so in order to * maintain backwards compatibility we map them here. The actual default * will be picked below based on the architecture and machine type. */ @@ -5428,6 +5431,16 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, } } + + if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && + chr->source && + chr->source->type == VIR_DOMAIN_CHR_TYPE_FILE && + chr->source->data.file.append == VIR_TRISTATE_SWITCH_ABSENT) { + + chr->source->data.file.append = + virTristateSwitchTypeFromString(cfg->serialFileAppend); + } + return 0; } diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in index 1dbd692921..d1ca9c8d3d 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -117,3 +117,4 @@ module Test_libvirtd_qemu = } { "deprecation_behavior" = "none" } { "sched_core" = "none" } +{ "serial_file_append" = "default" } -- 2.38.1

On Tue, Nov 29, 2022 at 09:54:51PM +0600, Oleg Vasilev wrote:
Serial log file contains lots of useful information for debugging configuration problems. It makes sense to preserve the log in between restarts, so that one can later figure out what was going on.
I don't understand why is the default not set in the mgmt app which creates the XMLs since we allow that per domain, but I'll go with that.
Signed-off-by: Oleg Vasilev <oleg.vasilev@virtuozzo.com> --- src/qemu/libvirtd_qemu.aug | 3 +++ src/qemu/qemu.conf.in | 10 ++++++++++ src/qemu/qemu_conf.c | 4 ++++ src/qemu/qemu_conf.h | 2 ++ src/qemu/qemu_domain.c | 13 +++++++++++++ src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 33 insertions(+)
diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index ed097ea3d9..7f3eec7cfd 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -147,6 +147,8 @@ module Libvirtd_qemu =
let capability_filters_entry = str_array_entry "capability_filters"
+ let serial_file_append_entry = str_entry "serial_file_append" + (* Each entry in the config is one of the following ... *) let entry = default_tls_entry | vnc_entry @@ -171,6 +173,7 @@ module Libvirtd_qemu = | swtpm_entry | capability_filters_entry | obsolete_entry + | serial_file_append_entry
let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ] let empty = [ label "#empty" . eol ] diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 3895d42514..6b38bbeca0 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -968,3 +968,13 @@ # "full" - both QEMU and its helper processes are placed into separate # scheduling group #sched_core = "none" + +# Default append mode for writing to serial file. QEMU will set the chosen +# value everytime it processes the config, unless some value is already there. +# +# Possible options are: +# "default" - leave as-is, omit "append=..." from conf, leave for QEMU to decide.
I'd remove the 'omit "append=..." from conf, ' part as it might be confusing for some.
+# The default for QEMU is the same as with append="off".
You mention the default is to leave QEMU to decide, but also specify the default behaviour of QEMU itself. That way, if there is any change, however unlikely, we might get some users complaining that the default is specified to be "off" while it is not. I'd just leave out this one line.
+# "on" - set append value to "on", meaning file won't be truncated on restart +# "off" - set append value to "off", file will be cleared on restart +#serial_file_append = "default" diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ae5bbcd138..bfd93a168f 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -288,6 +288,7 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, return NULL;
cfg->deprecationBehavior = g_strdup("none"); + cfg->serialFileAppend = g_strdup("default");
return g_steal_pointer(&cfg); } @@ -376,6 +377,7 @@ static void virQEMUDriverConfigDispose(void *obj) g_strfreev(cfg->capabilityfilters);
g_free(cfg->deprecationBehavior); + g_free(cfg->serialFileAppend); }
@@ -903,6 +905,8 @@ virQEMUDriverConfigLoadDebugEntry(virQEMUDriverConfig *cfg, return -1; if (virConfGetValueString(conf, "deprecation_behavior", &cfg->deprecationBehavior) < 0) return -1; + if (virConfGetValueString(conf, "serial_file_append", &cfg->serialFileAppend) < 0) + return -1;
return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8cf2dd2ec5..316200f38d 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -229,6 +229,8 @@ struct _virQEMUDriverConfig { char *deprecationBehavior;
virQEMUSchedCore schedCore; + + char *serialFileAppend; };
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUDriverConfig, virObjectUnref); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8ae458ae45..0d1fe1ffcc 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -37,6 +37,7 @@ #include "qemu_validate.h" #include "qemu_namespace.h" #include "viralloc.h" +#include "virenum.h" #include "virlog.h" #include "virerror.h" #include "viridentity.h" @@ -5357,6 +5358,8 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, virQEMUDriver *driver, unsigned int parseFlags) { + g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); + /* Historically, isa-serial and the default matched, so in order to * maintain backwards compatibility we map them here. The actual default * will be picked below based on the architecture and machine type. */ @@ -5428,6 +5431,16 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, } }
+ + if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && + chr->source && + chr->source->type == VIR_DOMAIN_CHR_TYPE_FILE && + chr->source->data.file.append == VIR_TRISTATE_SWITCH_ABSENT) { + + chr->source->data.file.append = + virTristateSwitchTypeFromString(cfg->serialFileAppend);
If we translate this during startup then we don't have to do that on every XML parse, but I see some other things are used the same way. Couple of places do a change to default if there is an _ABSENT option, maybe it'd be nicer to have something like virTristateSwitchMerge() that'd do the same, but that's just my rambling, an idea for future someone, unrelated to your patch.
+ } + return 0; }
diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in index 1dbd692921..d1ca9c8d3d 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -117,3 +117,4 @@ module Test_libvirtd_qemu = } { "deprecation_behavior" = "none" } { "sched_core" = "none" } +{ "serial_file_append" = "default" } -- 2.38.1

On 05.01.2023 19:19, Martin Kletzander wrote:
On Tue, Nov 29, 2022 at 09:54:51PM +0600, Oleg Vasilev wrote:
Serial log file contains lots of useful information for debugging configuration problems. It makes sense to preserve the log in between restarts, so that one can later figure out what was going on.
I don't understand why is the default not set in the mgmt app which creates the XMLs since we allow that per domain, but I'll go with that.
We are aiming to make all our mgmt apps as shallow as possible, brining the source of truth into libvirt. We are hoping this will streamline our configuration process and bring the new features to the community as well :) The rest of the comments, I believe I've fixed in a v2. Thanks! Oleg
Signed-off-by: Oleg Vasilev <oleg.vasilev@virtuozzo.com> --- src/qemu/libvirtd_qemu.aug | 3 +++ src/qemu/qemu.conf.in | 10 ++++++++++ src/qemu/qemu_conf.c | 4 ++++ src/qemu/qemu_conf.h | 2 ++ src/qemu/qemu_domain.c | 13 +++++++++++++ src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 33 insertions(+)
diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index ed097ea3d9..7f3eec7cfd 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -147,6 +147,8 @@ module Libvirtd_qemu =
let capability_filters_entry = str_array_entry "capability_filters"
+ let serial_file_append_entry = str_entry "serial_file_append" + (* Each entry in the config is one of the following ... *) let entry = default_tls_entry | vnc_entry @@ -171,6 +173,7 @@ module Libvirtd_qemu = | swtpm_entry | capability_filters_entry | obsolete_entry + | serial_file_append_entry
let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ] let empty = [ label "#empty" . eol ] diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 3895d42514..6b38bbeca0 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -968,3 +968,13 @@ # "full" - both QEMU and its helper processes are placed into separate # scheduling group #sched_core = "none" + +# Default append mode for writing to serial file. QEMU will set the chosen +# value everytime it processes the config, unless some value is already there. +# +# Possible options are: +# "default" - leave as-is, omit "append=..." from conf, leave for QEMU to decide.
I'd remove the 'omit "append=..." from conf, ' part as it might be confusing for some.
+# The default for QEMU is the same as with append="off".
You mention the default is to leave QEMU to decide, but also specify the default behaviour of QEMU itself. That way, if there is any change, however unlikely, we might get some users complaining that the default is specified to be "off" while it is not. I'd just leave out this one line.
+# "on" - set append value to "on", meaning file won't be truncated on restart +# "off" - set append value to "off", file will be cleared on restart +#serial_file_append = "default" diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ae5bbcd138..bfd93a168f 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -288,6 +288,7 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, return NULL;
cfg->deprecationBehavior = g_strdup("none"); + cfg->serialFileAppend = g_strdup("default");
return g_steal_pointer(&cfg); } @@ -376,6 +377,7 @@ static void virQEMUDriverConfigDispose(void *obj) g_strfreev(cfg->capabilityfilters);
g_free(cfg->deprecationBehavior); + g_free(cfg->serialFileAppend); }
@@ -903,6 +905,8 @@ virQEMUDriverConfigLoadDebugEntry(virQEMUDriverConfig *cfg, return -1; if (virConfGetValueString(conf, "deprecation_behavior", &cfg->deprecationBehavior) < 0) return -1; + if (virConfGetValueString(conf, "serial_file_append", &cfg->serialFileAppend) < 0) + return -1;
return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8cf2dd2ec5..316200f38d 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -229,6 +229,8 @@ struct _virQEMUDriverConfig { char *deprecationBehavior;
virQEMUSchedCore schedCore; + + char *serialFileAppend; };
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUDriverConfig, virObjectUnref); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8ae458ae45..0d1fe1ffcc 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -37,6 +37,7 @@ #include "qemu_validate.h" #include "qemu_namespace.h" #include "viralloc.h" +#include "virenum.h" #include "virlog.h" #include "virerror.h" #include "viridentity.h" @@ -5357,6 +5358,8 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, virQEMUDriver *driver, unsigned int parseFlags) { + g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); + /* Historically, isa-serial and the default matched, so in order to * maintain backwards compatibility we map them here. The actual default * will be picked below based on the architecture and machine type. */ @@ -5428,6 +5431,16 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, } }
+ + if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && + chr->source && + chr->source->type == VIR_DOMAIN_CHR_TYPE_FILE && + chr->source->data.file.append == VIR_TRISTATE_SWITCH_ABSENT) { + + chr->source->data.file.append = + virTristateSwitchTypeFromString(cfg->serialFileAppend);
If we translate this during startup then we don't have to do that on every XML parse, but I see some other things are used the same way.
Couple of places do a change to default if there is an _ABSENT option, maybe it'd be nicer to have something like virTristateSwitchMerge() that'd do the same, but that's just my rambling, an idea for future someone, unrelated to your patch.
+ } + return 0; }
diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in index 1dbd692921..d1ca9c8d3d 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -117,3 +117,4 @@ module Test_libvirtd_qemu = } { "deprecation_behavior" = "none" } { "sched_core" = "none" } +{ "serial_file_append" = "default" } -- 2.38.1

Previous commit has introduced the config option to enable append=on for serial files. Here we test it. Signed-off-by: Oleg Vasilev <oleg.vasilev@virtuozzo.com> --- tests/qemuxml2argvdata/serial-append.xml | 56 +++++++++++++++++++ .../serial-append.x86_64-latest.xml | 56 +++++++++++++++++++ tests/qemuxml2xmltest.c | 4 ++ 3 files changed, 116 insertions(+) create mode 100644 tests/qemuxml2argvdata/serial-append.xml create mode 100644 tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml diff --git a/tests/qemuxml2argvdata/serial-append.xml b/tests/qemuxml2argvdata/serial-append.xml new file mode 100644 index 0000000000..3f2cb210e4 --- /dev/null +++ b/tests/qemuxml2argvdata/serial-append.xml @@ -0,0 +1,56 @@ +<domain type='qemu'> + <name>machine</name> + <uuid>2187c512-ff97-47d7-b67c-c02d3bdc219d</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='ide' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <serial type='file'> + <source path='/tmp/serial.file'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='isa-serial' port='0'> + <model name='isa-serial'/> + </target> + </serial> + <serial type='unix'> + <source mode='connect' path='/tmp/serial.sock'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='isa-serial' port='1'> + <model name='isa-serial'/> + </target> + </serial> + <console type='file'> + <source path='/tmp/serial.file'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='serial' port='0'/> + </console> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml b/tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml new file mode 100644 index 0000000000..0bd5f3db81 --- /dev/null +++ b/tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml @@ -0,0 +1,56 @@ +<domain type='qemu'> + <name>machine</name> + <uuid>2187c512-ff97-47d7-b67c-c02d3bdc219d</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='ide' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <serial type='file'> + <source path='/tmp/serial.file' append='on'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='isa-serial' port='0'> + <model name='isa-serial'/> + </target> + </serial> + <serial type='unix'> + <source mode='connect' path='/tmp/serial.sock'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='isa-serial' port='1'> + <model name='isa-serial'/> + </target> + </serial> + <console type='file'> + <source path='/tmp/serial.file' append='on'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='serial' port='0'/> + </console> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index e13da8bd2c..5502456328 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -915,6 +915,10 @@ mymain(void) QEMU_CAPS_DEVICE_VIRTIO_RNG, QEMU_CAPS_OBJECT_RNG_EGD); + g_free(cfg->serialFileAppend); + cfg->serialFileAppend = g_strdup("on"); + DO_TEST_CAPS_LATEST("serial-append"); + DO_TEST_NOCAPS("cpu-numa1"); DO_TEST_NOCAPS("cpu-numa2"); DO_TEST_NOCAPS("cpu-numa-no-memory-element"); -- 2.38.1

On Tue, Nov 29, 2022 at 09:54:52PM +0600, Oleg Vasilev wrote:
Previous commit has introduced the config option to enable append=on for serial files. Here we test it.
Signed-off-by: Oleg Vasilev <oleg.vasilev@virtuozzo.com> --- tests/qemuxml2argvdata/serial-append.xml | 56 +++++++++++++++++++ .../serial-append.x86_64-latest.xml | 56 +++++++++++++++++++ tests/qemuxml2xmltest.c | 4 ++ 3 files changed, 116 insertions(+) create mode 100644 tests/qemuxml2argvdata/serial-append.xml create mode 100644 tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml
diff --git a/tests/qemuxml2argvdata/serial-append.xml b/tests/qemuxml2argvdata/serial-append.xml new file mode 100644 index 0000000000..3f2cb210e4 --- /dev/null +++ b/tests/qemuxml2argvdata/serial-append.xml @@ -0,0 +1,56 @@ +<domain type='qemu'> + <name>machine</name> + <uuid>2187c512-ff97-47d7-b67c-c02d3bdc219d</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='ide' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <serial type='file'> + <source path='/tmp/serial.file'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='isa-serial' port='0'> + <model name='isa-serial'/> + </target> + </serial> + <serial type='unix'> + <source mode='connect' path='/tmp/serial.sock'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='isa-serial' port='1'> + <model name='isa-serial'/> + </target> + </serial> + <console type='file'> + <source path='/tmp/serial.file'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='serial' port='0'/> + </console> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml b/tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml new file mode 100644 index 0000000000..0bd5f3db81 --- /dev/null +++ b/tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml @@ -0,0 +1,56 @@ +<domain type='qemu'> + <name>machine</name> + <uuid>2187c512-ff97-47d7-b67c-c02d3bdc219d</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='ide' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <serial type='file'> + <source path='/tmp/serial.file' append='on'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='isa-serial' port='0'> + <model name='isa-serial'/> + </target> + </serial> + <serial type='unix'> + <source mode='connect' path='/tmp/serial.sock'> + <seclabel model='dac' relabel='no'/> + </source> + <target type='isa-serial' port='1'> + <model name='isa-serial'/> + </target> + </serial> + <console type='file'> + <source path='/tmp/serial.file' append='on'>
Since there are several outcomes the previous patch could have it'd be nicer if one XML file tested more of them. The same file then can be ran with different config options and we'd have all the possibilities tested with just three additional tests, which is not that much. Also this patch should be merged into the previous one.
+ <seclabel model='dac' relabel='no'/> + </source> + <target type='serial' port='0'/> + </console> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index e13da8bd2c..5502456328 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -915,6 +915,10 @@ mymain(void) QEMU_CAPS_DEVICE_VIRTIO_RNG, QEMU_CAPS_OBJECT_RNG_EGD);
+ g_free(cfg->serialFileAppend); + cfg->serialFileAppend = g_strdup("on"); + DO_TEST_CAPS_LATEST("serial-append"); + DO_TEST_NOCAPS("cpu-numa1"); DO_TEST_NOCAPS("cpu-numa2"); DO_TEST_NOCAPS("cpu-numa-no-memory-element"); -- 2.38.1

Ping On 29.11.2022 21:54, Oleg Vasilev wrote:
Serial log file contains lots of useful information for debugging configuration problems. It makes sense to preserve the log in between restarts, so that one can later figure out what was going on.
Oleg Vasilev (2): qemu: add append mode config for serial file qemuxml2xmltest: add serial append=on test
src/qemu/libvirtd_qemu.aug | 3 + src/qemu/qemu.conf.in | 10 ++++ src/qemu/qemu_conf.c | 4 ++ src/qemu/qemu_conf.h | 2 + src/qemu/qemu_domain.c | 13 +++++ src/qemu/test_libvirtd_qemu.aug.in | 1 + tests/qemuxml2argvdata/serial-append.xml | 56 +++++++++++++++++++ .../serial-append.x86_64-latest.xml | 56 +++++++++++++++++++ tests/qemuxml2xmltest.c | 4 ++ 9 files changed, 149 insertions(+) create mode 100644 tests/qemuxml2argvdata/serial-append.xml create mode 100644 tests/qemuxml2xmloutdata/serial-append.x86_64-latest.xml
participants (2)
-
Martin Kletzander
-
Oleg Vasilev