File libvirt-Revert-qemu-Remove-maximum-cpu-limit-when-setting-processor-count-using-the-API.patch of Package libvirt

From 20681539d663687fe9c0779e9dc09a87e8ccaa04 Mon Sep 17 00:00:00 2001
Message-Id: <20681539d663687fe9c0779e9dc09a87e8ccaa04.1376483447.git.jdenemar@redhat.com>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 25 Jul 2013 14:10:55 +0200
Subject: [PATCH] Revert "qemu: Remove maximum cpu limit when setting processor
 count using the API"

https://bugzilla.redhat.com/show_bug.cgi?id=855296

RHEL Only.

KVM in RHEL6 supports only 160 cpus. Without this patch it's possible to
start a guest with maxcpus > 160 and then hotplug more than 160 cpus
leading to a qemu crash. The original bug can't be otherwise fully fixed
as it requires qemu support to report the maximum count of CPUs
supported and that won't happen for RHEL6.

This reverts downstream commit 95697c10e5efb018dccc51e0d42b1d1c6f2846f9.
In upstream we do query qemu for the maximum count thus the upstream
commit won't be reverted ( ce65b435899066243c303dd1cefd671de46ae592 ).
---
 src/qemu/qemu_driver.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8703462..b87750a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4160,6 +4160,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
     virDomainDefPtr persistentDef;
+    const char * type;
+    int max;
     int ret = -1;
     bool maximum;
     qemuAgentCPUInfoPtr cpuinfo = NULL;
@@ -4208,11 +4210,27 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
         goto endjob;
     }
 
-    if (!maximum && nvcpus > vm->def->maxvcpus) {
+    if (!(type = virDomainVirtTypeToString(vm->def->virtType))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unknown virt type in domain definition '%d'"),
+                       vm->def->virtType);
+        goto endjob;
+    }
+
+    if ((max = qemudGetMaxVCPUs(NULL, type)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("could not determine max vcpus for the domain"));
+        goto endjob;
+    }
+
+    if (!maximum && vm->def->maxvcpus < max) {
+        max = vm->def->maxvcpus;
+    }
+
+    if (nvcpus > max) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("requested vcpus is greater than max allowable"
-                         " vcpus for the domain: %d > %d"),
-                       nvcpus, vm->def->maxvcpus);
+                         " vcpus for the domain: %d > %d"), nvcpus, max);
         goto endjob;
     }
 
-- 
1.8.3.2

openSUSE Build Service is sponsored by