All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Parse commandline in grub-xen
@ 2015-05-11  9:28 Olaf Hering
  2015-05-11  9:33 ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 29+ messages in thread
From: Olaf Hering @ 2015-05-11  9:28 UTC (permalink / raw)
  To: grub-devel; +Cc: Olaf Hering

If grub is used as the kernel in a Xen PV guest there is no way to pass
information into grub. This includes info like which disk should be used
first when searching for files.

Up to now the workaround for the host admin is to rebuild grub-xen every
time with grub-mkimage and include a custom script. Such step should be
avoided if possible, the distro provided grub-xen binary should be used.

With this change the command line (extra= in domU.cfg) will be evaluated
by grub. Each 'name=val' pair will be exported as shell variable, other
strings will be ignored. This makes it possible to provide a generic
grub-xen binary for PV guests. It is now up to the scripts in such
binary to interpret the variables as they see fit.

It should be noted that some variables may be set by grub itself,
overriding anything provided in the cmdline. This depends on the way
grub-xen is built, which modules are included.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 grub-core/kern/xen/init.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c
index 0559c03..1dbc01f 100644
--- a/grub-core/kern/xen/init.c
+++ b/grub-core/kern/xen/init.c
@@ -524,6 +524,77 @@ map_all_pages (void)
   grub_mm_init_region ((void *) heap_start, heap_end - heap_start);
 }
 
+/*
+ * Find all name=val pairs in the provided cmd_line and export them
+ * so that scripts can evaluate the variables for their own purpose.
+ */
+static void
+parse_cmdline (void)
+{
+  grub_size_t i;
+  char *p, *name, *val;
+  int found;
+
+  p = grub_malloc (MAX_GUEST_CMDLINE + 1);
+  if (!p)
+    return;
+
+  grub_memcpy (p, grub_xen_start_page_addr->cmd_line, MAX_GUEST_CMDLINE);
+  p[MAX_GUEST_CMDLINE] = '\0';
+
+  for (i = 0; i < MAX_GUEST_CMDLINE && p[i]; i++)
+    {
+      if (grub_isspace (p[i]))
+        continue;
+
+      name = &p[i];
+      found = 0;
+      do
+        {
+          if (grub_isspace (p[i]))
+            break;
+          if (p[i] == '=')
+            {
+              p[i] = '\0';
+              found = 1;
+              break;
+            }
+          if (!p[i + 1])
+            break;
+          i++;
+        }
+      while (i < MAX_GUEST_CMDLINE);
+
+      if (!found)
+        continue;
+
+      i++;
+      val = &p[i];
+      found = 0;
+      do
+        {
+          if (grub_isspace (p[i]))
+            {
+              p[i] = '\0';
+              found = 1;
+            }
+          if (!p[i + 1])
+            found = 1;
+          if (found)
+              break;
+          i++;
+        }
+      while (i < MAX_GUEST_CMDLINE);
+
+      if (!found)
+        continue;
+
+      grub_env_set (name, val);
+      grub_env_export (name);
+    }
+    grub_free (p);
+}
+
 extern char _end[];
 
 void
@@ -539,6 +610,8 @@ grub_machine_init (void)
 
   map_all_pages ();
 
+  parse_cmdline ();
+
   grub_console_init ();
 
   grub_tsc_init ();


^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2015-05-12  9:42 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-11  9:28 [PATCH] Parse commandline in grub-xen Olaf Hering
2015-05-11  9:33 ` Vladimir 'phcoder' Serbinenko
2015-05-11  9:43   ` Olaf Hering
2015-05-11 10:29     ` Andrei Borzenkov
2015-05-11 10:41       ` Olaf Hering
2015-05-11 10:48         ` Vladimir 'phcoder' Serbinenko
2015-05-11 11:01           ` Olaf Hering
2015-05-11 11:24             ` Vladimir 'phcoder' Serbinenko
2015-05-11 11:51               ` Olaf Hering
2015-05-11 12:02                 ` Vladimir 'phcoder' Serbinenko
2015-05-11 12:06                   ` Olaf Hering
2015-05-11 12:03                 ` Andrei Borzenkov
2015-05-11 12:15                   ` Olaf Hering
2015-05-11 12:53                     ` Vladimir 'phcoder' Serbinenko
2015-05-11 13:34                       ` Olaf Hering
2015-05-11 13:43                         ` Vladimir 'phcoder' Serbinenko
2015-05-11 16:53                     ` Andrei Borzenkov
2015-05-11 17:08                       ` Olaf Hering
2015-05-11 17:12                         ` Vladimir 'phcoder' Serbinenko
2015-05-12  8:06                           ` Olaf Hering
2015-05-12  8:48                             ` Vladimir 'phcoder' Serbinenko
2015-05-12  9:09                               ` Olaf Hering
2015-05-12  9:42                                 ` Vladimir 'phcoder' Serbinenko
2015-05-11 12:55                   ` Vladimir 'phcoder' Serbinenko
2015-05-11 16:52                     ` Andrei Borzenkov
     [not found]                       ` <CAEaD8JOJw7sGD2SHdnnsWR8FFExesfg-892ZjxwPPqVMNCqMfg@mail.gmail.com>
2015-05-11 18:45                         ` Andrei Borzenkov
2015-05-11 18:49                           ` Vladimir 'phcoder' Serbinenko
2015-05-11 12:01             ` Michael Chang
2015-05-12  4:16               ` Andrei Borzenkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.