From patchwork Mon Jun 7 23:51:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 54912 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 4056BB7D29 for ; Tue, 8 Jun 2010 10:20:34 +1000 (EST) Received: from localhost ([127.0.0.1]:37651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLmY3-0002vR-2Z for incoming@patchwork.ozlabs.org; Mon, 07 Jun 2010 20:20:07 -0400 Received: from [140.186.70.92] (port=43948 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLm7F-0004NQ-KG for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLm7C-0003AM-Tg for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:25 -0400 Received: from e2.ny.us.ibm.com ([32.97.182.142]:48535) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLm7C-0003AE-P9 for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:22 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by e2.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o57NdqBL020592 for ; Mon, 7 Jun 2010 19:39:52 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o57NqLx31450128 for ; Mon, 7 Jun 2010 19:52:21 -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 o57NqLnL010376 for ; Mon, 7 Jun 2010 20:52:21 -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 o57NqDr0009965; Mon, 7 Jun 2010 20:52:21 -0300 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 7 Jun 2010 18:51:59 -0500 Message-Id: <1275954730-8196-12-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 Subject: [Qemu-devel] [PATCH 11/22] machine: replace compat_props with opts_default 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 Right now, machine structs can hard code GlobalProperty lists of default qdev global properties. This doesn't generalize well to a config file though because there are three parameters: driver, property, value. This patch moves this data to the generic machine opts default list. In the process, it converts the form to driver.property=value. Now any option with a '.' in the name is treated as a compat global property. Signed-off-by: Anthony Liguori diff --git a/hw/boards.h b/hw/boards.h index 06b9f73..c7358ae 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -24,7 +24,6 @@ struct QEMUMachine { no_cdrom:1, no_sdcard:1; int is_default; - GlobalProperty *compat_props; QemuOptDesc *opts_desc; QemuOptValue *opts_default; struct QEMUMachine *next; diff --git a/hw/pc_piix.c b/hw/pc_piix.c index 0ad1145..28c1408 100644 --- a/hw/pc_piix.c +++ b/hw/pc_piix.c @@ -225,20 +225,15 @@ static QEMUMachine pc_machine_v0_12 = { .name = "cpu", .value = PC_DEFAULT_CPU_MODEL, }, - { /* end of list */ } - }, - .compat_props = (GlobalProperty[]) { { - .driver = "virtio-serial-pci", - .property = "max_nr_ports", - .value = stringify(1), + .name = "virtio-serial-pci.max_nr_ports", + .value = stringify(1), },{ - .driver = "virtio-serial-pci", - .property = "vectors", - .value = stringify(0), + .name = "virtio-serial-pci.vectors", + .value = stringify(0), }, { /* end of list */ } - } + }, }; static QEMUMachine pc_machine_v0_11 = { @@ -260,33 +255,24 @@ static QEMUMachine pc_machine_v0_11 = { .name = "cpu", .value = PC_DEFAULT_CPU_MODEL, }, - { /* end of list */ } - }, - .compat_props = (GlobalProperty[]) { { - .driver = "virtio-blk-pci", - .property = "vectors", - .value = stringify(0), + .name = "virtio-blk-pci.vectors", + .value = stringify(0), },{ - .driver = "virtio-serial-pci", - .property = "max_nr_ports", - .value = stringify(1), + .name = "virtio-serial-pci.max_nr_ports", + .value = stringify(1), },{ - .driver = "virtio-serial-pci", - .property = "vectors", - .value = stringify(0), + .name = "virtio-serial-pci.vectors", + .value = stringify(0), },{ - .driver = "ide-drive", - .property = "ver", - .value = "0.11", + .name = "ide-drive.ver", + .value = "0.11", },{ - .driver = "scsi-disk", - .property = "ver", - .value = "0.11", + .name = "scsi-disk.ver", + .value = "0.11", },{ - .driver = "PCI", - .property = "rombar", - .value = stringify(0), + .name = "PCI.rombar", + .value = stringify(0), }, { /* end of list */ } } @@ -311,45 +297,33 @@ static QEMUMachine pc_machine_v0_10 = { .name = "cpu", .value = PC_DEFAULT_CPU_MODEL, }, - { /* end of list */ } - }, - .compat_props = (GlobalProperty[]) { { - .driver = "virtio-blk-pci", - .property = "class", - .value = stringify(PCI_CLASS_STORAGE_OTHER), + .name = "virtio-blk-pci.class", + .value = stringify(PCI_CLASS_STORAGE_OTHER), },{ - .driver = "virtio-serial-pci", - .property = "class", - .value = stringify(PCI_CLASS_DISPLAY_OTHER), + .name = "virtio-serial-pci.class", + .value = stringify(PCI_CLASS_DISPLAY_OTHER), },{ - .driver = "virtio-serial-pci", - .property = "max_nr_ports", - .value = stringify(1), + .name = "virtio-serial-pci.max_nr_ports", + .value = stringify(1), },{ - .driver = "virtio-serial-pci", - .property = "vectors", - .value = stringify(0), + .name = "virtio-serial-pci.vectors", + .value = stringify(0), },{ - .driver = "virtio-net-pci", - .property = "vectors", - .value = stringify(0), + .name = "virtio-net-pci.vectors", + .value = stringify(0), },{ - .driver = "virtio-blk-pci", - .property = "vectors", - .value = stringify(0), + .name = "virtio-blk-pci.vectors", + .value = stringify(0), },{ - .driver = "ide-drive", - .property = "ver", - .value = "0.10", + .name = "ide-drive.ver", + .value = "0.10", },{ - .driver = "scsi-disk", - .property = "ver", - .value = "0.10", + .name = "scsi-disk.ver", + .value = "0.10", },{ - .driver = "PCI", - .property = "rombar", - .value = stringify(0), + .name = "PCI.rombar", + .value = stringify(0), }, { /* end of list */ } }, diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c index ddbefb7..8ed4632 100644 --- a/hw/ppc440_bamboo.c +++ b/hw/ppc440_bamboo.c @@ -183,15 +183,13 @@ static QEMUMachine bamboo_machine_v0_12 = { .name = "bamboo-0.12", .desc = "bamboo", .init = bamboo_init, - .compat_props = (GlobalProperty[]) { + .opts_default = (QemuOptValue[]) { { - .driver = "virtio-serial-pci", - .property = "max_nr_ports", - .value = stringify(1), + .name = "virtio-serial-pci.max_nr_ports", + .value = stringify(1), },{ - .driver = "virtio-serial-pci", - .property = "vectors", - .value = stringify(0), + .name = "virtio-serial-pci.vectors", + .value = stringify(0), }, { /* end of list */ } }, diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 9ffdba7..edd5ebd 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -661,7 +661,7 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props) static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props); -static void qdev_prop_register_global(GlobalProperty *prop) +void qdev_prop_register_global(GlobalProperty *prop) { QTAILQ_INSERT_TAIL(&global_props, prop, next); } diff --git a/hw/qdev.h b/hw/qdev.h index a44060e..9700b7a 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -277,6 +277,7 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_set_defaults(DeviceState *dev, Property *props); +void qdev_prop_register_global(GlobalProperty *props); void qdev_prop_register_global_list(GlobalProperty *props); void qdev_prop_set_globals(DeviceState *dev); diff --git a/vl.c b/vl.c index a7f0a3d..0a31a45 100644 --- a/vl.c +++ b/vl.c @@ -2558,7 +2558,42 @@ static QemuOptDesc common_machine_opts[] = { static int machine_combine_opt(const char *name, const char *value, void *opaque) { QemuOpts *base_opts = opaque; - qemu_opt_set(base_opts, name, value); + char *ptr; + + ptr = strchr(name, '.'); + if (ptr) { + GlobalProperty *prop; + char *driver, *property; + + prop = qemu_mallocz(sizeof(*prop)); + driver = qemu_mallocz(strlen(name) + 1); + property = qemu_mallocz(strlen(name) + 1); + + memcpy(driver, name, (ptr - name)); + driver[(ptr - name)] = 0; + strcpy(property, ptr + 1); + + prop->driver = driver; + prop->property = property; + prop->value = strdup(value); + + qdev_prop_register_global(prop); + } else { + qemu_opt_set(base_opts, name, value); + } + return 0; +} + +static int machine_find(QemuOpts *opts, void *opaque) +{ + QEMUMachine **machinep = opaque; + const char *driver; + + driver = qemu_opt_get(opts, "driver"); + if (driver) { + *machinep = find_machine(driver); + } + return 0; } @@ -3428,20 +3463,20 @@ int main(int argc, char **argv, char **envp) data_dir = CONFIG_QEMU_SHAREDIR; } - /* Combine all -machine options into one option group */ - machine_opts = qemu_opts_create(&qemu_machine_opts, NULL, 0); - qemu_opts_foreach(&qemu_machine_opts, machine_combine_opts, machine_opts, 0); - - if (!qemu_opt_get(machine_opts, "driver")) { + qemu_opts_foreach(&qemu_machine_opts, machine_find, &machine, 0); + if (!machine) { machine = find_default_machine(); - } else { - machine = find_machine(qemu_opt_get(machine_opts, "driver")); } if (machine->opts_default) { - qemu_opts_set_defaults(machine_opts, machine->opts_default); + opts = qemu_opts_create(&qemu_machine_opts, NULL, 0); + qemu_opts_set_defaults(opts, machine->opts_default); } + /* Combine all -machine options into one option group */ + machine_opts = qemu_opts_create(&qemu_machine_opts, NULL, 0); + qemu_opts_foreach(&qemu_machine_opts, machine_combine_opts, machine_opts, 0); + if (machine->opts_desc) { if (qemu_opts_validate(machine_opts, machine->opts_desc) < 0) { exit(1); @@ -3746,9 +3781,6 @@ int main(int argc, char **argv, char **envp) exit (i == 1 ? 1 : 0); } - if (machine->compat_props) { - qdev_prop_register_global_list(machine->compat_props); - } qemu_add_globals(); qemu_opt_set(machine_opts, "boot_device", boot_devices);