From patchwork Tue Dec 8 12:11:34 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 40615 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 C5C5CB6F1A for ; Tue, 8 Dec 2009 23:36:47 +1100 (EST) Received: from localhost ([127.0.0.1]:35398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHzJ7-0001Cu-3u for incoming@patchwork.ozlabs.org; Tue, 08 Dec 2009 07:36:45 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHyvN-0005gl-D9 for qemu-devel@nongnu.org; Tue, 08 Dec 2009 07:12:13 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHyvI-0005el-Oe for qemu-devel@nongnu.org; Tue, 08 Dec 2009 07:12:12 -0500 Received: from [199.232.76.173] (port=44197 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHyvI-0005eg-3r for qemu-devel@nongnu.org; Tue, 08 Dec 2009 07:12:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:28809) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NHyvH-00082h-G8 for qemu-devel@nongnu.org; Tue, 08 Dec 2009 07:12:07 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB8CC6BM019020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Dec 2009 07:12:06 -0500 Received: from zweiblum.home.kraxel.org (vpn2-9-91.ams2.redhat.com [10.36.9.91]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB8CC2CJ017078; Tue, 8 Dec 2009 07:12:03 -0500 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 0401F700CB; Tue, 8 Dec 2009 13:11:57 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 8 Dec 2009 13:11:34 +0100 Message-Id: <1260274314-2906-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1260274314-2906-1-git-send-email-kraxel@redhat.com> References: <1260274314-2906-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann , agraf@suse.de, lcapitulino@redhat.com Subject: [Qemu-devel] [FOR 0.12 PATCH v4 02/22] qdev: add command line option to set global defaults for properties. 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 adds infrastructure and command line option for setting global defaults for device properties, i.e. you can for example use -global virtio-blk-pci.vectors=0 to turn off msi by default for all virtio block devices. The config file syntax is: [global] driver = "virtio-blk-pci" property = "vectors" value = "0" This can also be used to set properties for devices which are not created via -device but implicitly via machine init, i.e. -global isa-fdc,driveA= This patch uses the mechanism which configures properties for the compatibility machine types (pc-0.10 & friends). The command line takes precedence over the machine type values. Signed-off-by: Gerd Hoffmann --- qemu-config.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-config.h | 2 + qemu-options.hx | 3 ++ vl.c | 6 +++++ 4 files changed, 67 insertions(+), 0 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 92b5363..a23b125 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -2,6 +2,7 @@ #include "qemu-option.h" #include "qemu-config.h" #include "sysemu.h" +#include "hw/qdev.h" QemuOptsList qemu_drive_opts = { .name = "drive", @@ -205,6 +206,24 @@ QemuOptsList qemu_rtc_opts = { }, }; +QemuOptsList qemu_global_opts = { + .name = "global", + .head = QTAILQ_HEAD_INITIALIZER(qemu_global_opts.head), + .desc = { + { + .name = "driver", + .type = QEMU_OPT_STRING, + },{ + .name = "property", + .type = QEMU_OPT_STRING, + },{ + .name = "value", + .type = QEMU_OPT_STRING, + }, + { /* end if list */ } + }, +}; + static QemuOptsList *lists[] = { &qemu_drive_opts, &qemu_chardev_opts, @@ -212,6 +231,7 @@ static QemuOptsList *lists[] = { &qemu_netdev_opts, &qemu_net_opts, &qemu_rtc_opts, + &qemu_global_opts, NULL, }; @@ -260,6 +280,42 @@ int qemu_set_option(const char *str) return 0; } +int qemu_global_option(const char *str) +{ + char driver[64], property[64]; + QemuOpts *opts; + int rc, offset; + + rc = sscanf(str, "%63[^.].%63[^=]%n", driver, property, &offset); + if (rc < 2 || str[offset] != '=') { + qemu_error("can't parse: \"%s\"\n", str); + return -1; + } + + opts = qemu_opts_create(&qemu_global_opts, NULL, 0); + qemu_opt_set(opts, "driver", driver); + qemu_opt_set(opts, "property", property); + qemu_opt_set(opts, "value", str+offset+1); + return 0; +} + +static int qemu_add_one_global(QemuOpts *opts, void *opaque) +{ + GlobalProperty *g; + + g = qemu_mallocz(sizeof(*g)); + g->driver = qemu_opt_get(opts, "driver"); + g->property = qemu_opt_get(opts, "property"); + g->value = qemu_opt_get(opts, "value"); + qdev_prop_register_global(g); + return 0; +} + +void qemu_add_globals(void) +{ + qemu_opts_foreach(&qemu_global_opts, qemu_add_one_global, NULL, 0); +} + struct ConfigWriteData { QemuOptsList *list; FILE *fp; diff --git a/qemu-config.h b/qemu-config.h index b564851..6246e76 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -9,6 +9,8 @@ extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_rtc_opts; int qemu_set_option(const char *str); +int qemu_global_option(const char *str); +void qemu_add_globals(void); void qemu_config_write(FILE *fp); int qemu_config_parse(FILE *fp); diff --git a/qemu-options.hx b/qemu-options.hx index 1b5781a..b6f3075 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -109,6 +109,9 @@ DEF("set", HAS_ARG, QEMU_OPTION_set, "-set group.id.arg=value\n" " set parameter for item of type \n" " i.e. -set drive.$id.file=/path/to/image\n") +DEF("global", HAS_ARG, QEMU_OPTION_global, + "-global driver.property=value\n" + " set a global default for a driver property\n") STEXI @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] diff --git a/vl.c b/vl.c index a242a11..f7acdd4 100644 --- a/vl.c +++ b/vl.c @@ -4851,6 +4851,10 @@ int main(int argc, char **argv, char **envp) if (qemu_set_option(optarg) != 0) exit(1); break; + case QEMU_OPTION_global: + if (qemu_global_option(optarg) != 0) + exit(1); + break; case QEMU_OPTION_mtdblock: drive_add(optarg, MTD_ALIAS); break; @@ -5781,6 +5785,8 @@ int main(int argc, char **argv, char **envp) if (machine->compat_props) { qdev_prop_register_global_list(machine->compat_props); } + qemu_add_globals(); + machine->init(ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model);