[libvirt RFCv8 11/27] qemu: saveimage: wire up saveimage code with the multifd helper

Claudio Fontana cfontana at suse.de
Sat May 7 13:43:04 UTC 2022


use the multifd helper and the new virQEMUSaveFd APIs for multifd.

Signed-off-by: Claudio Fontana <cfontana at suse.de>
---
 src/qemu/qemu_saveimage.c | 42 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c
index 264868b5a4..2a9ef622be 100644
--- a/src/qemu/qemu_saveimage.c
+++ b/src/qemu/qemu_saveimage.c
@@ -17,6 +17,7 @@
  */
 
 #include <config.h>
+#include <configmake.h>
 
 #include "qemu_saveimage.h"
 #include "qemu_domain.h"
@@ -478,6 +479,7 @@ qemuSaveImageCreate(virQEMUDriver *driver,
 {
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     virQEMUSaveFd saveFd = QEMU_SAVEFD_INVALID;
+    virQEMUSaveFd *multiFd = NULL;
     unsigned int oflags = O_WRONLY | O_TRUNC | O_CREAT;
     int ret = -1;
 
@@ -497,9 +499,42 @@ qemuSaveImageCreate(virQEMUDriver *driver,
     if (virQEMUSaveDataWrite(data, saveFd.fd, saveFd.path) < 0)
         goto cleanup;
 
-    /* Perform the migration */
-    if (qemuMigrationSrcToFile(driver, vm, saveFd.fd, compressor, asyncJob) < 0)
-        goto cleanup;
+    if (flags & VIR_DOMAIN_SAVE_PARALLEL) {
+        g_autoptr(virCommand) cmd = NULL;
+        g_autofree char *helper_path = NULL;
+        qemuDomainObjPrivate *priv = vm->privateData;
+        g_autofree char *sun_path = g_strdup_printf("%s/save-multifd.sock", priv->libDir);
+        char buf[1];
+        int helper_out = -1;
+        if (!(helper_path = virFileFindResource("libvirt_multifd_helper",
+                                                abs_top_builddir "/src",
+                                                LIBEXECDIR)))
+            goto cleanup;
+        cmd = virCommandNewArgList(helper_path, sun_path, NULL);
+        virCommandAddArgFormat(cmd, "%d", nconn);
+        virCommandAddArgFormat(cmd, "%d", saveFd.fd);
+        virCommandPassFD(cmd, saveFd.fd, 0);
+        virCommandSetOutputFD(cmd, &helper_out); /* should create pipe automagically */
+
+        /* Perform parallel multifd migration to files (main fd + channels) */
+        if (!(multiFd = qemuSaveImageCreateMultiFd(driver, vm, cmd, saveFd.path, oflags, cfg, nconn)))
+            goto cleanup;
+        if (virCommandRunAsync(cmd, NULL) < 0)
+            goto cleanup;
+        if (saferead(helper_out, &buf, 1) != 1 || buf[0] != 'R')
+            goto cleanup;
+        if (chown(sun_path, cfg->user, cfg->group) < 0)
+            goto cleanup;
+        /* still using single fd migration for now */
+        if (qemuMigrationSrcToFile(driver, vm, saveFd.fd, compressor, asyncJob) < 0)
+            goto cleanup;
+        if (qemuSaveImageCloseMultiFd(multiFd, nconn, vm) < 0)
+            goto cleanup;
+    } else {
+        /* Perform non-parallel migration to file */
+        if (qemuMigrationSrcToFile(driver, vm, saveFd.fd, compressor, asyncJob) < 0)
+            goto cleanup;
+    }
 
     if (virQEMUSaveFdClose(&saveFd, vm) < 0)
         goto cleanup;
@@ -518,6 +553,7 @@ qemuSaveImageCreate(virQEMUDriver *driver,
     ret = 0;
 
  cleanup:
+    ret = qemuSaveImageFreeMultiFd(multiFd, vm, nconn, ret);
     ret = virQEMUSaveFdFini(&saveFd, vm, ret);
     return ret;
 }
-- 
2.35.3



More information about the libvir-list mailing list