From patchwork Mon Dec 22 08:56:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 423308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6D7401400B7 for ; Mon, 22 Dec 2014 19:59:52 +1100 (AEDT) Received: from localhost ([::1]:39661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2yqE-0006ku-Og for incoming@patchwork.ozlabs.org; Mon, 22 Dec 2014 03:59:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2yoE-0002sp-C7 for qemu-devel@nongnu.org; Mon, 22 Dec 2014 03:57:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y2yo9-0007Ig-9j for qemu-devel@nongnu.org; Mon, 22 Dec 2014 03:57:46 -0500 Received: from szxga01-in.huawei.com ([119.145.14.64]:11218) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2yo7-0007I0-L3 for qemu-devel@nongnu.org; Mon, 22 Dec 2014 03:57:41 -0500 Received: from 172.24.2.119 (EHLO szxeml415-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CGL02538; Mon, 22 Dec 2014 16:57:01 +0800 (CST) Received: from localhost (10.177.19.102) by szxeml415-hub.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.158.1; Mon, 22 Dec 2014 16:56:50 +0800 From: To: Date: Mon, 22 Dec 2014 16:56:37 +0800 Message-ID: <1419238601-5844-2-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 In-Reply-To: <1419238601-5844-1-git-send-email-arei.gonglei@huawei.com> References: <1419238601-5844-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.64 Cc: peter.maydell@linaro.org, Gonglei , Jan Kiszka Subject: [Qemu-devel] [PULL 1/5] bootdevice: move code about bootorder from vl.c to bootdevice.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei 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 --- bootdevice.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/hw.h | 6 ----- include/sysemu/sysemu.h | 8 ++++++ vl.c | 62 ----------------------------------------------- 4 files changed, 70 insertions(+), 68 deletions(-) diff --git a/bootdevice.c b/bootdevice.c index b29970c..aae4cac 100644 --- a/bootdevice.c +++ b/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,67 @@ 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; +} + +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) { diff --git a/include/hw/hw.h b/include/hw/hw.h index 33bdb92..c78adae 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 9fea3bc..84798ef 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); diff --git a/vl.c b/vl.c index 113e98e..f665621 100644 --- a/vl.c +++ b/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",