qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 06/12] rng-backend: Implement .instance_config


From: Kevin Wolf
Subject: [RFC PATCH 06/12] rng-backend: Implement .instance_config
Date: Wed, 3 Nov 2021 18:29:56 +0100

This commit really only serves as an illustration because the only
property in rng-backend is 'opened', which is useless and deprecated.

Implement .instance_config in order to show that .instance_config is
working both when parent class and subclass implement it (rng-random)
and when only the parent class implements it (rng-egd).

'opened' cannot be set after creation any more with this change. This is
an incompatible change, but its deprecation period is up anyway.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 backends/rng.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/backends/rng.c b/backends/rng.c
index 3757b04485..840daf0392 100644
--- a/backends/rng.c
+++ b/backends/rng.c
@@ -46,11 +46,6 @@ static bool rng_backend_prop_get_opened(Object *obj, Error 
**errp)
     return s->opened;
 }
 
-static void rng_backend_complete(UserCreatable *uc, Error **errp)
-{
-    object_property_set_bool(OBJECT(uc), "opened", true, errp);
-}
-
 static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
 {
     RngBackend *s = RNG_BACKEND(obj);
@@ -77,6 +72,29 @@ static void rng_backend_prop_set_opened(Object *obj, bool 
value, Error **errp)
     s->opened = true;
 }
 
+static void rng_backend_complete(UserCreatable *uc, Error **errp)
+{
+    rng_backend_prop_set_opened(OBJECT(uc), true, errp);
+}
+
+static bool rng_backend_config(Object *obj, bool opened, Error **errp)
+{
+    ERRP_GUARD();
+    rng_backend_prop_set_opened(obj, opened, errp);
+    return *errp == NULL;
+}
+
+static bool rng_backend_marshal_config(Object *obj, Visitor *v, Error **errp)
+{
+    bool opened;
+
+    if (!visit_type_bool(v, "opened", &opened, errp)) {
+        return false;
+    }
+
+    return rng_backend_config(obj, opened, errp);
+}
+
 static void rng_backend_free_request(RngRequest *req)
 {
     g_free(req->data);
@@ -122,7 +140,7 @@ static void rng_backend_class_init(ObjectClass *oc, void 
*data)
 
     object_class_property_add_bool(oc, "opened",
                                    rng_backend_prop_get_opened,
-                                   rng_backend_prop_set_opened);
+                                   NULL);
 }
 
 static const TypeInfo rng_backend_info = {
@@ -130,6 +148,7 @@ static const TypeInfo rng_backend_info = {
     .parent = TYPE_OBJECT,
     .instance_size = sizeof(RngBackend),
     .instance_init = rng_backend_init,
+    .instance_config = rng_backend_marshal_config,
     .instance_finalize = rng_backend_finalize,
     .class_size = sizeof(RngBackendClass),
     .class_init = rng_backend_class_init,
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]