Patchwork [Qemu,v2] add a boot option to do strict boot

login
register
mail settings
Submitter Amos Kong
Date Jan. 9, 2013, 8:39 a.m.
Message ID <1357720753-3119-1-git-send-email-akong@redhat.com>
Download mbox | patch
Permalink /patch/210640/
State New
Headers show

Comments

Amos Kong - Jan. 9, 2013, 8:39 a.m.
Current seabios will try to boot from selected devices first,
if they are all failed, seabios will also try to boot from
un-selected devices.

We need to make it configurable. I already posted a seabios
patch to add a new device type to halt booting. Qemu can add
"HALT" at the end of bootindex string, then seabios will halt
booting after trying to boot from selected devices.

This option only effects when boot priority is changed by
bootindex options, the old style(-boot order=..) will still
try to boot from un-selected devices.

v2: add HALT entry in get_boot_devices_list()
    define boot_strict to bool

Signed-off-by: Amos Kong <akong@redhat.com>
---
[SeaBIOS PATCH v3] boot: add a new type to halt booting
https://github.com/kongove/seabios/commit/39aeded2da6254eab2c34de92371ce1cad5c793e
bios.bin: http://kongove.fedorapeople.org/pub/added-halt-type-bios.bin
---
 qemu-config.c   |    3 +++
 qemu-options.hx |    8 ++++++--
 vl.c            |   22 +++++++++++++++++++++-
 3 files changed, 30 insertions(+), 3 deletions(-)
Gleb Natapov - Jan. 9, 2013, 9:56 a.m.
On Wed, Jan 09, 2013 at 04:39:13PM +0800, Amos Kong wrote:
> Current seabios will try to boot from selected devices first,
> if they are all failed, seabios will also try to boot from
> un-selected devices.
> 
> We need to make it configurable. I already posted a seabios
> patch to add a new device type to halt booting. Qemu can add
> "HALT" at the end of bootindex string, then seabios will halt
> booting after trying to boot from selected devices.
> 
> This option only effects when boot priority is changed by
> bootindex options, the old style(-boot order=..) will still
> try to boot from un-selected devices.
> 
> v2: add HALT entry in get_boot_devices_list()
>     define boot_strict to bool
> 
> Signed-off-by: Amos Kong <akong@redhat.com>
Acked-by: Gleb Natapov <gleb@redhat.com>

> ---
> [SeaBIOS PATCH v3] boot: add a new type to halt booting
> https://github.com/kongove/seabios/commit/39aeded2da6254eab2c34de92371ce1cad5c793e
> bios.bin: http://kongove.fedorapeople.org/pub/added-halt-type-bios.bin
> ---
>  qemu-config.c   |    3 +++
>  qemu-options.hx |    8 ++++++--
>  vl.c            |   22 +++++++++++++++++++++-
>  3 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/qemu-config.c b/qemu-config.c
> index 2188c3e..dd6d249 100644
> --- a/qemu-config.c
> +++ b/qemu-config.c
> @@ -612,6 +612,9 @@ QemuOptsList qemu_boot_opts = {
>          }, {
>              .name = "reboot-timeout",
>              .type = QEMU_OPT_STRING,
> +        }, {
> +            .name = "strict",
> +            .type = QEMU_OPT_STRING,
>          },
>          { /*End of list */ }
>      },
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 9df0cde..5408837 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -376,14 +376,14 @@ ETEXI
>  
>  DEF("boot", HAS_ARG, QEMU_OPTION_boot,
>      "-boot [order=drives][,once=drives][,menu=on|off]\n"
> -    "      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time]\n"
> +    "      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]\n"
>      "                'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)\n"
>      "                'sp_name': the file's name that would be passed to bios as logo picture, if menu=on\n"
>      "                'sp_time': the period that splash picture last if menu=on, unit is ms\n"
>      "                'rb_timeout': the timeout before guest reboot when boot failed, unit is ms\n",
>      QEMU_ARCH_ALL)
>  STEXI
> -@item -boot [order=@var{drives}][,once=@var{drives}][,menu=on|off][,splash=@var{sp_name}][,splash-time=@var{sp_time}][,reboot-timeout=@var{rb_timeout}]
> +@item -boot [order=@var{drives}][,once=@var{drives}][,menu=on|off][,splash=@var{sp_name}][,splash-time=@var{sp_time}][,reboot-timeout=@var{rb_timeout}][,strict=on|off]
>  @findex -boot
>  Specify boot order @var{drives} as a string of drive letters. Valid
>  drive letters depend on the target achitecture. The x86 PC uses: a, b
> @@ -407,6 +407,10 @@ when boot failed, then reboot. If @var{rb_timeout} is '-1', guest will not
>  reboot, qemu passes '-1' to bios by default. Currently Seabios for X86
>  system support it.
>  
> +Do strict boot via @option{strict=on} as far as firmware/BIOS
> +supports it. This only effects when boot priority is changed by
> +bootindex options. The default is non-strict boot.
> +
>  @example
>  # try to boot from network first, then from hard disk
>  qemu-system-i386 -boot order=nc
> diff --git a/vl.c b/vl.c
> index 79e5122..1c64449 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -230,6 +230,7 @@ int ctrl_grab = 0;
>  unsigned int nb_prom_envs = 0;
>  const char *prom_envs[MAX_PROM_ENVS];
>  int boot_menu;
> +bool boot_strict = false;
>  uint8_t *boot_splash_filedata;
>  int boot_splash_filedata_size;
>  uint8_t qemu_extra_params_fw[2];
> @@ -1052,6 +1053,12 @@ char *get_boot_devices_list(uint32_t *size)
>  
>      *size = total;
>  
> +    if (boot_strict && *size > 0) {
> +        list[total-1] = '\n';
> +        list = g_realloc(list, total + 4);
> +        memcpy(&list[total], "HALT", 4);
> +        *size = total + 4;
> +    }
>      return list;
>  }
>  
> @@ -2804,7 +2811,7 @@ int main(int argc, char **argv, char **envp)
>                      static const char * const params[] = {
>                          "order", "once", "menu",
>                          "splash", "splash-time",
> -                        "reboot-timeout", NULL
> +                        "reboot-timeout", "strict", NULL
>                      };
>                      char buf[sizeof(boot_devices)];
>                      char *standard_boot_devices;
> @@ -2847,6 +2854,19 @@ int main(int argc, char **argv, char **envp)
>                                  exit(1);
>                              }
>                          }
> +                        if (get_param_value(buf, sizeof(buf),
> +                                            "strict", optarg)) {
> +                            if (!strcmp(buf, "on")) {
> +                                boot_strict = true;
> +                            } else if (!strcmp(buf, "off")) {
> +                                boot_strict = false;
> +                            } else {
> +                                fprintf(stderr,
> +                                        "qemu: invalid option value '%s'\n",
> +                                        buf);
> +                                exit(1);
> +                            }
> +                        }
>                          qemu_opts_parse(qemu_find_opts("boot-opts"),
>                                          optarg, 0);
>                      }
> -- 
> 1.7.1

--
			Gleb.
Eric Blake - Jan. 9, 2013, 3:14 p.m.
On 01/09/2013 01:39 AM, Amos Kong wrote:
> Current seabios will try to boot from selected devices first,
> if they are all failed, seabios will also try to boot from
> un-selected devices.
> 
> We need to make it configurable. I already posted a seabios
> patch to add a new device type to halt booting. Qemu can add
> "HALT" at the end of bootindex string, then seabios will halt
> booting after trying to boot from selected devices.
> 
> This option only effects when boot priority is changed by
> bootindex options, the old style(-boot order=..) will still
> try to boot from un-selected devices.
> 
> v2: add HALT entry in get_boot_devices_list()
>     define boot_strict to bool
> 
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---

Libvirt will need to expose an attribute that lets the user control
whether to use this new option; how do we probe via QMP whether the new
-boot strict=on command-line option is available?

> +++ b/qemu-options.hx
> @@ -376,14 +376,14 @@ ETEXI
>  
>  DEF("boot", HAS_ARG, QEMU_OPTION_boot,
>      "-boot [order=drives][,once=drives][,menu=on|off]\n"
> -    "      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time]\n"
> +    "      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]\n"
>      "                'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)\n"
>      "                'sp_name': the file's name that would be passed to bios as logo picture, if menu=on\n"
>      "                'sp_time': the period that splash picture last if menu=on, unit is ms\n"
>      "                'rb_timeout': the timeout before guest reboot when boot failed, unit is ms\n",

So if I understand correctly, -boot order=... is incompatible with -boot
strict=on; even though you have listed both options under a single -boot
entry in the -help. We've already declared that -help output is no
longer guaranteed stable, so this doesn't really impact libvirt, but
would it make any more sense to list this as two orthogonal entries, to
make it clear that they don't mix?

-boot order=drivers[,once=drives]...
-boot strict=on|off[,menu=on|off]...

But this is all bikeshedding, so it's not worth a v3 if you disagree.
Daniel P. Berrange - Jan. 9, 2013, 3:22 p.m.
On Wed, Jan 09, 2013 at 08:14:07AM -0700, Eric Blake wrote:
> On 01/09/2013 01:39 AM, Amos Kong wrote:
> > Current seabios will try to boot from selected devices first,
> > if they are all failed, seabios will also try to boot from
> > un-selected devices.
> > 
> > We need to make it configurable. I already posted a seabios
> > patch to add a new device type to halt booting. Qemu can add
> > "HALT" at the end of bootindex string, then seabios will halt
> > booting after trying to boot from selected devices.
> > 
> > This option only effects when boot priority is changed by
> > bootindex options, the old style(-boot order=..) will still
> > try to boot from un-selected devices.
> > 
> > v2: add HALT entry in get_boot_devices_list()
> >     define boot_strict to bool
> > 
> > Signed-off-by: Amos Kong <akong@redhat.com>
> > ---
> 
> Libvirt will need to expose an attribute that lets the user control
> whether to use this new option; how do we probe via QMP whether the new
> -boot strict=on command-line option is available?

While libvirt should make use of this, we don't need to
expose it in the XML. This new behaviour is what we wanted
to have all along, so we should just enable it.

Daniel
Amos Kong - Jan. 9, 2013, 3:52 p.m.
On Wed, Jan 09, 2013 at 08:14:07AM -0700, Eric Blake wrote:
> On 01/09/2013 01:39 AM, Amos Kong wrote:
> > Current seabios will try to boot from selected devices first,
> > if they are all failed, seabios will also try to boot from
> > un-selected devices.
> > 
> > We need to make it configurable. I already posted a seabios
> > patch to add a new device type to halt booting. Qemu can add
> > "HALT" at the end of bootindex string, then seabios will halt
> > booting after trying to boot from selected devices.
> > 
> > This option only effects when boot priority is changed by
> > bootindex options, the old style(-boot order=..) will still
> > try to boot from un-selected devices.
> > 
> > v2: add HALT entry in get_boot_devices_list()
> >     define boot_strict to bool
> > 
> > Signed-off-by: Amos Kong <akong@redhat.com>
> > ---
> 
> Libvirt will need to expose an attribute that lets the user control
> whether to use this new option; how do we probe via QMP whether the new
> -boot strict=on command-line option is available?


Old style to adjust boot priority by order parameter:
-boot order=n,strict=on (BAD, unselected devices will be tried)

New style to adjust boot priority by bootindex:
-device virtio-net-pci,...,bootindex=1 -boot strict=on (OK)

We only want strict option to support new style.

(those two styles are implemented in two different way insider
seabios, the latest simple patch only changed the bootindex way)
 
> > +++ b/qemu-options.hx
> > @@ -376,14 +376,14 @@ ETEXI
> >  
> >  DEF("boot", HAS_ARG, QEMU_OPTION_boot,
> >      "-boot [order=drives][,once=drives][,menu=on|off]\n"
> > -    "      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time]\n"
> > +    "      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]\n"
> >      "                'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)\n"
> >      "                'sp_name': the file's name that would be passed to bios as logo picture, if menu=on\n"
> >      "                'sp_time': the period that splash picture last if menu=on, unit is ms\n"
> >      "                'rb_timeout': the timeout before guest reboot when boot failed, unit is ms\n",
> 
> So if I understand correctly, -boot order=... is incompatible with -boot
> strict=on; even though you have listed both options under a single -boot
> entry in the -help. We've already declared that -help output is no
> longer guaranteed stable, so this doesn't really impact libvirt, but
> would it make any more sense to list this as two orthogonal entries, to
> make it clear that they don't mix?
> 
> -boot order=drivers[,once=drives]...
> -boot strict=on|off[,menu=on|off]...
> 
> But this is all bikeshedding, so it's not worth a v3 if you disagree.
> 
> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
Laine Stump - Jan. 9, 2013, 5:28 p.m.
On 01/09/2013 10:22 AM, Daniel P. Berrange wrote:
> On Wed, Jan 09, 2013 at 08:14:07AM -0700, Eric Blake wrote:
>> On 01/09/2013 01:39 AM, Amos Kong wrote:
>>> Current seabios will try to boot from selected devices first,
>>> if they are all failed, seabios will also try to boot from
>>> un-selected devices.
>>>
>>> We need to make it configurable. I already posted a seabios
>>> patch to add a new device type to halt booting. Qemu can add
>>> "HALT" at the end of bootindex string, then seabios will halt
>>> booting after trying to boot from selected devices.
>>>
>>> This option only effects when boot priority is changed by
>>> bootindex options, the old style(-boot order=..) will still
>>> try to boot from un-selected devices.
>>>
>>> v2: add HALT entry in get_boot_devices_list()
>>>     define boot_strict to bool
>>>
>>> Signed-off-by: Amos Kong <akong@redhat.com>
>>> ---
>> Libvirt will need to expose an attribute that lets the user control
>> whether to use this new option; how do we probe via QMP whether the new
>> -boot strict=on command-line option is available?
> While libvirt should make use of this, we don't need to
> expose it in the XML. This new behaviour is what we wanted
> to have all along, so we should just enable it.

I agree that this is the way it *should* always work, but apparently
there are people who depend on the old behavior, so just doing a blanket
switch to the new behavior could lead to setups that no longer work
"properly" after an upgrade, which unfortunately means that existing
functionality needs to be maintained, and "correct" functionality must
be triggered by a config switch (maybe Gleb can expand on the use cases
that require this if more details are needed, as it's him I heard this from)
Gleb Natapov - Jan. 9, 2013, 5:46 p.m.
On Wed, Jan 09, 2013 at 12:28:57PM -0500, Laine Stump wrote:
> On 01/09/2013 10:22 AM, Daniel P. Berrange wrote:
> > On Wed, Jan 09, 2013 at 08:14:07AM -0700, Eric Blake wrote:
> >> On 01/09/2013 01:39 AM, Amos Kong wrote:
> >>> Current seabios will try to boot from selected devices first,
> >>> if they are all failed, seabios will also try to boot from
> >>> un-selected devices.
> >>>
> >>> We need to make it configurable. I already posted a seabios
> >>> patch to add a new device type to halt booting. Qemu can add
> >>> "HALT" at the end of bootindex string, then seabios will halt
> >>> booting after trying to boot from selected devices.
> >>>
> >>> This option only effects when boot priority is changed by
> >>> bootindex options, the old style(-boot order=..) will still
> >>> try to boot from un-selected devices.
> >>>
> >>> v2: add HALT entry in get_boot_devices_list()
> >>>     define boot_strict to bool
> >>>
> >>> Signed-off-by: Amos Kong <akong@redhat.com>
> >>> ---
> >> Libvirt will need to expose an attribute that lets the user control
> >> whether to use this new option; how do we probe via QMP whether the new
> >> -boot strict=on command-line option is available?
> > While libvirt should make use of this, we don't need to
> > expose it in the XML. This new behaviour is what we wanted
> > to have all along, so we should just enable it.
> 
> I agree that this is the way it *should* always work, but apparently
> there are people who depend on the old behavior, so just doing a blanket
> switch to the new behavior could lead to setups that no longer work
> "properly" after an upgrade, which unfortunately means that existing
> functionality needs to be maintained, and "correct" functionality must
> be triggered by a config switch (maybe Gleb can expand on the use cases
> that require this if more details are needed, as it's him I heard this from)

It is common to configure PXE boot as highest prio for easy re-imaging,
Usually boot from PXE fails and other bootable device is used instead,
but if re-installation is needed it is as easy as configuring PXE server
and rebooting the machine. With current behaviour it is enough to boost
PXE priority, if we will change it setups that didn't explicitly specify
all devices' priorities will stop working. The rule is easy: if exist
command line that will work differently before and after the change you
probably break someones setup with your patch.

--
			Gleb.
Amos Kong - Jan. 22, 2013, 3:23 p.m.
----- Original Message -----
> On 01/09/2013 01:39 AM, Amos Kong wrote:
> > Current seabios will try to boot from selected devices first,
> > if they are all failed, seabios will also try to boot from
> > un-selected devices.
> > 
> > We need to make it configurable. I already posted a seabios
> > patch to add a new device type to halt booting. Qemu can add
> > "HALT" at the end of bootindex string, then seabios will halt
> > booting after trying to boot from selected devices.
> > 
> > This option only effects when boot priority is changed by
> > bootindex options, the old style(-boot order=..) will still
> > try to boot from un-selected devices.
> > 
> > v2: add HALT entry in get_boot_devices_list()
> >     define boot_strict to bool
> > 
> > Signed-off-by: Amos Kong <akong@redhat.com>
> > ---
> 
> Libvirt will need to expose an attribute that lets the user control
> whether to use this new option; how do we probe via QMP whether the
> new
> -boot strict=on command-line option is available?

Hi all,

How about add new info/query command?

(hmp) info strict-boot
      on

(qmp) {"execute": "query-strict-boot"}
      {"return": {"state": true}}


> > +++ b/qemu-options.hx
> > @@ -376,14 +376,14 @@ ETEXI
> >  
> >  DEF("boot", HAS_ARG, QEMU_OPTION_boot,
> >      "-boot [order=drives][,once=drives][,menu=on|off]\n"
> > -    "
> >      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time]\n"
> > +    "
> >      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]\n"
> >      "                'drives': floppy (a), hard disk (c), CD-ROM
> >      (d), network (n)\n"
> >      "                'sp_name': the file's name that would be
> >      passed to bios as logo picture, if menu=on\n"
> >      "                'sp_time': the period that splash picture
> >      last if menu=on, unit is ms\n"
> >      "                'rb_timeout': the timeout before guest reboot
> >      when boot failed, unit is ms\n",
> 
> So if I understand correctly, -boot order=... is incompatible with
> -boot
> strict=on; 

They are not incompatible, order will effect the priority,
strict decides if boot from un-selected device.

> even though you have listed both options under a single
> -boot
> entry in the -help. We've already declared that -help output is no
> longer guaranteed stable, so this doesn't really impact libvirt, but
> would it make any more sense to list this as two orthogonal entries,
> to
> make it clear that they don't mix?
> 
> -boot order=drivers[,once=drives]...
> -boot strict=on|off[,menu=on|off]...
> 
> But this is all bikeshedding, so it's not worth a v3 if you disagree.
> 
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
> 
>
Amos Kong - Jan. 22, 2013, 3:52 p.m.
On Tue, Jan 22, 2013 at 10:23:32AM -0500, Amos Kong wrote:
> ----- Original Message -----
> > On 01/09/2013 01:39 AM, Amos Kong wrote:
> > > Current seabios will try to boot from selected devices first,
> > > if they are all failed, seabios will also try to boot from
> > > un-selected devices.
> > > 
> > > We need to make it configurable. I already posted a seabios
> > > patch to add a new device type to halt booting. Qemu can add
> > > "HALT" at the end of bootindex string, then seabios will halt
> > > booting after trying to boot from selected devices.
> > > 
> > > This option only effects when boot priority is changed by
> > > bootindex options, the old style(-boot order=..) will still
> > > try to boot from un-selected devices.
> > > 
> > > v2: add HALT entry in get_boot_devices_list()
> > >     define boot_strict to bool
> > > 
> > > Signed-off-by: Amos Kong <akong@redhat.com>
> > > ---
> > 
> > Libvirt will need to expose an attribute that lets the user control
> > whether to use this new option; how do we probe via QMP whether the
> > new
> > -boot strict=on command-line option is available?
> 
> Hi all,
> 
> How about add new info/query command?
> 
> (hmp) info strict-boot
>       on
> 
> (qmp) {"execute": "query-strict-boot"}
>       {"return": {"state": true}}

It might be not a good solution, I already updated qemu-options.hx,
we can check help message to know if this new option is added or not.

Daniel, Laine, do you have some suggestion?
 
> > > +++ b/qemu-options.hx
> > > @@ -376,14 +376,14 @@ ETEXI
> > >  
> > >  DEF("boot", HAS_ARG, QEMU_OPTION_boot,
> > >      "-boot [order=drives][,once=drives][,menu=on|off]\n"
> > > -    "
> > >      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time]\n"
> > > +    "
> > >      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]\n"
> > >      "                'drives': floppy (a), hard disk (c), CD-ROM
> > >      (d), network (n)\n"
> > >      "                'sp_name': the file's name that would be
> > >      passed to bios as logo picture, if menu=on\n"
> > >      "                'sp_time': the period that splash picture
> > >      last if menu=on, unit is ms\n"
> > >      "                'rb_timeout': the timeout before guest reboot
> > >      when boot failed, unit is ms\n",
> > 
> > So if I understand correctly, -boot order=... is incompatible with
> > -boot
> > strict=on; 
> 
> They are not incompatible, order will effect the priority,
> strict decides if boot from un-selected device.
> 
> > even though you have listed both options under a single
> > -boot
> > entry in the -help. We've already declared that -help output is no
> > longer guaranteed stable, so this doesn't really impact libvirt, but
> > would it make any more sense to list this as two orthogonal entries,
> > to
> > make it clear that they don't mix?
> > 
> > -boot order=drivers[,once=drives]...
> > -boot strict=on|off[,menu=on|off]...
> > 
> > But this is all bikeshedding, so it's not worth a v3 if you disagree.
> > 
> > --
> > Eric Blake   eblake redhat com    +1-919-301-3266
> > Libvirt virtualization library http://libvirt.org
> > 
> >
Eric Blake - Jan. 22, 2013, 4 p.m.
On 01/22/2013 08:52 AM, Amos Kong wrote:

>>>
>>> Libvirt will need to expose an attribute that lets the user control
>>> whether to use this new option; how do we probe via QMP whether the
>>> new
>>> -boot strict=on command-line option is available?
>>
>> Hi all,
>>
>> How about add new info/query command?
>>
>> (hmp) info strict-boot
>>       on
>>
>> (qmp) {"execute": "query-strict-boot"}
>>       {"return": {"state": true}}
> 
> It might be not a good solution, I already updated qemu-options.hx,
> we can check help message to know if this new option is added or not.

Having libvirt probe the -help output is out of the question.  We
already declared that for qemu 1.3 and beyond, ALL command line behavior
must ALSO be probe-able via QMP.  I think Anthony had a trick for
testing for existence of various command line options without needing to
add a new query-strict-boot command, but I don't remember what that
trick was.
Anthony Liguori - Jan. 22, 2013, 6:26 p.m.
Eric Blake <eblake@redhat.com> writes:

> On 01/22/2013 08:52 AM, Amos Kong wrote:
>
>>>>
>>>> Libvirt will need to expose an attribute that lets the user control
>>>> whether to use this new option; how do we probe via QMP whether the
>>>> new
>>>> -boot strict=on command-line option is available?
>>>
>>> Hi all,
>>>
>>> How about add new info/query command?
>>>
>>> (hmp) info strict-boot
>>>       on
>>>
>>> (qmp) {"execute": "query-strict-boot"}
>>>       {"return": {"state": true}}
>> 
>> It might be not a good solution, I already updated qemu-options.hx,
>> we can check help message to know if this new option is added or not.
>
> Having libvirt probe the -help output is out of the question.  We
> already declared that for qemu 1.3 and beyond, ALL command line behavior
> must ALSO be probe-able via QMP.  I think Anthony had a trick for
> testing for existence of various command line options without needing to
> add a new query-strict-boot command, but I don't remember what that
> trick was.

We need a generic query-config-schema command.

Regards,

Anthony Liguori

>
> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org

Patch

diff --git a/qemu-config.c b/qemu-config.c
index 2188c3e..dd6d249 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -612,6 +612,9 @@  QemuOptsList qemu_boot_opts = {
         }, {
             .name = "reboot-timeout",
             .type = QEMU_OPT_STRING,
+        }, {
+            .name = "strict",
+            .type = QEMU_OPT_STRING,
         },
         { /*End of list */ }
     },
diff --git a/qemu-options.hx b/qemu-options.hx
index 9df0cde..5408837 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -376,14 +376,14 @@  ETEXI
 
 DEF("boot", HAS_ARG, QEMU_OPTION_boot,
     "-boot [order=drives][,once=drives][,menu=on|off]\n"
-    "      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time]\n"
+    "      [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]\n"
     "                'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)\n"
     "                'sp_name': the file's name that would be passed to bios as logo picture, if menu=on\n"
     "                'sp_time': the period that splash picture last if menu=on, unit is ms\n"
     "                'rb_timeout': the timeout before guest reboot when boot failed, unit is ms\n",
     QEMU_ARCH_ALL)
 STEXI
-@item -boot [order=@var{drives}][,once=@var{drives}][,menu=on|off][,splash=@var{sp_name}][,splash-time=@var{sp_time}][,reboot-timeout=@var{rb_timeout}]
+@item -boot [order=@var{drives}][,once=@var{drives}][,menu=on|off][,splash=@var{sp_name}][,splash-time=@var{sp_time}][,reboot-timeout=@var{rb_timeout}][,strict=on|off]
 @findex -boot
 Specify boot order @var{drives} as a string of drive letters. Valid
 drive letters depend on the target achitecture. The x86 PC uses: a, b
@@ -407,6 +407,10 @@  when boot failed, then reboot. If @var{rb_timeout} is '-1', guest will not
 reboot, qemu passes '-1' to bios by default. Currently Seabios for X86
 system support it.
 
+Do strict boot via @option{strict=on} as far as firmware/BIOS
+supports it. This only effects when boot priority is changed by
+bootindex options. The default is non-strict boot.
+
 @example
 # try to boot from network first, then from hard disk
 qemu-system-i386 -boot order=nc
diff --git a/vl.c b/vl.c
index 79e5122..1c64449 100644
--- a/vl.c
+++ b/vl.c
@@ -230,6 +230,7 @@  int ctrl_grab = 0;
 unsigned int nb_prom_envs = 0;
 const char *prom_envs[MAX_PROM_ENVS];
 int boot_menu;
+bool boot_strict = false;
 uint8_t *boot_splash_filedata;
 int boot_splash_filedata_size;
 uint8_t qemu_extra_params_fw[2];
@@ -1052,6 +1053,12 @@  char *get_boot_devices_list(uint32_t *size)
 
     *size = total;
 
+    if (boot_strict && *size > 0) {
+        list[total-1] = '\n';
+        list = g_realloc(list, total + 4);
+        memcpy(&list[total], "HALT", 4);
+        *size = total + 4;
+    }
     return list;
 }
 
@@ -2804,7 +2811,7 @@  int main(int argc, char **argv, char **envp)
                     static const char * const params[] = {
                         "order", "once", "menu",
                         "splash", "splash-time",
-                        "reboot-timeout", NULL
+                        "reboot-timeout", "strict", NULL
                     };
                     char buf[sizeof(boot_devices)];
                     char *standard_boot_devices;
@@ -2847,6 +2854,19 @@  int main(int argc, char **argv, char **envp)
                                 exit(1);
                             }
                         }
+                        if (get_param_value(buf, sizeof(buf),
+                                            "strict", optarg)) {
+                            if (!strcmp(buf, "on")) {
+                                boot_strict = true;
+                            } else if (!strcmp(buf, "off")) {
+                                boot_strict = false;
+                            } else {
+                                fprintf(stderr,
+                                        "qemu: invalid option value '%s'\n",
+                                        buf);
+                                exit(1);
+                            }
+                        }
                         qemu_opts_parse(qemu_find_opts("boot-opts"),
                                         optarg, 0);
                     }