[PATCH 3/9] qemu: Convert virExec usage to virCommand

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

 



v2:
    Have virCommand cleanup intermediate process for us

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c  |   35 +++++++++++------------------------
 src/qemu/qemu_process.c |    2 +-
 2 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fff41e0..a826b6d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3238,11 +3238,9 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
     int ret = -1;
     virDomainEventPtr event;
     int intermediatefd = -1;
-    pid_t intermediate_pid = -1;
-    int childstat;
+    virCommandPtr cmd = NULL;
 
     if (header->version == 2) {
-        const char *intermediate_argv[3] = { NULL, "-dc", NULL };
         const char *prog = qemudSaveCompressionTypeToString(header->compressed);
         if (prog == NULL) {
             qemuReportError(VIR_ERR_OPERATION_FAILED,
@@ -3252,14 +3250,17 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
         }
 
         if (header->compressed != QEMUD_SAVE_FORMAT_RAW) {
-            intermediate_argv[0] = prog;
+            cmd = virCommandNewArgList(prog, "-dc", NULL);
             intermediatefd = *fd;
             *fd = -1;
-            if (virExec(intermediate_argv, NULL, NULL,
-                        &intermediate_pid, intermediatefd, fd, NULL, 0) < 0) {
+
+            virCommandSetInputFD(cmd, intermediatefd);
+            virCommandSetOutputFD(cmd, fd);
+
+            if (virCommandRunAsync(cmd, NULL) < 0) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
                                 _("Failed to start decompression binary %s"),
-                                intermediate_argv[0]);
+                                prog);
                 *fd = intermediatefd;
                 goto out;
             }
@@ -3270,23 +3271,8 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
     ret = qemuProcessStart(conn, driver, vm, "stdio", true, *fd, path,
                            VIR_VM_OP_RESTORE);
 
-    if (intermediate_pid != -1) {
-        if (ret < 0) {
-            /* if there was an error setting up qemu, the intermediate
-             * process will wait forever to write to stdout, so we
-             * must manually kill it.
-             */
-            VIR_FORCE_CLOSE(intermediatefd);
-            VIR_FORCE_CLOSE(*fd);
-            kill(intermediate_pid, SIGTERM);
-        }
-
-        /* Wait for intermediate process to exit */
-        while (waitpid(intermediate_pid, &childstat, 0) == -1 &&
-               errno == EINTR) {
-            /* empty */
-        }
-    }
+    if (cmd && virCommandWait(cmd, NULL) < 0)
+        goto out;
     VIR_FORCE_CLOSE(intermediatefd);
 
     if (VIR_CLOSE(*fd) < 0) {
@@ -3324,6 +3310,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
     ret = 0;
 
 out:
+    virCommandFree(cmd);
     if (virSecurityManagerRestoreSavedStateLabel(driver->securityManager,
                                                  vm, path) < 0)
         VIR_WARN("failed to restore save state label on %s", path);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f745aea..96c01f7 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2275,7 +2275,7 @@ int qemuProcessStart(virConnectPtr conn,
          * because the child no longer exists.
          */
 
-        /* The virExec process that launches the daemon failed. Pending on
+        /* The virCommand process that launches the daemon failed. Pending on
          * when it failed (we can't determine for sure), there may be
          * extra info in the domain log (if the hook failed for example).
          *
-- 
1.7.4.4

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