[libvirt] [PATCH 2/2] tool/virsh-domain.c: Fix the display of Affinity in function cmdVcpuinfo.

yangdongsheng yangds.fnst at cn.fujitsu.com
Fri May 24 09:21:07 UTC 2013


(1).Introduce a symbol 'x' to mean the physical cpu on host is offline.
(2).And the symbol '-' means the physical cpu on host is online but the
affinity of domain for this cpu is not set.

There was no diffrence in display between the two kinds of cpu state
before this patch, both are '-'.

Signed-off-by: yangdongsheng <yangds.fnst at cn.fujitsu.com>
---
 tools/virsh-domain.c |   23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ebaca2d..3a8da00 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5325,6 +5325,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom;
     virVcpuInfoPtr cpuinfo;
     unsigned char *cpumaps;
+    unsigned char *hostcpumap;
     int ncpus, maxcpu;
     size_t cpumaplen;
     bool ret = true;
@@ -5338,6 +5339,11 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
+    if ((vshNodeGetCPUMap(ctl->conn, &hostcpumap)) < 0) {
+        virDomainFree(dom);
+        return false;
+    }
+
     if (virDomainGetInfo(dom, &info) != 0) {
         virDomainFree(dom);
         return false;
@@ -5364,7 +5370,13 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
             }
             vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
             for (m = 0; m < maxcpu; m++) {
-                vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ? 'y' : '-');
+                if VIR_CPU_USED(hostcpumap, m) {
+                    vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumaps,
+                                            cpumaplen, n, m) ? 'y' : '-');
+                }
+                else {
+                    vshPrint(ctl, "%c", 'x');
+                }
             }
             vshPrint(ctl, "\n");
             if (n < (ncpus - 1)) {
@@ -5386,8 +5398,13 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
                 vshPrint(ctl, "%-15s %s\n", _("CPU time"), _("N/A"));
                 vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
                 for (m = 0; m < maxcpu; m++) {
-                    vshPrint(ctl, "%c",
-                             VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ? 'y' : '-');
+                    if VIR_CPU_USED(hostcpumap, m) {
+                        vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumaps,
+                                            cpumaplen, n, m) ? 'y' : '-');
+                    }
+                    else {
+                        vshPrint(ctl, "%c", 'x');
+                    }
                 }
                 vshPrint(ctl, "\n");
                 if (n < (ncpus - 1)) {
-- 
1.7.10.1




More information about the libvir-list mailing list