Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > ebe084c140192657f9094e135a84202c > files > 48

libvirt-0.8.2-29.el5.src.rpm

From e7bef02fb28a9ebc648f382af2a7912c4a78727c Mon Sep 17 00:00:00 2001
Message-Id: <e7bef02fb28a9ebc648f382af2a7912c4a78727c.1304950497.git.jdenemar@redhat.com>
From: Eric Blake <eblake@redhat.com>
Date: Fri, 22 Apr 2011 11:43:21 -0600
Subject: [PATCH] Manually kill gzip if restore fails before starting qemu

5.7: https://bugzilla.redhat.com/show_bug.cgi?id=681623

If a guest image is saved in compressed format, and the restore fails
in some way after the intermediate process used to uncompress the
image has been started, but before qemu has been started to hook up to
the uncompressor, libvirt will endlessly wait for the uncompressor to
finish, but it never will because it's still waiting to have something
hooked up to drain its output.

The solution is to close the pipes on both sides of the uncompressor,
then send a SIGTERM before calling waitpid on it (only if the restore
has failed, of course).
(cherry picked from commit c9c794b52bea18d998e9affa0c166c6bcf475348)

Conflicts:

	src/qemu/qemu_driver.c - no VIR_FORCE_CLOSE yet
---
 src/qemu/qemu_driver.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9d5d95a..84dc7b8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6471,6 +6471,21 @@ qemudDomainSaveImageStartVM(virConnectPtr conn,
     ret = qemudStartVMDaemon(conn, driver, vm, "stdio", true, fd, path);
 
     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.
+             */
+            if (intermediatefd != -1) {
+                close(intermediatefd);
+                intermediatefd = -1;
+            }
+            if (fd != -1) {
+                close(fd);
+                fd = -1;
+            }
+            kill(intermediate_pid, SIGTERM);
+        }
+
         /* Wait for intermediate process to exit */
         while (waitpid(intermediate_pid, &childstat, 0) == -1 &&
                errno == EINTR) {
-- 
1.7.5.rc3