ch: prepare host for PCI passthrough

Prepare host to passthrough PCI devices for ch guests.

Co-authored-by: Wei Liu <liuwe@microsoft.com>
Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Wei Liu 2024-10-11 13:13:08 -05:00 committed by Michal Privoznik
parent acfe2e7a50
commit c6dbc6042d
3 changed files with 55 additions and 0 deletions

View File

@ -22,11 +22,31 @@
#include "ch_hostdev.h" #include "ch_hostdev.h"
#include "virlog.h" #include "virlog.h"
#include "virerror.h"
#include "virhostdev.h"
#define VIR_FROM_THIS VIR_FROM_CH #define VIR_FROM_THIS VIR_FROM_CH
VIR_LOG_INIT("ch.ch_hostdev"); VIR_LOG_INIT("ch.ch_hostdev");
int
virCHHostdevPrepareDomainDevices(virCHDriver *driver,
virDomainDef *def,
unsigned int flags)
{
if (!def->nhostdevs)
return 0;
if (virHostdevPreparePCIDevices(driver->hostdevMgr, CH_DRIVER_NAME,
def->name, def->uuid,
def->hostdevs, def->nhostdevs,
flags) < 0)
return -1;
return 0;
}
static int static int
virCHDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev) virCHDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev)
{ {

View File

@ -25,3 +25,8 @@
int int
virCHDomainPrepareHostdev(virDomainHostdevDef *hostdev); virCHDomainPrepareHostdev(virDomainHostdevDef *hostdev);
int
virCHHostdevPrepareDomainDevices(virCHDriver *driver,
virDomainDef *def,
unsigned int flags);

View File

@ -824,6 +824,33 @@ virCHProcessPrepareDomainHostdevs(virDomainObj *vm)
return 0; return 0;
} }
/**
* virCHProcessPrepareHost:
* @driver: ch driver
* @vm: domain object
*
* This function groups all code that modifies host system to prepare
* environment for a domain which is about to start.
*
* This function MUST be called only after virCHProcessPrepareDomain().
*/
static int
virCHProcessPrepareHost(virCHDriver *driver, virDomainObj *vm)
{
unsigned int hostdev_flags = 0;
virCHDomainObjPrivate *priv = vm->privateData;
g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver);
if (virCHHostdevPrepareDomainDevices(driver, vm->def, hostdev_flags) < 0)
return -1;
/* Ensure no historical cgroup for this VM is lying around */
VIR_DEBUG("Ensuring no historical cgroup is lying around");
virDomainCgroupRemoveCgroup(vm, priv->cgroup, priv->machineName);
return 0;
}
/** /**
* virCHProcessPrepareDomain: * virCHProcessPrepareDomain:
* @vm: domain object * @vm: domain object
@ -878,6 +905,9 @@ virCHProcessStart(virCHDriver *driver,
return -1; return -1;
} }
if (virCHProcessPrepareHost(driver, vm) < 0)
return -1;
if (!priv->monitor) { if (!priv->monitor) {
/* And we can get the first monitor connection now too */ /* And we can get the first monitor connection now too */
if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm))) { if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm))) {