The previous syntax was severely limited in its options
-usbdevice disk:/home/berrange/output.img
The new syntax is the same as for other disk types
-drive file=/home/berrange/output.img,if=none,id=usb-1,index=1
-device usb-storage,drive=usb-1
Again, the index= arg is wrong here, and will be removed in a
later merge
---
src/qemu/qemu_conf.c | 9 +++++-
.../qemuxml2argv-disk-usb-device.args | 1 +
.../qemuxml2argv-disk-usb-device.xml | 26 ++++++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
4 files changed, 35 insertions(+), 2 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.xml
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 709c3f4..53866eb 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1945,7 +1945,9 @@ qemuBuildDriveDevStr(virConnectPtr conn,
virBufferAddLit(&opt, "virtio-blk-pci");
qemuBuildDeviceAddressStr(&opt, &disk->info);
break;
-
+ case VIR_DOMAIN_DISK_BUS_USB:
+ virBufferAddLit(&opt, "usb-storage");
+ break;
default:
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("unsupported disk bus '%s' with device
setup"), bus);
@@ -2947,7 +2949,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
virDomainDiskDefPtr disk = def->disks[i];
int withDeviceArg = 0;
- if (disk->bus == VIR_DOMAIN_DISK_BUS_USB) {
+ /* Unless we have -device, then USB disks need special
+ handling */
+ if ((disk->bus == VIR_DOMAIN_DISK_BUS_USB) &&
+ !(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
ADD_USBDISK(disk->src);
} else {
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args
b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args
new file mode 100644
index 0000000..d12d61c
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args
@@ -0,0 +1 @@
+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-0 -device
ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -drive
file=/tmp/usbdisk.img,if=none,id=drive-usb-disk0 -device
usb-storage,drive=drive-usb-disk0,id=usb-disk0 -usb
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.xml
b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.xml
new file mode 100644
index 0000000..d59e1c0
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.xml
@@ -0,0 +1,26 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory>219200</memory>
+ <currentMemory>219200</currentMemory>
+ <vcpu>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/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ </disk>
+ <disk type='file' device='disk'>
+ <source file='/tmp/usbdisk.img'/>
+ <target dev='sda' bus='usb'/>
+ </disk>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 645f6b4..8c88a79 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -235,6 +235,7 @@ mymain(int argc, char **argv)
DO_TEST("disk-drive-cache-v2-none", QEMUD_CMD_FLAG_DRIVE |
QEMUD_CMD_FLAG_DRIVE_CACHE_V2 | QEMUD_CMD_FLAG_DRIVE_FORMAT);
DO_TEST("disk-usb", 0);
+ DO_TEST("disk-usb-device", QEMUD_CMD_FLAG_DRIVE | QEMUD_CMD_FLAG_DEVICE);
DO_TEST("graphics-vnc", 0);
driver.vncSASL = 1;
--
1.6.5.2