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 <jan.kiszka@siemens.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Gonglei 2014-12-03 16:49:46 +00:00 committed by root
parent 328b3b6c44
commit 9816833d3b
4 changed files with 70 additions and 68 deletions

View File

@ -25,6 +25,7 @@
#include "sysemu/sysemu.h" #include "sysemu/sysemu.h"
#include "qapi/visitor.h" #include "qapi/visitor.h"
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "hw/hw.h"
typedef struct FWBootEntry FWBootEntry; typedef struct FWBootEntry FWBootEntry;
@ -37,6 +38,67 @@ struct FWBootEntry {
static QTAILQ_HEAD(, FWBootEntry) fw_boot_order = static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
QTAILQ_HEAD_INITIALIZER(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;
}
int qemu_boot_set(const char *boot_order)
{
if (!boot_set_handler) {
return -EINVAL;
}
return boot_set_handler(boot_set_opaque, boot_order);
}
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');
}
}
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);
}
void check_boot_index(int32_t bootindex, Error **errp) void check_boot_index(int32_t bootindex, Error **errp)
{ {

View File

@ -41,12 +41,6 @@ typedef void QEMUResetHandler(void *opaque);
void qemu_register_reset(QEMUResetHandler *func, void *opaque); void qemu_register_reset(QEMUResetHandler *func, void *opaque);
void qemu_unregister_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 #ifdef NEED_CPU_H
#if TARGET_LONG_BITS == 64 #if TARGET_LONG_BITS == 64
#define VMSTATE_UINTTL_V(_f, _s, _v) \ #define VMSTATE_UINTTL_V(_f, _s, _v) \

View File

@ -216,6 +216,14 @@ void del_boot_device_path(DeviceState *dev, const char *suffix);
void device_add_bootindex_property(Object *obj, int32_t *bootindex, 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 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); QemuOpts *qemu_get_machine_opts(void);

62
vl.c
View File

@ -196,9 +196,6 @@ NodeInfo numa_info[MAX_NODES];
uint8_t qemu_uuid[16]; uint8_t qemu_uuid[16];
bool qemu_uuid_set; bool qemu_uuid_set;
static QEMUBootSetHandler *boot_set_handler;
static void *boot_set_opaque;
static NotifierList exit_notifiers = static NotifierList exit_notifiers =
NOTIFIER_LIST_INITIALIZER(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 = { static QemuOptsList qemu_smp_opts = {
.name = "smp-opts", .name = "smp-opts",
.implied_opt_name = "cpus", .implied_opt_name = "cpus",