mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
virhostdev: Introduce and use virHostdevIsVFIODevice
In some places we need to check if a hostdev has VFIO backend. Because of how complicated virDomainHostdevDef structure is, the check consists of three lines. Move them to a function and replace all checks with the function call. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
72cbc1800b
commit
82a2486236
@ -31486,10 +31486,7 @@ virDomainDefHasVFIOHostdev(const virDomainDef *def)
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < def->nhostdevs; i++) {
|
||||
const virDomainHostdevDef *tmp = def->hostdevs[i];
|
||||
if (tmp->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
|
||||
tmp->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
|
||||
tmp->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO)
|
||||
if (virHostdevIsVFIODevice(def->hostdevs[i]))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2112,6 +2112,7 @@ virHostCPUStatsAssign;
|
||||
virHostdevFindUSBDevice;
|
||||
virHostdevIsMdevDevice;
|
||||
virHostdevIsSCSIDevice;
|
||||
virHostdevIsVFIODevice;
|
||||
virHostdevManagerGetDefault;
|
||||
virHostdevPCINodeDeviceDetach;
|
||||
virHostdevPCINodeDeviceReAttach;
|
||||
|
@ -413,9 +413,7 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm,
|
||||
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES))
|
||||
return 0;
|
||||
|
||||
if (dev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
|
||||
dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
|
||||
dev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO &&
|
||||
if (virHostdevIsVFIODevice(dev) &&
|
||||
qemuDomainGetHostdevPath(vm->def, dev, true,
|
||||
&npaths, &path, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
@ -11761,9 +11761,7 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def)
|
||||
for (i = 0; i < def->nhostdevs; i++) {
|
||||
virDomainHostdevDefPtr dev = def->hostdevs[i];
|
||||
|
||||
if (dev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
|
||||
dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
|
||||
dev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
|
||||
if (virHostdevIsVFIODevice(dev)) {
|
||||
usesVFIO = true;
|
||||
|
||||
pciAddr = &dev->source.subsys.u.pci.addr;
|
||||
@ -11915,12 +11913,8 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
|
||||
* Note that this may not be valid for all platforms.
|
||||
*/
|
||||
for (i = 0; i < def->nhostdevs; i++) {
|
||||
virDomainHostdevSubsysPtr subsys = &def->hostdevs[i]->source.subsys;
|
||||
|
||||
if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
|
||||
(subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV ||
|
||||
(subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
|
||||
subsys->u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO))) {
|
||||
if (virHostdevIsVFIODevice(def->hostdevs[i]) ||
|
||||
virHostdevIsMdevDevice(def->hostdevs[i])) {
|
||||
memKB = virDomainDefGetMemoryTotal(def) + 1024 * 1024;
|
||||
goto done;
|
||||
}
|
||||
|
@ -4437,16 +4437,10 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
g_autofree char *drivealias = NULL;
|
||||
g_autofree char *objAlias = NULL;
|
||||
bool is_vfio = false;
|
||||
|
||||
VIR_DEBUG("Removing host device %s from domain %p %s",
|
||||
hostdev->info->alias, vm, vm->def->name);
|
||||
|
||||
if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
|
||||
int backend = hostdev->source.subsys.u.pci.backend;
|
||||
is_vfio = backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO;
|
||||
}
|
||||
|
||||
if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
|
||||
virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
|
||||
virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
|
||||
@ -4494,7 +4488,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
|
||||
virDomainAuditHostdev(vm, hostdev, "detach", true);
|
||||
|
||||
if (!is_vfio &&
|
||||
if (!virHostdevIsVFIODevice(hostdev) &&
|
||||
qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0)
|
||||
VIR_WARN("Failed to restore host device labelling");
|
||||
|
||||
|
@ -389,6 +389,21 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virHostdevIsVFIODevice:
|
||||
* @hostdev: host device to check
|
||||
*
|
||||
* Returns true if @hostdev is a PCI device with VFIO backend, false otherwise.
|
||||
*/
|
||||
bool
|
||||
virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
|
||||
{
|
||||
return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
|
||||
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
|
||||
hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
|
||||
virNetDevVPortProfilePtr virtPort,
|
||||
|
@ -193,6 +193,9 @@ virHostdevIsSCSIDevice(const virDomainHostdevDef *hostdev)
|
||||
bool
|
||||
virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
bool
|
||||
virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
/* functions used by NodeDevDetach/Reattach/Reset */
|
||||
int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr,
|
||||
|
Loading…
Reference in New Issue
Block a user