From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com,
armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com
Subject: [RFC PATCH 04/12] qom: Add instance_config() to TypeInfo
Date: Wed, 3 Nov 2021 18:29:54 +0100 [thread overview]
Message-ID: <20211103173002.209906-5-kwolf@redhat.com> (raw)
In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com>
Instead of providing the whole configuration through property setters,
object_config() can now use the instance_config() callback. Options that
are not consumed by the callback (e.g. because they belong to a parent
class that hasn't been converted to the new callback yet) are still set
as properties.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/qom/object.h | 4 ++++
qom/object.c | 15 +++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index d67ba2411d..e60cacb54b 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -384,6 +384,9 @@ struct Object
* for initializing its own members.
* @instance_post_init: This function is called to finish initialization of
* an object, after all @instance_init functions were called.
+ * @instance_config: This function is called to set the initial configuration
+ * of an object. If not provided, configuration is done through property
+ * setters.
* @instance_finalize: This function is called during object destruction. This
* is called before the parent @instance_finalize function has been called.
* An object should only free the members that are unique to its type in this
@@ -419,6 +422,7 @@ struct TypeInfo
size_t instance_align;
void (*instance_init)(Object *obj);
void (*instance_post_init)(Object *obj);
+ bool (*instance_config)(Object *obj, Visitor *v, Error **errp);
void (*instance_finalize)(Object *obj);
bool abstract;
diff --git a/qom/object.c b/qom/object.c
index d8da362987..6cacfa9ab1 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -60,6 +60,7 @@ struct TypeImpl
void (*instance_init)(Object *obj);
void (*instance_post_init)(Object *obj);
+ bool (*instance_config)(Object *obj, Visitor *v, Error **errp);
void (*instance_finalize)(Object *obj);
bool abstract;
@@ -124,6 +125,7 @@ static TypeImpl *type_new(const TypeInfo *info)
ti->instance_init = info->instance_init;
ti->instance_post_init = info->instance_post_init;
+ ti->instance_config = info->instance_config;
ti->instance_finalize = info->instance_finalize;
ti->abstract = info->abstract;
@@ -303,6 +305,7 @@ static void type_initialize(TypeImpl *ti)
assert(ti->abstract);
assert(!ti->instance_init);
assert(!ti->instance_post_init);
+ assert(!ti->instance_config);
assert(!ti->instance_finalize);
assert(!ti->num_interfaces);
}
@@ -607,11 +610,23 @@ void object_initialize_child_internal(Object *parent,
void object_configure(Object *obj, Visitor *v, Error **errp)
{
+ TypeImpl *ti;
const char *key;
if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
return;
}
+
+ /* Call .instance_config, including for all parent classes */
+ for (ti = obj->class->type; ti; ti = ti->parent_type) {
+ if (ti->instance_config) {
+ if (!ti->instance_config(obj, v, errp)) {
+ goto out;
+ }
+ }
+ }
+
+ /* Set options not consumed by .instance_config as properties */
while ((key = visit_next_struct_member(v))) {
if (!object_property_set(obj, key, v, errp)) {
goto out;
--
2.31.1
next prev parent reply other threads:[~2021-11-03 17:37 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-03 17:29 [RFC PATCH 00/12] QOM/QAPI integration part 1 Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 01/12] qapi: Add visit_next_struct_member() Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 02/12] qom: Create object_configure() Kevin Wolf
2021-11-23 15:23 ` Markus Armbruster
2021-12-14 9:52 ` Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 03/12] qom: Make object_configure() public Kevin Wolf
2021-11-03 17:29 ` Kevin Wolf [this message]
2021-11-03 17:29 ` [RFC PATCH 05/12] rng-random: Implement .instance_config Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 06/12] rng-backend: " Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 07/12] qapi: Allow defining QOM classes Kevin Wolf
2021-11-23 10:02 ` Markus Armbruster
2021-12-10 17:53 ` Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 08/12] qapi: Create qom-config:... type for classes Kevin Wolf
2021-11-23 13:00 ` Markus Armbruster
2021-12-10 17:41 ` Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 09/12] qapi/qom: Convert rng-backend/random to class Kevin Wolf
2021-11-23 13:15 ` Markus Armbruster
2021-12-10 17:57 ` Kevin Wolf
2021-11-03 17:30 ` [RFC PATCH 10/12] qapi: Generate QOM config marshalling code Kevin Wolf
2021-11-23 14:16 ` Markus Armbruster
2021-12-10 16:50 ` Kevin Wolf
2021-11-03 17:30 ` [RFC PATCH 11/12] qapi/qom: Add class definition for rng-builtin Kevin Wolf
2021-11-03 17:30 ` [RFC PATCH 12/12] qapi/qom: Add class definition for rng-egd Kevin Wolf
2021-11-03 21:26 ` [RFC PATCH 00/12] QOM/QAPI integration part 1 Paolo Bonzini
2021-11-04 9:07 ` Kevin Wolf
2021-11-04 12:39 ` Paolo Bonzini
2021-11-04 14:26 ` Kevin Wolf
2021-11-04 14:49 ` Paolo Bonzini
2021-11-04 15:51 ` Kevin Wolf
2021-11-04 15:52 ` Damien Hedde
2021-11-05 13:55 ` Kevin Wolf
2021-11-23 16:05 ` Markus Armbruster
2021-12-14 10:23 ` Kevin Wolf
2021-12-14 10:40 ` Peter Maydell
2021-12-14 11:52 ` Kevin Wolf
2021-12-14 14:45 ` Markus Armbruster
2021-12-14 16:00 ` Kevin Wolf
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=20211103173002.209906-5-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.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).