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>
This commit is contained in:
parent
8a000250f1
commit
3a4641054e
5
hmp.c
5
hmp.c
@ -1808,7 +1808,6 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
|
|||||||
{
|
{
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
Visitor *v;
|
|
||||||
Object *obj = NULL;
|
Object *obj = NULL;
|
||||||
|
|
||||||
opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
|
opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
|
||||||
@ -1817,9 +1816,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
v = opts_visitor_new(opts);
|
obj = user_creatable_add_opts(opts, &err);
|
||||||
obj = user_creatable_add(qdict, v, &err);
|
|
||||||
visit_free(v);
|
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -75,23 +75,6 @@ void user_creatable_complete(Object *obj, Error **errp);
|
|||||||
*/
|
*/
|
||||||
bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp);
|
bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp);
|
||||||
|
|
||||||
/**
|
|
||||||
* user_creatable_add:
|
|
||||||
* @qdict: the object definition
|
|
||||||
* @v: the visitor
|
|
||||||
* @errp: if an error occurs, a pointer to an area to store the error
|
|
||||||
*
|
|
||||||
* Create an instance of the user creatable object whose type
|
|
||||||
* is defined in @qdict by the 'qom-type' field, placing it
|
|
||||||
* in the object composition tree with name provided by the
|
|
||||||
* 'id' field. The remaining fields in @qdict are used to
|
|
||||||
* initialize the object properties.
|
|
||||||
*
|
|
||||||
* Returns: the newly created object or NULL on error
|
|
||||||
*/
|
|
||||||
Object *user_creatable_add(const QDict *qdict,
|
|
||||||
Visitor *v, Error **errp);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* user_creatable_add_type:
|
* user_creatable_add_type:
|
||||||
* @type: the object type name
|
* @type: the object type name
|
||||||
|
@ -34,57 +34,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,
|
Object *user_creatable_add_type(const char *type, const char *id,
|
||||||
const QDict *qdict,
|
const QDict *qdict,
|
||||||
Visitor *v, Error **errp)
|
Visitor *v, Error **errp)
|
||||||
@ -157,13 +106,27 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
|
|||||||
{
|
{
|
||||||
Visitor *v;
|
Visitor *v;
|
||||||
QDict *pdict;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdict = qemu_opts_to_qdict(opts, NULL);
|
||||||
|
qdict_del(pdict, "qom-type");
|
||||||
|
qdict_del(pdict, "id");
|
||||||
|
|
||||||
v = opts_visitor_new(opts);
|
v = opts_visitor_new(opts);
|
||||||
pdict = qemu_opts_to_qdict(opts, NULL);
|
obj = user_creatable_add_type(type, id, pdict, v, errp);
|
||||||
|
|
||||||
obj = user_creatable_add(pdict, v, errp);
|
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
|
|
||||||
QDECREF(pdict);
|
QDECREF(pdict);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user