Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- src/qemu/qemu_command.c | 20 -------------------- src/qemu/qemu_validate.c | 25 +++++++++++++++++++++++++ tests/qemuxml2argvtest.c | 6 +++--- tests/qemuxml2xmltest.c | 4 ++-- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a5abd814a2..06ac175b67 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1693,19 +1693,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, break; case VIR_DOMAIN_DISK_BUS_USB: - if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && - disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("unexpected address type for usb disk")); - return NULL; - } - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("This QEMU doesn't support '-device " - "usb-storage'")); - return NULL; - - } virBufferAddLit(&opt, "usb-storage"); if (qemuBuildDeviceAddressStr(&opt, def, &disk->info, qemuCaps) < 0) @@ -1772,13 +1759,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, virBufferAddLit(&opt, ",removable=on"); else virBufferAddLit(&opt, ",removable=off"); - } else { - if (disk->removable != VIR_TRISTATE_SWITCH_ABSENT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("This QEMU doesn't support setting the " - "removable flag of USB storage devices")); - return NULL; - } } } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 4a74265ced..beaa1aedce 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2275,6 +2275,31 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk, } 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'")); + return -1; + } + + if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && + disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unexpected address type for usb disk")); + return -1; + } + + if (disk->removable != VIR_TRISTATE_SWITCH_ABSENT && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_STORAGE_REMOVABLE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("This QEMU doesn't support setting the " + "removable flag of USB storage devices")); + return -1; + } + + break; + case VIR_DOMAIN_DISK_BUS_XEN: case VIR_DOMAIN_DISK_BUS_SD: break; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index cd15ce5138..cf1d3c7ded 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1220,14 +1220,14 @@ mymain(void) DO_TEST_PARSE_ERROR("disk-device-lun-type-invalid", QEMU_CAPS_VIRTIO_SCSI); DO_TEST_CAPS_LATEST_PARSE_ERROR("disk-attaching-partition-nosupport"); - DO_TEST_FAILURE("disk-usb-nosupport", NONE); + DO_TEST_PARSE_ERROR("disk-usb-nosupport", NONE); DO_TEST("disk-usb-device", QEMU_CAPS_DEVICE_USB_STORAGE); DO_TEST("disk-usb-device-removable", QEMU_CAPS_DEVICE_USB_STORAGE, QEMU_CAPS_USB_STORAGE_REMOVABLE); - DO_TEST_FAILURE("disk-usb-pci", - QEMU_CAPS_DEVICE_USB_STORAGE); + DO_TEST_PARSE_ERROR("disk-usb-pci", + QEMU_CAPS_DEVICE_USB_STORAGE); DO_TEST_CAPS_LATEST("disk-scsi"); DO_TEST_CAPS_VER("disk-scsi-device-auto", "1.5.3"); DO_TEST_CAPS_LATEST("disk-scsi-device-auto"); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index d8040e8871..f4a5aa18f7 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -328,9 +328,9 @@ mymain(void) DO_TEST_CAPS_LATEST("disk-aio-io_uring"); DO_TEST("disk-cdrom", NONE); DO_TEST_CAPS_LATEST("disk-cdrom-empty-network-invalid"); - DO_TEST("disk-cdrom-bus-other", NONE); + DO_TEST("disk-cdrom-bus-other", QEMU_CAPS_DEVICE_USB_STORAGE); DO_TEST("disk-floppy", NONE); - DO_TEST("disk-usb-device", NONE); + DO_TEST("disk-usb-device", QEMU_CAPS_DEVICE_USB_STORAGE); DO_TEST("disk-virtio", NONE); DO_TEST("floppy-drive-fat", NONE); DO_TEST("disk-virtio-queues", QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES); -- 2.26.2