[PATCH v2 2/8] 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.

* 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, 27 insertions(+), 18 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 2562326..fb9c009 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1443,8 +1443,7 @@ typedef enum {
     VSH_CMD_BLOCK_JOB_INFO = 1,
     VSH_CMD_BLOCK_JOB_SPEED = 2,
     VSH_CMD_BLOCK_JOB_PULL = 3,
-    VSH_CMD_BLOCK_JOB_COPY = 4,
-    VSH_CMD_BLOCK_JOB_COMMIT = 5,
+    VSH_CMD_BLOCK_JOB_COMMIT = 4,
 } vshCmdBlockJobMode;

 static int
@@ -1453,14 +1452,14 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
              virDomainPtr *pdom)
 {
     virDomainPtr dom = NULL;
-    const char *name, *path;
+    const char *path;
     unsigned long bandwidth = 0;
     int ret = -1;
     const char *base = NULL;
     const char *top = NULL;
     unsigned int flags = 0;

-    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         goto cleanup;

     if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
@@ -1513,17 +1512,6 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
             flags |= VIR_DOMAIN_BLOCK_COMMIT_RELATIVE;
         ret = virDomainBlockCommit(dom, path, base, top, bandwidth, flags);
         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 (vshCommandOptStringReq(ctl, cmd, "dest", &base) < 0)
-            goto cleanup;
-        ret = virDomainBlockRebase(dom, path, base, bandwidth, flags);
     }

  cleanup:
@@ -1859,6 +1847,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");
@@ -1874,6 +1865,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) {
@@ -1882,8 +1876,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;

@@ -1902,7 +1894,24 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
         return false;
     }

-    if (blockJobImpl(ctl, cmd, NULL, VSH_CMD_BLOCK_JOB_COPY, &dom) < 0)
+    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 (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]