From 5aee81a0cb60308b8614ee37c0b69c1dde1f00d8 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 23 Feb 2015 12:34:23 +0100 Subject: [PATCH] qemu: Allow spaces in disk serial https://bugzilla.redhat.com/show_bug.cgi?id=1195660 There's been a bug report appearing on the qemu-devel list, that libvirt is unable to pass spaces in disk serial number [1]. Not only our RNG schema forbids that, the code is not prepared either. However, with a bit of escaping (if needed) we can allow spaces there. 1: https://lists.gnu.org/archive/html/qemu-devel/2015-02/msg04041.html Signed-off-by: Michal Privoznik --- docs/schemas/domaincommon.rng | 2 +- src/qemu/qemu_command.c | 5 ++-- .../qemuxml2argv-disk-serial.args | 7 +++++ .../qemuxml2argv-disk-serial.xml | 27 +++++++++++++++++++ tests/qemuxml2argvtest.c | 5 ++++ 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-serial.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-serial.xml diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 66fcbeebda..56ea6a43e3 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -5089,7 +5089,7 @@ - [A-Za-z0-9_\.\+\-]+ + [A-Za-z0-9_\.\+\- ]+ diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c112619669..a5a1f11f21 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2630,7 +2630,7 @@ qemuBuildIoEventFdStr(virBufferPtr buf, } #define QEMU_SERIAL_PARAM_ACCEPTED_CHARS \ - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_" + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ " static int qemuSafeSerialParamValue(const char *value) @@ -3613,7 +3613,8 @@ qemuBuildDriveStr(virConnectPtr conn, virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_SERIAL)) { if (qemuSafeSerialParamValue(disk->serial) < 0) goto error; - virBufferAsprintf(&opt, ",serial=%s", disk->serial); + virBufferAddLit(&opt, ",serial="); + virBufferEscape(&opt, '\\', " ", "%s", disk->serial); } if (disk->cachemode) { diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-serial.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-serial.args new file mode 100644 index 0000000000..794b94b758 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-serial.args @@ -0,0 +1,7 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ +/usr/libexec/qemu-kvm -S -M pc -cpu qemu32 -m 214 -smp 1 -nographic -nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \ +-drive 'file=/dev/HostVG/QEMUGuest1,if=none,\ +id=drive-ide0-0-1,serial=\ \ WD-WMAP9A966149' \ +-device ide-drive,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-serial.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-serial.xml new file mode 100644 index 0000000000..0fe75f3c31 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-serial.xml @@ -0,0 +1,27 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/libexec/qemu-kvm + + + + WD-WMAP9A966149 +
+ + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 681f8fe64c..00fd044ffb 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -897,6 +897,11 @@ mymain(void) QEMU_CAPS_DEVICE, QEMU_CAPS_SCSI_BLOCK, QEMU_CAPS_VIRTIO_BLK_SG_IO, QEMU_CAPS_SCSI_LSI, QEMU_CAPS_VIRTIO_SCSI); + DO_TEST("disk-serial", + QEMU_CAPS_KVM, + QEMU_CAPS_DEVICE, + QEMU_CAPS_DRIVE, + QEMU_CAPS_DRIVE_SERIAL); DO_TEST("graphics-vnc", QEMU_CAPS_VNC); DO_TEST("graphics-vnc-socket", QEMU_CAPS_VNC); -- GitLab