[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 05/12] rng-random: Implement .instance_config
From: |
Kevin Wolf |
Subject: |
[RFC PATCH 05/12] rng-random: Implement .instance_config |
Date: |
Wed, 3 Nov 2021 18:29:55 +0100 |
This adds an implementation for .instance_config to the rng-random
object. It is split into a function doing the actual configuration and
providing a native C interface and a marshalling function with a visitor
interface that we want to generate from the QAPI schema later.
rng-random objects are not created internally, so all callers use the
.instance_config interface, and setting the 'filename' property fails
after object creation, so the property setter for it can be removed now.
This commit demonstrates that you can have subclasses implementing
.instance_config while the parent class still uses properties for
initialisation.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
backends/rng-random.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/backends/rng-random.c b/backends/rng-random.c
index 7add272edd..b221308091 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -14,6 +14,7 @@
#include "sysemu/rng-random.h"
#include "sysemu/rng.h"
#include "qapi/error.h"
+#include "qapi/visitor.h"
#include "qapi/qmp/qerror.h"
#include "qemu/main-loop.h"
#include "qemu/module.h"
@@ -89,19 +90,25 @@ static char *rng_random_get_filename(Object *obj, Error
**errp)
return g_strdup(s->filename);
}
-static void rng_random_set_filename(Object *obj, const char *filename,
- Error **errp)
+static bool rng_random_config(Object *obj, const char *filename, Error **errp)
{
- RngBackend *b = RNG_BACKEND(obj);
RngRandom *s = RNG_RANDOM(obj);
- if (b->opened) {
- error_setg(errp, QERR_PERMISSION_DENIED);
- return;
- }
-
g_free(s->filename);
s->filename = g_strdup(filename);
+
+ return true;
+}
+
+static bool rng_random_marshal_config(Object *obj, Visitor *v, Error **errp)
+{
+ g_autofree char *filename = NULL;
+
+ if (!visit_type_str(v, "filename", &filename, errp)) {
+ return false;
+ }
+
+ return rng_random_config(obj, filename, errp);
}
static void rng_random_init(Object *obj)
@@ -131,8 +138,7 @@ static void rng_random_class_init(ObjectClass *klass, void
*data)
rbc->request_entropy = rng_random_request_entropy;
rbc->opened = rng_random_opened;
object_class_property_add_str(klass, "filename",
- rng_random_get_filename,
- rng_random_set_filename);
+ rng_random_get_filename, NULL);
}
@@ -142,6 +148,7 @@ static const TypeInfo rng_random_info = {
.instance_size = sizeof(RngRandom),
.class_init = rng_random_class_init,
.instance_init = rng_random_init,
+ .instance_config = rng_random_marshal_config,
.instance_finalize = rng_random_finalize,
};
--
2.31.1
- [RFC PATCH 00/12] QOM/QAPI integration part 1, Kevin Wolf, 2021/11/03
- [RFC PATCH 02/12] qom: Create object_configure(), Kevin Wolf, 2021/11/03
- [RFC PATCH 01/12] qapi: Add visit_next_struct_member(), Kevin Wolf, 2021/11/03
- [RFC PATCH 03/12] qom: Make object_configure() public, Kevin Wolf, 2021/11/03
- [RFC PATCH 04/12] qom: Add instance_config() to TypeInfo, Kevin Wolf, 2021/11/03
- [RFC PATCH 05/12] rng-random: Implement .instance_config,
Kevin Wolf <=
- [RFC PATCH 06/12] rng-backend: Implement .instance_config, Kevin Wolf, 2021/11/03
- [RFC PATCH 07/12] qapi: Allow defining QOM classes, Kevin Wolf, 2021/11/03
- [RFC PATCH 08/12] qapi: Create qom-config:... type for classes, Kevin Wolf, 2021/11/03
- [RFC PATCH 09/12] qapi/qom: Convert rng-backend/random to class, Kevin Wolf, 2021/11/03
- [RFC PATCH 12/12] qapi/qom: Add class definition for rng-egd, Kevin Wolf, 2021/11/03
- [RFC PATCH 11/12] qapi/qom: Add class definition for rng-builtin, Kevin Wolf, 2021/11/03
- [RFC PATCH 10/12] qapi: Generate QOM config marshalling code, Kevin Wolf, 2021/11/03