From 09d2547f96920c6fddc00ea3f1efcafb65c0845b Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Wed, 17 Apr 2013 21:23:44 +0800 Subject: [PATCH] qemu: Allow the disk wwn to have "0x" prefix The recent qemu requires "0x" prefix for the disk wwn, this patch changes virValidateWWN to allow the prefix, and prepend "0x" if it's not specified. E.g. qemu-kvm: -device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,\ drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,wwn=6000c60016ea71ad: Property 'scsi-hd.wwn' doesn't take value '6000c60016ea71ad' Though it's a qemu regression, but it's nice to allow the prefix, and doesn't hurt for us to always output "0x". --- docs/schemas/basictypes.rng | 2 +- src/qemu/qemu_command.c | 8 ++++++-- src/util/virutil.c | 12 +++++++++--- .../qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args | 2 +- .../qemuxml2argv-disk-scsi-disk-wwn.args | 4 ++-- .../qemuxml2argv-disk-scsi-disk-wwn.xml | 2 +- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng index adaedd8794..34c2254330 100644 --- a/docs/schemas/basictypes.rng +++ b/docs/schemas/basictypes.rng @@ -280,7 +280,7 @@ - [0-9a-fA-F]{16} + (0x)?[0-9a-fA-F]{16} diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 63b9350c2b..009d42d452 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3358,8 +3358,12 @@ qemuBuildDriveDevStr(virDomainDefPtr def, disk->blockio.physical_block_size); } - if (disk->wwn) - virBufferAsprintf(&opt, ",wwn=%s", disk->wwn); + if (disk->wwn) { + if (STRPREFIX(disk->wwn, "0x")) + virBufferAsprintf(&opt, ",wwn=%s", disk->wwn); + else + virBufferAsprintf(&opt, ",wwn=0x%s", disk->wwn); + } if (disk->vendor) virBufferAsprintf(&opt, ",vendor=%s", disk->vendor); diff --git a/src/util/virutil.c b/src/util/virutil.c index 0e4063b2a7..6890362890 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -3228,12 +3228,18 @@ bool virIsDevMapperDevice(const char *dev_name ATTRIBUTE_UNUSED) bool virValidateWWN(const char *wwn) { int i; + const char *p = wwn; - for (i = 0; wwn[i]; i++) - if (!c_isxdigit(wwn[i])) + if (STRPREFIX(wwn, "0x")) { + p += 2; + } + + for (i = 0; p[i]; i++) { + if (!c_isxdigit(p[i])) break; + } - if (i != 16 || wwn[i]) { + if (i != 16 || p[i]) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Malformed wwn: %s")); return false; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args index 1633d29c38..3b9693cc6d 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args @@ -2,5 +2,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \ /usr/bin/qemu -S -M pc -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-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1,wwn=5000c50015ea71ad \ +-device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1,wwn=0x5000c50015ea71ad \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args index 0393640cbd..0dd2aa9d83 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args @@ -5,7 +5,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \ -device lsi,id=scsi1,bus=pci.0,addr=0x4 \ -usb \ -drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-scsi0-0-1-0 \ --device scsi-cd,bus=scsi0.0,channel=0,scsi-id=1,lun=0,drive=drive-scsi0-0-1-0,id=scsi0-0-1-0,wwn=5000c50015ea71ac \ +-device scsi-cd,bus=scsi0.0,channel=0,scsi-id=1,lun=0,drive=drive-scsi0-0-1-0,id=scsi0-0-1-0,wwn=0x5000c50015ea71ac \ -drive file=/dev/HostVG/QEMUGuest2,if=none,id=drive-scsi0-0-0-0 \ --device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,wwn=5000c50015ea71ad \ +-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,wwn=0x5000c50015ea71ad \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml index dc355484bd..caf957b66b 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml @@ -25,7 +25,7 @@
- 5000c50015ea71ad + 0x5000c50015ea71ad