提交 703008e8 编写于 作者: G Gonglei 提交者: root

bootdevice: add Error **errp argument for validate_bootdevices()

It will be useful for checking when we change traditional
boot order dynamically and propagate error message
to the monitor.
Signed-off-by: NGonglei <arei.gonglei@huawei.com>
Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
上级 9816833d
...@@ -55,7 +55,7 @@ int qemu_boot_set(const char *boot_order) ...@@ -55,7 +55,7 @@ int qemu_boot_set(const char *boot_order)
return boot_set_handler(boot_set_opaque, boot_order); return boot_set_handler(boot_set_opaque, boot_order);
} }
void validate_bootdevices(const char *devices) void validate_bootdevices(const char *devices, Error **errp)
{ {
/* We just do some generic consistency checks */ /* We just do some generic consistency checks */
const char *p; const char *p;
...@@ -72,12 +72,12 @@ void validate_bootdevices(const char *devices) ...@@ -72,12 +72,12 @@ void validate_bootdevices(const char *devices)
* features. * features.
*/ */
if (*p < 'a' || *p > 'p') { if (*p < 'a' || *p > 'p') {
fprintf(stderr, "Invalid boot device '%c'\n", *p); error_setg(errp, "Invalid boot device '%c'", *p);
exit(1); return;
} }
if (bitmap & (1 << (*p - 'a'))) { if (bitmap & (1 << (*p - 'a'))) {
fprintf(stderr, "Boot device '%c' was given twice\n", *p); error_setg(errp, "Boot device '%c' was given twice", *p);
exit(1); return;
} }
bitmap |= 1 << (*p - 'a'); bitmap |= 1 << (*p - 'a');
} }
......
...@@ -217,7 +217,7 @@ void device_add_bootindex_property(Object *obj, int32_t *bootindex, ...@@ -217,7 +217,7 @@ void device_add_bootindex_property(Object *obj, int32_t *bootindex,
const char *name, const char *suffix, const char *name, const char *suffix,
DeviceState *dev, Error **errp); DeviceState *dev, Error **errp);
void restore_boot_order(void *opaque); void restore_boot_order(void *opaque);
void validate_bootdevices(const char *devices); void validate_bootdevices(const char *devices, Error **errp);
/* handler to set the boot_device order for a specific type of QEMUMachine */ /* handler to set the boot_device order for a specific type of QEMUMachine */
/* return 0 if success */ /* return 0 if success */
......
...@@ -4087,16 +4087,25 @@ int main(int argc, char **argv, char **envp) ...@@ -4087,16 +4087,25 @@ int main(int argc, char **argv, char **envp)
if (opts) { if (opts) {
char *normal_boot_order; char *normal_boot_order;
const char *order, *once; const char *order, *once;
Error *local_err = NULL;
order = qemu_opt_get(opts, "order"); order = qemu_opt_get(opts, "order");
if (order) { if (order) {
validate_bootdevices(order); validate_bootdevices(order, &local_err);
if (local_err) {
error_report("%s", error_get_pretty(local_err));
exit(1);
}
boot_order = order; boot_order = order;
} }
once = qemu_opt_get(opts, "once"); once = qemu_opt_get(opts, "once");
if (once) { if (once) {
validate_bootdevices(once); validate_bootdevices(once, &local_err);
if (local_err) {
error_report("%s", error_get_pretty(local_err));
exit(1);
}
normal_boot_order = g_strdup(boot_order); normal_boot_order = g_strdup(boot_order);
boot_order = once; boot_order = once;
qemu_register_reset(restore_boot_order, normal_boot_order); qemu_register_reset(restore_boot_order, normal_boot_order);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册