mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0034-launch-direct-Don-t-run-qemu-version.patch

e76f14
From c29743cdbdd8f5b526704705de7cc2ae3d0790c7 Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Tue, 22 Mar 2016 14:04:26 +0000
e76f14
Subject: [PATCH] launch: direct: Don't run qemu -version.
e76f14
e76f14
Dr. David Gilbert pointed out to me that the first line of the
e76f14
qemu -help output includes the qemu version, so we don't need
e76f14
to run qemu -version at all.
e76f14
e76f14
This saves about 0.04s on the launch time when using the direct
e76f14
backend.
e76f14
e76f14
(cherry picked from commit b7b34119766349522528fdfe56237bede0794b6a)
e76f14
---
e76f14
 src/launch-direct.c | 54 +++++++++++++++++++----------------------------------
e76f14
 1 file changed, 19 insertions(+), 35 deletions(-)
e76f14
e76f14
diff --git a/src/launch-direct.c b/src/launch-direct.c
e76f14
index cbaf4f3..646f9c6 100644
e76f14
--- a/src/launch-direct.c
e76f14
+++ b/src/launch-direct.c
e76f14
@@ -61,7 +61,6 @@ struct backend_direct_data {
e76f14
   pid_t recoverypid;          /* Recovery process PID. */
e76f14
 
e76f14
   char *qemu_help;            /* Output of qemu -help. */
e76f14
-  char *qemu_version;         /* Output of qemu -version. */
e76f14
   char *qemu_devices;         /* Output of qemu -device ? */
e76f14
 
e76f14
   /* qemu version (0, 0 if unable to parse). */
e76f14
@@ -935,22 +934,18 @@ print_qemu_command_line (guestfs_h *g, char **argv)
e76f14
 static void parse_qemu_version (guestfs_h *g, struct backend_direct_data *data);
e76f14
 static void read_all (guestfs_h *g, void *retv, const char *buf, size_t len);
e76f14
 
e76f14
-/* Test qemu binary (or wrapper) runs, and do 'qemu -help' and
e76f14
- * 'qemu -version' so we know what options this qemu supports and
e76f14
- * the version.
e76f14
+/* Test qemu binary (or wrapper) runs, and do 'qemu -help' so we know
e76f14
+ * the version of qemu what options this qemu supports.
e76f14
  */
e76f14
 static int
e76f14
 test_qemu (guestfs_h *g, struct backend_direct_data *data)
e76f14
 {
e76f14
   CLEANUP_CMD_CLOSE struct command *cmd1 = guestfs_int_new_command (g);
e76f14
   CLEANUP_CMD_CLOSE struct command *cmd2 = guestfs_int_new_command (g);
e76f14
-  CLEANUP_CMD_CLOSE struct command *cmd3 = guestfs_int_new_command (g);
e76f14
   int r;
e76f14
 
e76f14
   free (data->qemu_help);
e76f14
   data->qemu_help = NULL;
e76f14
-  free (data->qemu_version);
e76f14
-  data->qemu_version = NULL;
e76f14
   free (data->qemu_devices);
e76f14
   data->qemu_devices = NULL;
e76f14
 
e76f14
@@ -964,34 +959,24 @@ test_qemu (guestfs_h *g, struct backend_direct_data *data)
e76f14
   if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0)
e76f14
     goto error;
e76f14
 
e76f14
+  parse_qemu_version (g, data);
e76f14
+
e76f14
   guestfs_int_cmd_add_arg (cmd2, g->hv);
e76f14
   guestfs_int_cmd_add_arg (cmd2, "-display");
e76f14
   guestfs_int_cmd_add_arg (cmd2, "none");
e76f14
-  guestfs_int_cmd_add_arg (cmd2, "-version");
e76f14
-  guestfs_int_cmd_set_stdout_callback (cmd2, read_all, &data->qemu_version,
e76f14
-				       CMD_STDOUT_FLAG_WHOLE_BUFFER);
e76f14
-  r = guestfs_int_cmd_run (cmd2);
e76f14
-  if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0)
e76f14
-    goto error;
e76f14
-
e76f14
-  parse_qemu_version (g, data);
e76f14
-
e76f14
-  guestfs_int_cmd_add_arg (cmd3, g->hv);
e76f14
-  guestfs_int_cmd_add_arg (cmd3, "-display");
e76f14
-  guestfs_int_cmd_add_arg (cmd3, "none");
e76f14
-  guestfs_int_cmd_add_arg (cmd3, "-machine");
e76f14
-  guestfs_int_cmd_add_arg (cmd3,
e76f14
+  guestfs_int_cmd_add_arg (cmd2, "-machine");
e76f14
+  guestfs_int_cmd_add_arg (cmd2,
e76f14
 #ifdef MACHINE_TYPE
e76f14
                            MACHINE_TYPE ","
e76f14
 #endif
e76f14
                            "accel=kvm:tcg");
e76f14
-  guestfs_int_cmd_add_arg (cmd3, "-device");
e76f14
-  guestfs_int_cmd_add_arg (cmd3, "?");
e76f14
-  guestfs_int_cmd_clear_capture_errors (cmd3);
e76f14
-  guestfs_int_cmd_set_stderr_to_stdout (cmd3);
e76f14
-  guestfs_int_cmd_set_stdout_callback (cmd3, read_all, &data->qemu_devices,
e76f14
+  guestfs_int_cmd_add_arg (cmd2, "-device");
e76f14
+  guestfs_int_cmd_add_arg (cmd2, "?");
e76f14
+  guestfs_int_cmd_clear_capture_errors (cmd2);
e76f14
+  guestfs_int_cmd_set_stderr_to_stdout (cmd2);
e76f14
+  guestfs_int_cmd_set_stdout_callback (cmd2, read_all, &data->qemu_devices,
e76f14
 				       CMD_STDOUT_FLAG_WHOLE_BUFFER);
e76f14
-  r = guestfs_int_cmd_run (cmd3);
e76f14
+  r = guestfs_int_cmd_run (cmd2);
e76f14
   if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0)
e76f14
     goto error;
e76f14
 
e76f14
@@ -1005,8 +990,9 @@ test_qemu (guestfs_h *g, struct backend_direct_data *data)
e76f14
   return -1;
e76f14
 }
e76f14
 
e76f14
-/* Parse data->qemu_version (if not NULL) into the major and minor
e76f14
- * version of qemu, but don't fail if parsing is not possible.
e76f14
+/* Parse the first line of data->qemu_help (if not NULL) into the
e76f14
+ * major and minor version of qemu, but don't fail if parsing is not
e76f14
+ * possible.
e76f14
  */
e76f14
 static void
e76f14
 parse_qemu_version (guestfs_h *g, struct backend_direct_data *data)
e76f14
@@ -1017,13 +1003,13 @@ parse_qemu_version (guestfs_h *g, struct backend_direct_data *data)
e76f14
   data->qemu_version_major = 0;
e76f14
   data->qemu_version_minor = 0;
e76f14
 
e76f14
-  if (!data->qemu_version)
e76f14
+  if (!data->qemu_help)
e76f14
     return;
e76f14
 
e76f14
-  if (!match2 (g, data->qemu_version, re_major_minor, &major_s, &minor_s)) {
e76f14
+  if (!match2 (g, data->qemu_help, re_major_minor, &major_s, &minor_s)) {
e76f14
   parse_failed:
e76f14
-    debug (g, "%s: failed to parse qemu version string '%s'",
e76f14
-           __func__, data->qemu_version);
e76f14
+    debug (g, "%s: failed to parse qemu version string from the first line of the output of '%s -help'.  When reporting this bug please include the -help output.",
e76f14
+           __func__, g->hv);
e76f14
     return;
e76f14
   }
e76f14
 
e76f14
@@ -1505,8 +1491,6 @@ shutdown_direct (guestfs_h *g, void *datav, int check_for_errors)
e76f14
 
e76f14
   free (data->qemu_help);
e76f14
   data->qemu_help = NULL;
e76f14
-  free (data->qemu_version);
e76f14
-  data->qemu_version = NULL;
e76f14
   free (data->qemu_devices);
e76f14
   data->qemu_devices = NULL;
e76f14
 
e76f14
-- 
aa0300
2.7.4
e76f14