mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0118-p2v-Poll-to-make-Cancel-Conversion-button-more-respo.patch

e76f14
From a5806c1b4be3f74b25ec733328259e7966af6af6 Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Mon, 20 Jun 2016 10:18:22 +0100
e76f14
Subject: [PATCH] p2v: Poll to make Cancel Conversion button more responsive.
e76f14
e76f14
Previously cancelling the conversion only set a flag, which was
e76f14
checked when the run dialog displayed new output from virt-v2v.  When
e76f14
virt-v2v was showing hundreds of debugging messages, this wasn't a
e76f14
problem, but now that we are hiding those messages, cancelling the
e76f14
conversion might mean a wait of seconds or minutes.
e76f14
e76f14
By polling (albeit infrequently) we can make the cancel button more
e76f14
responsive.
e76f14
e76f14
(cherry picked from commit 6da4941db7f8a85997d6281b9b4c5165768e6489)
e76f14
---
e76f14
 p2v/conversion.c | 27 +++++++++++++++++++++++++--
e76f14
 1 file changed, 25 insertions(+), 2 deletions(-)
e76f14
e76f14
diff --git a/p2v/conversion.c b/p2v/conversion.c
e76f14
index b54f971..de2a4b2 100644
e76f14
--- a/p2v/conversion.c
e76f14
+++ b/p2v/conversion.c
e76f14
@@ -25,6 +25,7 @@
e76f14
 #include <fcntl.h>
e76f14
 #include <inttypes.h>
e76f14
 #include <unistd.h>
e76f14
+#include <poll.h>
e76f14
 #include <time.h>
e76f14
 #include <errno.h>
e76f14
 #include <error.h>
e76f14
@@ -346,13 +347,35 @@ start_conversion (struct config *config,
e76f14
   }
e76f14
 
e76f14
   /* Read output from the virt-v2v process and echo it through the
e76f14
-   * notify function, until virt-v2v closes the connection.
e76f14
+   * notify function, until virt-v2v closes the connection.  We
e76f14
+   * actually poll in this loop (albeit it only every 2 seconds) so
e76f14
+   * that the user won't have to wait too long between pressing the
e76f14
+   * cancel button and having the conversion cancelled.
e76f14
    */
e76f14
   while (!is_cancel_requested ()) {
e76f14
+    int fd = mexp_get_fd (control_h);
e76f14
+    struct pollfd fds[1];
e76f14
+    int rp;
e76f14
     char buf[257];
e76f14
     ssize_t r;
e76f14
 
e76f14
-    r = read (mexp_get_fd (control_h), buf, sizeof buf - 1);
e76f14
+    fds[0].fd = fd;
e76f14
+    fds[0].events = POLLIN;
e76f14
+    fds[0].revents = 0;
e76f14
+    rp = poll (fds, 1, 2000 /* ms */);
e76f14
+    if (rp == -1) {
e76f14
+      /* See comment about this in miniexpect.c. */
e76f14
+      if (errno == EIO)
e76f14
+        break;
e76f14
+      set_conversion_error ("poll: %m");
e76f14
+      goto out;
e76f14
+    }
e76f14
+    else if (rp == 0)
e76f14
+      /* Timeout. */
e76f14
+      continue;
e76f14
+    /* ... else rp == 1, ignore revents and just do the read. */
e76f14
+
e76f14
+    r = read (fd, buf, sizeof buf - 1);
e76f14
     if (r == -1) {
e76f14
       /* See comment about this in miniexpect.c. */
e76f14
       if (errno == EIO)
e76f14
-- 
7af31e
1.8.3.1
e76f14