From patchwork Wed Nov 7 12:36:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 994233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qmMy1bFlz9sB7 for ; Wed, 7 Nov 2018 23:45:02 +1100 (AEDT) Received: from localhost ([::1]:47657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNCd-0006Bm-P0 for incoming@patchwork.ozlabs.org; Wed, 07 Nov 2018 07:44:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKN5t-0005vV-Gw for qemu-devel@nongnu.org; Wed, 07 Nov 2018 07:38:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKN5s-0006fa-5i for qemu-devel@nongnu.org; Wed, 07 Nov 2018 07:38:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39086) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gKN5n-0006bX-GE; Wed, 07 Nov 2018 07:37:55 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CE9E30B7DF5; Wed, 7 Nov 2018 12:37:54 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCF4F18E3D; Wed, 7 Nov 2018 12:37:46 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 16:36:44 +0400 Message-Id: <20181107123652.23417-7-marcandre.lureau@redhat.com> In-Reply-To: <20181107123652.23417-1-marcandre.lureau@redhat.com> References: <20181107123652.23417-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 07 Nov 2018 12:37:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 v3 06/14] qdev: do not mix compat props with global props X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefano Stabellini , xen-devel@lists.xenproject.org, Corey Minyard , Amit Shah , =?utf-8?q?Herv=C3=A9_Poussineau?= , "Michael S. Tsirkin" , Mark Cave-Ayland , dgilbert@redhat.com, Eduardo Habkost , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , Anthony Perard , Paolo Bonzini , Stefan Berger , =?utf-8?q?Andreas_F=C3=A4rber?= , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Machine & Accel props are not provided by user. Let's not mix them with the global properties. Call a new helper function object_apply_global_props() during device_post_init(). Add a stub for current_machine, so qemu-user and tests can find a fallback symbol when linking with QDev. The following patches is going to reuse object_apply_global_props() for qdev globals. Signed-off-by: Marc-André Lureau --- include/hw/boards.h | 1 - include/qom/object.h | 2 ++ include/sysemu/accel.h | 4 +--- accel/accel.c | 12 ------------ hw/core/machine.c | 18 ------------------ hw/core/qdev.c | 8 ++++++++ hw/xen/xen-common.c | 9 ++++++++- qom/object.c | 25 +++++++++++++++++++++++++ stubs/machine.c | 4 ++++ tests/test-qdev-global-props.c | 1 - vl.c | 2 -- stubs/Makefile.objs | 1 + 12 files changed, 49 insertions(+), 38 deletions(-) create mode 100644 stubs/machine.c diff --git a/include/hw/boards.h b/include/hw/boards.h index f82f28468b..c02190fc52 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -69,7 +69,6 @@ int machine_kvm_shadow_mem(MachineState *machine); int machine_phandle_start(MachineState *machine); bool machine_dump_guest_core(MachineState *machine); bool machine_mem_merge(MachineState *machine); -void machine_register_compat_props(MachineState *machine); HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine); void machine_set_cpu_numa_node(MachineState *machine, const CpuInstanceProperties *props, diff --git a/include/qom/object.h b/include/qom/object.h index f0b0bf39cc..e58eeb280f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -679,6 +679,8 @@ Object *object_new_with_propv(const char *typename, Error **errp, va_list vargs); +void object_apply_global_props(Object *obj, GArray *props, Error **errp); + /** * object_set_props: * @obj: the object instance to set properties on diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h index 637358f430..f4f71134b5 100644 --- a/include/sysemu/accel.h +++ b/include/sysemu/accel.h @@ -49,7 +49,7 @@ typedef struct AccelClass { * global properties may be overridden by machine-type * compat_props or user-provided global properties. */ - GlobalProperty *global_props; + GArray *compat_props; } AccelClass; #define TYPE_ACCEL "accel" @@ -67,8 +67,6 @@ typedef struct AccelClass { extern unsigned long tcg_tb_size; void configure_accelerator(MachineState *ms); -/* Register accelerator specific global properties */ -void accel_register_compat_props(AccelState *accel); /* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post(MachineState *ms); diff --git a/accel/accel.c b/accel/accel.c index 3da26eb90f..6db5d8f4df 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -119,18 +119,6 @@ void configure_accelerator(MachineState *ms) } } -void accel_register_compat_props(AccelState *accel) -{ - AccelClass *class = ACCEL_GET_CLASS(accel); - GlobalProperty *prop = class->global_props; - - for (; prop && prop->driver; prop++) { - /* Any compat_props must never cause error */ - prop->errp = &error_abort; - qdev_prop_register_global(prop); - } -} - void accel_setup_post(MachineState *ms) { AccelState *accel = ms->accelerator; diff --git a/hw/core/machine.c b/hw/core/machine.c index da50ad6de7..4444d45945 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -844,24 +844,6 @@ static void machine_class_finalize(ObjectClass *klass, void *data) g_free(mc->name); } -void machine_register_compat_props(MachineState *machine) -{ - MachineClass *mc = MACHINE_GET_CLASS(machine); - int i; - GlobalProperty *p; - - if (!mc->compat_props) { - return; - } - - for (i = 0; i < mc->compat_props->len; i++) { - p = g_array_index(mc->compat_props, GlobalProperty *, i); - /* Machine compat_props must never cause errors: */ - p->errp = &error_abort; - qdev_prop_register_global(p); - } -} - static const TypeInfo machine_info = { .name = TYPE_MACHINE, .parent = TYPE_OBJECT, diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 6b3cc55b27..30890f2c8d 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -972,6 +972,14 @@ static void device_initfn(Object *obj) static void device_post_init(Object *obj) { + if (current_machine) { + MachineClass *mc = MACHINE_GET_CLASS(current_machine); + AccelClass *ac = ACCEL_GET_CLASS(current_machine->accelerator); + + object_apply_global_props(obj, mc->compat_props, &error_abort); + object_apply_global_props(obj, ac->compat_props, &error_abort); + } + qdev_prop_set_globals(DEVICE(obj)); } diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c index 6ec14c73ca..d1ef7a53cc 100644 --- a/hw/xen/xen-common.c +++ b/hw/xen/xen-common.c @@ -181,11 +181,18 @@ static GlobalProperty xen_compat_props[] = { static void xen_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); + int i; + ac->name = "Xen"; ac->init_machine = xen_init; ac->setup_post = xen_setup_post; ac->allowed = &xen_allowed; - ac->global_props = xen_compat_props; + + ac->compat_props = g_array_new(false, false, sizeof(void *)); + for (i = 0; xen_compat_props[i].driver != NULL; i++) { + GlobalProperty *prop = &xen_compat_props[i]; + g_array_append_val(ac->compat_props, prop); + } } #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen") diff --git a/qom/object.c b/qom/object.c index eb770dbf7f..9acdf9e16d 100644 --- a/qom/object.c +++ b/qom/object.c @@ -372,6 +372,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti) } } +void object_apply_global_props(Object *obj, GArray *props, Error **errp) +{ + Error *err = NULL; + int i; + + if (!props) { + return; + } + + for (i = 0; i < props->len; i++) { + GlobalProperty *p = g_array_index(props, GlobalProperty *, i); + + if (object_dynamic_cast(obj, p->driver) == NULL) { + continue; + } + p->used = true; + object_property_parse(obj, p->value, p->property, &err); + if (err != NULL) { + error_prepend(&err, "can't apply global %s.%s=%s: ", + p->driver, p->property, p->value); + error_propagate(errp, err); + } + } +} + static void object_initialize_with_type(void *data, size_t size, TypeImpl *type) { Object *obj = data; diff --git a/stubs/machine.c b/stubs/machine.c new file mode 100644 index 0000000000..51d40fd677 --- /dev/null +++ b/stubs/machine.c @@ -0,0 +1,4 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" + +MachineClass *current_machine; diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c index b1eb505442..3a8d3170a0 100644 --- a/tests/test-qdev-global-props.c +++ b/tests/test-qdev-global-props.c @@ -28,7 +28,6 @@ #include "qom/object.h" #include "qapi/visitor.h" - #define TYPE_STATIC_PROPS "static_prop_type" #define STATIC_TYPE(obj) \ OBJECT_CHECK(MyType, (obj), TYPE_STATIC_PROPS) diff --git a/vl.c b/vl.c index 55bab005b6..2aea884c9d 100644 --- a/vl.c +++ b/vl.c @@ -2963,8 +2963,6 @@ static void user_register_global_props(void) */ static void register_global_properties(MachineState *ms) { - accel_register_compat_props(ms->accelerator); - machine_register_compat_props(ms); user_register_global_props(); } diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 5dd0aeeec6..6ce33ae46f 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -18,6 +18,7 @@ stub-obj-y += iothread-lock.o stub-obj-y += is-daemonized.o stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o stub-obj-y += machine-init-done.o +stub-obj-y += machine.o stub-obj-y += migr-blocker.o stub-obj-y += change-state-handler.o stub-obj-y += monitor.o