mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 01:03:55 -06:00
qom: move user_creatable_add_opts logic to vl.c and QAPIfy it
Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options: -object memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi. In order to minimize code changes, the predicate still takes a string. This can be changed later to use the ObjectType QAPI enum directly. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20210312173547.1283477-3-pbonzini@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
53c9956d8b
commit
bc2f4fcb1d
3 changed files with 57 additions and 119 deletions
|
@ -141,60 +141,6 @@ void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
|
|||
visit_free(v);
|
||||
}
|
||||
|
||||
Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
|
||||
{
|
||||
Visitor *v;
|
||||
QDict *pdict;
|
||||
Object *obj;
|
||||
const char *id = qemu_opts_id(opts);
|
||||
char *type = qemu_opt_get_del(opts, "qom-type");
|
||||
|
||||
if (!type) {
|
||||
error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
|
||||
return NULL;
|
||||
}
|
||||
if (!id) {
|
||||
error_setg(errp, QERR_MISSING_PARAMETER, "id");
|
||||
qemu_opt_set(opts, "qom-type", type, &error_abort);
|
||||
g_free(type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
qemu_opts_set_id(opts, NULL);
|
||||
pdict = qemu_opts_to_qdict(opts, NULL);
|
||||
|
||||
v = opts_visitor_new(opts);
|
||||
obj = user_creatable_add_type(type, id, pdict, v, errp);
|
||||
visit_free(v);
|
||||
|
||||
qemu_opts_set_id(opts, (char *) id);
|
||||
qemu_opt_set(opts, "qom-type", type, &error_abort);
|
||||
g_free(type);
|
||||
qobject_unref(pdict);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp)
|
||||
{
|
||||
bool (*type_opt_predicate)(const char *, QemuOpts *) = opaque;
|
||||
Object *obj = NULL;
|
||||
const char *type;
|
||||
|
||||
type = qemu_opt_get(opts, "qom-type");
|
||||
if (type && type_opt_predicate &&
|
||||
!type_opt_predicate(type, opts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
obj = user_creatable_add_opts(opts, errp);
|
||||
if (!obj) {
|
||||
return -1;
|
||||
}
|
||||
object_unref(obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *object_property_help(const char *name, const char *type,
|
||||
QObject *defval, const char *description)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue