From 6e73850b01ee7d5816a803d684e9d669dad036f3 Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Tue, 11 Sep 2012 16:57:04 +0800 Subject: [PATCH] qemu: Use disk wwn in qemu command line All of ide-drive, ide-hd, ide-cd, scsi-disk, scsi-hd, and scsi-cd supports wwn property. (NB, scsi-block doesn't support to set wwn). * src/qemu/qemu_command.c: Error out if underlying QEMU doesn't support wwn property for the device; Set wwn for the device otherwise. * tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args: New test * tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.xml: Likewise * tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args: Likewise * tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml: Likewise * tests/qemuxml2argvtest.c: Add the new tests. --- src/qemu/qemu_command.c | 33 +++++++++++++++++ .../qemuxml2argv-disk-ide-wwn.args | 6 ++++ .../qemuxml2argv-disk-ide-wwn.xml | 28 +++++++++++++++ .../qemuxml2argv-disk-scsi-disk-wwn.args | 10 ++++++ .../qemuxml2argv-disk-scsi-disk-wwn.xml | 35 +++++++++++++++++++ tests/qemuxml2argvtest.c | 7 ++++ 6 files changed, 119 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 06a4bac878..ec29d4e9b6 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2453,6 +2453,15 @@ qemuBuildDriveDevStr(virDomainDefPtr def, goto error; } + if (disk->wwn) { + if ((disk->bus != VIR_DOMAIN_DISK_BUS_IDE) && + (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only ide and scsi disk support wwn")); + goto error; + } + } + if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { /* make sure that both the bus and the qemu binary support * type='lun' (SG_IO). @@ -2475,6 +2484,11 @@ qemuBuildDriveDevStr(virDomainDefPtr def, _("disk device='lun' is not supported by this QEMU")); goto error; } + if (disk->wwn) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Setting wwn is not supported for lun device")); + goto error; + } } switch (disk->bus) { @@ -2485,6 +2499,14 @@ qemuBuildDriveDevStr(virDomainDefPtr def, goto error; } + if (disk->wwn && + !qemuCapsGet(caps, QEMU_CAPS_IDE_DRIVE_WWN)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Setting wwn for ide disk is not supported " + "by this QEMU")); + goto error; + } + if (qemuCapsGet(caps, QEMU_CAPS_IDE_CD)) { if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) virBufferAddLit(&opt, "ide-cd"); @@ -2508,6 +2530,14 @@ qemuBuildDriveDevStr(virDomainDefPtr def, } } + if (disk->wwn && + !qemuCapsGet(caps, QEMU_CAPS_SCSI_DISK_WWN)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Setting wwn for scsi disk is not supported " + "by this QEMU")); + goto error; + } + controllerModel = virDomainDiskFindControllerModel(def, disk, VIR_DOMAIN_CONTROLLER_TYPE_SCSI); @@ -2647,6 +2677,9 @@ qemuBuildDriveDevStr(virDomainDefPtr def, disk->blockio.physical_block_size); } + if (disk->wwn) + virBufferAsprintf(&opt, ",wwn=%s", disk->wwn); + if (virBufferError(&opt)) { virReportOOMError(); goto error; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args new file mode 100644 index 0000000000..4b8a543813 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.args @@ -0,0 +1,6 @@ +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 \ +-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 \ +-usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.xml new file mode 100644 index 0000000000..dccec95705 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-wwn.xml @@ -0,0 +1,28 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + WD-WMAP9A966149 + 5000c50015ea71ad +
+ + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args new file mode 100644 index 0000000000..fe4591bd5d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.args @@ -0,0 +1,10 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \ +/usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \ +-device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3 \ +-device lsi,id=scsi1,bus=pci.0,addr=0x4 \ +-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 \ +-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 \ +-usb -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 new file mode 100644 index 0000000000..dc355484bd --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-wwn.xml @@ -0,0 +1,35 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ WD-WMAP9A966149 + 5000c50015ea71ac + + + + +
+ 5000c50015ea71ad + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 4daa68d0f6..0ec3c2cb69 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -471,6 +471,10 @@ mymain(void) DO_TEST("disk-scsi-disk-split", QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_SCSI_CD, QEMU_CAPS_SCSI_LSI, QEMU_CAPS_VIRTIO_SCSI_PCI); + DO_TEST("disk-scsi-disk-wwn", + QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, + QEMU_CAPS_SCSI_CD, QEMU_CAPS_SCSI_LSI, QEMU_CAPS_VIRTIO_SCSI_PCI, + QEMU_CAPS_SCSI_DISK_WWN); DO_TEST("disk-scsi-vscsi", QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("disk-scsi-virtio-scsi", @@ -802,6 +806,9 @@ mymain(void) DO_TEST("disk-ide-drive-split", QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_IDE_CD); + DO_TEST("disk-ide-wwn", + QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_IDE_CD, + QEMU_CAPS_DRIVE_SERIAL, QEMU_CAPS_IDE_DRIVE_WWN); DO_TEST("disk-geometry", QEMU_CAPS_DRIVE); DO_TEST("disk-blockio",