[PATCH 2/7] virsh-domain: Adapt to new error reporting

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

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/vcpupin        |  1 -
 tools/virsh-domain.c | 75 +++++++++++++++++-----------------------------------
 2 files changed, 24 insertions(+), 52 deletions(-)

diff --git a/tests/vcpupin b/tests/vcpupin
index a616216..638f62b 100755
--- a/tests/vcpupin
+++ b/tests/vcpupin
@@ -35,7 +35,6 @@ $abs_top_builddir/tools/virsh --connect test:///default vcpupin test a 0,1 > out
 test $? = 1 || fail=1
 cat <<\EOF > exp || fail=1
 error: Unable to parse integer parameter to --vcpu
-error: vcpupin: Invalid or missing vCPU number.
 
 EOF
 compare exp out || fail=1
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 73414f8..6e1eb17 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1120,7 +1120,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     if ((rv = vshCommandOptULongLong(cmd, "total-bytes-sec", &value)) < 0) {
-        goto interror;
+        goto error;
     } else if (rv > 0) {
         if (virTypedParamsAddULLong(&params, &nparams, &maxparams,
                                     VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC,
@@ -1129,7 +1129,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
     }
 
     if ((rv = vshCommandOptULongLong(cmd, "read-bytes-sec", &value)) < 0) {
-        goto interror;
+        goto error;
     } else if (rv > 0) {
         if (virTypedParamsAddULLong(&params, &nparams, &maxparams,
                                     VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC,
@@ -1138,7 +1138,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
     }
 
     if ((rv = vshCommandOptULongLong(cmd, "write-bytes-sec", &value)) < 0) {
-        goto interror;
+        goto error;
     } else if (rv > 0) {
         if (virTypedParamsAddULLong(&params, &nparams, &maxparams,
                                     VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC,
@@ -1147,7 +1147,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
     }
 
     if ((rv = vshCommandOptULongLong(cmd, "total-iops-sec", &value)) < 0) {
-        goto interror;
+        goto error;
     } else if (rv > 0) {
         if (virTypedParamsAddULLong(&params, &nparams, &maxparams,
                                     VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC,
@@ -1156,7 +1156,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
     }
 
     if ((rv = vshCommandOptULongLong(cmd, "read-iops-sec", &value)) < 0) {
-        goto interror;
+        goto error;
     } else if (rv > 0) {
         if (virTypedParamsAddULLong(&params, &nparams, &maxparams,
                                     VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC,
@@ -1165,7 +1165,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
     }
 
     if ((rv = vshCommandOptULongLong(cmd, "write-iops-sec", &value)) < 0) {
-        goto interror;
+        goto error;
     } else if (rv > 0) {
         if (virTypedParamsAddULLong(&params, &nparams, &maxparams,
                                     VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC,
@@ -1216,10 +1216,6 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
  error:
     vshError(ctl, "%s", _("Unable to change block I/O throttle"));
     goto cleanup;
-
- interror:
-    vshError(ctl, "%s", _("Unable to parse integer parameter"));
-    goto cleanup;
 }
 
 /*
@@ -1316,7 +1312,6 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
         return false;
 
     if ((rv = vshCommandOptInt(cmd, "weight", &weight)) < 0) {
-        vshError(ctl, "%s", _("Unable to parse integer parameter"));
         goto cleanup;
     } else if (rv > 0) {
         if (weight <= 0) {
@@ -1457,10 +1452,8 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
     if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
         goto cleanup;
 
-    if (vshCommandOptUL(cmd, "bandwidth", &bandwidth) < 0) {
-        vshError(ctl, "%s", _("bandwidth must be a number"));
+    if (vshCommandOptUL(cmd, "bandwidth", &bandwidth) < 0)
         goto cleanup;
-    }
 
     switch ((vshCmdBlockJobMode) mode) {
     case VSH_CMD_BLOCK_JOB_ABORT:
@@ -2215,10 +2208,8 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0)
         return false;
 
-    if (vshCommandOptScaledInt(cmd, "size", &size, 1024, ULLONG_MAX) < 0) {
-        vshError(ctl, "%s", _("Unable to parse integer"));
+    if (vshCommandOptScaledInt(cmd, "size", &size, 1024, ULLONG_MAX) < 0)
         return false;
-    }
 
     /* Prefer the older interface of KiB.  */
     if (size % 1024 == 0)
@@ -2805,10 +2796,8 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
         return false;
 
-    if (vshCommandOptULongLong(cmd, "duration", &duration) < 0) {
-        vshError(ctl, _("Invalid duration argument"));
+    if (vshCommandOptULongLong(cmd, "duration", &duration) < 0)
         goto cleanup;
-    }
 
     if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0)
         goto cleanup;
@@ -4709,10 +4698,8 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "file", (const char **) &file) < 0)
         return false;
 
-    if (vshCommandOptUInt(cmd, "screen", &screen) < 0) {
-        vshError(ctl, "%s", _("invalid screen ID"));
+    if (vshCommandOptUInt(cmd, "screen", &screen) < 0)
         return false;
-    }
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
         return false;
@@ -5820,8 +5807,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
 
     /* In query mode, "vcpu" is optional */
     if (vshCommandOptInt(cmd, "vcpu", &vcpu) < !query) {
-        vshError(ctl, "%s",
-                 _("vcpupin: Invalid or missing vCPU number."));
         virDomainFree(dom);
         return false;
     }
@@ -6089,7 +6074,10 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
 
-    if (vshCommandOptInt(cmd, "count", &count) < 0 || count <= 0) {
+    if (vshCommandOptInt(cmd, "count", &count) < 0)
+        goto cleanup;
+
+    if (count <= 0) {
         vshError(ctl, "%s", _("Invalid number of virtual CPUs"));
         goto cleanup;
     }
@@ -6385,7 +6373,6 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
     show_total = vshCommandOptBool(cmd, "total");
 
     if ((rv = vshCommandOptInt(cmd, "start", &cpu)) < 0) {
-        vshError(ctl, "%s", _("Unable to parse integer parameter for start"));
         goto cleanup;
     } else if (rv > 0) {
         if (cpu < 0) {
@@ -6396,8 +6383,6 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
     }
 
     if ((rv = vshCommandOptInt(cmd, "count", &show_count)) < 0) {
-        vshError(ctl, "%s",
-                 _("Unable to parse integer parameter for CPUs to show"));
         goto cleanup;
     } else if (rv > 0) {
         if (show_count < 0) {
@@ -7157,10 +7142,8 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptString(cmd, "codeset", &codeset_option) <= 0)
         codeset_option = "linux";
 
-    if (vshCommandOptUInt(cmd, "holdtime", &holdtime) < 0) {
-        vshError(ctl, _("invalid value of --holdtime"));
+    if (vshCommandOptUInt(cmd, "holdtime", &holdtime) < 0)
         goto cleanup;
-    }
 
     codeset = virKeycodeSetTypeFromString(codeset_option);
     if (codeset < 0) {
@@ -7385,7 +7368,6 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
     else
         max = ULONG_MAX;
     if (vshCommandOptScaledInt(cmd, "size", &bytes, 1024, max) < 0) {
-        vshError(ctl, "%s", _("memory size has to be a number"));
         virDomainFree(dom);
         return false;
     }
@@ -7482,7 +7464,6 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
     else
         max = ULONG_MAX;
     if (vshCommandOptScaledInt(cmd, "size", &bytes, 1024, max) < 0) {
-        vshError(ctl, "%s", _("memory size has to be a number"));
         virDomainFree(dom);
         return false;
     }
@@ -8124,10 +8105,8 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd)
     unsigned int flags = 0;
     unsigned int pid_value; /* API uses unsigned int, not pid_t */
 
-    if (vshCommandOptUInt(cmd, "pid", &pid_value) <= 0) {
-        vshError(ctl, "%s", _("missing pid value"));
+    if (vshCommandOptUInt(cmd, "pid", &pid_value) <= 0)
         goto cleanup;
-    }
 
     if (!(dom = virDomainQemuAttach(ctl->conn, pid_value, flags)))
         goto cleanup;
@@ -8220,9 +8199,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
     }
     guest_agent_cmd = virBufferContentAndReset(&buf);
 
-    judge = vshCommandOptInt(cmd, "timeout", &timeout);
-    if (judge < 0) {
-        vshError(ctl, "%s", _("timeout number has to be a number"));
+    if ((judge = vshCommandOptInt(cmd, "timeout", &timeout)) < 0) {
         goto cleanup;
     } else if (judge > 0) {
         judge = 1;
@@ -9095,8 +9072,10 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
 
-    if (vshCommandOptLongLong(cmd, "downtime", &downtime) < 0 ||
-        downtime < 1) {
+    if (vshCommandOptLongLong(cmd, "downtime", &downtime) < 0)
+        goto done;
+
+    if (downtime < 1) {
         vshError(ctl, "%s", _("migrate: Invalid downtime"));
         goto done;
     }
@@ -9152,9 +9131,7 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
 
-    rc = vshCommandOptULongLong(cmd, "size", &size);
-    if (rc < 0) {
-        vshError(ctl, "%s", _("Unable to parse size parameter"));
+    if ((rc = vshCommandOptULongLong(cmd, "size", &size)) < 0) {
         goto cleanup;
     } else if (rc != 0) {
         if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0)
@@ -9211,10 +9188,8 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
 
-    if (vshCommandOptUL(cmd, "bandwidth", &bandwidth) < 0) {
-        vshError(ctl, "%s", _("migrate: Invalid bandwidth"));
+    if (vshCommandOptUL(cmd, "bandwidth", &bandwidth) < 0)
         goto done;
-    }
 
     if (virDomainMigrateSetMaxSpeed(dom, bandwidth, 0) < 0)
         goto done;
@@ -11371,10 +11346,8 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return ret;
 
-    if (vshCommandOptULongLong(cmd, "minimum", &minimum) < 0) {
-        vshError(ctl, _("Unable to parse integer parameter minimum"));
+    if (vshCommandOptULongLong(cmd, "minimum", &minimum) < 0)
         goto cleanup;
-    }
 
     if (vshCommandOptStringReq(ctl, cmd, "mountpoint", &mountPoint) < 0)
         goto cleanup;
-- 
1.9.0

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