[PATCH 2/8] virsh: cmdBlockJob: Switch to declarative flag interlocking

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

 



Use the VSH_EXCLUSIVE_OPTIONS_VAR to interlock incompatible options
---
 tools/virsh-domain.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 01c6b9e..720bc68 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2548,26 +2548,31 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     bool raw = vshCommandOptBool(cmd, "raw");
     bool bytes = vshCommandOptBool(cmd, "bytes");
-    bool abortMode = (vshCommandOptBool(cmd, "abort") ||
-                      vshCommandOptBool(cmd, "async") ||
-                      vshCommandOptBool(cmd, "pivot"));
-    bool infoMode = vshCommandOptBool(cmd, "info") || raw;
+    bool abort = vshCommandOptBool(cmd, "abort");
+    bool pivot = vshCommandOptBool(cmd, "pivot");
+    bool async = vshCommandOptBool(cmd, "async");
+    bool info = vshCommandOptBool(cmd, "info");
     bool bandwidth = vshCommandOptBool(cmd, "bandwidth");
     virDomainPtr dom = NULL;
     const char *path;

-    if (abortMode + infoMode + bandwidth > 1) {
-        vshError(ctl, "%s",
-                 _("conflict between abort, info, and bandwidth modes"));
-        return false;
-    }
+    VSH_EXCLUSIVE_OPTIONS_VAR(raw, abort);
+    VSH_EXCLUSIVE_OPTIONS_VAR(raw, pivot);
+    VSH_EXCLUSIVE_OPTIONS_VAR(raw, async);
+    VSH_EXCLUSIVE_OPTIONS_VAR(raw, bandwidth);
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(info, abort);
+    VSH_EXCLUSIVE_OPTIONS_VAR(info, pivot);
+    VSH_EXCLUSIVE_OPTIONS_VAR(info, async);
+    VSH_EXCLUSIVE_OPTIONS_VAR(info, bandwidth);
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(bytes, abort);
+    VSH_EXCLUSIVE_OPTIONS_VAR(bytes, pivot);
+    VSH_EXCLUSIVE_OPTIONS_VAR(bytes, async);
     /* XXX also support --bytes with bandwidth mode */
-    if (bytes && (abortMode || bandwidth)) {
-        vshError(ctl, "%s", _("--bytes requires info mode"));
-        return false;
-    }
+    VSH_EXCLUSIVE_OPTIONS_VAR(bytes, bandwidth);

-    if (abortMode)
+    if (abort || pivot || async)
         return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_ABORT, NULL);
     if (bandwidth)
         return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_SPEED, NULL);
-- 
2.3.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]