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

[libvirt] [PATCH 2/2] qemu: Implement validation for max-cpu in XML



Check whether vcpu setting or maxvcpu settings exceeds number of
maximum cpus for selected machine type on virDomainDefineXML() and
virDomainCreateXML() API calls or not.

Signed-off-by: Michal Novotny <minovotn redhat com>
---
 src/qemu/qemu_driver.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7c167b7..abe4f8b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1454,6 +1454,30 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
 }
 
 
+static bool
+qemuValidateCpuMax(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
+{
+    int cpu_max;
+
+    cpu_max = virQEMUCapsGetMachineMaxCpus(qemuCaps, def->os.machine);
+    if (!cpu_max)
+        return true;
+
+    if (def->vcpus > cpu_max) {
+        virReportError(VIR_ERR_XML_DETAIL,
+                       "%s", _("CPUs greater than machine limit"));
+        return false;
+    }
+
+    if (def->maxvcpus > cpu_max) {
+        virReportError(VIR_ERR_XML_DETAIL,
+                       "%s", _("Maximum CPUs greater than machine limit"));
+        return false;
+    }
+
+    return true;
+}
+
 static virDomainPtr qemuDomainCreate(virConnectPtr conn, const char *xml,
                                      unsigned int flags) {
     virQEMUDriverPtr driver = conn->privateData;
@@ -1491,6 +1515,9 @@ static virDomainPtr qemuDomainCreate(virConnectPtr conn, const char *xml,
     if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
         goto cleanup;
 
+    if (!qemuValidateCpuMax(def, qemuCaps))
+        goto cleanup;
+
     if (qemuDomainAssignAddresses(def, qemuCaps, NULL) < 0)
         goto cleanup;
 
@@ -5461,6 +5488,9 @@ static virDomainPtr qemuDomainDefine(virConnectPtr conn, const char *xml) {
     if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
         goto cleanup;
 
+    if (!qemuValidateCpuMax(def, qemuCaps))
+        goto cleanup;
+
     if (qemuDomainAssignAddresses(def, qemuCaps, NULL) < 0)
         goto cleanup;
 
-- 
1.7.11.7


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