[libvirt] [PATCH] qemu: Allow the disk wwn to have "0x" prefix

Osier Yang jyang at redhat.com
Wed Apr 17 13:26:49 UTC 2013


On 17/04/13 21:23, Osier Yang wrote:
> 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'

Add this in the commit log:

     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 +++++++++---
>   tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args       |  2 +-
>   tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args |  4 ++--
>   tests/qemuxml2argvdata/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 adaedd8..34c2254 100644
> --- a/docs/schemas/basictypes.rng
> +++ b/docs/schemas/basictypes.rng
> @@ -280,7 +280,7 @@
>   
>     <define name='wwn'>
>       <data type='string'>
> -      <param name='pattern'>[0-9a-fA-F]{16}</param>
> +      <param name='pattern'>(0x)?[0-9a-fA-F]{16}</param>
>       </data>
>     </define>
>   
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 63b9350..009d42d 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 0e4063b..6890362 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 1633d29..3b9693c 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 0393640..0dd2aa9 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 dc35548..caf957b 100644
> --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml
> @@ -25,7 +25,7 @@
>         <source dev='/dev/HostVG/QEMUGuest2'/>
>         <target dev='sdb' bus='scsi'/>
>         <address type='drive' controller='0' bus='0' target='0' unit='0'/>
> -      <wwn>5000c50015ea71ad</wwn>
> +      <wwn>0x5000c50015ea71ad</wwn>
>       </disk>
>       <controller type='usb' index='0'/>
>       <controller type='scsi' index='0' model='virtio-scsi'/>




More information about the libvir-list mailing list