[PATCH 2/2] ch: Check for hypervisor while starting guests

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

 



While initializing ch driver, confirm either /dev/kvm or /dev/mshv
device is present. Before starting domains, validate the requested
hypervisor device exists on the host.

Users can specify hypervisor in ch guests's domain definitions like
below:

<domain type='kvm'>

_or_

<domain type='mshv'>

Signed-off-by: Praveen K Paladugu <prapal@xxxxxxxxxxxxxxxxxxx>
---
 src/ch/ch_conf.c    |  2 ++
 src/ch/ch_driver.c  |  7 +++++++
 src/ch/ch_process.c | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c
index f421af5121..7cb113bca5 100644
--- a/src/ch/ch_conf.c
+++ b/src/ch/ch_conf.c
@@ -69,6 +69,8 @@ virCaps *virCHDriverCapsInit(void)
 
     virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
                                   NULL, NULL, 0, NULL);
+    virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_MSHV,
+                                  NULL, NULL, 0, NULL);
     return g_steal_pointer(&caps);
 }
 
diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c
index 96de5044ac..d6294c76ee 100644
--- a/src/ch/ch_driver.c
+++ b/src/ch/ch_driver.c
@@ -32,6 +32,7 @@
 #include "viraccessapicheck.h"
 #include "virchrdev.h"
 #include "virerror.h"
+#include "virfile.h"
 #include "virlog.h"
 #include "virobject.h"
 #include "virtypedparam.h"
@@ -876,6 +877,12 @@ static int chStateInitialize(bool privileged,
         return -1;
     }
 
+    if (!(virFileExists("/dev/kvm") || virFileExists("/dev/mshv"))) {
+        virReportError(VIR_ERR_DEVICE_MISSING, "%s",
+                       _("/dev/kvm and /dev/mshv. ch driver failed to initialize."));
+        return VIR_DRV_STATE_INIT_ERROR;
+    }
+
     ch_driver = g_new0(virCHDriver, 1);
 
     if (virMutexInit(&ch_driver->lock) < 0) {
diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c
index f3bb4a7280..d9f943c50b 100644
--- a/src/ch/ch_process.c
+++ b/src/ch/ch_process.c
@@ -28,6 +28,7 @@
 #include "ch_process.h"
 #include "domain_cgroup.h"
 #include "virerror.h"
+#include "virfile.h"
 #include "virjson.h"
 #include "virlog.h"
 
@@ -448,6 +449,35 @@ virCHProcessSetupVcpus(virDomainObj *vm)
     return 0;
 }
 
+/**
+ * virCHProcessStartValidate:
+ * @vm: domain object
+ *
+ * Checks done before starting a VM.
+ *
+ * Returns 0 on success or -1 in case of error
+ */
+static int virCHProcessStartValidate(virDomainObj *vm)
+{
+    if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) {
+        VIR_DEBUG("Checking for KVM availability");
+        if (!virFileExists("/dev/kvm")) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Domain requires KVM, but it is not available. Check that virtualization is enabled in the host BIOS, and host configuration is setup to load the kvm modules."));
+                return -1;
+            }
+    } else if (vm->def->virtType == VIR_DOMAIN_VIRT_MSHV) {
+        VIR_DEBUG("Checking for MSHV availability");
+        if (!virFileExists("/dev/mshv")) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Domain requires MSHV, but it is not available. Check that virtualization is enabled in the host BIOS, and host configuration is setup to load the mshv modules."));
+                return -1;
+            }
+    }
+    return 0;
+
+}
+
 /**
  * virCHProcessStart:
  * @driver: pointer to driver structure
@@ -475,6 +505,10 @@ virCHProcessStart(virCHDriver *driver,
         return -1;
     }
 
+    if (virCHProcessStartValidate(vm) < 0) {
+        return -1;
+    }
+
     if (!priv->monitor) {
         /* And we can get the first monitor connection now too */
         if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm))) {
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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