mbox series

[00/14] discover/grub2: Add support for grub2 file specifiers

Message ID 20191120024306.16526-1-jk@ozlabs.org
Headers show
Series discover/grub2: Add support for grub2 file specifiers | expand

Message

Jeremy Kerr Nov. 20, 2019, 2:42 a.m. UTC
This series implements grub2-syle file references, of the form:

 (device)/path

- as documented at
https://www.gnu.org/software/grub/manual/grub/html_node/File-name-syntax.html

This allows cross-device specifiers for boot option resources, as well
as general scripting (eg., the '-f' tests, and a new 'source' command).

The (device) component of these specifiers corresponds to the petitboot
device ID, which in turn is just the kernel name for the device. As with
actual grub, these names may be volatile, so are rarely used directly in
scripts. Instead, most scripts will use the 'search' function to resolve
a UUID or label into one of these IDs. To enable this, we extend support
for proper resolution for the search builtin.

We also add a 'source' command, supporting this specifier syntax.

Finally, this change adds a couple of tests using example RHEL8 boot
configs, which depend on these features.

Cheers,


Jeremy

---


Jeremy Kerr (14):
  discover/grub2: 'search' set-variable defaults to root
  discover/grub2: Use getopt for `search` argument parsing
  discover/grub2: test for (ignored) --no-floppy argument
  discover/grub2: Add support for UUID and label for 'search' command
  discover/grub2: expose a struct for grub2 file references
  discover/grub2: Add parsing code for grub2 file specifiers
  discover/grub2: add support for grub2-style path specifiers in resources
  discover/grub2: Allow (device)/path references in general script usage
  discover/grub2: Add a reference from script to parser
  discover/grub2: expose internal parse function
  discover/grub2: make statements_execute non-static
  discover/grub2: implement 'source' command
  test/parser: Add test for recent RHCOS grub2 config
  test/parser: Add RHEL8 grub config test

 discover/grub2/blscfg.c                       |  19 +-
 discover/grub2/builtins.c                     | 208 +++++++++++++++---
 discover/grub2/grub2-parser.y                 |  17 +-
 discover/grub2/grub2.c                        | 110 +++++++--
 discover/grub2/grub2.h                        |  32 ++-
 discover/grub2/script.c                       |   3 +-
 test/parser/Makefile.am                       |  11 +
 test/parser/data/grub2-rhcos-ootpa.conf       | 194 ++++++++++++++++
 test/parser/data/grub2-rhel8.conf             | 190 ++++++++++++++++
 test/parser/test-grub2-devpath-scripting.c    |  56 +++++
 test/parser/test-grub2-devpath.c              |  88 ++++++++
 test/parser/test-grub2-rhcos-ootpa.c          |  38 ++++
 test/parser/test-grub2-rhel8.c                |  21 ++
 test/parser/test-grub2-search-args.c          |  35 +++
 test/parser/test-grub2-search-label.c         |  47 ++++
 test/parser/test-grub2-search-uuid.c          |  55 +++++
 test/parser/test-grub2-source-functions.c     |  46 ++++
 .../test-grub2-source-recursion-infinite.c    |  43 ++++
 test/parser/test-grub2-source-recursion.c     |  58 +++++
 test/parser/test-grub2-source.c               |  54 +++++
 20 files changed, 1254 insertions(+), 71 deletions(-)
 create mode 100644 test/parser/data/grub2-rhcos-ootpa.conf
 create mode 100644 test/parser/data/grub2-rhel8.conf
 create mode 100644 test/parser/test-grub2-devpath-scripting.c
 create mode 100644 test/parser/test-grub2-devpath.c
 create mode 100644 test/parser/test-grub2-rhcos-ootpa.c
 create mode 100644 test/parser/test-grub2-rhel8.c
 create mode 100644 test/parser/test-grub2-search-args.c
 create mode 100644 test/parser/test-grub2-search-label.c
 create mode 100644 test/parser/test-grub2-search-uuid.c
 create mode 100644 test/parser/test-grub2-source-functions.c
 create mode 100644 test/parser/test-grub2-source-recursion-infinite.c
 create mode 100644 test/parser/test-grub2-source-recursion.c
 create mode 100644 test/parser/test-grub2-source.c

Comments

samjonas Dec. 2, 2019, 5:51 a.m. UTC | #1
On Wed, 2019-11-20 at 10:42 +0800, Jeremy Kerr wrote:
> This series implements grub2-syle file references, of the form:
> 
>  (device)/path
> 
> - as documented at
> https://www.gnu.org/software/grub/manual/grub/html_node/File-name-syntax.html
> 
> This allows cross-device specifiers for boot option resources, as
> well
> as general scripting (eg., the '-f' tests, and a new 'source'
> command).
> 
> The (device) component of these specifiers corresponds to the
> petitboot
> device ID, which in turn is just the kernel name for the device. As
> with
> actual grub, these names may be volatile, so are rarely used directly
> in
> scripts. Instead, most scripts will use the 'search' function to
> resolve
> a UUID or label into one of these IDs. To enable this, we extend
> support
> for proper resolution for the search builtin.
> 
> We also add a 'source' command, supporting this specifier syntax.
> 
> Finally, this change adds a couple of tests using example RHEL8 boot
> configs, which depend on these features.
> 
> Cheers,
> 
> 
> Jeremy

Belated review but looks good! I look forward to the first bug report
titled "Petitboot only supports 10 nested grub configurations".

Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>

> 
> ---
> 
> 
> Jeremy Kerr (14):
>   discover/grub2: 'search' set-variable defaults to root
>   discover/grub2: Use getopt for `search` argument parsing
>   discover/grub2: test for (ignored) --no-floppy argument
>   discover/grub2: Add support for UUID and label for 'search' command
>   discover/grub2: expose a struct for grub2 file references
>   discover/grub2: Add parsing code for grub2 file specifiers
>   discover/grub2: add support for grub2-style path specifiers in
> resources
>   discover/grub2: Allow (device)/path references in general script
> usage
>   discover/grub2: Add a reference from script to parser
>   discover/grub2: expose internal parse function
>   discover/grub2: make statements_execute non-static
>   discover/grub2: implement 'source' command
>   test/parser: Add test for recent RHCOS grub2 config
>   test/parser: Add RHEL8 grub config test
> 
>  discover/grub2/blscfg.c                       |  19 +-
>  discover/grub2/builtins.c                     | 208 +++++++++++++++-
> --
>  discover/grub2/grub2-parser.y                 |  17 +-
>  discover/grub2/grub2.c                        | 110 +++++++--
>  discover/grub2/grub2.h                        |  32 ++-
>  discover/grub2/script.c                       |   3 +-
>  test/parser/Makefile.am                       |  11 +
>  test/parser/data/grub2-rhcos-ootpa.conf       | 194 ++++++++++++++++
>  test/parser/data/grub2-rhel8.conf             | 190 ++++++++++++++++
>  test/parser/test-grub2-devpath-scripting.c    |  56 +++++
>  test/parser/test-grub2-devpath.c              |  88 ++++++++
>  test/parser/test-grub2-rhcos-ootpa.c          |  38 ++++
>  test/parser/test-grub2-rhel8.c                |  21 ++
>  test/parser/test-grub2-search-args.c          |  35 +++
>  test/parser/test-grub2-search-label.c         |  47 ++++
>  test/parser/test-grub2-search-uuid.c          |  55 +++++
>  test/parser/test-grub2-source-functions.c     |  46 ++++
>  .../test-grub2-source-recursion-infinite.c    |  43 ++++
>  test/parser/test-grub2-source-recursion.c     |  58 +++++
>  test/parser/test-grub2-source.c               |  54 +++++
>  20 files changed, 1254 insertions(+), 71 deletions(-)
>  create mode 100644 test/parser/data/grub2-rhcos-ootpa.conf
>  create mode 100644 test/parser/data/grub2-rhel8.conf
>  create mode 100644 test/parser/test-grub2-devpath-scripting.c
>  create mode 100644 test/parser/test-grub2-devpath.c
>  create mode 100644 test/parser/test-grub2-rhcos-ootpa.c
>  create mode 100644 test/parser/test-grub2-rhel8.c
>  create mode 100644 test/parser/test-grub2-search-args.c
>  create mode 100644 test/parser/test-grub2-search-label.c
>  create mode 100644 test/parser/test-grub2-search-uuid.c
>  create mode 100644 test/parser/test-grub2-source-functions.c
>  create mode 100644 test/parser/test-grub2-source-recursion-
> infinite.c
>  create mode 100644 test/parser/test-grub2-source-recursion.c
>  create mode 100644 test/parser/test-grub2-source.c
>