Skip to contentSkip to conversation

bootdevcie: change the boot order validation logic

PATCH Superseded [email protected] 2 participants 9 messages Feb 3, 2015 – Feb 6, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover bootdevcie: change the boot order validation logic

From: Gonglei <[email protected]>

The reset logic can be done by both machine reset and boot handler. So we shouldn't return error when the boot handler callback don't be set in patch 1.

Patch 2 check boot order argument validation
before vm running.

Patch 3 passing &error_abort instead of NULL.

v2 -> v1:
- add patch 2 suggested by Markus.
- rework patch 3. (Maruks)
- add R-by in patch 1.

Gonglei (3):
bootdevice: remove the check about boot_set_handler
bootdevice: check boot order argument validation before vm running
bootdevice: add check in restore_boot_order()

 bootdevice.c | 12 ++++--------
 vl.c         | 13 +++++++++++--
 2 files changed, 15 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH v2 1/3 bootdevice: remove the check about boot_set_handler

From: Gonglei <[email protected]>

The reset logic can be done by both machine reset and boot handler. So we shouldn't return error when the boot handler callback don't be set.

---
 bootdevice.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
bootdevice.c +3 -7
index 5914417..52d3f9e 100644
@@ -51,19 +51,15 @@ void qemu_boot_set(const char *boot_order, Error **errp)
 {
     Error *local_err = NULL;
 
-    if (!boot_set_handler) {
-        error_setg(errp, "no function defined to set boot device list for"
-                         " this architecture");
-        return;
-    }
-
     validate_bootdevices(boot_order, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return;
     }
 
-    boot_set_handler(boot_set_opaque, boot_order, errp);
+    if (boot_set_handler) {
+        boot_set_handler(boot_set_opaque, boot_order, errp);
+    }
 }
 
 void validate_bootdevices(const char *devices, Error **errp)
Signature · 1 line
1.7.12.4
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] bootdevice: remove the check about boot_set_handler

Quoted 29 lines · <[email protected]> writes:

From: Gonglei <[email protected]>

The reset logic can be done by both machine reset and boot handler. So we shouldn't return error when the boot handler callback don't be set.

---
 bootdevice.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
bootdevice.c +0 -6
index 5914417..52d3f9e 100644
@@ -51,19 +51,15 @@ void qemu_boot_set(const char *boot_order, Error **errp)
 {
     Error *local_err = NULL;
 
-    if (!boot_set_handler) {
-        error_setg(errp, "no function defined to set boot device list for"
-                         " this architecture");
-        return;
-    }
-
     validate_bootdevices(boot_order, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);

bootdevice.c void qemu_boot_set(const char *boot_order, Error **errp) · line 65

Quoted 10 lines
bootdevice.c +3 -1
         return;
     }
 
-    boot_set_handler(boot_set_opaque, boot_order, errp);
+    if (boot_set_handler) {
+        boot_set_handler(boot_set_opaque, boot_order, errp);
+    }
 }
 
 void validate_bootdevices(const char *devices, Error **errp)

Two callers:

* HMP command boot_set

Before your patch: command fails when the target doesn't support changing the boot order.

After your patch: command silently does nothing. I'm afraid that's a regression.

Aside: looks like there's no QMP command.

* restore_boot_order()

No change yet, because restore_boot_order() ignores errors. But PATCH 3 will make it abort on error. I guess that's why you make the change here.

To avoid the regression, you could drop PATCH 1, and change PATCH 3 to something like

- qemu_boot_set(normal_boot_order, NULL);
+ if (boot_set_handler) {
+ qemu_boot_set(normal_boot_order, &error_abort);
+ }

There are other ways, but this looks like the simplest one.

author
#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] bootdevice: remove the check about boot_set_handler

Quoted 46 lines · Markus Armbruster
Quoted 29 lines · <[email protected]> writes:

From: Gonglei <[email protected]>

The reset logic can be done by both machine reset and boot handler. So we shouldn't return error when the boot handler callback don't be set.

---
 bootdevice.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
bootdevice.c +0 -6
index 5914417..52d3f9e 100644
@@ -51,19 +51,15 @@ void qemu_boot_set(const char *boot_order, Error **errp)
 {
     Error *local_err = NULL;
 
-    if (!boot_set_handler) {
-        error_setg(errp, "no function defined to set boot device list for"
-                         " this architecture");
-        return;
-    }
-
     validate_bootdevices(boot_order, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);

bootdevice.c void qemu_boot_set(const char *boot_order, Error **errp) · line 65

Quoted 10 lines
bootdevice.c +3 -1
         return;
     }
 
-    boot_set_handler(boot_set_opaque, boot_order, errp);
+    if (boot_set_handler) {
+        boot_set_handler(boot_set_opaque, boot_order, errp);
+    }
 }
 
 void validate_bootdevices(const char *devices, Error **errp)

Two callers:

* HMP command boot_set

Quoted 8 lines

Before your patch: command fails when the target doesn't support changing the boot order.

After your patch: command silently does nothing. I'm afraid that's a regression.

Aside: looks like there's no QMP command.

Yes.

Quoted 6 lines

* restore_boot_order()

No change yet, because restore_boot_order() ignores errors. But PATCH 3 will make it abort on error. I guess that's why you make the change here.

Actually, I add this patch based on the previous conversation:
It duplicates the reset logic as well as information holder locality (machine struct vs parameter).
http://lists.gnu.org/archive/html/qemu-devel/2015-01/msg04172.html
and
http://lists.gnu.org/archive/html/qemu-devel/2015-01/msg04292.html

Regards,
-Gonglei

Quoted 10 lines

To avoid the regression, you could drop PATCH 1, and change PATCH 3 to something like

bootdevice.c +3 -1
-    qemu_boot_set(normal_boot_order, NULL);
+    if (boot_set_handler) {
+        qemu_boot_set(normal_boot_order, &error_abort);
+    }

There are other ways, but this looks like the simplest one.

#4 lore raw

PATCH v2 2/3 bootdevice: check boot order argument validation before vm running

In reply to [email protected]

From: Gonglei <[email protected]>

Either 'once' option or 'order' option can take effect for -boot at the same time, that is say initial startup processing can check only one. And pc.c's set_boot_dev() fails when its boot order argument is invalid. This patch provide a solution fix this problem:

1. If "once" is given, register reset handler to restore boot order.

2. Pass the normal boot order to machine creation. Should fail when the normal boot order is invalid.

3. If "once" is given, set it with qemu_boot_set(). Fails when the once boot order is invalid.

4. Start the machine.

5. On reset, the reset handler calls qemu_boot_set() to restore boot order. Should never fail.

---
 vl.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
vl.c +11 -2
index 983259b..0d90d98 100644
@@ -2734,6 +2734,7 @@ int main(int argc, char **argv, char **envp)
     const char *initrd_filename;
     const char *kernel_filename, *kernel_cmdline;
     const char *boot_order;
+    const char *once = NULL;
     DisplayState *ds;
     int cyls, heads, secs, translation;
     QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL;
@@ -4046,7 +4047,7 @@ int main(int argc, char **argv, char **envp)
     opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
     if (opts) {
         char *normal_boot_order;
-        const char *order, *once;
+        const char *order;
         Error *local_err = NULL;
 
         order = qemu_opt_get(opts, "order");
@@ -4067,7 +4068,6 @@ int main(int argc, char **argv, char **envp)
                 exit(1);
             }
             normal_boot_order = g_strdup(boot_order);
-            boot_order = once;
             qemu_register_reset(restore_boot_order, normal_boot_order);
         }
 
@@ -4246,6 +4246,15 @@ int main(int argc, char **argv, char **envp)
 
     net_check_clients();
 
+    if (once) {
+        Error *local_err = NULL;
+        qemu_boot_set(once, &local_err);
+        if (local_err) {
+            error_report("%s", error_get_pretty(local_err));
+            exit(1);
+        }
+    }
+
     ds = init_displaystate();
 
     /* init local displays */
Signature · 1 line
1.7.12.4
#5 lore raw

Re: [Qemu-devel] [PATCH v2 2/3] bootdevice: check boot order argument validation before vm running

Quoted 31 lines · <[email protected]> writes:

From: Gonglei <[email protected]>

Either 'once' option or 'order' option can take effect for -boot at the same time, that is say initial startup processing can check only one. And pc.c's set_boot_dev() fails when its boot order argument is invalid. This patch provide a solution fix this problem:

1. If "once" is given, register reset handler to restore boot order.

2. Pass the normal boot order to machine creation. Should fail when the normal boot order is invalid.

3. If "once" is given, set it with qemu_boot_set(). Fails when the once boot order is invalid.

4. Start the machine.

5. On reset, the reset handler calls qemu_boot_set() to restore boot order. Should never fail.

---
 vl.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
vl.c +0 -0
index 983259b..0d90d98 100644

vl.c int main(int argc, char **argv, char **envp) · line 2737

Quoted 4 lines
vl.c +1 -0
@@ -2734,6 +2734,7 @@ int main(int argc, char **argv, char **envp)
     const char *initrd_filename;
     const char *kernel_filename, *kernel_cmdline;
     const char *boot_order;
+    const char *once = NULL;

Consider renaming once to boot_once. In its much larger scope, the boot context isn't obvious anymore, so a more telling name would be in order.

Quoted 13 lines
vl.c +1 -1
     DisplayState *ds;
     int cyls, heads, secs, translation;
     QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL;
@@ -4046,7 +4047,7 @@ int main(int argc, char **argv, char **envp)
     opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
     if (opts) {
         char *normal_boot_order;
-        const char *order, *once;
+        const char *order;
         Error *local_err = NULL;
 
         order = qemu_opt_get(opts, "order");

vl.c int main(int argc, char **argv, char **envp) · line 4073

Quoted 7 lines
vl.c +0 -1
@@ -4067,7 +4068,6 @@ int main(int argc, char **argv, char **envp)
                 exit(1);
             }
             normal_boot_order = g_strdup(boot_order);
-            boot_order = once;
             qemu_register_reset(restore_boot_order, normal_boot_order);
         }
 

normal_boot_order can be eliminated now.

        }
        qemu_register_reset(restore_boot_order, strdup(order));
    }

Even better, move qemu_register_reset()...

vl.c int main(int argc, char **argv, char **envp) · line 4255

Quoted 11 lines
vl.c +7 -0
@@ -4246,6 +4246,15 @@ int main(int argc, char **argv, char **envp)
 
     net_check_clients();
 
+    if (once) {
+        Error *local_err = NULL;
+        qemu_boot_set(once, &local_err);
+        if (local_err) {
+            error_report("%s", error_get_pretty(local_err));
+            exit(1);
+        }

... here:

           qemu_register_reset(restore_boot_order, strdup(boot_order));

vl.c int main(int argc, char **argv, char **envp) · line 4260

Quoted 5 lines
vl.c +2 -0
+    }
+
     ds = init_displaystate();
 
     /* init local displays */

Clearer, don't you think?

author
#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/3] bootdevice: check boot order argument validation before vm running

Quoted 28 lines · Markus Armbruster
Quoted 26 lines · <[email protected]> writes:

From: Gonglei <[email protected]>

Either 'once' option or 'order' option can take effect for -boot at the same time, that is say initial startup processing can check only one. And pc.c's set_boot_dev() fails when its boot order argument is invalid. This patch provide a solution fix this problem:

1. If "once" is given, register reset handler to restore boot order.

2. Pass the normal boot order to machine creation. Should fail when the normal boot order is invalid.

3. If "once" is given, set it with qemu_boot_set(). Fails when the once boot order is invalid.

4. Start the machine.

5. On reset, the reset handler calls qemu_boot_set() to restore boot order. Should never fail.

---
 vl.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
Quoted 13 lines

vl.c int main(int argc, char **argv, char **envp) · line 2737

Quoted 9 lines
vl.c +1 -0
index 983259b..0d90d98 100644
@@ -2734,6 +2734,7 @@ int main(int argc, char **argv, char **envp)
     const char *initrd_filename;
     const char *kernel_filename, *kernel_cmdline;
     const char *boot_order;
+    const char *once = NULL;

Consider renaming once to boot_once. In its much larger scope, the boot context isn't obvious anymore, so a more telling name would be in order.

Agree.

Quoted 45 lines
Quoted 13 lines
vl.c +1 -1
     DisplayState *ds;
     int cyls, heads, secs, translation;
     QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL;
@@ -4046,7 +4047,7 @@ int main(int argc, char **argv, char **envp)
     opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
     if (opts) {
         char *normal_boot_order;
-        const char *order, *once;
+        const char *order;
         Error *local_err = NULL;
 
         order = qemu_opt_get(opts, "order");

vl.c int main(int argc, char **argv, char **envp) · line 4073

Quoted 7 lines
vl.c +0 -1
@@ -4067,7 +4068,6 @@ int main(int argc, char **argv, char **envp)
                 exit(1);
             }
             normal_boot_order = g_strdup(boot_order);
-            boot_order = once;
             qemu_register_reset(restore_boot_order, normal_boot_order);
         }
 

normal_boot_order can be eliminated now.

        }
        qemu_register_reset(restore_boot_order, strdup(order));
    }

Even better, move qemu_register_reset()...

vl.c int main(int argc, char **argv, char **envp) · line 4255

Quoted 11 lines
vl.c +7 -0
@@ -4246,6 +4246,15 @@ int main(int argc, char **argv, char **envp)
 
     net_check_clients();
 
+    if (once) {
+        Error *local_err = NULL;
+        qemu_boot_set(once, &local_err);
+        if (local_err) {
+            error_report("%s", error_get_pretty(local_err));
+            exit(1);
+        }

... here:

           qemu_register_reset(restore_boot_order, strdup(boot_order));
Quoted 7 lines

vl.c int main(int argc, char **argv, char **envp) · line 4260

Quoted 5 lines
vl.c +2 -0
+    }
+
     ds = init_displaystate();
 
     /* init local displays */

Clearer, don't you think?

Yes, it's cool. :)

Regards,
-Gonglei

#7 lore raw

PATCH v2 3/3 bootdevice: add check in restore_boot_order()

In reply to [email protected]

From: Gonglei <[email protected]>

qemu_boot_set() can't fail in restore_boot_order(), then simply assert it doesn't fail, by passing &error_abort.

---
 bootdevice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bootdevice.c +1 -1
index 52d3f9e..d3d4277 100644
@@ -101,7 +101,7 @@ void restore_boot_order(void *opaque)
         return;
     }
 
-    qemu_boot_set(normal_boot_order, NULL);
+    qemu_boot_set(normal_boot_order, &error_abort);
 
     qemu_unregister_reset(restore_boot_order, normal_boot_order);
     g_free(normal_boot_order);
Signature · 1 line
1.7.12.4
author
#8 lore raw
In reply to [email protected]
Quoted 9 lines · Gonglei (Arei)

From: Gonglei <[email protected]>

The reset logic can be done by both machine reset and boot handler. So we shouldn't return error when the boot handler callback don't be set in patch 1.

Patch 2 check boot order argument validation
before vm running.

Quoted 7 lines

Patch 3 passing &error_abort instead of NULL.

v2 -> v1:
- add patch 2 suggested by Markus.
- rework patch 3. (Markus)
- add R-by in patch 1.

Markus, any thoughts? Thanks.

Regards,
-Gonglei

Quoted 9 lines

Gonglei (3):
bootdevice: remove the check about boot_set_handler
bootdevice: check boot order argument validation before vm running
bootdevice: add check in restore_boot_order()

 bootdevice.c | 12 ++++--------
 vl.c         | 13 +++++++++++--
 2 files changed, 15 insertions(+), 10 deletions(-)