[libvirt] [PATCH 7/9] Separate out code for sending tunnelled data

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

 



Simplify the doTunnelMigrate code by pulling out the code for
sending all tunnelled data into separate helper

* qemu/qemu_driver.c: introduce doTunnelSendAll() method
---
 src/qemu/qemu_driver.c |   63 ++++++++++++++++++++++++++---------------------
 1 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fe5a376..eea85b3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6466,6 +6466,40 @@ cleanup:
 }
 
 
+static int doTunnelSendAll(virDomainPtr dom,
+                           virStreamPtr st,
+                           int sock)
+{
+    char buffer[65536];
+    int nbytes = sizeof(buffer);
+
+    /* XXX should honour the 'resource' parameter here */
+    for (;;) {
+        nbytes = saferead(sock, buffer, nbytes);
+        if (nbytes < 0) {
+            virStreamAbort(st);
+            virReportSystemError(dom->conn, errno, "%s",
+                                 _("tunnelled migration failed to read from qemu"));
+            return -1;
+        }
+        else if (nbytes == 0)
+            /* EOF; get out of here */
+            break;
+
+        if (virStreamSend(st, buffer, nbytes) < 0) {
+            qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+                             _("Failed to write migration data to remote libvirtd"));
+            return -1;
+        }
+    }
+
+    if (virStreamFinish(st) < 0)
+        /* virStreamFinish set the error for us */
+        return -1;
+
+    return 0;
+}
+
 static int doTunnelMigrate(virDomainPtr dom,
                            virConnectPtr dconn,
                            virDomainObjPtr vm,
@@ -6482,7 +6516,6 @@ static int doTunnelMigrate(virDomainPtr dom,
     virDomainPtr ddomain;
     int retval = -1;
     ssize_t bytes;
-    char buffer[65536];
     virStreamPtr st;
     char *unixfile = NULL;
     int internalret;
@@ -6591,34 +6624,8 @@ static int doTunnelMigrate(virDomainPtr dom,
         goto qemu_cancel_migration;
     }
 
+    retval = doTunnelSendAll(dom, st, client_sock);
 
-    /* XXX should honour the 'resource' parameter here */
-    for (;;) {
-        bytes = saferead(client_sock, buffer, sizeof(buffer));
-        if (bytes < 0) {
-            virStreamAbort(st);
-            virReportSystemError(dconn, errno, "%s",
-                                 _("tunnelled migration failed to read from qemu"));
-            goto close_client_sock;
-        }
-        else if (bytes == 0)
-            /* EOF; get out of here */
-            break;
-
-        if (virStreamSend(st, buffer, bytes) < 0) {
-            qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
-                             _("Failed to write migration data to remote libvirtd"));
-            goto close_client_sock;
-        }
-    }
-
-    if (virStreamFinish(st) < 0)
-        /* virStreamFinish set the error for us */
-        goto close_client_sock;
-
-    retval = 0;
-
-close_client_sock:
     close(client_sock);
 
 qemu_cancel_migration:
-- 
1.6.2.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]