[PATCH 3/3] virsh: Use virNodeGetCPUMap if possible

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

 



Modified the places where virNodeGetInfo was used for the purpose
of obtaining the maximum node CPU number. Transparently falling
back to virNodeGetInfo in case of failure.

Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx>
---
 tools/virsh-domain.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0906267..0aa643a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4508,9 +4508,14 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
 
-    if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
-        virDomainFree(dom);
-        return false;
+    if ((maxcpu = virNodeGetCPUMap(ctl->conn, NULL, NULL, 0)) < 0) {
+        /* fall back to nodeinfo */
+        if (virNodeGetInfo(ctl->conn, &nodeinfo) == 0) {
+            maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
+        } else {
+            virDomainFree(dom);
+            return false;
+        }
     }
 
     if (virDomainGetInfo(dom, &info) != 0) {
@@ -4519,7 +4524,6 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
     }
 
     cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu);
-    maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
     cpumaplen = VIR_CPU_MAPLEN(maxcpu);
     cpumaps = vshMalloc(ctl, info.nrVirtCpu * cpumaplen);
 
@@ -4695,9 +4699,14 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
-        virDomainFree(dom);
-        return false;
+    if ((maxcpu = virNodeGetCPUMap(ctl->conn, NULL, NULL, 0)) < 0) {
+        /* fall back to nodeinfo */
+        if (virNodeGetInfo(ctl->conn, &nodeinfo) == 0) {
+            maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
+        } else {
+            virDomainFree(dom);
+            return false;
+        }
     }
 
     if (virDomainGetInfo(dom, &info) != 0) {
@@ -4712,7 +4721,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
     cpumaplen = VIR_CPU_MAPLEN(maxcpu);
 
     /* Query mode: show CPU affinity information then exit.*/
@@ -4905,12 +4913,16 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
     }
     query = !cpulist;
 
-    if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
-        virDomainFree(dom);
-        return false;
+    if ((maxcpu = virNodeGetCPUMap(ctl->conn, NULL, NULL, 0)) < 0) {
+        /* fall back to nodeinfo */
+        if (virNodeGetInfo(ctl->conn, &nodeinfo) == 0) {
+            maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
+        } else {
+            virDomainFree(dom);
+            return false;
+        }
     }
 
-    maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
     cpumaplen = VIR_CPU_MAPLEN(maxcpu);
 
     /* Query mode: show CPU affinity information then exit.*/
-- 
1.7.12.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]