mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
hypervisor: move HostdevHostSupportsPassthroughVFIO
Move HostdevHostSupportsPassthroughVFIO method to hypervisor to be shared between qemu and ch drivers. Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
b05f6134c9
commit
89ef0c0f2b
@ -29,6 +29,7 @@
|
|||||||
#include "virhostdev.h"
|
#include "virhostdev.h"
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
|
#include "virfile.h"
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "virutil.h"
|
#include "virutil.h"
|
||||||
#include "virnetdev.h"
|
#include "virnetdev.h"
|
||||||
@ -38,6 +39,7 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("util.hostdev");
|
VIR_LOG_INIT("util.hostdev");
|
||||||
|
|
||||||
|
#define VIR_DEV_VFIO "/dev/vfio/vfio"
|
||||||
#define HOSTDEV_STATE_DIR RUNSTATEDIR "/libvirt/hostdevmgr"
|
#define HOSTDEV_STATE_DIR RUNSTATEDIR "/libvirt/hostdevmgr"
|
||||||
|
|
||||||
static virHostdevManager *manager; /* global hostdev manager, never freed */
|
static virHostdevManager *manager; /* global hostdev manager, never freed */
|
||||||
@ -2519,3 +2521,17 @@ virHostdevNeedsVFIO(const virDomainHostdevDef *hostdev)
|
|||||||
return virHostdevIsPCIDevice(hostdev) ||
|
return virHostdevIsPCIDevice(hostdev) ||
|
||||||
virHostdevIsMdevDevice(hostdev);
|
virHostdevIsMdevDevice(hostdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
virHostdevHostSupportsPassthroughVFIO(void)
|
||||||
|
{
|
||||||
|
/* condition 1 - host has IOMMU */
|
||||||
|
if (!virHostHasIOMMU())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* condition 2 - /dev/vfio/vfio exists */
|
||||||
|
if (!virFileExists(VIR_DEV_VFIO))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -235,3 +235,5 @@ virHostdevUpdateActiveNVMeDevices(virHostdevManager *hostdev_mgr,
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
virHostdevNeedsVFIO(const virDomainHostdevDef *hostdev);
|
virHostdevNeedsVFIO(const virDomainHostdevDef *hostdev);
|
||||||
|
|
||||||
|
bool virHostdevHostSupportsPassthroughVFIO(void);
|
||||||
|
@ -1673,6 +1673,7 @@ virCloseCallbacksDomainRunForConn;
|
|||||||
|
|
||||||
# hypervisor/virhostdev.h
|
# hypervisor/virhostdev.h
|
||||||
virHostdevFindUSBDevice;
|
virHostdevFindUSBDevice;
|
||||||
|
virHostdevHostSupportsPassthroughVFIO;
|
||||||
virHostdevManagerGetDefault;
|
virHostdevManagerGetDefault;
|
||||||
virHostdevNeedsVFIO;
|
virHostdevNeedsVFIO;
|
||||||
virHostdevPCINodeDeviceDetach;
|
virHostdevPCINodeDeviceDetach;
|
||||||
|
@ -6430,7 +6430,7 @@ static void
|
|||||||
virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCaps *qemuCaps,
|
virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCaps *qemuCaps,
|
||||||
virDomainCapsDeviceHostdev *hostdev)
|
virDomainCapsDeviceHostdev *hostdev)
|
||||||
{
|
{
|
||||||
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
|
bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO();
|
||||||
|
|
||||||
hostdev->supported = VIR_TRISTATE_BOOL_YES;
|
hostdev->supported = VIR_TRISTATE_BOOL_YES;
|
||||||
hostdev->mode.report = true;
|
hostdev->mode.report = true;
|
||||||
|
@ -9865,7 +9865,7 @@ static int
|
|||||||
qemuDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev,
|
qemuDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev,
|
||||||
virQEMUCaps *qemuCaps)
|
virQEMUCaps *qemuCaps)
|
||||||
{
|
{
|
||||||
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
|
bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO();
|
||||||
virDeviceHostdevPCIDriverName *driverName = &hostdev->source.subsys.u.pci.driver.name;
|
virDeviceHostdevPCIDriverName *driverName = &hostdev->source.subsys.u.pci.driver.name;
|
||||||
|
|
||||||
/* assign defaults for hostdev passthrough */
|
/* assign defaults for hostdev passthrough */
|
||||||
|
@ -11482,7 +11482,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
|||||||
* further validation until then.
|
* further validation until then.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!qemuHostdevHostSupportsPassthroughVFIO()) {
|
if (!virHostdevHostSupportsPassthroughVFIO()) {
|
||||||
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
|
||||||
_("VFIO device assignment is currently not supported on this system"));
|
_("VFIO device assignment is currently not supported on this system"));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -130,21 +130,6 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
qemuHostdevHostSupportsPassthroughVFIO(void)
|
|
||||||
{
|
|
||||||
/* condition 1 - host has IOMMU */
|
|
||||||
if (!virHostHasIOMMU())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* condition 2 - /dev/vfio/vfio exists */
|
|
||||||
if (!virFileExists(QEMU_DEV_VFIO))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
qemuHostdevPrepareOneNVMeDisk(virQEMUDriver *driver,
|
qemuHostdevPrepareOneNVMeDisk(virQEMUDriver *driver,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
#include "qemu_conf.h"
|
#include "qemu_conf.h"
|
||||||
|
|
||||||
bool qemuHostdevHostSupportsPassthroughVFIO(void);
|
|
||||||
|
|
||||||
int qemuHostdevUpdateActiveNVMeDisks(virQEMUDriver *driver,
|
int qemuHostdevUpdateActiveNVMeDisks(virQEMUDriver *driver,
|
||||||
virDomainDef *def);
|
virDomainDef *def);
|
||||||
int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriver *driver,
|
int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriver *driver,
|
||||||
|
@ -105,7 +105,7 @@ fillQemuCaps(virDomainCaps *domCaps,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* The function above tries to query host's VFIO capabilities by calling
|
/* The function above tries to query host's VFIO capabilities by calling
|
||||||
* qemuHostdevHostSupportsPassthroughVFIO() which, however, can't be
|
* virHostdevHostSupportsPassthroughVFIO() which, however, can't be
|
||||||
* successfully mocked as they are not exposed as internal APIs. Therefore,
|
* successfully mocked as they are not exposed as internal APIs. Therefore,
|
||||||
* instead of mocking set the expected values here by hand. */
|
* instead of mocking set the expected values here by hand. */
|
||||||
VIR_DOMAIN_CAPS_ENUM_SET(domCaps->hostdev.pciBackend,
|
VIR_DOMAIN_CAPS_ENUM_SET(domCaps->hostdev.pciBackend,
|
||||||
|
Loading…
Reference in New Issue
Block a user