|
|
e76f14 |
From 547504706ea62956201d40c230d2ab85bd99fbc4 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Thu, 30 Jun 2016 14:13:24 +0100
|
|
|
e76f14 |
Subject: [PATCH] p2v: Send ^C to remote end to cancel the conversion.
|
|
|
e76f14 |
|
|
|
e76f14 |
We are now able to cancel the conversion instantly by sending ^C to
|
|
|
e76f14 |
the remote virt-v2v process.
|
|
|
e76f14 |
|
|
|
e76f14 |
Also, this reverts:
|
|
|
e76f14 |
"p2v: Poll to make Cancel Conversion button more responsive."
|
|
|
e76f14 |
(commit 6da4941db7f8a85997d6281b9b4c5165768e6489)
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit 87131d8681b6e72dac4d8c952f3b3fb7ade02eed)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
p2v/conversion.c | 60 +++++++++++++++++++++++++++-----------------------------
|
|
|
e76f14 |
1 file changed, 29 insertions(+), 31 deletions(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/p2v/conversion.c b/p2v/conversion.c
|
|
|
e76f14 |
index f9b8350..484c0e4 100644
|
|
|
e76f14 |
--- a/p2v/conversion.c
|
|
|
e76f14 |
+++ b/p2v/conversion.c
|
|
|
e76f14 |
@@ -25,7 +25,6 @@
|
|
|
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 |
@@ -127,6 +126,7 @@ static pthread_mutex_t running_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
e76f14 |
static int running = 0;
|
|
|
e76f14 |
static pthread_mutex_t cancel_requested_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
e76f14 |
static int cancel_requested = 0;
|
|
|
e76f14 |
+static mexp_h *control_h = NULL;
|
|
|
e76f14 |
|
|
|
e76f14 |
static int
|
|
|
e76f14 |
is_running (void)
|
|
|
e76f14 |
@@ -161,6 +161,21 @@ set_cancel_requested (int r)
|
|
|
e76f14 |
{
|
|
|
e76f14 |
pthread_mutex_lock (&cancel_requested_mutex);
|
|
|
e76f14 |
cancel_requested = r;
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+ /* Send ^C to the remote so that virt-v2v "knows" the connection has
|
|
|
e76f14 |
+ * been cancelled. mexp_send_interrupt is a single write(2) call.
|
|
|
e76f14 |
+ */
|
|
|
e76f14 |
+ if (r && control_h)
|
|
|
e76f14 |
+ ignore_value (mexp_send_interrupt (control_h));
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+ pthread_mutex_unlock (&cancel_requested_mutex);
|
|
|
e76f14 |
+}
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+static void
|
|
|
e76f14 |
+set_control_h (mexp_h *new_h)
|
|
|
e76f14 |
+{
|
|
|
e76f14 |
+ pthread_mutex_lock (&cancel_requested_mutex);
|
|
|
e76f14 |
+ control_h = new_h;
|
|
|
e76f14 |
pthread_mutex_unlock (&cancel_requested_mutex);
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
@@ -175,7 +190,6 @@ start_conversion (struct config *config,
|
|
|
e76f14 |
const size_t nr_disks = guestfs_int_count_strings (config->disks);
|
|
|
e76f14 |
time_t now;
|
|
|
e76f14 |
struct tm tm;
|
|
|
e76f14 |
- mexp_h *control_h = NULL;
|
|
|
e76f14 |
struct data_conn data_conns[nr_disks];
|
|
|
e76f14 |
CLEANUP_FREE char *remote_dir = NULL;
|
|
|
e76f14 |
char tmpdir[] = "/tmp/p2v.XXXXXX";
|
|
|
e76f14 |
@@ -189,6 +203,7 @@ start_conversion (struct config *config,
|
|
|
e76f14 |
fprintf (stderr, "\n");
|
|
|
e76f14 |
#endif
|
|
|
e76f14 |
|
|
|
e76f14 |
+ set_control_h (NULL);
|
|
|
e76f14 |
set_running (1);
|
|
|
e76f14 |
set_cancel_requested (0);
|
|
|
e76f14 |
|
|
|
e76f14 |
@@ -299,7 +314,7 @@ start_conversion (struct config *config,
|
|
|
e76f14 |
if (notify_ui)
|
|
|
e76f14 |
notify_ui (NOTIFY_STATUS, _("Setting up the control connection ..."));
|
|
|
e76f14 |
|
|
|
e76f14 |
- control_h = start_remote_connection (config, remote_dir);
|
|
|
e76f14 |
+ set_control_h (start_remote_connection (config, remote_dir));
|
|
|
e76f14 |
if (control_h == NULL) {
|
|
|
e76f14 |
set_conversion_error ("could not open control connection over SSH to the conversion server: %s",
|
|
|
e76f14 |
get_ssh_error ());
|
|
|
e76f14 |
@@ -346,35 +361,13 @@ 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. 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 |
+ * notify function, until virt-v2v closes the connection.
|
|
|
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 |
- 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 |
+ r = read (mexp_get_fd (control_h), buf, sizeof buf - 1);
|
|
|
e76f14 |
if (r == -1) {
|
|
|
e76f14 |
/* See comment about this in miniexpect.c. */
|
|
|
e76f14 |
if (errno == EIO)
|
|
|
e76f14 |
@@ -402,12 +395,17 @@ start_conversion (struct config *config,
|
|
|
e76f14 |
ret = 0;
|
|
|
e76f14 |
out:
|
|
|
e76f14 |
if (control_h) {
|
|
|
e76f14 |
- if ((status = mexp_close (control_h)) == -1) {
|
|
|
e76f14 |
+ mexp_h *h = control_h;
|
|
|
e76f14 |
+ set_control_h (NULL);
|
|
|
e76f14 |
+ status = mexp_close (h);
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+ if (status == -1) {
|
|
|
e76f14 |
set_conversion_error ("mexp_close: %m");
|
|
|
e76f14 |
ret = -1;
|
|
|
e76f14 |
- } else if (ret == 0 &&
|
|
|
e76f14 |
- WIFEXITED (status) &&
|
|
|
e76f14 |
- WEXITSTATUS (status) != 0) {
|
|
|
e76f14 |
+ }
|
|
|
e76f14 |
+ else if (ret == 0 &&
|
|
|
e76f14 |
+ WIFEXITED (status) &&
|
|
|
e76f14 |
+ WEXITSTATUS (status) != 0) {
|
|
|
e76f14 |
set_conversion_error ("virt-v2v exited with status %d",
|
|
|
e76f14 |
WEXITSTATUS (status));
|
|
|
e76f14 |
ret = -1;
|
|
|
e76f14 |
--
|
|
|
e76f14 |
1.8.3.1
|
|
|
e76f14 |
|