[PATCH 07/13] virsh: Refactor argument checking in cmdBlockCommit

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

 



Use the VSH_EXCLUSIVE_OPTIONS to exclude combinations of --pivot and
--keep-overlay and refactor the enforcing of the --wait option and other
flags that imply --wait.
---
 tools/virsh-domain.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 8b354bb..43eff4f 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1802,7 +1802,8 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
     bool pivot = vshCommandOptBool(cmd, "pivot");
     bool finish = vshCommandOptBool(cmd, "keep-overlay");
     bool active = vshCommandOptBool(cmd, "active") || pivot || finish;
-    bool blocking = vshCommandOptBool(cmd, "wait");
+    bool blocking = vshCommandOptBool(cmd, "wait") || pivot || finish;
+    bool async = vshCommandOptBool(cmd, "async");
     int timeout = 0;
     struct sigaction sig_action;
     struct sigaction old_sig_action;
@@ -1819,6 +1820,8 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
     unsigned int flags = 0;
     unsigned long bandwidth = 0;

+    VSH_EXCLUSIVE_OPTIONS("pivot", "keep-overlay");
+
     if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
         return false;

@@ -1845,17 +1848,30 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
    if (vshCommandOptBool(cmd, "keep-relative"))
         flags |= VIR_DOMAIN_BLOCK_COMMIT_RELATIVE;

-    blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish;
-    if (blocking) {
-        if (pivot && finish) {
-            vshError(ctl, "%s", _("cannot mix --pivot and --keep-overlay"));
+    if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
+        return false;
+
+    if (timeout)
+        blocking = true;
+
+    if (!blocking) {
+        if (verbose) {
+            vshError(ctl, "%s", _("--verbose requires at least one of --timeout, "
+                                  "--wait, --pivot, or --keep-overlay"));
             return false;
         }
-        if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
+
+        if (async) {
+            vshError(ctl, "%s", _("--async requires at least one of --timeout, "
+                                  "--wait, --pivot, or --keep-overlay"));
             return false;
-        if (vshCommandOptBool(cmd, "async"))
-            abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
+        }
+    }

+    if (async)
+        abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
+
+    if (blocking) {
         sigemptyset(&sigmask);
         sigaddset(&sigmask, SIGINT);

@@ -1866,9 +1882,6 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
         sigaction(SIGINT, &sig_action, &old_sig_action);

         GETTIMEOFDAY(&start);
-    } else if (verbose || vshCommandOptBool(cmd, "async")) {
-        vshError(ctl, "%s", _("missing --wait option"));
-        return false;
     }

     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
-- 
2.4.5

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