|
|
0d20ef |
From 34bc94a474600195a8f0bd5450a5d7523afb86ee Mon Sep 17 00:00:00 2001
|
|
|
0d20ef |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
0d20ef |
Date: Thu, 20 Nov 2014 16:08:43 +0000
|
|
|
0d20ef |
Subject: [PATCH] p2v: Make the "Cancel Conversion" button work (RHBZ#1165569).
|
|
|
0d20ef |
|
|
|
0d20ef |
This relies on the remote to keep sending us data. If it hangs, then
|
|
|
0d20ef |
the cancel button won't work. This could also be fixed by introducing
|
|
|
0d20ef |
a timeout to the read syscall.
|
|
|
0d20ef |
|
|
|
0d20ef |
(cherry picked from commit 25b979a0c4a5942aaf62fcbe0e48d7526bd5e9b0)
|
|
|
0d20ef |
---
|
|
|
0d20ef |
p2v/conversion.c | 15 ++++++++++++++-
|
|
|
0d20ef |
p2v/gui.c | 12 +++++++++++-
|
|
|
0d20ef |
p2v/p2v.h | 1 +
|
|
|
0d20ef |
3 files changed, 26 insertions(+), 2 deletions(-)
|
|
|
0d20ef |
|
|
|
0d20ef |
diff --git a/p2v/conversion.c b/p2v/conversion.c
|
|
|
0d20ef |
index 6f414de..cb2deed 100644
|
|
|
0d20ef |
--- a/p2v/conversion.c
|
|
|
0d20ef |
+++ b/p2v/conversion.c
|
|
|
0d20ef |
@@ -86,6 +86,8 @@ get_conversion_error (void)
|
|
|
0d20ef |
return conversion_error;
|
|
|
0d20ef |
}
|
|
|
0d20ef |
|
|
|
0d20ef |
+static volatile sig_atomic_t stop = 0;
|
|
|
0d20ef |
+
|
|
|
0d20ef |
#pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
|
|
|
0d20ef |
int
|
|
|
0d20ef |
start_conversion (struct config *config,
|
|
|
0d20ef |
@@ -271,7 +273,7 @@ start_conversion (struct config *config,
|
|
|
0d20ef |
/* Read output from the virt-v2v process and echo it through the
|
|
|
0d20ef |
* notify function, until virt-v2v closes the connection.
|
|
|
0d20ef |
*/
|
|
|
0d20ef |
- for (;;) {
|
|
|
0d20ef |
+ while (!stop) {
|
|
|
0d20ef |
char buf[257];
|
|
|
0d20ef |
ssize_t r;
|
|
|
0d20ef |
|
|
|
0d20ef |
@@ -290,6 +292,11 @@ start_conversion (struct config *config,
|
|
|
0d20ef |
notify_ui (NOTIFY_REMOTE_MESSAGE, buf);
|
|
|
0d20ef |
}
|
|
|
0d20ef |
|
|
|
0d20ef |
+ if (stop) {
|
|
|
0d20ef |
+ set_conversion_error ("cancelled by user");
|
|
|
0d20ef |
+ goto out;
|
|
|
0d20ef |
+ }
|
|
|
0d20ef |
+
|
|
|
0d20ef |
if (notify_ui)
|
|
|
0d20ef |
notify_ui (NOTIFY_STATUS, _("Control connection closed by remote."));
|
|
|
0d20ef |
|
|
|
0d20ef |
@@ -301,6 +308,12 @@ start_conversion (struct config *config,
|
|
|
0d20ef |
return ret;
|
|
|
0d20ef |
}
|
|
|
0d20ef |
|
|
|
0d20ef |
+void
|
|
|
0d20ef |
+cancel_conversion (void)
|
|
|
0d20ef |
+{
|
|
|
0d20ef |
+ stop = 1;
|
|
|
0d20ef |
+}
|
|
|
0d20ef |
+
|
|
|
0d20ef |
/* Send a shell-quoted string to remote. */
|
|
|
0d20ef |
static int
|
|
|
0d20ef |
send_quoted (mexp_h *h, const char *s)
|
|
|
0d20ef |
diff --git a/p2v/gui.c b/p2v/gui.c
|
|
|
0d20ef |
index 523b028..194f9fb 100644
|
|
|
0d20ef |
--- a/p2v/gui.c
|
|
|
0d20ef |
+++ b/p2v/gui.c
|
|
|
0d20ef |
@@ -1058,6 +1058,7 @@ static void set_log_dir (const char *remote_dir);
|
|
|
0d20ef |
static void set_status (const char *msg);
|
|
|
0d20ef |
static void add_v2v_output (const char *msg);
|
|
|
0d20ef |
static void *start_conversion_thread (void *data);
|
|
|
0d20ef |
+static void cancel_conversion_clicked (GtkWidget *w, gpointer data);
|
|
|
0d20ef |
static void reboot_clicked (GtkWidget *w, gpointer data);
|
|
|
0d20ef |
|
|
|
0d20ef |
static void
|
|
|
0d20ef |
@@ -1105,6 +1106,8 @@ create_running_dialog (void)
|
|
|
0d20ef |
/* Signals. */
|
|
|
0d20ef |
g_signal_connect_swapped (G_OBJECT (run_dlg), "destroy",
|
|
|
0d20ef |
G_CALLBACK (gtk_main_quit), NULL);
|
|
|
0d20ef |
+ g_signal_connect (G_OBJECT (cancel_button), "clicked",
|
|
|
0d20ef |
+ G_CALLBACK (cancel_conversion_clicked), NULL);
|
|
|
0d20ef |
g_signal_connect (G_OBJECT (reboot_button), "clicked",
|
|
|
0d20ef |
G_CALLBACK (reboot_clicked), NULL);
|
|
|
0d20ef |
}
|
|
|
0d20ef |
@@ -1118,7 +1121,7 @@ show_running_dialog (void)
|
|
|
0d20ef |
|
|
|
0d20ef |
/* Show the running dialog. */
|
|
|
0d20ef |
gtk_widget_show_all (run_dlg);
|
|
|
0d20ef |
- gtk_widget_set_sensitive (cancel_button, FALSE);
|
|
|
0d20ef |
+ gtk_widget_set_sensitive (cancel_button, TRUE);
|
|
|
0d20ef |
gtk_widget_set_sensitive (reboot_button, FALSE);
|
|
|
0d20ef |
}
|
|
|
0d20ef |
|
|
|
0d20ef |
@@ -1364,6 +1367,13 @@ notify_ui_callback (int type, const char *data)
|
|
|
0d20ef |
}
|
|
|
0d20ef |
|
|
|
0d20ef |
static void
|
|
|
0d20ef |
+cancel_conversion_clicked (GtkWidget *w, gpointer data)
|
|
|
0d20ef |
+{
|
|
|
0d20ef |
+ /* This makes start_conversion return an error (eventually). */
|
|
|
0d20ef |
+ cancel_conversion ();
|
|
|
0d20ef |
+}
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+static void
|
|
|
0d20ef |
reboot_clicked (GtkWidget *w, gpointer data)
|
|
|
0d20ef |
{
|
|
|
0d20ef |
sync ();
|
|
|
0d20ef |
diff --git a/p2v/p2v.h b/p2v/p2v.h
|
|
|
0d20ef |
index 6067d5f..c3ca0f6 100644
|
|
|
0d20ef |
--- a/p2v/p2v.h
|
|
|
0d20ef |
+++ b/p2v/p2v.h
|
|
|
0d20ef |
@@ -97,6 +97,7 @@ extern int start_conversion (struct config *, void (*notify_ui) (int type, const
|
|
|
0d20ef |
#define NOTIFY_REMOTE_MESSAGE 2 /* log message from remote virt-v2v */
|
|
|
0d20ef |
#define NOTIFY_STATUS 3 /* stage in conversion process */
|
|
|
0d20ef |
extern const char *get_conversion_error (void);
|
|
|
0d20ef |
+extern void cancel_conversion (void);
|
|
|
0d20ef |
|
|
|
0d20ef |
/* ssh.c */
|
|
|
0d20ef |
extern int test_connection (struct config *);
|
|
|
0d20ef |
--
|
|
|
0d20ef |
1.8.3.1
|
|
|
0d20ef |
|