[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3.1 07/31] vl: redo -object parsing
From: |
Hu Tao |
Subject: |
[Qemu-devel] [PATCH v3.1 07/31] vl: redo -object parsing |
Date: |
Tue, 6 May 2014 17:27:28 +0800 |
From: Paolo Bonzini <address@hidden>
Follow the lines of the HMP implementation, using OptsVisitor
to parse the options. This gives access to OptsVisitor's
rich parsing of integer lists.
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Hu Tao <address@hidden>
---
vl.c | 87 +++++++++++++++++++++++++++-----------------------------------------
1 file changed, 35 insertions(+), 52 deletions(-)
diff --git a/vl.c b/vl.c
index 78144c4..167856e 100644
--- a/vl.c
+++ b/vl.c
@@ -115,8 +115,7 @@ int main(int argc, char **argv)
#include "qemu/osdep.h"
#include "ui/qemu-spice.h"
-#include "qapi/string-input-visitor.h"
-#include "qom/object_interfaces.h"
+#include "qapi/opts-visitor.h"
#define DEFAULT_RAM_SIZE 128
@@ -2768,69 +2767,53 @@ static void free_and_trace(gpointer mem)
free(mem);
}
-static int object_set_property(const char *name, const char *value, void
*opaque)
-{
- Object *obj = OBJECT(opaque);
- StringInputVisitor *siv;
- Error *local_err = NULL;
-
- if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0) {
- return 0;
- }
-
- siv = string_input_visitor_new(value);
- object_property_set(obj, string_input_get_visitor(siv), name, &local_err);
- string_input_visitor_cleanup(siv);
-
- if (local_err) {
- qerror_report_err(local_err);
- error_free(local_err);
- return -1;
- }
-
- return 0;
-}
-
static int object_create(QemuOpts *opts, void *opaque)
{
- const char *type = qemu_opt_get(opts, "qom-type");
- const char *id = qemu_opts_id(opts);
- Error *local_err = NULL;
- Object *obj;
-
- g_assert(type != NULL);
-
- if (id == NULL) {
- qerror_report(QERR_MISSING_PARAMETER, "id");
- return -1;
+ Error *err = NULL;
+ char *type = NULL;
+ char *id = NULL;
+ void *dummy = NULL;
+ OptsVisitor *ov;
+ QDict *pdict;
+
+ ov = opts_visitor_new(opts);
+ pdict = qemu_opts_to_qdict(opts, NULL);
+
+ visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
+ if (err) {
+ goto out;
}
- obj = object_new(type);
- if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) {
- object_unref(obj);
- return -1;
+ qdict_del(pdict, "qom-type");
+ visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
+ if (err) {
+ goto out;
}
- if (!object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
- error_setg(&local_err, "object '%s' isn't supported by -object",
- id);
+ qdict_del(pdict, "id");
+ visit_type_str(opts_get_visitor(ov), &id, "id", &err);
+ if (err) {
goto out;
}
- user_creatable_complete(obj, &local_err);
- if (local_err) {
+ object_add(type, id, pdict, opts_get_visitor(ov), &err);
+ if (err) {
goto out;
}
-
- object_property_add_child(container_get(object_get_root(), "/objects"),
- id, obj, &local_err);
+ visit_end_struct(opts_get_visitor(ov), &err);
+ if (err) {
+ qmp_object_del(id, NULL);
+ }
out:
- object_unref(obj);
- if (local_err) {
- qerror_report_err(local_err);
- error_free(local_err);
- return -1;
+ opts_visitor_cleanup(ov);
+
+ QDECREF(pdict);
+ g_free(id);
+ g_free(type);
+ g_free(dummy);
+ if (err) {
+ qerror_report_err(err);
}
return 0;
}
--
1.8.5.2.229.g4448466
- [Qemu-devel] [PATCH v3.1 02/31] NUMA: check if the total numa memory size is equal to ram_size, (continued)
- [Qemu-devel] [PATCH v3.1 02/31] NUMA: check if the total numa memory size is equal to ram_size, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 03/31] NUMA: Add numa_info structure to contain numa nodes info, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 09/31] qmp: improve error reporting for -object and object-add, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 12/31] add memdev backend infrastructure, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 11/31] numa: introduce memory_region_allocate_system_memory, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 15/31] memory: move mem_path handling to memory_region_allocate_system_memory, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 08/31] qmp: allow object-add completion handler to get canonical path, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 01/31] NUMA: move numa related code to new file numa.c, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 05/31] NUMA: expand MAX_NODES from 64 to 128, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 13/31] numa: add -numa node, memdev= option, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 07/31] vl: redo -object parsing,
Hu Tao <=
- [Qemu-devel] [PATCH v3.1 10/31] pc: pass QEMUMachineInitArgs to pc_memory_init, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 04/31] NUMA: convert -numa option to use OptsVisitor, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 06/31] man: improve -numa doc, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 16/31] memory: add error propagation to file-based RAM allocation, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 18/31] memory: move RAM_PREALLOC_MASK to exec.c, rename, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 19/31] hostmem: add file-based HostMemoryBackend, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 20/31] hostmem: separate allocation from UserCreatable complete method, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 17/31] memory: move preallocation code out of exec.c, Hu Tao, 2014/05/06
- [Qemu-devel] [PATCH v3.1 14/31] memory: reorganize file-based allocation, Hu Tao, 2014/05/06