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

[libvirt] [PATCH 03/20] qemu_agent: Move updater function for VCPU hotplug into qemu_agent.c



To allow testing of the cpu updater function, this function needs to be
available separately. Export it from qemu_agent.c where it should
belong.
---
 src/qemu/qemu_agent.c  | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_agent.h  |  3 +++
 src/qemu/qemu_driver.c | 64 +-------------------------------------------------
 3 files changed, 67 insertions(+), 63 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 1607e88..fc85e3e 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1597,3 +1597,66 @@ cleanup:
     virJSONValueFree(cpus);
     return ret;
 }
+
+
+/* modify the cpu info structure to set the correct amount of cpus */
+int
+qemuAgentUpdateCPUInfo(unsigned int nvcpus,
+                       qemuAgentCPUInfoPtr cpuinfo,
+                       int ncpuinfo)
+{
+    size_t i;
+    int nonline = 0;
+    int nofflinable = 0;
+
+    /* count the active and offlinable cpus */
+    for (i = 0; i < ncpuinfo; i++) {
+        if (cpuinfo[i].online)
+            nonline++;
+
+        if (cpuinfo[i].offlinable && cpuinfo[i].online)
+            nofflinable++;
+
+        /* This shouldn't happen, but we can't trust the guest agent */
+        if (!cpuinfo[i].online && !cpuinfo[i].offlinable) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Invalid data provided by guest agent"));
+            return -1;
+        }
+    }
+
+    /* the guest agent reported less cpus than requested */
+    if (nvcpus > ncpuinfo) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("guest agent reports less cpu than requested"));
+        return -1;
+    }
+
+    /* not enough offlinable CPUs to support the request */
+    if (nvcpus < nonline - nofflinable) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("Cannot offline enough CPUs"));
+        return -1;
+    }
+
+    for (i = 0; i < ncpuinfo; i++) {
+        if (nvcpus < nonline) {
+            /* unplug */
+            if (cpuinfo[i].offlinable && cpuinfo[i].online) {
+                cpuinfo[i].online = false;
+                nonline--;
+            }
+        } else if (nvcpus > nonline) {
+            /* plug */
+            if (!cpuinfo[i].online) {
+                cpuinfo[i].online = true;
+                nonline++;
+            }
+        } else {
+            /* done */
+            break;
+        }
+    }
+
+    return 0;
+}
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index cf70653..5fbacdb 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -94,4 +94,7 @@ struct _qemuAgentCPUInfo {

 int qemuAgentGetVCPUs(qemuAgentPtr mon, qemuAgentCPUInfoPtr *info);
 int qemuAgentSetVCPUs(qemuAgentPtr mon, qemuAgentCPUInfoPtr cpus, size_t ncpus);
+int qemuAgentUpdateCPUInfo(unsigned int nvcpus,
+                           qemuAgentCPUInfoPtr cpuinfo,
+                           int ncpuinfo);
 #endif /* __QEMU_AGENT_H__ */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5634abf..2daafa8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4090,68 +4090,6 @@ unsupported:


 static int
-qemuDomainPrepareAgentVCPUs(unsigned int nvcpus,
-                            qemuAgentCPUInfoPtr cpuinfo,
-                            int ncpuinfo)
-{
-    size_t i;
-    int nonline = 0;
-    int nofflinable = 0;
-
-    /* count the active and offlinable cpus */
-    for (i = 0; i < ncpuinfo; i++) {
-        if (cpuinfo[i].online)
-            nonline++;
-
-        if (cpuinfo[i].offlinable && cpuinfo[i].online)
-            nofflinable++;
-
-        /* This shouldn't happen, but we can't trust the guest agent */
-        if (!cpuinfo[i].online && !cpuinfo[i].offlinable) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("Invalid data provided by guest agent"));
-            return -1;
-        }
-    }
-
-    /* the guest agent reported less cpus than requested */
-    if (nvcpus > ncpuinfo) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("guest agent reports less cpu than requested"));
-        return -1;
-    }
-
-    /* not enough offlinable CPUs to support the request */
-    if (nvcpus < nonline - nofflinable) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("Cannot offline enough CPUs"));
-        return -1;
-    }
-
-    for (i = 0; i < ncpuinfo; i++) {
-        if (nvcpus < nonline) {
-            /* unplug */
-            if (cpuinfo[i].offlinable && cpuinfo[i].online) {
-                cpuinfo[i].online = false;
-                nonline--;
-            }
-        } else if (nvcpus > nonline) {
-            /* plug */
-            if (!cpuinfo[i].online) {
-                cpuinfo[i].online = true;
-                nonline++;
-            }
-        } else {
-            /* done */
-            break;
-        }
-    }
-
-    return 0;
-}
-
-
-static int
 qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
                         unsigned int flags)
 {
@@ -4243,7 +4181,7 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
         if (ncpuinfo < 0)
             goto endjob;

-        if (qemuDomainPrepareAgentVCPUs(nvcpus, cpuinfo, ncpuinfo) < 0)
+        if (qemuAgentUpdateCPUInfo(nvcpus, cpuinfo, ncpuinfo) < 0)
             goto endjob;

         qemuDomainObjEnterAgent(vm);
-- 
1.8.3.2


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