]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
qemu_agent: Move updater function for VCPU hotplug into qemu_agent.c
authorPeter Krempa <pkrempa@redhat.com>
Tue, 30 Jul 2013 10:04:21 +0000 (12:04 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 31 Jul 2013 12:25:43 +0000 (14:25 +0200)
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
src/qemu/qemu_agent.h
src/qemu/qemu_driver.c

index 1607e88c0ef4735cd56eba126e620649890c0a88..fc85e3e08d104352119dbb925520b538a455e0a2 100644 (file)
@@ -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;
+}
index cf70653b7ab7e29c18cee2214f1dbb90e161e1b6..5fbacdbc6ed9964ee936e7aca2d719fedf901e59 100644 (file)
@@ -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__ */
index 5634abf037a107321627fca65c499d970b4b40e4..2daafa8d16810e8191974488b87887ff18d1b68f 100644 (file)
@@ -4089,68 +4089,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);