[PATCH 07/10] ch: prepare host for PCI passthrough

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Wei Liu <liuwe@xxxxxxxxxxxxx>

Prepare host to passthrough PCI devices for ch guests.

Co-authored-by: Wei Liu <liuwe@xxxxxxxxxxxxx>
Signed-off-by: Praveen K Paladugu <prapal@xxxxxxxxxxxxxxxxxxx>
---
 src/ch/ch_hostdev.c | 20 ++++++++++++++++++++
 src/ch/ch_hostdev.h |  5 +++++
 src/ch/ch_process.c | 30 ++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)

diff --git a/src/ch/ch_hostdev.c b/src/ch/ch_hostdev.c
index 1e6210e162..a2ef56e098 100644
--- a/src/ch/ch_hostdev.c
+++ b/src/ch/ch_hostdev.c
@@ -22,11 +22,31 @@
 
 #include "ch_hostdev.h"
 #include "virlog.h"
+#include "virerror.h"
+#include "virhostdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_CH
 
 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
 virCHDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev)
 {
diff --git a/src/ch/ch_hostdev.h b/src/ch/ch_hostdev.h
index f9ba40ab71..f949ecbe87 100644
--- a/src/ch/ch_hostdev.h
+++ b/src/ch/ch_hostdev.h
@@ -25,3 +25,8 @@
 
 int
 virCHDomainPrepareHostdev(virDomainHostdevDef *hostdev);
+
+int
+virCHHostdevPrepareDomainDevices(virCHDriver *driver,
+                                 virDomainDef *def,
+                                 unsigned int flags);
diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c
index c5b5b6ebb2..ed0fa1fedb 100644
--- a/src/ch/ch_process.c
+++ b/src/ch/ch_process.c
@@ -824,6 +824,33 @@ virCHProcessPrepareDomainHostdevs(virDomainObj *vm)
     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:
  * @vm: domain object
@@ -878,6 +905,9 @@ virCHProcessStart(virCHDriver *driver,
         return -1;
     }
 
+    if (virCHProcessPrepareHost(driver, vm) < 0)
+        return -1;
+
     if (!priv->monitor) {
         /* And we can get the first monitor connection now too */
         if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm))) {
-- 
2.44.0



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux