[PATCH] virsh: fix no error output when parse cpulist fail

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

 



When we pass a invalid cpulist or the lastcpu in the
cpulist exceed the maxcpu, we cannot get any error.
like this:

 # virsh vcpupin test3 1 aaa

 # virsh vcpupin test3 1 1000

Because virBitmapParse() use virReportError() to set
the error message, virsh client use vshError to output error.
If we want get the error which set by virReportError(), we need
virGetLastError/virGetLastErrorMessage to help us.
However instead of do this, i chose use vshError to output
error when parse failed.

Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
---
 tools/virsh-domain.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 14e1e35..64bfbfd 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6362,9 +6362,7 @@ vshParseCPUList(int *cpumaplen, const char *cpulist, int maxcpu)
             return NULL;
     }
 
-    if (virBitmapToData(map, &cpumap, cpumaplen) < 0)
-        goto cleanup;
-
+    virBitmapToData(map, &cpumap, cpumaplen);
  cleanup:
     virBitmapFree(map);
     return cpumap;
@@ -6458,8 +6456,10 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
         }
     } else {
         /* Pin mode: pinning specified vcpu to specified physical cpus*/
-        if (!(cpumap = vshParseCPUList(&cpumaplen, cpulist, maxcpu)))
+        if (!(cpumap = vshParseCPUList(&cpumaplen, cpulist, maxcpu))) {
+            vshError(ctl, _("vcpupin: invalid cpulist '%s'"), cpulist);
             goto cleanup;
+        }
 
         if (flags == -1) {
             if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0)
@@ -6577,8 +6577,10 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
     }
 
     /* Pin mode: pinning emulator threads to specified physical cpus*/
-    if (!(cpumap = vshParseCPUList(&cpumaplen, cpulist, maxcpu)))
+    if (!(cpumap = vshParseCPUList(&cpumaplen, cpulist, maxcpu))) {
+        vshError(ctl, _("emulatorpin: invalid cpulist '%s'"), cpulist);
         goto cleanup;
+    }
 
     if (flags == -1)
         flags = VIR_DOMAIN_AFFECT_LIVE;
@@ -6854,16 +6856,14 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    if (vshCommandOptString(cmd, "cpulist", &cpulist) < 0) {
-        vshError(ctl, "%s", _("iothreadpin: invalid cpulist."));
-        goto cleanup;
-    }
-
     if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
         goto cleanup;
 
-    if (!(cpumap = vshParseCPUList(&cpumaplen, cpulist, maxcpu)))
+    if ((vshCommandOptString(cmd, "cpulist", &cpulist) < 0) ||
+        !(cpumap = vshParseCPUList(&cpumaplen, cpulist, maxcpu))) {
+        vshError(ctl, "%s", _("iothreadpin: invalid cpulist."));
         goto cleanup;
+    }
 
     if (virDomainPinIOThread(dom, iothread_id,
                              cpumap, cpumaplen, flags) != 0)
-- 
1.8.3.1

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