]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Convert USB disks over to -device
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 14 Dec 2009 19:15:05 +0000 (19:15 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 18 Jan 2010 13:55:56 +0000 (13:55 +0000)
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
tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-disk-usb-device.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index 18884793fc7ae7cbcce9919eaaeb31e633f46dbb..49e4c08a5d29d6414b578c41087f6eac557e322a 100644 (file)
@@ -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);
@@ -2948,7 +2950,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 (file)
index 0000000..d12d61c
--- /dev/null
@@ -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 (file)
index 0000000..d59e1c0
--- /dev/null
@@ -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>
index 645f6b4de1210d4cef6029e6422a46efecc6d21e..8c88a7921fbe76ed633809741a7e331fbf17d7eb 100644 (file)
@@ -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;