[PATCH 05/13] virsh: Split out block pull implementation from blockJobImpl

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

 



---
 tools/virsh-domain.c | 50 ++++++++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 98b6870..4f58caa 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1665,7 +1665,6 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
 }

 typedef enum {
-    VSH_CMD_BLOCK_JOB_PULL,
     VSH_CMD_BLOCK_JOB_COMMIT,
 } vshCmdBlockJobMode;

@@ -1691,21 +1690,6 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
         goto cleanup;

     switch (mode) {
-    case VSH_CMD_BLOCK_JOB_PULL:
-        if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0)
-            goto cleanup;
-        if (vshCommandOptBool(cmd, "keep-relative"))
-            flags |= VIR_DOMAIN_BLOCK_REBASE_RELATIVE;
-
-        if (base || flags) {
-            if (virDomainBlockRebase(dom, path, base, bandwidth, flags) < 0)
-                goto cleanup;
-        } else {
-            if (virDomainBlockPull(dom, path, bandwidth, 0) < 0)
-                goto cleanup;
-        }
-
-        break;
     case VSH_CMD_BLOCK_JOB_COMMIT:
         if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0 ||
             vshCommandOptStringReq(ctl, cmd, "top", &top) < 0)
@@ -2681,16 +2665,31 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
     struct timeval start;
     struct timeval curr;
     const char *path = NULL;
+    const char *base = NULL;
+    unsigned long bandwidth = 0;
     bool quit = false;
     int abort_flags = 0;
     int status = -1;
     int cb_id = -1;
+    unsigned int flags = 0;
+
+    if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
+        return false;
+
+    if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0)
+        return false;
+
+    if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) {
+        vshError(ctl, "%s", _("bandwidth must be a number"));
+        return false;
+    }
+
+    if (vshCommandOptBool(cmd, "keep-relative"))
+        flags |= VIR_DOMAIN_BLOCK_REBASE_RELATIVE;

     if (blocking) {
         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;

@@ -2710,6 +2709,9 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
         return false;
     }

+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
     virConnectDomainEventGenericCallback cb =
         VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);

@@ -2721,8 +2723,13 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
                                                   NULL)) < 0)
         vshResetLibvirtError();

-    if (!blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_PULL, &dom))
-        goto cleanup;
+    if (base || flags) {
+        if (virDomainBlockRebase(dom, path, base, bandwidth, flags) < 0)
+            goto cleanup;
+    } else {
+        if (virDomainBlockPull(dom, path, bandwidth, 0) < 0)
+            goto cleanup;
+    }

     if (!blocking) {
         vshPrint(ctl, "%s", _("Block Pull started"));
@@ -2780,8 +2787,7 @@ cmdBlockPull(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.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]