From: Paolo Bonzini <pbonzini@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v1 RFC 07/34] qom: don't pass string table to object_get_enum method
Date: Fri, 17 Apr 2015 17:05:44 +0200 [thread overview]
Message-ID: <55312148.6070005@redhat.com> (raw)
In-Reply-To: <1429280557-8887-8-git-send-email-berrange@redhat.com>
On 17/04/2015 16:22, Daniel P. Berrange wrote:
> Now that properties can be explicitly registered as an enum
> type, there is no need to pass the string table to the
> object_get_enum method. The object property registration
> already has a pointer to the string table.
>
> In changing this method signature, the hostmem backend object
> has to be converted to use the new enum property registration
> code, which simplifies it somewhat.
>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
> backends/hostmem.c | 22 ++++++++--------------
> include/qom/object.h | 3 +--
> numa.c | 1 -
> qom/object.c | 32 ++++++++++++++++++++++++--------
> 4 files changed, 33 insertions(+), 25 deletions(-)
>
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index b7b6cf8..c3b9df1 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -113,24 +113,17 @@ host_memory_backend_set_host_nodes(Object *obj, Visitor *v, void *opaque,
> #endif
> }
>
> -static void
> -host_memory_backend_get_policy(Object *obj, Visitor *v, void *opaque,
> - const char *name, Error **errp)
> +static int
> +host_memory_backend_get_policy(Object *obj, Error **errp G_GNUC_UNUSED)
> {
> HostMemoryBackend *backend = MEMORY_BACKEND(obj);
> - int policy = backend->policy;
> -
> - visit_type_enum(v, &policy, HostMemPolicy_lookup, NULL, name, errp);
> + return backend->policy;
> }
>
> static void
> -host_memory_backend_set_policy(Object *obj, Visitor *v, void *opaque,
> - const char *name, Error **errp)
> +host_memory_backend_set_policy(Object *obj, int policy, Error **errp)
> {
> HostMemoryBackend *backend = MEMORY_BACKEND(obj);
> - int policy;
> -
> - visit_type_enum(v, &policy, HostMemPolicy_lookup, NULL, name, errp);
> backend->policy = policy;
>
> #ifndef CONFIG_NUMA
> @@ -252,9 +245,10 @@ static void host_memory_backend_init(Object *obj)
> object_property_add(obj, "host-nodes", "int",
> host_memory_backend_get_host_nodes,
> host_memory_backend_set_host_nodes, NULL, NULL, NULL);
> - object_property_add(obj, "policy", "str",
> - host_memory_backend_get_policy,
> - host_memory_backend_set_policy, NULL, NULL, NULL);
> + object_property_add_enum(obj, "policy",
> + HostMemPolicy_lookup,
> + host_memory_backend_get_policy,
> + host_memory_backend_set_policy, NULL);
> }
>
> MemoryRegion *
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 3462821..bfad22f 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -1003,7 +1003,6 @@ int64_t object_property_get_int(Object *obj, const char *name,
> * object_property_get_enum:
> * @obj: the object
> * @name: the name of the property
> - * @strings: strings corresponding to enums
> * @errp: returns an error if this function fails
> *
> * Returns: the value of the property, converted to an integer, or
> @@ -1011,7 +1010,7 @@ int64_t object_property_get_int(Object *obj, const char *name,
> * an enum).
> */
> int object_property_get_enum(Object *obj, const char *name,
> - const char * const strings[], Error **errp);
> + Error **errp);
>
> /**
> * object_property_get_uint16List:
> diff --git a/numa.c b/numa.c
> index c975fb2..881a123 100644
> --- a/numa.c
> +++ b/numa.c
> @@ -457,7 +457,6 @@ static int query_memdev(Object *obj, void *opaque)
>
> m->value->policy = object_property_get_enum(obj,
> "policy",
> - HostMemPolicy_lookup,
> &err);
> if (err) {
> goto error;
> diff --git a/qom/object.c b/qom/object.c
> index 543cc57..e99b3c9 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1024,13 +1024,35 @@ int64_t object_property_get_int(Object *obj, const char *name,
> return retval;
> }
>
> +typedef struct EnumProperty {
> + const char * const *strings;
> + int (*get)(Object *, Error **);
> + void (*set)(Object *, int, Error **);
> +} EnumProperty;
> +
> +
> int object_property_get_enum(Object *obj, const char *name,
> - const char * const strings[], Error **errp)
> + Error **errp)
> {
> StringOutputVisitor *sov;
> StringInputVisitor *siv;
> char *str;
> int ret;
> + ObjectProperty *prop = object_property_find(obj, name, errp);
> + EnumProperty *enumprop;
> +
> + if (prop == NULL) {
> + return 0;
> + }
> +
> + if (!g_str_equal(prop->type, "enum")) {
Inspecting the type is a bit gross, and in fact it breaks if you keep
the QAPI type name in patch 6. The HostMemPolicy conversion is
certainly okay, but unfortunately this is not.
If you decide to go with macros in patch 6, perhaps you can do the same
here so that object_property_get_enum(obj, "policy", HostMemPolicy,
&err) can compare against the "HostMemPolicy" type.
The fact that HostMemPolicy_lookup exists is then a (mild, but
sufficient) guarantee that the opaque pointer of the property is really
an EnumProperty pointer.
Paolo
> + error_setg(errp, "Property %s on %s is not an 'enum' type",
> + name, object_class_get_name(
> + object_get_class(obj)));
> + return 0;
> + }
> +
> + enumprop = prop->opaque;
>
> sov = string_output_visitor_new(false);
> object_property_get(obj, string_output_get_visitor(sov), name, errp);
> @@ -1038,7 +1060,7 @@ int object_property_get_enum(Object *obj, const char *name,
> siv = string_input_visitor_new(str);
> string_output_visitor_cleanup(sov);
> visit_type_enum(string_input_get_visitor(siv),
> - &ret, strings, NULL, name, errp);
> + &ret, enumprop->strings, NULL, name, errp);
>
> g_free(str);
> string_input_visitor_cleanup(siv);
> @@ -1607,12 +1629,6 @@ void object_property_add_bool(Object *obj, const char *name,
> }
> }
>
> -typedef struct EnumProperty {
> - const char * const *strings;
> - int (*get)(Object *, Error **);
> - void (*set)(Object *, int, Error **);
> -} EnumProperty;
> -
> static void property_get_enum(Object *obj, Visitor *v, void *opaque,
> const char *name, Error **errp)
> {
>
next prev parent reply other threads:[~2015-04-17 15:05 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-17 14:22 [Qemu-devel] [PATCH v1 RFC 00/34] Generic support for TLS protocol & I/O channels Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 01/34] ui: remove check for failure of qemu_acl_init() Daniel P. Berrange
2015-04-17 15:56 ` Eric Blake
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 02/34] qom: document user creatable object types in help text Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 03/34] qom: create objects in two phases Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 04/34] qom: add object_new_propv / object_new_proplist constructors Daniel P. Berrange
2015-04-17 14:55 ` Paolo Bonzini
2015-04-17 15:16 ` Daniel P. Berrange
2015-04-17 16:11 ` Eric Blake
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 05/34] qom: make enum string tables const-correct Daniel P. Berrange
2015-04-17 14:56 ` Paolo Bonzini
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 06/34] qom: add a object_property_add_enum helper method Daniel P. Berrange
2015-04-17 14:56 ` Paolo Bonzini
2015-04-17 15:01 ` Paolo Bonzini
2015-04-17 15:11 ` Daniel P. Berrange
2015-04-17 15:19 ` Paolo Bonzini
2015-04-17 15:22 ` Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 07/34] qom: don't pass string table to object_get_enum method Daniel P. Berrange
2015-04-17 15:05 ` Paolo Bonzini [this message]
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 08/34] crypto: introduce new module for computing hash digests Daniel P. Berrange
2015-05-13 17:04 ` Daniel P. Berrange
2015-05-13 17:12 ` Paolo Bonzini
2015-05-13 17:21 ` Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 09/34] crypto: move built-in AES implementation into crypto/ Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 10/34] crypto: move built-in D3DES " Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 11/34] crypto: introduce generic cipher API & built-in implementation Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 12/34] crypto: add a gcrypt cipher implementation Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 13/34] crypto: add a nettle " Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 14/34] crypto: introduce new module for handling TLS credentials Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 15/34] crypto: add sanity checking of " Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 16/34] crypto: introduce new module for handling TLS sessions Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 17/34] block: convert quorum blockdrv to use crypto APIs Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 18/34] ui: convert VNC websockets " Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 19/34] block: convert qcow/qcow2 to use generic cipher API Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 20/34] ui: convert VNC " Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 21/34] io: add abstract QIOChannel classes Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 22/34] io: add helper module for creating watches on UNIX FDs Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 23/34] io: add QIOChannelSocket class Daniel P. Berrange
2015-04-17 15:28 ` Paolo Bonzini
2015-04-17 15:52 ` Daniel P. Berrange
2015-04-17 16:00 ` Paolo Bonzini
2015-04-20 7:18 ` Gerd Hoffmann
2015-04-23 12:31 ` Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 24/34] io: add QIOChannelFile class Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 25/34] io: add QIOTask class for async operations Daniel P. Berrange
2015-04-17 15:16 ` Paolo Bonzini
2015-04-17 15:49 ` Daniel P. Berrange
2015-04-17 15:57 ` Paolo Bonzini
2015-04-17 16:11 ` Daniel P. Berrange
2015-04-17 17:06 ` Paolo Bonzini
2015-04-17 17:38 ` Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 26/34] io: add QIOChannelTLS class Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 27/34] io: pull Buffer code out of VNC module Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 28/34] io: add QIOChannelWebsock class Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 29/34] ui: convert VNC server to use QEMUIOChannelSocket classes Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 30/34] ui: convert VNC server to use QIOChannelTLS Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 31/34] ui: convert VNC server to use QIOChannelWebsock Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 32/34] char: convert from GIOChannel to QIOChannel Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 33/34] char: don't assume telnet initialization will not block Daniel P. Berrange
2015-04-17 14:22 ` [Qemu-devel] [PATCH v1 RFC 34/34] char: introduce support for TLS encrypted TCP chardev backend Daniel P. Berrange
2015-04-17 18:27 ` Eric Blake
2015-04-23 12:32 ` Daniel P. Berrange
2015-05-04 20:07 ` Kashyap Chamarthy
2015-05-05 13:49 ` Daniel P. Berrange
2015-05-05 13:53 ` Paolo Bonzini
2015-05-05 13:56 ` Daniel P. Berrange
2015-05-05 14:54 ` Kashyap Chamarthy
2015-05-06 8:34 ` Kashyap Chamarthy
2015-05-06 10:18 ` Daniel P. Berrange
2015-05-06 11:38 ` Kashyap Chamarthy
2015-04-23 12:28 ` [Qemu-devel] [PATCH v1 RFC 00/34] Generic support for TLS protocol & I/O channels Stefan Hajnoczi
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=55312148.6070005@redhat.com \
--to=pbonzini@redhat.com \
--cc=berrange@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).