]> xenbits.xensource.com Git - people/liuw/osstest.git/commitdiff
Parsing grub which has 'submenu' primitive
authorlongtao.pang <longtaox.pang@intel.com>
Tue, 26 May 2015 09:08:19 +0000 (17:08 +0800)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 26 May 2015 11:44:49 +0000 (12:44 +0100)
Now auto-gen kernel grub2 config file's boot menu entries can have
2-level hierarchy, containing 'submenu' primitive, which is comprised by
several sub-menuentries. Xen boot entries are grouped into such kind of
'submenu' block. This patch adds setupboot_grub2() ability to handle
such new grub.cfg format

Signed-off-by: longtao.pang <longtaox.pang@intel.com>
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
[ ijc -- minor coding style fixup and dropped comment made obsolete by
         this change ]

Osstest/Debian.pm

index 46388d8626025bd0b736ac0420a21fa6ee4e8c1b..a1c9def31610574efffd7145e94cd4d0fecb6dec 100644 (file)
@@ -393,8 +393,6 @@ sub setupboot_grub1 ($$$$) {
 # Note on running OSSTest on Squeeze with old Xen kernel: check out
 # Debian bug #633127 "/etc/grub/20_linux does not recognise some old
 # Xen kernels"
-# Currently setupboot_grub2 relies on Grub menu not having submenu.
-# Check Debian bug #690538.
 sub setupboot_grub2 ($$$$) {
     my ($ho,$want_kernver,$want_xsm,$xenhopt,$xenkopt) = @_;
     my $bl= { };
@@ -405,12 +403,22 @@ sub setupboot_grub2 ($$$$) {
     my $parsemenu= sub {
         my $f= bl_getmenu_open($ho, $rmenu, "$stash/$ho->{Name}--grub.cfg.1");
     
-        my $count= 0;
+        my @offsets = (0);
         my $entry;
+        my $submenu;
         while (<$f>) {
             next if m/^\s*\#/ || !m/\S/;
             if (m/^\s*\}\s*$/) {
-                die unless $entry;
+                die unless $entry || $submenu;
+                if (!defined $entry && defined $submenu) {
+                    logm("Met end of a submenu starting from ".
+                        "$submenu->{StartLine}. ".
+                        "Our want kern is $want_kernver");
+                    $submenu=undef;
+                    pop @offsets;
+                    $offsets[$#offsets]++;
+                    next;
+                }
                 my (@missing) =
                     grep { !defined $entry->{$_} } 
                        (defined $xenhopt
@@ -438,8 +446,12 @@ sub setupboot_grub2 ($$$$) {
             }
             if (m/^menuentry\s+[\'\"](.*)[\'\"].*\{\s*$/) {
                 die $entry->{StartLine} if $entry;
-                $entry= { Title => $1, StartLine => $., Number => $count };
-                $count++;
+                $entry= { Title => $1, StartLine => $., MenuEntryPath => join ">", @offsets };
+                $offsets[$#offsets]++;
+            }
+            if (m/^submenu\s+[\'\"](.*)[\'\"].*\{\s*$/) {
+                $submenu={ StartLine =>$., MenuEntryPath => join ">", @offsets };
+                push @offsets,(0);
             }
             if (m/^\s*multiboot\s*\/(xen\-[0-9][-+.0-9a-z]*\S+)/) {
                 die unless $entry;
@@ -500,7 +512,7 @@ sub setupboot_grub2 ($$$$) {
             }
             print ::EO <<END or die $!;
 
-GRUB_DEFAULT=$entry->{Number}
+GRUB_DEFAULT="$entry->{MenuEntryPath}"
 END
 
             print ::EO <<END or die $! if defined $xenhopt;