[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [XEN PATCH 1/3] set default kernel from grubenv next_entry or saved_entry


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "YOUNG, MICHAEL A." <m.a.young@xxxxxxxxxxxx>
  • Date: Fri, 25 Oct 2019 22:52:17 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=durham.ac.uk; dmarc=pass action=none header.from=durham.ac.uk; dkim=pass header.d=durham.ac.uk; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cqQssvL0QFp0PYbissrRB7wzp7O6AgiJU0bpAsVoq18=; b=oFXFkqCRJYt3ttE7wQQa0p5wBzji9ktFPTT08U0QMIdyVIk5Gl8Ue65Dna6ZYtoQRqwYGORX4Wg+2byhQzWOt3ztcG/xVh4dENoLskUajWsJhqSbR4+qrmaDArzr+LQBWXWDcuUDcCK/+/fFE5/A8mzjdBEB9nMwzVSHg4LghGOC+ZXflSQnYXVBleGtztstqUbUOn/4tE43E6pn9V46ocqcKd8L9baNwabYt/dz3kVCn76QAaUlm/mu4u3v9RYS34CFN5rEkcJdcxxOUBJOWxjNAV629Kt41HyHGbfb34z/GIKVAgeCGuMcKeSnO4tJX3nmOVBhb2s7l5xB4U+jgw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ckMrotn2uZ8SmceBwdIfloeui/Dq/j9zBQaKB8iaWhIKJ/FVH81EfrKhHBBvCShiQgcOFVWAwyohwqattFDDjM9fRM0Oo3Etw+IAmPnw3LYJVHl/C8tvuga+C5vmR0Vun6jlkJE6gUtIu5CYcoYQiFWm7wtyiiVEbFVSlN8bFoWolSAQzMMgqwmIhovTtX5OS4yMT4QWLK+y1BUr3ob8BgJ4Ze8/wkOpRjGjjntT50mcfRNNAoSKKWvUGFiY6NoGD9xO8YesNhtutFa8PLbzI90RzFw8gxoYAIBdiJp9Kp4SMTB1++W+FezEc5papd86A8ZpnHcRRWtLDgswb+SVcQ==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=m.a.young@xxxxxxxxxxxx;
  • Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "YOUNG, MICHAEL A." <m.a.young@xxxxxxxxxxxx>
  • Delivery-date: Fri, 25 Oct 2019 22:52:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVi4bZp6Rlls8E60iiZZ95hwr4Gg==
  • Thread-topic: [XEN PATCH 1/3] set default kernel from grubenv next_entry or saved_entry

This patch reads the contents of a grubenv file if available, and
uses the value of next_entry (in preference) or of saved_entry to
set the default kernel if there is a matching title or if it is a
number.  If either next_entry or saved_entry is set and neither is
used then the default is set to 0.

Signed-off-by: Michael Young <m.a.young@xxxxxxxxxxxx>
---
 tools/pygrub/src/GrubConf.py | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py
index 73f1bbed2f..1fc68cadb2 100644
--- a/tools/pygrub/src/GrubConf.py
+++ b/tools/pygrub/src/GrubConf.py
@@ -368,7 +368,7 @@ class Grub2ConfigFile(_GrubConfigFile):
     def new_image(self, title, lines):
         return Grub2Image(title, lines)
  
-    def parse(self, buf = None):
+    def parse(self, buf = None, grubenv = None):
         if buf is None:
             if self.filename is None:
                 raise ValueError("No config file defined to parse!")
@@ -379,10 +379,17 @@ class Grub2ConfigFile(_GrubConfigFile):
         else:
             lines = buf.split("\n")
 
+        if grubenv is not None:
+            lines = grubenv.split("\n") + lines
+
         in_function = False
         img = None
         title = ""
         menu_level=0
+        img_count=0
+        saved_entry = ""
+        next_entry = ""
+        entry_matched = False
         for l in lines:
             l = l.strip()
             # skip blank lines
@@ -408,6 +415,13 @@ class Grub2ConfigFile(_GrubConfigFile):
                     raise RuntimeError("syntax error: cannot nest menuentry 
(%d %s)" % (len(img),img))
                 img = []
                 title = title_match.group(1)
+                if title == next_entry:
+                    setattr(self, 'default', img_count)
+                    entry_matched = True
+                if title == saved_entry and not entry_matched:
+                    setattr(self, 'default', img_count)
+                    entry_matched = True
+                img_count += 1
                 continue
 
             if l.startswith("submenu"):
@@ -432,6 +446,14 @@ class Grub2ConfigFile(_GrubConfigFile):
 
             (com, arg) = grub_exact_split(l, 2)
         
+            if com == "next_entry":
+                next_entry = arg
+                continue
+
+            if com == "saved_entry":
+                saved_entry = arg
+                continue
+
             if com == "set":
                 (com,arg) = grub2_handle_set(arg)
                 
@@ -448,6 +470,13 @@ class Grub2ConfigFile(_GrubConfigFile):
                 pass
             else:
                 logging.warning("Unknown directive %s" %(com,))
+
+        if next_entry.isdigit():
+            setattr(self, 'default', next_entry)
+        elif saved_entry.isdigit() and not entry_matched:
+            setattr(self, 'default', saved_entry)
+        elif (next_entry != "" or saved_entry != "") and not entry_matched:
+            setattr(self, 'default', 0)
             
         if img is not None:
             raise RuntimeError("syntax error: end of file with open 
menuentry(%d %s)" % (len(img),img))
-- 
2.21.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.