We have something like pvpanic device. However, in some cases it does not have any address assigned, in which case we produce this ugly XML (still valid though): <devices> <emulator>/usr/bin/qemu</emulator> ... <panic> </panic> </devices> Lets format "<pvpanic/>" instead. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_conf.c | 20 ++++++++++----- .../qemuxml2argv-panic-no-address.args | 5 ++++ .../qemuxml2argv-panic-no-address.xml | 29 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 3 +++ tests/qemuxml2xmltest.c | 1 + 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6da02b0..a02d656 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18750,13 +18750,21 @@ virDomainWatchdogDefFormat(virBufferPtr buf, static int virDomainPanicDefFormat(virBufferPtr buf, virDomainPanicDefPtr def) { - virBufferAddLit(buf, "<panic>\n"); - virBufferAdjustIndent(buf, 2); - if (virDomainDeviceInfoFormat(buf, &def->info, 0) < 0) - return -1; - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "</panic>\n"); + virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; + int indent = virBufferGetIndent(buf, false); + virBufferAddLit(buf, "<panic"); + virBufferAdjustIndent(&childrenBuf, indent + 2); + if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0) + return -1; + if (virBufferUse(&childrenBuf)) { + virBufferAddLit(buf, ">\n"); + virBufferAddBuffer(buf, &childrenBuf); + virBufferAddLit(buf, "</panic>\n"); + } else { + virBufferAddLit(buf, "/>\n"); + } + virBufferFreeAndReset(&childrenBuf); return 0; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.args b/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.args new file mode 100644 index 0000000..3cbd688 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ +/usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \ +-hda /dev/HostVG/QEMUGuest1 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 -device pvpanic diff --git a/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.xml new file mode 100644 index 0000000..79f8a1e --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-panic-no-address.xml @@ -0,0 +1,29 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='usb' index='0'/> + <controller type='fdc' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='virtio'/> + <panic/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 00fd044..e2ad713 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1522,6 +1522,9 @@ mymain(void) DO_TEST("panic", QEMU_CAPS_DEVICE_PANIC, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("panic-no-address", QEMU_CAPS_DEVICE_PANIC, + QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("fips-enabled", QEMU_CAPS_ENABLE_FIPS); DO_TEST("shmem", QEMU_CAPS_PCIDEVICE, diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 58917c3..9e85d4e 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -400,6 +400,7 @@ mymain(void) DO_TEST("pcihole64-q35"); DO_TEST("panic"); + DO_TEST("panic-no-address"); DO_TEST_DIFFERENT("disk-backing-chains"); -- 2.0.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list