[PATCH v3 11/18] blockcopy: split out virsh implementation

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

 



I'm about to extend the capabilities of blockcopy.  Hiding a few
common lines of implementation gets in the way of the new required
logic, and putting the new logic in the common implementation won't
benefit any of the other blockjob operations.  Therefore, it is
simpler to just do the work inline.  There should be no semantic
change in this patch.

* tools/virsh-domain.c (blockJobImpl): Drop unused variable. Move
block copy guts...
(cmdBlockCopy): ...into their lone caller.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 tools/virsh-domain.c | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 813d8e0..b92b2eb 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1464,7 +1464,6 @@ typedef enum {
     VSH_CMD_BLOCK_JOB_ABORT,
     VSH_CMD_BLOCK_JOB_SPEED,
     VSH_CMD_BLOCK_JOB_PULL,
-    VSH_CMD_BLOCK_JOB_COPY,
     VSH_CMD_BLOCK_JOB_COMMIT,
 } vshCmdBlockJobMode;

@@ -1536,21 +1535,6 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
         if (virDomainBlockCommit(dom, path, base, top, bandwidth, flags) < 0)
             goto cleanup;
         break;
-    case VSH_CMD_BLOCK_JOB_COPY:
-        flags |= VIR_DOMAIN_BLOCK_REBASE_COPY;
-        if (vshCommandOptBool(cmd, "shallow"))
-            flags |= VIR_DOMAIN_BLOCK_REBASE_SHALLOW;
-        if (vshCommandOptBool(cmd, "reuse-external"))
-            flags |= VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT;
-        if (vshCommandOptBool(cmd, "raw"))
-            flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_RAW;
-        if (vshCommandOptBool(cmd, "blockdev"))
-            flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_DEV;
-        if (vshCommandOptStringReq(ctl, cmd, "dest", &base) < 0)
-            goto cleanup;
-        if (virDomainBlockRebase(dom, path, base, bandwidth, flags) < 0)
-            goto cleanup;
-        break;
     }

     ret = true;
@@ -1892,6 +1876,9 @@ static bool
 cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom = NULL;
+    const char *dest;
+    unsigned long bandwidth = 0;
+    unsigned int flags = VIR_DOMAIN_BLOCK_REBASE_COPY;
     bool ret = false;
     bool blocking = vshCommandOptBool(cmd, "wait");
     bool verbose = vshCommandOptBool(cmd, "verbose");
@@ -1907,6 +1894,9 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
     bool quit = false;
     int abort_flags = 0;

+    if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
+        return false;
+
     blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish;
     if (blocking) {
         if (pivot && finish) {
@@ -1915,8 +1905,6 @@ cmdBlockCopy(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;

@@ -1935,7 +1923,26 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
         return false;
     }

-    if (!blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_COPY, &dom))
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        goto cleanup;
+
+    if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) {
+        vshError(ctl, "%s", _("bandwidth must be a number"));
+        goto cleanup;
+    }
+
+    if (vshCommandOptBool(cmd, "shallow"))
+        flags |= VIR_DOMAIN_BLOCK_REBASE_SHALLOW;
+    if (vshCommandOptBool(cmd, "reuse-external"))
+        flags |= VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT;
+    if (vshCommandOptBool(cmd, "raw"))
+        flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_RAW;
+    if (vshCommandOptBool(cmd, "blockdev"))
+        flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_DEV;
+    if (vshCommandOptStringReq(ctl, cmd, "dest", &dest) < 0)
+        goto cleanup;
+
+    if (virDomainBlockRebase(dom, path, dest, bandwidth, flags) < 0)
         goto cleanup;

     if (!blocking) {
-- 
1.9.3

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