Blame SOURCES/0046-boot-analysis-Add-memsize-smp-and-append-options.patch

e76f14
From 66292c8c5f8b35ac5ce198cdc6996ba5c0cb3741 Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Tue, 29 Mar 2016 11:59:36 +0100
e76f14
Subject: [PATCH] boot-analysis: Add --memsize, --smp and --append options.
e76f14
e76f14
These options allow you to control the appliance memory size, number
e76f14
of vCPUs, and extra kernel options respectively.
e76f14
e76f14
Note that using --smp is not usually a good idea.  Not only does it
e76f14
slow down the appliance, but it tends to break the boot analysis
e76f14
program because it makes runs (more) non-deterministic.
e76f14
e76f14
(cherry picked from commit da7e22b648ce470980c17943efcc0c5c255c33bf)
e76f14
---
e76f14
 tests/qemu/boot-analysis.c | 72 ++++++++++++++++++++++++++++++++++++++++------
e76f14
 1 file changed, 63 insertions(+), 9 deletions(-)
e76f14
e76f14
diff --git a/tests/qemu/boot-analysis.c b/tests/qemu/boot-analysis.c
e76f14
index 71b265a..fc2c93b 100644
e76f14
--- a/tests/qemu/boot-analysis.c
e76f14
+++ b/tests/qemu/boot-analysis.c
e76f14
@@ -89,7 +89,10 @@ struct pass_data pass_data[NR_TEST_PASSES];
e76f14
 size_t nr_activities;
e76f14
 struct activity *activities;
e76f14
 
e76f14
+static const char *append = NULL;
e76f14
 static int force_colour = 0;
e76f14
+static int memsize = 0;
e76f14
+static int smp = 1;
e76f14
 static int verbose = 0;
e76f14
 
e76f14
 static void run_test (void);
e76f14
@@ -117,14 +120,28 @@ static void ansi_restore (void);
e76f14
 static void
e76f14
 usage (int exitcode)
e76f14
 {
e76f14
+  guestfs_h *g;
e76f14
+  int default_memsize = -1;
e76f14
+
e76f14
+  g = guestfs_create ();
e76f14
+  if (g) {
e76f14
+    default_memsize = guestfs_get_memsize (g);
e76f14
+    guestfs_close (g);
e76f14
+  }
e76f14
+
e76f14
   fprintf (stderr,
e76f14
            "boot-analysis: Trace and analyze the appliance boot process.\n"
e76f14
            "Usage:\n"
e76f14
            "  boot-analysis [--options]\n"
e76f14
            "Options:\n"
e76f14
-           "  --help        Display this usage text and exit.\n"
e76f14
-           "  --colour      Output colours, even if not a terminal.\n"
e76f14
-           "  -v|--verbose  Verbose output, useful for debugging.\n");
e76f14
+           "  --help         Display this usage text and exit.\n"
e76f14
+           "  --append OPTS  Append OPTS to kernel command line.\n"
e76f14
+           "  --colour       Output colours, even if not a terminal.\n"
e76f14
+           "  -m MB\n"
e76f14
+           "  --memsize MB   Set memory size in MB (default: %d).\n"
e76f14
+           "  --smp N        Enable N virtual CPUs (default: 1).\n"
e76f14
+           "  -v|--verbose   Verbose output, useful for debugging.\n",
e76f14
+           default_memsize);
e76f14
   exit (exitcode);
e76f14
 }
e76f14
 
e76f14
@@ -132,11 +149,14 @@ int
e76f14
 main (int argc, char *argv[])
e76f14
 {
e76f14
   enum { HELP_OPTION = CHAR_MAX + 1 };
e76f14
-  static const char *options = "v";
e76f14
+  static const char *options = "m:v";
e76f14
   static const struct option long_options[] = {
e76f14
     { "help", 0, 0, HELP_OPTION },
e76f14
+    { "append", 1, 0, 0 },
e76f14
     { "color", 0, 0, 0 },
e76f14
     { "colour", 0, 0, 0 },
e76f14
+    { "memsize", 1, 0, 'm' },
e76f14
+    { "smp", 1, 0, 0 },
e76f14
     { "verbose", 0, 0, 'v' },
e76f14
     { 0, 0, 0, 0 }
e76f14
   };
e76f14
@@ -148,15 +168,35 @@ main (int argc, char *argv[])
e76f14
 
e76f14
     switch (c) {
e76f14
     case 0:                     /* Options which are long only. */
e76f14
-      if (STREQ (long_options[option_index].name, "color") ||
e76f14
-          STREQ (long_options[option_index].name, "colour")) {
e76f14
+      if (STREQ (long_options[option_index].name, "append")) {
e76f14
+        append = optarg;
e76f14
+        break;
e76f14
+      }
e76f14
+      else if (STREQ (long_options[option_index].name, "color") ||
e76f14
+               STREQ (long_options[option_index].name, "colour")) {
e76f14
         force_colour = 1;
e76f14
         break;
e76f14
       }
e76f14
+      else if (STREQ (long_options[option_index].name, "smp")) {
e76f14
+        if (sscanf (optarg, "%d", &smp) != 1) {
e76f14
+          fprintf (stderr, "%s: could not parse smp parameter: %s\n",
e76f14
+                   guestfs_int_program_name, optarg);
e76f14
+          exit (EXIT_FAILURE);
e76f14
+        }
e76f14
+        break;
e76f14
+      }
e76f14
       fprintf (stderr, "%s: unknown long option: %s (%d)\n",
e76f14
                guestfs_int_program_name, long_options[option_index].name, option_index);
e76f14
       exit (EXIT_FAILURE);
e76f14
 
e76f14
+    case 'm':
e76f14
+      if (sscanf (optarg, "%d", &memsize) != 1) {
e76f14
+        fprintf (stderr, "%s: could not parse memsize parameter: %s\n",
e76f14
+                 guestfs_int_program_name, optarg);
e76f14
+        exit (EXIT_FAILURE);
e76f14
+      }
e76f14
+      break;
e76f14
+
e76f14
     case 'v':
e76f14
       verbose = 1;
e76f14
       break;
e76f14
@@ -267,6 +307,7 @@ static guestfs_h *
e76f14
 create_handle (void)
e76f14
 {
e76f14
   guestfs_h *g;
e76f14
+  CLEANUP_FREE char *full_append = NULL;
e76f14
 
e76f14
   g = guestfs_create ();
e76f14
   if (!g) error (EXIT_FAILURE, errno, "guestfs_create");
e76f14
@@ -279,12 +320,25 @@ create_handle (void)
e76f14
   if (guestfs_set_backend (g, "direct") == -1)
e76f14
     exit (EXIT_FAILURE);
e76f14
 
e76f14
+  if (memsize != 0)
e76f14
+    if (guestfs_set_memsize (g, memsize) == -1)
e76f14
+      exit (EXIT_FAILURE);
e76f14
+
e76f14
+  if (smp >= 2)
e76f14
+    if (guestfs_set_smp (g, smp) == -1)
e76f14
+      exit (EXIT_FAILURE);
e76f14
+
e76f14
   /* This changes some details in appliance/init and enables a
e76f14
    * detailed trace of calls to initcall functions in the kernel.
e76f14
    */
e76f14
-  if (guestfs_set_append (g,
e76f14
-                          "guestfs_boot_analysis=1 "
e76f14
-                          "ignore_loglevel initcall_debug") == -1)
e76f14
+  if (asprintf (&full_append,
e76f14
+                "guestfs_boot_analysis=1 "
e76f14
+                "ignore_loglevel initcall_debug "
e76f14
+                "%s",
e76f14
+                append != NULL ? append : "") == -1)
e76f14
+    error (EXIT_FAILURE, errno, "asprintf");
e76f14
+
e76f14
+  if (guestfs_set_append (g, full_append) == -1)
e76f14
     exit (EXIT_FAILURE);
e76f14
 
e76f14
   return g;
e76f14
-- 
e76f14
1.8.3.1
e76f14