aboutsummaryrefslogtreecommitdiff
path: root/qom/object_interfaces.c
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2017-01-10 13:53:14 +0100
committerMichael Roth <mdroth@linux.vnet.ibm.com>2017-03-30 12:30:09 -0500
commitdd39c544f4136ba390d1f976f520004a3ffad7e5 (patch)
tree46e1a896f8be71992aa2ec10282f1f64ca8495b2 /qom/object_interfaces.c
parent879b6454be1e29241d5b7d6986adcdb95d883856 (diff)
monitor: reuse user_creatable_add_opts() instead of user_creatable_add()
Simplify code by dropping ~57LOC by merging user_creatable_add() into user_creatable_add_opts() and using the later from monitor. Along with it allocate opts_visitor_new() once in user_creatable_add_opts(). As result we have one less API func and a more readable/simple user_creatable_add_opts() vs user_creatable_add(). Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1484052795-158195-3-git-send-email-imammedo@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> (cherry picked from commit 3a4641054e320d8ad7e780c30010b1c1dbfc56e8) * functional dep for 9a6d1ac Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qom/object_interfaces.c')
-rw-r--r--qom/object_interfaces.c71
1 files changed, 17 insertions, 54 deletions
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index ded4d84c85..f79a7ceae0 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -35,57 +35,6 @@ bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp)
}
}
-
-Object *user_creatable_add(const QDict *qdict,
- Visitor *v, Error **errp)
-{
- char *type = NULL;
- char *id = NULL;
- Object *obj = NULL;
- Error *local_err = NULL;
- QDict *pdict;
-
- pdict = qdict_clone_shallow(qdict);
-
- visit_start_struct(v, NULL, NULL, 0, &local_err);
- if (local_err) {
- goto out;
- }
-
- qdict_del(pdict, "qom-type");
- visit_type_str(v, "qom-type", &type, &local_err);
- if (local_err) {
- goto out_visit;
- }
-
- qdict_del(pdict, "id");
- visit_type_str(v, "id", &id, &local_err);
- if (local_err) {
- goto out_visit;
- }
- visit_check_struct(v, &local_err);
- if (local_err) {
- goto out_visit;
- }
-
- obj = user_creatable_add_type(type, id, pdict, v, &local_err);
-
-out_visit:
- visit_end_struct(v, NULL);
-
-out:
- QDECREF(pdict);
- g_free(id);
- g_free(type);
- if (local_err) {
- error_propagate(errp, local_err);
- object_unref(obj);
- return NULL;
- }
- return obj;
-}
-
-
Object *user_creatable_add_type(const char *type, const char *id,
const QDict *qdict,
Visitor *v, Error **errp)
@@ -158,13 +107,27 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
{
Visitor *v;
QDict *pdict;
- Object *obj = NULL;
+ Object *obj;
+ const char *id = qemu_opts_id(opts);
+ const char *type = qemu_opt_get(opts, "qom-type");
+
+ if (!type) {
+ error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
+ return NULL;
+ }
+ if (!id) {
+ error_setg(errp, QERR_MISSING_PARAMETER, "id");
+ return NULL;
+ }
- v = opts_visitor_new(opts);
pdict = qemu_opts_to_qdict(opts, NULL);
+ qdict_del(pdict, "qom-type");
+ qdict_del(pdict, "id");
- obj = user_creatable_add(pdict, v, errp);
+ v = opts_visitor_new(opts);
+ obj = user_creatable_add_type(type, id, pdict, v, errp);
visit_free(v);
+
QDECREF(pdict);
return obj;
}