From patchwork Mon Jun 7 23:51:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 54901 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 49A68B7D47 for ; Tue, 8 Jun 2010 09:59:10 +1000 (EST) Received: from localhost ([127.0.0.1]:45862 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLmDU-0007Xl-9Q for incoming@patchwork.ozlabs.org; Mon, 07 Jun 2010 19:58:52 -0400 Received: from [140.186.70.92] (port=43889 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLm7C-0004L2-Bp for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLm78-00038k-Md for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:22 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:57775) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLm78-00038D-FU for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:18 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e9.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o57NbqI4008904 for ; Mon, 7 Jun 2010 19:37:52 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o57NqHpW078580 for ; Mon, 7 Jun 2010 19:52:17 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o57NqGc5010112 for ; Mon, 7 Jun 2010 20:52:17 -0300 Received: from localhost.localdomain (sig-9-65-84-205.mts.ibm.com [9.65.84.205]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o57NqDqr009965; Mon, 7 Jun 2010 20:52:16 -0300 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 7 Jun 2010 18:51:52 -0500 Message-Id: <1275954730-8196-5-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1275954730-8196-1-git-send-email-aliguori@us.ibm.com> References: <1275954730-8196-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Glauber Costa , Anthony Liguori , Gerd Hoffman Subject: [Qemu-devel] [PATCH 04/22] machine: package all init arguments into a QemuOpts (v2) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch creates a QemuOpts structure and stores all of the machine init arguments in that structure. It introduces a temporary list of QemuOptDescs in vl.c such that the current common options can be validated. The long term vision is that that list becomes a #define and that each machine can optionally provide it's own QemuOptDescs list using the common options as a base. This enables per-machine options. Signed-off-by: Anthony Liguori --- v1 -> v2: - cpu_model -> cpu diff --git a/hw/pc.c b/hw/pc.c index 9b85c42..48b3730 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -534,6 +534,10 @@ static void load_linux(void *fw_cfg, FILE *f; char *vmode; + if (!kernel_cmdline) { + kernel_cmdline = ""; + } + /* Align to 16 bytes as a paranoia measure */ cmdline_size = (strlen(kernel_cmdline)+16) & ~15; diff --git a/qemu-config.c b/qemu-config.c index 5a4e61b..3679a9f 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -336,6 +336,14 @@ QemuOptsList qemu_cpudef_opts = { }, }; +QemuOptsList qemu_machine_opts = { + .name = "machine", + .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), + .desc = { + { /* end of list */ } + }, +}; + static QemuOptsList *vm_config_groups[] = { &qemu_drive_opts, &qemu_chardev_opts, @@ -346,6 +354,7 @@ static QemuOptsList *vm_config_groups[] = { &qemu_global_opts, &qemu_mon_opts, &qemu_cpudef_opts, + &qemu_machine_opts, NULL, }; diff --git a/qemu-config.h b/qemu-config.h index dca69d4..6f52188 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -14,6 +14,7 @@ extern QemuOptsList qemu_rtc_opts; extern QemuOptsList qemu_global_opts; extern QemuOptsList qemu_mon_opts; extern QemuOptsList qemu_cpudef_opts; +extern QemuOptsList qemu_machine_opts; QemuOptsList *qemu_find_opts(const char *group); int qemu_set_option(const char *str); diff --git a/vl.c b/vl.c index 7121cd0..5349fd5 100644 --- a/vl.c +++ b/vl.c @@ -2550,6 +2550,35 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } +/* TEMP: until we have proper -machine support */ +static QemuOptDesc common_machine_opts[] = { + { + .name = "ram_size", + .type = QEMU_OPT_SIZE, + }, + { + .name = "kernel", + .type = QEMU_OPT_STRING, + }, + { + .name = "cmdline", + .type = QEMU_OPT_STRING, + }, + { + .name = "initrd", + .type = QEMU_OPT_STRING, + }, + { + .name = "boot_device", + .type = QEMU_OPT_STRING, + }, + { + .name = "cpu", + .type = QEMU_OPT_STRING, + }, + { /* end of list */ }, +}; + int main(int argc, char **argv, char **envp) { const char *gdbstub_dev = NULL; @@ -3718,8 +3747,42 @@ int main(int argc, char **argv, char **envp) } qemu_add_globals(); - machine->init(ram_size, boot_devices, - kernel_filename, kernel_cmdline, initrd_filename, cpu_model); + opts = qemu_opts_create(&qemu_machine_opts, NULL, 0); + if (kernel_filename) { + qemu_opt_set(opts, "kernel", kernel_filename); + if (kernel_cmdline) { + qemu_opt_set(opts, "cmdline", kernel_cmdline); + } + if (initrd_filename) { + qemu_opt_set(opts, "initrd", initrd_filename); + } + } + + qemu_opt_set(opts, "boot_device", boot_devices); + + if (cpu_model) { + qemu_opt_set(opts, "cpu", cpu_model); + } + + if (ram_size) { + char buffer[64]; + snprintf(buffer, sizeof(buffer), + "%" PRId64, ram_size); + qemu_opt_set(opts, "ram_size", buffer); + } + + if (qemu_opts_validate(opts, common_machine_opts) < 0) { + exit(1); + } + + machine->init(qemu_opt_get_size(opts, "ram_size"), + qemu_opt_get(opts, "boot_device"), + qemu_opt_get(opts, "kernel"), + qemu_opt_get(opts, "cmdline"), + qemu_opt_get(opts, "initrd"), + qemu_opt_get(opts, "cpu")); + + qemu_opts_del(opts); cpu_synchronize_all_post_init();