bootdevice: Refactor and improvement
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAABAgAGBQJUl724AAoJELp6ZbDd4w+7OkkH/1J1GyquLSRSz6tp3nZxBk0A TBtzuKp7isl2qYw/54mJq2WBEBAVP649qLjc6ydYCmLghHlETTY/bzEra5mVhls5 FLYVOAjJK8upnX1MXQcvKoTOcy9RbmUGZpC2VK+Z4aos+oJL094G5o+8GLI2Q0qU ptDdkAjl+sx/vwceAnurhRaPFappQu9NyhMfCvOuKIEdzGltpif7NcFlWmeXxFlj FZ9RXX9hLgwjru+SkfA51f/nSb0UQd30r2TR7UC70sdWvALMWM9a6UL1A2Rftgmb U1159hL8B1dpTvqwxvcvp1NxRua/XEopSHlRSrrqpF7/8WaTIJK4AqgWFifhdo8= =3KIn -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/gonglei/tags/bootdevice-next-20141222' into staging bootdevice: Refactor and improvement # gpg: Signature made Mon 22 Dec 2014 06:44:08 GMT using RSA key ID DDE30FBB # gpg: Can't check signature: public key not found * remotes/gonglei/tags/bootdevice-next-20141222: bootdevice: add Error **errp argument for QEMUBootSetHandler bootdevice: add validate check for qemu_boot_set() bootdevice: add Error **errp argument for qemu_boot_set() bootdevice: add Error **errp argument for validate_bootdevices() bootdevice: move code about bootorder from vl.c to bootdevice.c Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
7e58e2ac77
73
bootdevice.c
73
bootdevice.c
@ -25,6 +25,7 @@
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "qapi/visitor.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "hw/hw.h"
|
||||
|
||||
typedef struct FWBootEntry FWBootEntry;
|
||||
|
||||
@ -37,6 +38,78 @@ struct FWBootEntry {
|
||||
|
||||
static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
|
||||
QTAILQ_HEAD_INITIALIZER(fw_boot_order);
|
||||
static QEMUBootSetHandler *boot_set_handler;
|
||||
static void *boot_set_opaque;
|
||||
|
||||
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
|
||||
{
|
||||
boot_set_handler = func;
|
||||
boot_set_opaque = opaque;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void validate_bootdevices(const char *devices, Error **errp)
|
||||
{
|
||||
/* We just do some generic consistency checks */
|
||||
const char *p;
|
||||
int bitmap = 0;
|
||||
|
||||
for (p = devices; *p != '\0'; p++) {
|
||||
/* Allowed boot devices are:
|
||||
* a-b: floppy disk drives
|
||||
* c-f: IDE disk drives
|
||||
* g-m: machine implementation dependent drives
|
||||
* n-p: network devices
|
||||
* It's up to each machine implementation to check if the given boot
|
||||
* devices match the actual hardware implementation and firmware
|
||||
* features.
|
||||
*/
|
||||
if (*p < 'a' || *p > 'p') {
|
||||
error_setg(errp, "Invalid boot device '%c'", *p);
|
||||
return;
|
||||
}
|
||||
if (bitmap & (1 << (*p - 'a'))) {
|
||||
error_setg(errp, "Boot device '%c' was given twice", *p);
|
||||
return;
|
||||
}
|
||||
bitmap |= 1 << (*p - 'a');
|
||||
}
|
||||
}
|
||||
|
||||
void restore_boot_order(void *opaque)
|
||||
{
|
||||
char *normal_boot_order = opaque;
|
||||
static int first = 1;
|
||||
|
||||
/* Restore boot order and remove ourselves after the first boot */
|
||||
if (first) {
|
||||
first = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_boot_set(normal_boot_order, NULL);
|
||||
|
||||
qemu_unregister_reset(restore_boot_order, normal_boot_order);
|
||||
g_free(normal_boot_order);
|
||||
}
|
||||
|
||||
void check_boot_index(int32_t bootindex, Error **errp)
|
||||
{
|
||||
|
22
hw/i386/pc.c
22
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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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) \
|
||||
|
@ -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, Error **errp);
|
||||
|
||||
/* handler to set the boot_device order for a specific type of QEMUMachine */
|
||||
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);
|
||||
|
||||
QemuOpts *qemu_get_machine_opts(void);
|
||||
|
||||
|
14
monitor.c
14
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
75
vl.c
75
vl.c
@ -196,9 +196,6 @@ NodeInfo numa_info[MAX_NODES];
|
||||
uint8_t qemu_uuid[16];
|
||||
bool qemu_uuid_set;
|
||||
|
||||
static QEMUBootSetHandler *boot_set_handler;
|
||||
static void *boot_set_opaque;
|
||||
|
||||
static NotifierList exit_notifiers =
|
||||
NOTIFIER_LIST_INITIALIZER(exit_notifiers);
|
||||
|
||||
@ -1198,65 +1195,6 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,
|
||||
|
||||
}
|
||||
|
||||
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
|
||||
{
|
||||
boot_set_handler = func;
|
||||
boot_set_opaque = opaque;
|
||||
}
|
||||
|
||||
int qemu_boot_set(const char *boot_order)
|
||||
{
|
||||
if (!boot_set_handler) {
|
||||
return -EINVAL;
|
||||
}
|
||||
return boot_set_handler(boot_set_opaque, boot_order);
|
||||
}
|
||||
|
||||
static void validate_bootdevices(const char *devices)
|
||||
{
|
||||
/* We just do some generic consistency checks */
|
||||
const char *p;
|
||||
int bitmap = 0;
|
||||
|
||||
for (p = devices; *p != '\0'; p++) {
|
||||
/* Allowed boot devices are:
|
||||
* a-b: floppy disk drives
|
||||
* c-f: IDE disk drives
|
||||
* g-m: machine implementation dependent drives
|
||||
* n-p: network devices
|
||||
* It's up to each machine implementation to check if the given boot
|
||||
* devices match the actual hardware implementation and firmware
|
||||
* features.
|
||||
*/
|
||||
if (*p < 'a' || *p > 'p') {
|
||||
fprintf(stderr, "Invalid boot device '%c'\n", *p);
|
||||
exit(1);
|
||||
}
|
||||
if (bitmap & (1 << (*p - 'a'))) {
|
||||
fprintf(stderr, "Boot device '%c' was given twice\n", *p);
|
||||
exit(1);
|
||||
}
|
||||
bitmap |= 1 << (*p - 'a');
|
||||
}
|
||||
}
|
||||
|
||||
static void restore_boot_order(void *opaque)
|
||||
{
|
||||
char *normal_boot_order = opaque;
|
||||
static int first = 1;
|
||||
|
||||
/* Restore boot order and remove ourselves after the first boot */
|
||||
if (first) {
|
||||
first = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_boot_set(normal_boot_order);
|
||||
|
||||
qemu_unregister_reset(restore_boot_order, normal_boot_order);
|
||||
g_free(normal_boot_order);
|
||||
}
|
||||
|
||||
static QemuOptsList qemu_smp_opts = {
|
||||
.name = "smp-opts",
|
||||
.implied_opt_name = "cpus",
|
||||
@ -4149,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);
|
||||
|
Loading…
Reference in New Issue
Block a user