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 <mprivozn(a)redhat.com>
---
diff to v1:
- Switch from virBufferEscapeShell to virBufferEscape
docs/schemas/domaincommon.rng | 2 +-
src/qemu/qemu_command.c | 5 ++--
.../qemuxml2argvdata/qemuxml2argv-disk-serial.args | 7 ++++++
.../qemuxml2argvdata/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 f41ca43..09bd921 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -5067,7 +5067,7 @@
</define>
<define name="diskSerial">
<data type="string">
- <param name="pattern">[A-Za-z0-9_\.\+\-]+</param>
+ <param name="pattern">[A-Za-z0-9_\.\+\- ]+</param>
</data>
</define>
<define name="bridgeMode">
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index fb3d5ab..25b6499 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2633,7 +2633,7 @@ qemuBuildIoEventFdStr(virBufferPtr buf,
}
#define QEMU_SERIAL_PARAM_ACCEPTED_CHARS \
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ "
static int
qemuSafeSerialParamValue(const char *value)
@@ -3616,7 +3616,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 0000000..794b94b
--- /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 0000000..0fe75f3
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-serial.xml
@@ -0,0 +1,27 @@
+<domain type='kvm'>
+ <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/libexec/qemu-kvm</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <serial> WD-WMAP9A966149</serial>
+ <address type='drive' controller='0' bus='0'
target='0' unit='1'/>
+ </disk>
+ <controller type='usb' index='0'/>
+ <controller type='ide' index='0'/>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 16f325e..3032d1b 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -904,6 +904,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);
--
2.0.5