From: Igor Mammedov <imammedo@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Amit Shah" <amit@kernel.org>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
dgilbert@redhat.com, "Richard Henderson" <rth@twiddle.net>,
"Andreas Färber" <afaerber@suse.de>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Artyom Tarasenko" <atar4qemu@gmail.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>
Subject: Re: [Qemu-devel] [PATCH v2 01/10] qom: make user_creatable_complete() specific to UserCreatable
Date: Thu, 1 Nov 2018 12:03:00 +0100 [thread overview]
Message-ID: <20181101120300.2320eda6@redhat.com> (raw)
In-Reply-To: <20181030150453.9344-2-marcandre.lureau@redhat.com>
On Tue, 30 Oct 2018 19:04:44 +0400
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:
> Instead of accepting any Object*, change user_creatable_complete() to
> require a UserCreatable*. Modify the callers to pass the appropriate
> argument, removing redundant dynamic cast checks in object creation.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Nice patch, it also reduces number of dynamic casts originated from
object_initialize_childv/object_new_with_propv.
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> include/qom/object_interfaces.h | 4 ++--
> hw/misc/ivshmem.c | 2 +-
> hw/virtio/virtio-rng.c | 2 +-
> qom/object.c | 12 ++++++++----
> qom/object_interfaces.c | 14 +++-----------
> 5 files changed, 15 insertions(+), 19 deletions(-)
>
> diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
> index 4d513fb329..7450cff908 100644
> --- a/include/qom/object_interfaces.h
> +++ b/include/qom/object_interfaces.h
> @@ -55,14 +55,14 @@ typedef struct UserCreatableClass {
>
> /**
> * user_creatable_complete:
> - * @obj: the object whose complete() method is called if defined
> + * @uc: the user-creatable object whose complete() method is called if defined
> * @errp: if an error occurs, a pointer to an area to store the error
> *
> * Wrapper to call complete() method if one of types it's inherited
> * from implements USER_CREATABLE interface, otherwise the call does
> * nothing.
> */
> -void user_creatable_complete(Object *obj, Error **errp);
> +void user_creatable_complete(UserCreatable *uc, Error **errp);
>
> /**
> * user_creatable_can_be_deleted:
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index f88910e55c..478f41044c 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -1279,7 +1279,7 @@ static void desugar_shm(IVShmemState *s)
> object_property_set_bool(obj, true, "share", &error_abort);
> object_property_add_child(OBJECT(s), "internal-shm-backend", obj,
> &error_abort);
> - user_creatable_complete(obj, &error_abort);
> + user_creatable_complete(USER_CREATABLE(obj), &error_abort);
> s->hostmem = MEMORY_BACKEND(obj);
> }
>
> diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
> index 855f1b41d1..30493a2586 100644
> --- a/hw/virtio/virtio-rng.c
> +++ b/hw/virtio/virtio-rng.c
> @@ -191,7 +191,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
> if (vrng->conf.rng == NULL) {
> vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
>
> - user_creatable_complete(OBJECT(vrng->conf.default_backend),
> + user_creatable_complete(USER_CREATABLE(vrng->conf.default_backend),
> &local_err);
> if (local_err) {
> error_propagate(errp, local_err);
> diff --git a/qom/object.c b/qom/object.c
> index 547dcf97c3..eb770dbf7f 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -417,6 +417,7 @@ void object_initialize_childv(Object *parentobj, const char *propname,
> {
> Error *local_err = NULL;
> Object *obj;
> + UserCreatable *uc;
>
> object_initialize(childobj, size, type);
> obj = OBJECT(childobj);
> @@ -431,8 +432,9 @@ void object_initialize_childv(Object *parentobj, const char *propname,
> goto out;
> }
>
> - if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
> - user_creatable_complete(obj, &local_err);
> + uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
> + if (uc) {
> + user_creatable_complete(uc, &local_err);
> if (local_err) {
> object_unparent(obj);
> goto out;
> @@ -590,6 +592,7 @@ Object *object_new_with_propv(const char *typename,
> Object *obj;
> ObjectClass *klass;
> Error *local_err = NULL;
> + UserCreatable *uc;
>
> klass = object_class_by_name(typename);
> if (!klass) {
> @@ -612,8 +615,9 @@ Object *object_new_with_propv(const char *typename,
> goto error;
> }
>
> - if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
> - user_creatable_complete(obj, &local_err);
> + uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
> + if (uc) {
> + user_creatable_complete(uc, &local_err);
> if (local_err) {
> object_unparent(obj);
> goto error;
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index 97b79b48bb..db85d1eb75 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -8,18 +8,10 @@
> #include "qapi/opts-visitor.h"
> #include "qemu/config-file.h"
>
> -void user_creatable_complete(Object *obj, Error **errp)
> +void user_creatable_complete(UserCreatable *uc, Error **errp)
> {
> + UserCreatableClass *ucc = USER_CREATABLE_GET_CLASS(uc);
>
> - UserCreatableClass *ucc;
> - UserCreatable *uc =
> - (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
> -
> - if (!uc) {
> - return;
> - }
> -
> - ucc = USER_CREATABLE_GET_CLASS(uc);
> if (ucc->complete) {
> ucc->complete(uc, errp);
> }
> @@ -89,7 +81,7 @@ Object *user_creatable_add_type(const char *type, const char *id,
> goto out;
> }
>
> - user_creatable_complete(obj, &local_err);
> + user_creatable_complete(USER_CREATABLE(obj), &local_err);
> if (local_err) {
> object_property_del(object_get_objects_root(),
> id, &error_abort);
next prev parent reply other threads:[~2018-11-01 11:03 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-30 15:04 [Qemu-devel] [PATCH v2 00/10] hostmem: use object "id" for memory region name with >= 3.1 Marc-André Lureau
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 01/10] qom: make user_creatable_complete() specific to UserCreatable Marc-André Lureau
2018-11-01 11:03 ` Igor Mammedov [this message]
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 02/10] accel: register global_props like machine globals Marc-André Lureau
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 03/10] qdev: move qdev_prop_register_global_list() to tests Marc-André Lureau
2018-10-31 20:22 ` Eduardo Habkost
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 04/10] qom/globals: move qdev globals to qom Marc-André Lureau
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 05/10] qom/globals: generalize object_property_set_globals() Marc-André Lureau
2018-10-31 20:12 ` Eduardo Habkost
2018-11-01 10:18 ` Igor Mammedov
2018-11-01 15:27 ` Eduardo Habkost
2018-11-01 15:58 ` Igor Mammedov
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 06/10] qom/object: set globals when initializing object Marc-André Lureau
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 07/10] qom/object: add set_globals flags Marc-André Lureau
2018-10-31 20:23 ` Eduardo Habkost
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 08/10] tests: add user-creatable test to test-qdev-global-props Marc-André Lureau
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 09/10] hw/i386: add pc-i440fx-3.1 & pc-q35-3.1 Marc-André Lureau
2018-10-31 20:14 ` Eduardo Habkost
2018-11-01 14:59 ` Igor Mammedov
2018-11-20 12:00 ` Marc-André Lureau
2018-10-30 15:04 ` [Qemu-devel] [PATCH v2 10/10] hostmem: use object id for memory region name with >= 3.1 Marc-André Lureau
2018-10-31 20:27 ` Eduardo Habkost
2018-11-01 15:16 ` Igor Mammedov
2018-11-01 15:31 ` Eduardo Habkost
2018-10-31 14:41 ` [Qemu-devel] [PATCH v2 00/10] hostmem: use object "id" " no-reply
2018-10-31 14:43 ` no-reply
2018-11-03 3:37 ` no-reply
2018-11-03 3:39 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181101120300.2320eda6@redhat.com \
--to=imammedo@redhat.com \
--cc=afaerber@suse.de \
--cc=amit@kernel.org \
--cc=atar4qemu@gmail.com \
--cc=dgilbert@redhat.com \
--cc=ehabkost@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.