qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: "Pavel Fedin" <p.fedin@samsung.com>, "Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v3 1/5] qom: introduce object_property_foreach method
Date: Thu, 8 Oct 2015 10:29:11 -0600	[thread overview]
Message-ID: <561699D7.1010105@redhat.com> (raw)
In-Reply-To: <1444313344-16196-2-git-send-email-berrange@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3955 bytes --]

On 10/08/2015 08:09 AM, Daniel P. Berrange wrote:
> Some users of QOM need to be able to iterate over properties
> defined against an object instance. Currently they are just
> directly using the QTAIL macros against the object properties
> data structure.
> 
> This is bad because it exposes them to changes in the data
> structure used to store properties, as well as changes in
> functionality such as ability to register properties against
> the class.
> 
> Providing an explicit object_property_foreach method provides
> a layer of insulation between the QOM user and the QOM internal
> implementation.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  include/qom/object.h | 23 +++++++++++++++++++++++
>  qom/object.c         | 17 +++++++++++++++++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index be7280c..71503af 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -960,6 +960,29 @@ void object_property_del(Object *obj, const char *name, Error **errp);
>  ObjectProperty *object_property_find(Object *obj, const char *name,
>                                       Error **errp);
>  
> +typedef void (*ObjectPropertyIterator)(Object *obj,
> +                                       ObjectProperty *prop,
> +                                       Error **errp,
> +                                       void *opaque);

Do we want the iterator to be able to return a value, and possibly allow
a non-zero value to abort iteration? [1]

> +
> +/**
> + * object_property_foreach:
> + * @obj: the object
> + * @iter: the iterator callback function
> + * @errp: returns an error if iterator function fails
> + * @opaque: opaque data to pass to @iter
> + *
> + * Iterates over all properties defined against the object
> + * instance calling @iter for each property.

Probably should mention that there is an early exit if error gets set [2]

> + *
> + * It is forbidden to modify the property list from @iter
> + * whether removing or adding properties.
> + */
> +void object_property_foreach(Object *obj,
> +                             ObjectPropertyIterator iter,
> +                             Error **errp,
> +                             void *opaque);

[1] if we allow the iterator to return a non-zero value to abort
iteration (particularly if it wants to abort iteration without setting
an error, just to save CPU cycles), should this foreach() function
return that value?

Of course, a caller can always use opaque to achieve the same purpose,
but it gets more verbose (the caller has to reserve space in their
opaque for tracking whether an interesting exit value is needed, as well
as having an early check on whether the value was already set in a
previous visit) and burns more CPU cycles (the iterator runs to
completion, even though the later callbacks are doing nothing).

> +++ b/qom/object.c
> @@ -917,6 +917,23 @@ ObjectProperty *object_property_find(Object *obj, const char *name,
>      return NULL;
>  }
>  
> +void object_property_foreach(Object *obj,
> +                             ObjectPropertyIterator iter,
> +                             Error **errp,
> +                             void *opaque)
> +{
> +    ObjectProperty *prop;
> +    Error *local_err = NULL;
> +
> +    QTAILQ_FOREACH(prop, &obj->properties, node) {
> +        iter(obj, prop, &local_err, opaque);
> +        if (local_err) {
> +            error_propagate(errp, local_err);
> +            return;

[2] there's the early exit if an error is set.

The code looks fine, but I think we need a documentation improvement for
issue [2], and we may want a design change for issue [1] if a non-void
return would be useful to any client later in the series.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-10-08 16:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-08 14:08 [Qemu-devel] [PATCH v3 0/5] qom: more efficient object property handling Daniel P. Berrange
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 1/5] qom: introduce object_property_foreach method Daniel P. Berrange
2015-10-08 16:29   ` Eric Blake [this message]
2015-10-09  8:31     ` [Qemu-devel] Stick to loops (was: [PATCH v3 1/5] qom: introduce object_property_foreach method) Markus Armbruster
2015-10-12 10:00       ` Daniel P. Berrange
2015-10-12 10:24         ` [Qemu-devel] Stick to loops Paolo Bonzini
2015-10-12 11:56           ` Markus Armbruster
2015-10-13 12:09         ` [Qemu-devel] Stick to loops (was: [PATCH v3 1/5] qom: introduce object_property_foreach method) Daniel P. Berrange
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 2/5] qmp: convert to use object_property_foreach iterators Daniel P. Berrange
2015-10-08 16:35   ` Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 3/5] vl: convert machine help to use object_property_foreach Daniel P. Berrange
2015-10-08 19:06   ` Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 4/5] qom: replace object property list with GHashTable Daniel P. Berrange
2015-10-08 15:05   ` Pavel Fedin
2015-10-08 19:13   ` Eric Blake
2015-10-08 14:09 ` [Qemu-devel] [PATCH v3 5/5] qom: allow properties to be registered against classes Daniel P. Berrange
2015-10-08 19:35   ` Eric Blake
2015-10-08 15:12 ` [Qemu-devel] [PATCH v3 0/5] qom: more efficient object property handling Eric Blake
2015-10-08 15:27 ` Pavel Fedin
2015-10-08 15:48   ` Daniel P. Berrange

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=561699D7.1010105@redhat.com \
    --to=eblake@redhat.com \
    --cc=afaerber@suse.de \
    --cc=berrange@redhat.com \
    --cc=p.fedin@samsung.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).