Final cleanup to get rid of the hub function.
---
tools/virsh-domain.c | 96 +++++++++++++++++++---------------------------------
1 file changed, 35 insertions(+), 61 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 081adfd..e2a38e7 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1665,62 +1665,6 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
goto cleanup;
}
-typedef enum {
- VSH_CMD_BLOCK_JOB_COMMIT,
-} vshCmdBlockJobMode;
-
-static bool
-blockJobImpl(vshControl *ctl, const vshCmd *cmd,
- vshCmdBlockJobMode mode, virDomainPtr *pdom)
-{
- virDomainPtr dom = NULL;
- const char *path;
- unsigned long bandwidth = 0;
- bool ret = false;
- const char *base = NULL;
- const char *top = NULL;
- unsigned int flags = 0;
-
- if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
- goto cleanup;
-
- if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
- goto cleanup;
-
- if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) {
- vshError(ctl, "%s", _("bandwidth must be a number"));
- goto cleanup;
- }
-
- switch (mode) {
- case VSH_CMD_BLOCK_JOB_COMMIT:
- if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0 ||
- vshCommandOptStringReq(ctl, cmd, "top", &top) < 0)
- goto cleanup;
- if (vshCommandOptBool(cmd, "shallow"))
- flags |= VIR_DOMAIN_BLOCK_COMMIT_SHALLOW;
- if (vshCommandOptBool(cmd, "delete"))
- flags |= VIR_DOMAIN_BLOCK_COMMIT_DELETE;
- if (vshCommandOptBool(cmd, "active") ||
- vshCommandOptBool(cmd, "pivot") ||
- vshCommandOptBool(cmd, "keep-overlay"))
- flags |= VIR_DOMAIN_BLOCK_COMMIT_ACTIVE;
- if (vshCommandOptBool(cmd, "keep-relative"))
- flags |= VIR_DOMAIN_BLOCK_COMMIT_RELATIVE;
- if (virDomainBlockCommit(dom, path, base, top, bandwidth, flags) < 0)
- goto cleanup;
- break;
- }
-
- ret = true;
-
- cleanup:
- if (pdom && ret)
- *pdom = dom;
- else if (dom)
- virDomainFree(dom);
- return ret;
-}
static void
vshPrintJobProgress(const char *label, unsigned long long remaining,
@@ -1867,10 +1811,40 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
struct timeval start;
struct timeval curr;
const char *path = NULL;
+ const char *base = NULL;
+ const char *top = NULL;
bool quit = false;
int abort_flags = 0;
int status = -1;
int cb_id = -1;
+ unsigned int flags = 0;
+ unsigned long bandwidth = 0;
+
+ if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
+ return false;
+
+ if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0)
+ return false;
+
+ if (vshCommandOptStringReq(ctl, cmd, "top", &top) < 0)
+ return false;
+
+ if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) {
+ vshError(ctl, "%s", _("bandwidth must be a number"));
+ return false;
+ }
+
+ if (vshCommandOptBool(cmd, "shallow"))
+ flags |= VIR_DOMAIN_BLOCK_COMMIT_SHALLOW;
+
+ if (vshCommandOptBool(cmd, "delete"))
+ flags |= VIR_DOMAIN_BLOCK_COMMIT_DELETE;
+
+ if (active)
+ flags |= VIR_DOMAIN_BLOCK_COMMIT_ACTIVE;
+
+ if (vshCommandOptBool(cmd, "keep-relative"))
+ flags |= VIR_DOMAIN_BLOCK_COMMIT_RELATIVE;
blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish;
if (blocking) {
@@ -1880,8 +1854,6 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
}
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
return false;
- if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
- return false;
if (vshCommandOptBool(cmd, "async"))
abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
@@ -1900,6 +1872,9 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
return false;
}
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
virConnectDomainEventGenericCallback cb =
VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);
@@ -1911,7 +1886,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
NULL)) < 0)
vshResetLibvirtError();
- if (!blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_COMMIT, &dom))
+ if (virDomainBlockCommit(dom, path, base, top, bandwidth, flags) < 0)
goto cleanup;
if (!blocking) {
@@ -1993,8 +1968,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
ret = true;
cleanup:
- if (dom)
- virDomainFree(dom);
+ virDomainFree(dom);
if (blocking)
sigaction(SIGINT, &old_sig_action, NULL);
if (cb_id >= 0)
--
2.3.5