mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0164-p2v-Warn-if-vcpus-or-memory-would-be-larger-than-sup.patch

ffd6ed
From 10d8b7f16ceeb9a43aff3d88544b075e58e336ab Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Tue, 5 May 2015 15:10:27 +0100
ffd6ed
Subject: [PATCH] p2v: Warn if vcpus or memory would be larger than supported
ffd6ed
 by RHEL (RHBZ#823758).
ffd6ed
ffd6ed
Display a warning if the number of vCPUs or memory selected in the GUI
ffd6ed
would be larger than the limits currently supported on RHEL 6 and RHEL 7.
ffd6ed
ffd6ed
This is just a warning -- the user is free to ignore it and continue
ffd6ed
anyway.
ffd6ed
ffd6ed
This warning does not apply if the selections were made through the
ffd6ed
kernel command line, because there is no place to display the warning
ffd6ed
for automated conversions.
ffd6ed
ffd6ed
(cherry picked from commit 1189d5919e4b3edceaa6a58b914ae29123754074)
ffd6ed
---
ffd6ed
 p2v/gui.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
ffd6ed
 1 file changed, 113 insertions(+), 2 deletions(-)
ffd6ed
ffd6ed
diff --git a/p2v/gui.c b/p2v/gui.c
ffd6ed
index 8a5cda1..f32ac53 100644
ffd6ed
--- a/p2v/gui.c
ffd6ed
+++ b/p2v/gui.c
ffd6ed
@@ -20,6 +20,7 @@
ffd6ed
 
ffd6ed
 #include <stdio.h>
ffd6ed
 #include <stdlib.h>
ffd6ed
+#include <stdarg.h>
ffd6ed
 #include <string.h>
ffd6ed
 #include <inttypes.h>
ffd6ed
 #include <unistd.h>
ffd6ed
@@ -58,6 +59,7 @@ static GtkWidget *conn_dlg,
ffd6ed
 /* The conversion dialog. */
ffd6ed
 static GtkWidget *conv_dlg,
ffd6ed
   *guestname_entry, *vcpus_entry, *memory_entry,
ffd6ed
+  *vcpus_warning, *memory_warning, *target_warning_label,
ffd6ed
   *o_combo, *oc_entry, *os_entry, *of_entry, *oa_combo,
ffd6ed
   *info_label,
ffd6ed
   *debug_button,
ffd6ed
@@ -374,6 +376,7 @@ static void set_removable_from_ui (struct config *);
ffd6ed
 static void set_interfaces_from_ui (struct config *);
ffd6ed
 static void conversion_back_clicked (GtkWidget *w, gpointer data);
ffd6ed
 static void start_conversion_clicked (GtkWidget *w, gpointer data);
ffd6ed
+static void vcpus_or_memory_check_callback (GtkWidget *w, gpointer data);
ffd6ed
 static void notify_ui_callback (int type, const char *data);
ffd6ed
 static int get_vcpus_from_conv_dlg (void);
ffd6ed
 static uint64_t get_memory_from_conv_dlg (void);
ffd6ed
@@ -421,7 +424,7 @@ create_conversion_dialog (struct config *config)
ffd6ed
   /* XXX It would be nice not to have to set this explicitly, but
ffd6ed
    * if we don't then Gtk chooses a very small window.
ffd6ed
    */
ffd6ed
-  gtk_widget_set_size_request (conv_dlg, 800, 500);
ffd6ed
+  gtk_widget_set_size_request (conv_dlg, 800, 560);
ffd6ed
 
ffd6ed
   /* The main dialog area. */
ffd6ed
   hbox = gtk_hbox_new (TRUE, 1);
ffd6ed
@@ -434,7 +437,7 @@ create_conversion_dialog (struct config *config)
ffd6ed
 
ffd6ed
   target_vbox = gtk_vbox_new (FALSE, 1);
ffd6ed
 
ffd6ed
-  target_tbl = gtk_table_new (3, 2, FALSE);
ffd6ed
+  target_tbl = gtk_table_new (3, 3, FALSE);
ffd6ed
   guestname_label = gtk_label_new (_("Name:"));
ffd6ed
   gtk_misc_set_alignment (GTK_MISC (guestname_label), 1., 0.5);
ffd6ed
   gtk_table_attach (GTK_TABLE (target_tbl), guestname_label,
ffd6ed
@@ -454,6 +457,10 @@ create_conversion_dialog (struct config *config)
ffd6ed
   gtk_entry_set_text (GTK_ENTRY (vcpus_entry), vcpus_str);
ffd6ed
   gtk_table_attach (GTK_TABLE (target_tbl), vcpus_entry,
ffd6ed
                     1, 2, 1, 2, GTK_FILL, GTK_FILL, 1, 1);
ffd6ed
+  vcpus_warning = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
ffd6ed
+                                            GTK_ICON_SIZE_BUTTON);
ffd6ed
+  gtk_table_attach (GTK_TABLE (target_tbl), vcpus_warning,
ffd6ed
+                    2, 3, 1, 2, 0, 0, 1, 1);
ffd6ed
 
ffd6ed
   memory_label = gtk_label_new (_("Memory (MB):"));
ffd6ed
   gtk_misc_set_alignment (GTK_MISC (memory_label), 1., 0.5);
ffd6ed
@@ -465,8 +472,20 @@ create_conversion_dialog (struct config *config)
ffd6ed
   gtk_entry_set_text (GTK_ENTRY (memory_entry), memory_str);
ffd6ed
   gtk_table_attach (GTK_TABLE (target_tbl), memory_entry,
ffd6ed
                     1, 2, 2, 3, GTK_FILL, GTK_FILL, 1, 1);
ffd6ed
+  memory_warning = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
ffd6ed
+                                             GTK_ICON_SIZE_BUTTON);
ffd6ed
+  gtk_table_attach (GTK_TABLE (target_tbl), memory_warning,
ffd6ed
+                    2, 3, 2, 3, 0, 0, 1, 1);
ffd6ed
 
ffd6ed
   gtk_box_pack_start (GTK_BOX (target_vbox), target_tbl, TRUE, TRUE, 0);
ffd6ed
+
ffd6ed
+  target_warning_label = gtk_label_new ("");
ffd6ed
+  gtk_label_set_line_wrap (GTK_LABEL (target_warning_label), TRUE);
ffd6ed
+  gtk_label_set_line_wrap_mode (GTK_LABEL (target_warning_label),
ffd6ed
+                                GTK_WRAP_WORD);
ffd6ed
+  gtk_widget_set_size_request (target_warning_label, -1, 7 * 16);
ffd6ed
+  gtk_box_pack_end (GTK_BOX (target_vbox), target_warning_label, TRUE, TRUE, 0);
ffd6ed
+
ffd6ed
   gtk_container_add (GTK_CONTAINER (target_frame), target_vbox);
ffd6ed
 
ffd6ed
   output_frame = gtk_frame_new (_("Virt-v2v output options"));
ffd6ed
@@ -619,6 +638,10 @@ create_conversion_dialog (struct config *config)
ffd6ed
                     G_CALLBACK (conversion_back_clicked), NULL);
ffd6ed
   g_signal_connect (G_OBJECT (start_button), "clicked",
ffd6ed
                     G_CALLBACK (start_conversion_clicked), config);
ffd6ed
+  g_signal_connect (G_OBJECT (vcpus_entry), "changed",
ffd6ed
+                    G_CALLBACK (vcpus_or_memory_check_callback), NULL);
ffd6ed
+  g_signal_connect (G_OBJECT (memory_entry), "changed",
ffd6ed
+                    G_CALLBACK (vcpus_or_memory_check_callback), NULL);
ffd6ed
 }
ffd6ed
 
ffd6ed
 static void
ffd6ed
@@ -630,6 +653,8 @@ show_conversion_dialog (void)
ffd6ed
 
ffd6ed
   /* Show the conversion dialog. */
ffd6ed
   gtk_widget_show_all (conv_dlg);
ffd6ed
+  gtk_widget_hide (vcpus_warning);
ffd6ed
+  gtk_widget_hide (memory_warning);
ffd6ed
 
ffd6ed
   /* output_drivers may have been updated, so repopulate o_combo. */
ffd6ed
   repopulate_output_combo (NULL);
ffd6ed
@@ -1053,6 +1078,92 @@ conversion_back_clicked (GtkWidget *w, gpointer data)
ffd6ed
   gtk_widget_set_sensitive (next_button, FALSE);
ffd6ed
 }
ffd6ed
 
ffd6ed
+/* Display a warning if the vCPUs or memory is outside the supported
ffd6ed
+ * range.  (RHBZ#823758).  See also:
ffd6ed
+ * https://access.redhat.com/articles/rhel-kvm-limits
ffd6ed
+ */
ffd6ed
+#define MAX_SUPPORTED_VCPUS 160
ffd6ed
+#define MAX_SUPPORTED_MEMORY_MB (UINT64_C (4000 * 1024))
ffd6ed
+
ffd6ed
+static char *concat_warning (char *warning, const char *fs, ...)
ffd6ed
+  __attribute__((format (printf,2,3)));
ffd6ed
+
ffd6ed
+static char *
ffd6ed
+concat_warning (char *warning, const char *fs, ...)
ffd6ed
+{
ffd6ed
+  va_list args;
ffd6ed
+  char *msg;
ffd6ed
+  size_t len, len2;
ffd6ed
+  int r;
ffd6ed
+
ffd6ed
+  if (warning == NULL) {
ffd6ed
+    warning = strdup ("");
ffd6ed
+    if (warning == NULL) {
ffd6ed
+    malloc_fail:
ffd6ed
+      perror ("malloc");
ffd6ed
+      exit (EXIT_FAILURE);
ffd6ed
+    }
ffd6ed
+  }
ffd6ed
+
ffd6ed
+  len = strlen (warning);
ffd6ed
+  if (len > 0 && warning[len-1] != '\n' && fs[0] != '\n') {
ffd6ed
+    warning = concat_warning (warning, "\n");
ffd6ed
+    len = strlen (warning);
ffd6ed
+  }
ffd6ed
+
ffd6ed
+  va_start (args, fs);
ffd6ed
+  r = vasprintf (&msg, fs, args);
ffd6ed
+  va_end (args);
ffd6ed
+  if (r == -1) goto malloc_fail;
ffd6ed
+
ffd6ed
+  len2 = strlen (msg);
ffd6ed
+  warning = realloc (warning, len + len2 + 1);
ffd6ed
+  if (warning == NULL) goto malloc_fail;
ffd6ed
+  memcpy (&warning[len], msg, len2 + 1);
ffd6ed
+  free (msg);
ffd6ed
+
ffd6ed
+  return warning;
ffd6ed
+}
ffd6ed
+
ffd6ed
+static void
ffd6ed
+vcpus_or_memory_check_callback (GtkWidget *w, gpointer data)
ffd6ed
+{
ffd6ed
+  int vcpus;
ffd6ed
+  uint64_t memory;
ffd6ed
+  CLEANUP_FREE char *warning = NULL;
ffd6ed
+
ffd6ed
+  vcpus = get_vcpus_from_conv_dlg ();
ffd6ed
+  memory = get_memory_from_conv_dlg ();
ffd6ed
+
ffd6ed
+  if (vcpus > MAX_SUPPORTED_VCPUS) {
ffd6ed
+    gtk_widget_show (vcpus_warning);
ffd6ed
+
ffd6ed
+    warning = concat_warning (warning,
ffd6ed
+                              _("Number of virtual CPUs is larger than what is supported for KVM (max: %d)."),
ffd6ed
+                              MAX_SUPPORTED_VCPUS);
ffd6ed
+  }
ffd6ed
+  else
ffd6ed
+    gtk_widget_hide (vcpus_warning);
ffd6ed
+
ffd6ed
+  if (memory > MAX_SUPPORTED_MEMORY_MB * 1024 * 1024) {
ffd6ed
+    gtk_widget_show (memory_warning);
ffd6ed
+
ffd6ed
+    warning = concat_warning (warning,
ffd6ed
+                              _("Memory size is larger than what is supported for KVM (max: %" PRIu64 ")."),
ffd6ed
+                              MAX_SUPPORTED_MEMORY_MB);
ffd6ed
+  }
ffd6ed
+  else
ffd6ed
+    gtk_widget_hide (memory_warning);
ffd6ed
+
ffd6ed
+  if (warning != NULL) {
ffd6ed
+    warning = concat_warning (warning,
ffd6ed
+                              _("If you ignore this warning, conversion can still succeed, but the guest may not work or may not be supported on the target."));
ffd6ed
+    gtk_label_set_text (GTK_LABEL (target_warning_label), warning);
ffd6ed
+  }
ffd6ed
+  else
ffd6ed
+    gtk_label_set_text (GTK_LABEL (target_warning_label), "");
ffd6ed
+}
ffd6ed
+
ffd6ed
 static int
ffd6ed
 get_vcpus_from_conv_dlg (void)
ffd6ed
 {
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed