|
|
7a3408 |
From a03fb4691c3df18caff2b2f4d8296dd9cec16c0c Mon Sep 17 00:00:00 2001
|
|
|
7a3408 |
Message-Id: <a03fb4691c3df18caff2b2f4d8296dd9cec16c0c@dist-git>
|
|
|
7a3408 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
7a3408 |
Date: Tue, 21 Jul 2015 16:18:23 +0200
|
|
|
7a3408 |
Subject: [PATCH] virsh: blockjob: Extract block job info code into a separate
|
|
|
7a3408 |
function
|
|
|
7a3408 |
|
|
|
7a3408 |
https://bugzilla.redhat.com/show_bug.cgi?id=1227551
|
|
|
7a3408 |
https://bugzilla.redhat.com/show_bug.cgi?id=1197592
|
|
|
7a3408 |
|
|
|
7a3408 |
cmdBlockJob will be converted to a hub that will call into the
|
|
|
7a3408 |
individual executor functions.
|
|
|
7a3408 |
|
|
|
7a3408 |
(cherry picked from commit dda95b531f1d2e9abd4df03c0461eaa7e3840b02)
|
|
|
7a3408 |
|
|
|
7a3408 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
7a3408 |
---
|
|
|
7a3408 |
tools/virsh-domain.c | 93 +++++++++++++++++++++++++++++++---------------------
|
|
|
7a3408 |
1 file changed, 56 insertions(+), 37 deletions(-)
|
|
|
7a3408 |
|
|
|
7a3408 |
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
|
|
|
7a3408 |
index f7edeeb..7a18204 100644
|
|
|
7a3408 |
--- a/tools/virsh-domain.c
|
|
|
7a3408 |
+++ b/tools/virsh-domain.c
|
|
|
7a3408 |
@@ -2451,47 +2451,19 @@ vshDomainBlockJobToString(int type)
|
|
|
7a3408 |
return str ? _(str) : _("Unknown job");
|
|
|
7a3408 |
}
|
|
|
7a3408 |
|
|
|
7a3408 |
+
|
|
|
7a3408 |
static bool
|
|
|
7a3408 |
-cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
|
|
|
7a3408 |
+vshBlockJobInfo(vshControl *ctl,
|
|
|
7a3408 |
+ virDomainPtr dom,
|
|
|
7a3408 |
+ const char *path,
|
|
|
7a3408 |
+ bool raw,
|
|
|
7a3408 |
+ bool bytes)
|
|
|
7a3408 |
{
|
|
|
7a3408 |
virDomainBlockJobInfo info;
|
|
|
7a3408 |
- bool ret = false;
|
|
|
7a3408 |
- int rc = -1;
|
|
|
7a3408 |
- bool raw = vshCommandOptBool(cmd, "raw");
|
|
|
7a3408 |
- bool bytes = vshCommandOptBool(cmd, "bytes");
|
|
|
7a3408 |
- bool abortMode = (vshCommandOptBool(cmd, "abort") ||
|
|
|
7a3408 |
- vshCommandOptBool(cmd, "async") ||
|
|
|
7a3408 |
- vshCommandOptBool(cmd, "pivot"));
|
|
|
7a3408 |
- bool infoMode = vshCommandOptBool(cmd, "info") || raw;
|
|
|
7a3408 |
- bool bandwidth = vshCommandOptBool(cmd, "bandwidth");
|
|
|
7a3408 |
- virDomainPtr dom = NULL;
|
|
|
7a3408 |
- const char *path;
|
|
|
7a3408 |
- unsigned int flags = 0;
|
|
|
7a3408 |
unsigned long long speed;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- if (abortMode + infoMode + bandwidth > 1) {
|
|
|
7a3408 |
- vshError(ctl, "%s",
|
|
|
7a3408 |
- _("conflict between abort, info, and bandwidth modes"));
|
|
|
7a3408 |
- return false;
|
|
|
7a3408 |
- }
|
|
|
7a3408 |
- /* XXX also support --bytes with bandwidth mode */
|
|
|
7a3408 |
- if (bytes && (abortMode || bandwidth)) {
|
|
|
7a3408 |
- vshError(ctl, "%s", _("--bytes requires info mode"));
|
|
|
7a3408 |
- return false;
|
|
|
7a3408 |
- }
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- if (abortMode)
|
|
|
7a3408 |
- return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_ABORT, NULL);
|
|
|
7a3408 |
- if (bandwidth)
|
|
|
7a3408 |
- return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_SPEED, NULL);
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- /* Everything below here is for --info mode */
|
|
|
7a3408 |
- if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
7a3408 |
- goto cleanup;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- /* XXX Allow path to be optional to list info on all devices at once */
|
|
|
7a3408 |
- if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
|
|
7a3408 |
- goto cleanup;
|
|
|
7a3408 |
+ unsigned int flags = 0;
|
|
|
7a3408 |
+ bool ret = false;
|
|
|
7a3408 |
+ int rc = -1;
|
|
|
7a3408 |
|
|
|
7a3408 |
/* If bytes were requested, or if raw mode is not forcing a MiB/s
|
|
|
7a3408 |
* query and cache can't prove failure, then query bytes/sec. */
|
|
|
7a3408 |
@@ -2556,7 +2528,54 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
|
|
|
7a3408 |
}
|
|
|
7a3408 |
vshPrint(ctl, "\n");
|
|
|
7a3408 |
}
|
|
|
7a3408 |
+
|
|
|
7a3408 |
ret = true;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ cleanup:
|
|
|
7a3408 |
+ return ret;
|
|
|
7a3408 |
+}
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+static bool
|
|
|
7a3408 |
+cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
|
|
|
7a3408 |
+{
|
|
|
7a3408 |
+ bool ret = false;
|
|
|
7a3408 |
+ bool raw = vshCommandOptBool(cmd, "raw");
|
|
|
7a3408 |
+ bool bytes = vshCommandOptBool(cmd, "bytes");
|
|
|
7a3408 |
+ bool abortMode = (vshCommandOptBool(cmd, "abort") ||
|
|
|
7a3408 |
+ vshCommandOptBool(cmd, "async") ||
|
|
|
7a3408 |
+ vshCommandOptBool(cmd, "pivot"));
|
|
|
7a3408 |
+ bool infoMode = vshCommandOptBool(cmd, "info") || raw;
|
|
|
7a3408 |
+ bool bandwidth = vshCommandOptBool(cmd, "bandwidth");
|
|
|
7a3408 |
+ virDomainPtr dom = NULL;
|
|
|
7a3408 |
+ const char *path;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (abortMode + infoMode + bandwidth > 1) {
|
|
|
7a3408 |
+ vshError(ctl, "%s",
|
|
|
7a3408 |
+ _("conflict between abort, info, and bandwidth modes"));
|
|
|
7a3408 |
+ return false;
|
|
|
7a3408 |
+ }
|
|
|
7a3408 |
+ /* XXX also support --bytes with bandwidth mode */
|
|
|
7a3408 |
+ if (bytes && (abortMode || bandwidth)) {
|
|
|
7a3408 |
+ vshError(ctl, "%s", _("--bytes requires info mode"));
|
|
|
7a3408 |
+ return false;
|
|
|
7a3408 |
+ }
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (abortMode)
|
|
|
7a3408 |
+ return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_ABORT, NULL);
|
|
|
7a3408 |
+ if (bandwidth)
|
|
|
7a3408 |
+ return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_SPEED, NULL);
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ /* Everything below here is for --info mode */
|
|
|
7a3408 |
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
|
|
7a3408 |
+ goto cleanup;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ /* XXX Allow path to be optional to list info on all devices at once */
|
|
|
7a3408 |
+ if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
|
|
|
7a3408 |
+ goto cleanup;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ ret = vshBlockJobInfo(ctl, dom, path, raw, bytes);
|
|
|
7a3408 |
+
|
|
|
7a3408 |
cleanup:
|
|
|
7a3408 |
if (dom)
|
|
|
7a3408 |
virDomainFree(dom);
|
|
|
7a3408 |
--
|
|
|
7a3408 |
2.5.0
|
|
|
7a3408 |
|