When preparing a SCSI <hostdev/> with passthrough of a host SCSI adapter (i.e. no protocol), a virStorageSource structure is initialized and stored inside virDomainHostdevDef. But the source structure is filled in many places, with almost the same code. Firstly, qemuProcessPrepareHostHostdev() and qemuConnectDomainXMLToNativePrepareHostHostdev() are the same. Secondly, qemuDomainPrepareHostdev() allocates the src structure, only to let qemuProcessPrepareHostHostdev() fill src->path later. Well, src->path can be filled at the same place where the src structure is allocated (qemuDomainPrepareHostdev()) which renders the other two functions needless. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_domain.c | 10 ++++++++++ src/qemu/qemu_driver.c | 32 +------------------------------- src/qemu/qemu_process.c | 32 +------------------------------- tests/qemuxml2argvmock.c | 10 ++++++++++ tests/qemuxml2argvtest.c | 22 ---------------------- 5 files changed, 22 insertions(+), 84 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 72f36c807b..c5520505bf 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11244,7 +11244,9 @@ qemuDomainPrepareHostdevSCSI(virDomainHostdevDef *hostdev, qemuDomainObjPrivate *priv) { virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi; + virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host; virStorageSource *src = NULL; + g_autofree char *devstr = NULL; switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: @@ -11252,7 +11254,15 @@ qemuDomainPrepareHostdevSCSI(virDomainHostdevDef *hostdev, scsisrc->u.host.src = virStorageSourceNew(); src = scsisrc->u.host.src; + if (!(devstr = virSCSIDeviceGetSgName(NULL, + scsihostsrc->adapter, + scsihostsrc->bus, + scsihostsrc->target, + scsihostsrc->unit))) + return -1; + src->type = VIR_STORAGE_TYPE_BLOCK; + src->path = g_strdup_printf("/dev/%s", devstr); break; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 523a83682c..d6f9d0796a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6166,38 +6166,8 @@ static char static int -qemuConnectDomainXMLToNativePrepareHostHostdev(virDomainHostdevDef *hostdev) +qemuConnectDomainXMLToNativePrepareHostHostdev(virDomainHostdevDef *hostdev G_GNUC_UNUSED) { - if (virHostdevIsSCSIDevice(hostdev)) { - virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi; - - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: { - virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host; - virStorageSource *src = scsisrc->u.host.src; - g_autofree char *devstr = NULL; - - if (!(devstr = virSCSIDeviceGetSgName(NULL, - scsihostsrc->adapter, - scsihostsrc->bus, - scsihostsrc->target, - scsihostsrc->unit))) - return -1; - - src->path = g_strdup_printf("/dev/%s", devstr); - break; - } - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: - break; - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: - default: - virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsisrc->protocol); - return -1; - } - } - return 0; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8baa882875..0bc19479d4 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6510,38 +6510,8 @@ qemuProcessPrepareDomainHostdevs(virDomainObj *vm, int -qemuProcessPrepareHostHostdev(virDomainHostdevDef *hostdev) +qemuProcessPrepareHostHostdev(virDomainHostdevDef *hostdev G_GNUC_UNUSED) { - if (virHostdevIsSCSIDevice(hostdev)) { - virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi; - - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: { - virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host; - virStorageSource *src = scsisrc->u.host.src; - g_autofree char *devstr = NULL; - - if (!(devstr = virSCSIDeviceGetSgName(NULL, - scsihostsrc->adapter, - scsihostsrc->bus, - scsihostsrc->target, - scsihostsrc->unit))) - return -1; - - src->path = g_strdup_printf("/dev/%s", devstr); - break; - } - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: - break; - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: - default: - virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsisrc->protocol); - return -1; - } - } - return 0; } diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index f566ec539a..400dd5c020 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -82,6 +82,16 @@ virSCSIVHostOpenVhostSCSI(int *vhostfd) return 0; } +char * +virSCSIDeviceGetSgName(const char *sysfs_prefix G_GNUC_UNUSED, + const char *adapter G_GNUC_UNUSED, + unsigned int bus G_GNUC_UNUSED, + unsigned int target G_GNUC_UNUSED, + unsigned long long unit G_GNUC_UNUSED) +{ + return g_strdup_printf("sg0"); +} + int virNetDevTapCreate(char **ifname, const char *tunpath G_GNUC_UNUSED, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b65db3bbd9..dad9758be4 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -404,28 +404,6 @@ testCompareXMLToArgvCreateArgs(virQEMUDriver *drv, disk->src->hostcdrom = true; } - for (i = 0; i < vm->def->nhostdevs; i++) { - virDomainHostdevDef *hostdev = vm->def->hostdevs[i]; - - if (virHostdevIsSCSIDevice(hostdev)) { - virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi; - - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: - scsisrc->u.host.src->path = g_strdup("/dev/sg0"); - break; - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: - break; - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: - default: - virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsisrc->protocol); - return NULL; - } - } - } - if (vm->def->vsock) { virDomainVsockDef *vsock = vm->def->vsock; qemuDomainVsockPrivate *vsockPriv = -- 2.39.2