Skip to content

Commit

Permalink
bootdevice: add Error **errp argument for qemu_boot_set()
Browse files Browse the repository at this point in the history
It will be useful for checking when we change traditional
boot order dynamically and propagate error message
to the monitor.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
  • Loading branch information
gongleiarei authored and root committed Dec 22, 2014
1 parent 703008e commit f183993
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
14 changes: 10 additions & 4 deletions bootdevice.c
Expand Up @@ -47,12 +47,18 @@ void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
boot_set_opaque = opaque;
}

int qemu_boot_set(const char *boot_order)
void qemu_boot_set(const char *boot_order, Error **errp)
{
if (!boot_set_handler) {
return -EINVAL;
error_setg(errp, "no function defined to set boot device list for"
" this architecture");
return;
}

if (boot_set_handler(boot_set_opaque, boot_order)) {
error_setg(errp, "setting boot device list failed");
return;
}
return boot_set_handler(boot_set_opaque, boot_order);
}

void validate_bootdevices(const char *devices, Error **errp)
Expand Down Expand Up @@ -94,7 +100,7 @@ void restore_boot_order(void *opaque)
return;
}

qemu_boot_set(normal_boot_order);
qemu_boot_set(normal_boot_order, NULL);

qemu_unregister_reset(restore_boot_order, normal_boot_order);
g_free(normal_boot_order);
Expand Down
2 changes: 1 addition & 1 deletion include/sysemu/sysemu.h
Expand Up @@ -223,7 +223,7 @@ void validate_bootdevices(const char *devices, Error **errp);
/* return 0 if success */
typedef int QEMUBootSetHandler(void *opaque, const char *boot_order);
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
int qemu_boot_set(const char *boot_order);
void qemu_boot_set(const char *boot_order, Error **errp);

QemuOpts *qemu_get_machine_opts(void);

Expand Down
14 changes: 6 additions & 8 deletions monitor.c
Expand Up @@ -1494,17 +1494,15 @@ static void do_ioport_write(Monitor *mon, const QDict *qdict)

static void do_boot_set(Monitor *mon, const QDict *qdict)
{
int res;
Error *local_err = NULL;
const char *bootdevice = qdict_get_str(qdict, "bootdevice");

res = qemu_boot_set(bootdevice);
if (res == 0) {
monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
} else if (res > 0) {
monitor_printf(mon, "setting boot device list failed\n");
qemu_boot_set(bootdevice, &local_err);
if (local_err) {
monitor_printf(mon, "%s\n", error_get_pretty(local_err));
error_free(local_err);
} else {
monitor_printf(mon, "no function defined to set boot device list for "
"this architecture\n");
monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
}
}

Expand Down

0 comments on commit f183993

Please sign in to comment.