[PATCHv2 1/2] qemu: Add capability flag for usb-storage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Fred A. Kemp" <anonym@xxxxxxxxxx>

Allow use of the usb-storage device only if the new capability flag
QEMU_CAPS_DEVICE_USB_STORAGE is set, which it is for qemu(-kvm)
versions >= 0.12.1.2-rhel62-beta.
---
 src/qemu/qemu_capabilities.c |    2 ++
 src/qemu/qemu_capabilities.h |    1 +
 src/qemu/qemu_command.c      |    7 +++++++
 tests/qemuhelptest.c         |   18 ++++++++++++------
 tests/qemuxml2argvtest.c     |    3 ++-
 5 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 47cc07a..5c566c1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -235,6 +235,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "vnc-share-policy", /* 150 */
               "device-del-event",
               "dmi-to-pci-bridge",
+              "usb-storage",
     );
 
 struct _virQEMUCaps {
@@ -1383,6 +1384,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
     { "vfio-pci", QEMU_CAPS_DEVICE_VFIO_PCI },
     { "scsi-generic", QEMU_CAPS_DEVICE_SCSI_GENERIC },
     { "i82801b11-bridge", QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE },
+    { "usb-storage", QEMU_CAPS_DEVICE_USB_STORAGE },
 };
 
 static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 074e55d..4a8b14b 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -191,6 +191,7 @@ enum virQEMUCapsFlags {
     QEMU_CAPS_VNC_SHARE_POLICY   = 150, /* set display sharing policy */
     QEMU_CAPS_DEVICE_DEL_EVENT   = 151, /* DEVICE_DELETED event */
     QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE  = 152, /* -device i82801b11-bridge */
+    QEMU_CAPS_DEVICE_USB_STORAGE = 153, /* -device usb-storage */
 
     QEMU_CAPS_LAST,                   /* this must always be the last item */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index b5ac15a..395b24a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4325,6 +4325,13 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
             goto error;
         break;
     case VIR_DOMAIN_DISK_BUS_USB:
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("This QEMU doesn't support '-device "
+                             "usb-storage'"));
+            goto error;
+
+        }
         virBufferAddLit(&opt, "usb-storage");
 
         if (qemuBuildDeviceAddressStr(&opt, def, &disk->info, qemuCaps) < 0)
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index d6cc04b..cbabe12 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -514,7 +514,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_USB_SERIAL,
             QEMU_CAPS_DEVICE_USB_NET,
             QEMU_CAPS_DEVICE_PCI_BRIDGE,
-            QEMU_CAPS_DEVICE_SCSI_GENERIC);
+            QEMU_CAPS_DEVICE_SCSI_GENERIC,
+            QEMU_CAPS_DEVICE_USB_STORAGE);
     DO_TEST("qemu-kvm-0.12.1.2-rhel61", 12001, 1, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -653,7 +654,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_QXL,
             QEMU_CAPS_DEVICE_VGA,
             QEMU_CAPS_DEVICE_CIRRUS_VGA,
-            QEMU_CAPS_DEVICE_PCI_BRIDGE);
+            QEMU_CAPS_DEVICE_PCI_BRIDGE,
+            QEMU_CAPS_DEVICE_USB_STORAGE);
     DO_TEST("qemu-1.0", 1000000, 0, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -736,7 +738,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_USB_SERIAL,
             QEMU_CAPS_DEVICE_USB_NET,
             QEMU_CAPS_DEVICE_SCSI_GENERIC,
-            QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX);
+            QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX,
+            QEMU_CAPS_DEVICE_USB_STORAGE);
     DO_TEST("qemu-1.1.0", 1001000, 0, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -831,7 +834,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_PCI_BRIDGE,
             QEMU_CAPS_DEVICE_SCSI_GENERIC,
             QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX,
-            QEMU_CAPS_VNC_SHARE_POLICY);
+            QEMU_CAPS_VNC_SHARE_POLICY,
+            QEMU_CAPS_DEVICE_USB_STORAGE);
     DO_TEST("qemu-1.2.0", 1002000, 0, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -937,7 +941,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_PCI_BRIDGE,
             QEMU_CAPS_DEVICE_SCSI_GENERIC,
             QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX,
-            QEMU_CAPS_VNC_SHARE_POLICY);
+            QEMU_CAPS_VNC_SHARE_POLICY,
+            QEMU_CAPS_DEVICE_USB_STORAGE);
     DO_TEST("qemu-kvm-1.2.0", 1002000, 1, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -1048,7 +1053,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_PCI_BRIDGE,
             QEMU_CAPS_DEVICE_SCSI_GENERIC,
             QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX,
-            QEMU_CAPS_VNC_SHARE_POLICY);
+            QEMU_CAPS_VNC_SHARE_POLICY,
+            QEMU_CAPS_DEVICE_USB_STORAGE);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 3a3c304..5dbf941 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -540,7 +540,8 @@ mymain(void)
             QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_BOOTINDEX);
     DO_TEST("disk-usb",  NONE);
     DO_TEST("disk-usb-device",
-            QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+            QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_USB_STORAGE,
+            QEMU_CAPS_NODEFCONFIG);
     DO_TEST("disk-scsi-device",
             QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
             QEMU_CAPS_SCSI_LSI);
-- 
1.7.10.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]