qemu: Move <hostdev> SCSI path generation into qemuDomainPrepareHostdev()

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@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Michal Privoznik 2023-04-14 13:09:53 +02:00
parent 57e4e9791a
commit fea0d8c40d
5 changed files with 22 additions and 84 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,

View File

@ -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 =