From 9816833d3b8ec9adfb63b6a53f1b56f5304f4c40 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 3 Dec 2014 16:49:46 +0000 Subject: bootdevice: move code about bootorder from vl.c to bootdevice.c First, we can downsize vl.c, make it simpler by little and little. Second, I can maintain those code and make some improvement. Cc: Jan Kiszka Signed-off-by: Gonglei Reviewed-by: Markus Armbruster --- include/hw/hw.h | 6 ------ include/sysemu/sysemu.h | 8 ++++++++ 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/hw/hw.h b/include/hw/hw.h index 33bdb92712..c78adae06a 100644 --- a/include/hw/hw.h +++ b/include/hw/hw.h @@ -41,12 +41,6 @@ typedef void QEMUResetHandler(void *opaque); void qemu_register_reset(QEMUResetHandler *func, void *opaque); void qemu_unregister_reset(QEMUResetHandler *func, void *opaque); -/* handler to set the boot_device order for a specific type of QEMUMachine */ -/* 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); - #ifdef NEED_CPU_H #if TARGET_LONG_BITS == 64 #define VMSTATE_UINTTL_V(_f, _s, _v) \ diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 9fea3bc3af..84798efd72 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -216,6 +216,14 @@ void del_boot_device_path(DeviceState *dev, const char *suffix); void device_add_bootindex_property(Object *obj, int32_t *bootindex, const char *name, const char *suffix, DeviceState *dev, Error **errp); +void restore_boot_order(void *opaque); +void validate_bootdevices(const char *devices); + +/* handler to set the boot_device order for a specific type of QEMUMachine */ +/* 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); QemuOpts *qemu_get_machine_opts(void); -- cgit v1.2.3-55-g7522 From 703008e81a6ace40f227aae16d630014e5016af1 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 3 Dec 2014 17:11:39 +0000 Subject: 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: Gonglei Reviewed-by: Markus Armbruster --- bootdevice.c | 10 +++++----- include/sysemu/sysemu.h | 2 +- vl.c | 13 +++++++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/bootdevice.c b/bootdevice.c index aae4cac27f..184348ecd2 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -55,7 +55,7 @@ int qemu_boot_set(const char *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 */ const char *p; @@ -72,12 +72,12 @@ void validate_bootdevices(const char *devices) * features. */ if (*p < 'a' || *p > 'p') { - fprintf(stderr, "Invalid boot device '%c'\n", *p); - exit(1); + error_setg(errp, "Invalid boot device '%c'", *p); + return; } if (bitmap & (1 << (*p - 'a'))) { - fprintf(stderr, "Boot device '%c' was given twice\n", *p); - exit(1); + error_setg(errp, "Boot device '%c' was given twice", *p); + return; } bitmap |= 1 << (*p - 'a'); } diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 84798efd72..1382d63fb1 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -217,7 +217,7 @@ void device_add_bootindex_property(Object *obj, int32_t *bootindex, const char *name, const char *suffix, DeviceState *dev, Error **errp); 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 */ /* return 0 if success */ diff --git a/vl.c b/vl.c index f665621f12..a824a7d8b4 100644 --- a/vl.c +++ b/vl.c @@ -4087,16 +4087,25 @@ int main(int argc, char **argv, char **envp) if (opts) { char *normal_boot_order; const char *order, *once; + Error *local_err = NULL; order = qemu_opt_get(opts, "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; } once = qemu_opt_get(opts, "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); boot_order = once; qemu_register_reset(restore_boot_order, normal_boot_order); -- cgit v1.2.3-55-g7522 From f1839938b090b28537d9be2c1b255b834f3cfbb8 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 3 Dec 2014 18:20:58 +0000 Subject: bootdevice: add Error **errp argument for qemu_boot_set() It will be useful for checking when we change traditional boot order dynamically and propagate error message to the monitor. Signed-off-by: Gonglei Reviewed-by: Markus Armbruster --- bootdevice.c | 14 ++++++++++---- include/sysemu/sysemu.h | 2 +- monitor.c | 14 ++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/bootdevice.c b/bootdevice.c index 184348ecd2..7f07507a95 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -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) @@ -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); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 1382d63fb1..ee7fee7726 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -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); diff --git a/monitor.c b/monitor.c index 503cf515ad..1808e41932 100644 --- a/monitor.c +++ b/monitor.c @@ -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); } } -- cgit v1.2.3-55-g7522 From ddcd55316fb2851e144e719171621ad2816487dc Mon Sep 17 00:00:00 2001 From: Gonglei Date: Wed, 3 Dec 2014 19:04:02 +0000 Subject: bootdevice: add Error **errp argument for QEMUBootSetHandler It will be useful for checking when we change traditional boot order dynamically and propagate error message to the monitor. For x86 architecture, we pass &local_err to set_boot_dev() when vm startup in pc_coms_init(). Cc: Michael S. Tsirkin Cc: Alexander Graf Cc: Blue Swirl Cc: qemu-ppc@nongnu.org Signed-off-by: Gonglei Reviewed-by: Markus Armbruster --- bootdevice.c | 5 +---- hw/i386/pc.c | 22 ++++++++++++---------- hw/ppc/mac_newworld.c | 4 ++-- hw/ppc/mac_oldworld.c | 5 ++--- hw/sparc/sun4m.c | 4 ++-- hw/sparc64/sun4u.c | 4 ++-- include/sysemu/sysemu.h | 4 ++-- 7 files changed, 23 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/bootdevice.c b/bootdevice.c index 9de34babb0..5914417027 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -63,10 +63,7 @@ void qemu_boot_set(const char *boot_order, Error **errp) return; } - if (boot_set_handler(boot_set_opaque, boot_order)) { - error_setg(errp, "setting boot device list failed"); - return; - } + boot_set_handler(boot_set_opaque, boot_order, errp); } void validate_bootdevices(const char *devices, Error **errp) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c0e55a6446..1ec7290dca 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -282,7 +282,7 @@ static int boot_device2nibble(char boot_device) return 0; } -static int set_boot_dev(ISADevice *s, const char *boot_device) +static void set_boot_dev(ISADevice *s, const char *boot_device, Error **errp) { #define PC_MAX_BOOT_DEVICES 3 int nbds, bds[3] = { 0, }; @@ -290,25 +290,24 @@ static int set_boot_dev(ISADevice *s, const char *boot_device) nbds = strlen(boot_device); if (nbds > PC_MAX_BOOT_DEVICES) { - error_report("Too many boot devices for PC"); - return(1); + error_setg(errp, "Too many boot devices for PC"); + return; } for (i = 0; i < nbds; i++) { bds[i] = boot_device2nibble(boot_device[i]); if (bds[i] == 0) { - error_report("Invalid boot device for PC: '%c'", - boot_device[i]); - return(1); + error_setg(errp, "Invalid boot device for PC: '%c'", + boot_device[i]); + return; } } rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]); rtc_set_memory(s, 0x38, (bds[2] << 4) | (fd_bootchk ? 0x0 : 0x1)); - return(0); } -static int pc_boot_set(void *opaque, const char *boot_device) +static void pc_boot_set(void *opaque, const char *boot_device, Error **errp) { - return set_boot_dev(opaque, boot_device); + set_boot_dev(opaque, boot_device, errp); } typedef struct pc_cmos_init_late_arg { @@ -365,6 +364,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE }; static pc_cmos_init_late_arg arg; PCMachineState *pc_machine = PC_MACHINE(machine); + Error *local_err = NULL; /* various important CMOS locations needed by PC/Bochs bios */ @@ -412,7 +412,9 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, object_property_set_link(OBJECT(machine), OBJECT(s), "rtc_state", &error_abort); - if (set_boot_dev(s, boot_device)) { + set_boot_dev(s, boot_device, &local_err); + if (local_err) { + error_report("%s", error_get_pretty(local_err)); exit(1); } diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c index 89aee716d4..ee1ed8a344 100644 --- a/hw/ppc/mac_newworld.c +++ b/hw/ppc/mac_newworld.c @@ -116,10 +116,10 @@ static const MemoryRegionOps unin_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int fw_cfg_boot_set(void *opaque, const char *boot_device) +static void fw_cfg_boot_set(void *opaque, const char *boot_device, + Error **errp) { fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); - return 0; } static uint64_t translate_kernel_address(void *opaque, uint64_t addr) diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c index 32c21a4286..15109c294a 100644 --- a/hw/ppc/mac_oldworld.c +++ b/hw/ppc/mac_oldworld.c @@ -49,13 +49,12 @@ #define CLOCKFREQ 266000000UL #define BUSFREQ 66000000UL -static int fw_cfg_boot_set(void *opaque, const char *boot_device) +static void fw_cfg_boot_set(void *opaque, const char *boot_device, + Error **errp) { fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); - return 0; } - static uint64_t translate_kernel_address(void *opaque, uint64_t addr) { return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR; diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c index 8273199f11..df259ad605 100644 --- a/hw/sparc/sun4m.c +++ b/hw/sparc/sun4m.c @@ -121,10 +121,10 @@ void DMA_register_channel (int nchan, { } -static int fw_cfg_boot_set(void *opaque, const char *boot_device) +static void fw_cfg_boot_set(void *opaque, const char *boot_device, + Error **errp) { fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); - return 0; } static void nvram_init(M48t59State *nvram, uint8_t *macaddr, diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index f42112c1b2..acac8f9ed0 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -124,10 +124,10 @@ void DMA_register_channel (int nchan, { } -static int fw_cfg_boot_set(void *opaque, const char *boot_device) +static void fw_cfg_boot_set(void *opaque, const char *boot_device, + Error **errp) { fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); - return 0; } static int sun4u_NVRAM_set_params(M48t59State *nvram, uint16_t NVRAM_size, diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index ee7fee7726..503e5a48a7 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -220,8 +220,8 @@ void restore_boot_order(void *opaque); void validate_bootdevices(const char *devices, Error **errp); /* handler to set the boot_device order for a specific type of QEMUMachine */ -/* return 0 if success */ -typedef int QEMUBootSetHandler(void *opaque, const char *boot_order); +typedef void QEMUBootSetHandler(void *opaque, const char *boot_order, + Error **errp); void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque); void qemu_boot_set(const char *boot_order, Error **errp); -- cgit v1.2.3-55-g7522