2019-06-19 23:10:38 +03:00
|
|
|
/*
|
|
|
|
* QMP commands related to QOM
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
2020-02-24 17:29:55 +03:00
|
|
|
#include "block/qdict.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-core.h"
|
2019-06-19 23:10:38 +03:00
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "qapi/qapi-commands-qdev.h"
|
|
|
|
#include "qapi/qapi-commands-qom.h"
|
2020-10-20 14:27:22 +03:00
|
|
|
#include "qapi/qapi-visit-qom.h"
|
2019-06-19 23:10:38 +03:00
|
|
|
#include "qapi/qmp/qdict.h"
|
|
|
|
#include "qapi/qmp/qerror.h"
|
2020-10-20 14:27:22 +03:00
|
|
|
#include "qapi/qobject-input-visitor.h"
|
|
|
|
#include "qapi/qobject-output-visitor.h"
|
2019-06-19 23:10:38 +03:00
|
|
|
#include "qemu/cutils.h"
|
|
|
|
#include "qom/object_interfaces.h"
|
|
|
|
#include "qom/qom-qobject.h"
|
|
|
|
|
|
|
|
ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
|
|
|
|
{
|
|
|
|
Object *obj;
|
|
|
|
bool ambiguous = false;
|
|
|
|
ObjectPropertyInfoList *props = NULL;
|
|
|
|
ObjectProperty *prop;
|
|
|
|
ObjectPropertyIterator iter;
|
|
|
|
|
|
|
|
obj = object_resolve_path(path, &ambiguous);
|
|
|
|
if (obj == NULL) {
|
|
|
|
if (ambiguous) {
|
|
|
|
error_setg(errp, "Path '%s' is ambiguous", path);
|
|
|
|
} else {
|
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", path);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_property_iter_init(&iter, obj);
|
|
|
|
while ((prop = object_property_iter_next(&iter))) {
|
2022-03-15 17:41:56 +03:00
|
|
|
ObjectPropertyInfo *value = g_new0(ObjectPropertyInfo, 1);
|
2019-06-19 23:10:38 +03:00
|
|
|
|
2020-11-13 04:13:37 +03:00
|
|
|
QAPI_LIST_PREPEND(props, value);
|
2019-06-19 23:10:38 +03:00
|
|
|
|
2020-11-13 04:13:37 +03:00
|
|
|
value->name = g_strdup(prop->name);
|
|
|
|
value->type = g_strdup(prop->type);
|
2019-06-19 23:10:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qmp_qom_set(const char *path, const char *property, QObject *value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
Object *obj;
|
|
|
|
|
|
|
|
obj = object_resolve_path(path, NULL);
|
|
|
|
if (!obj) {
|
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 19:05:54 +03:00
|
|
|
object_property_set_qobject(obj, property, value, errp);
|
2019-06-19 23:10:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
|
|
|
|
{
|
|
|
|
Object *obj;
|
|
|
|
|
|
|
|
obj = object_resolve_path(path, NULL);
|
|
|
|
if (!obj) {
|
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return object_property_get_qobject(obj, property, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qom_list_types_tramp(ObjectClass *klass, void *data)
|
|
|
|
{
|
2020-11-13 04:13:37 +03:00
|
|
|
ObjectTypeInfoList **pret = data;
|
2019-06-19 23:10:38 +03:00
|
|
|
ObjectTypeInfo *info;
|
|
|
|
ObjectClass *parent = object_class_get_parent(klass);
|
|
|
|
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->name = g_strdup(object_class_get_name(klass));
|
|
|
|
info->has_abstract = info->abstract = object_class_is_abstract(klass);
|
|
|
|
if (parent) {
|
|
|
|
info->has_parent = true;
|
|
|
|
info->parent = g_strdup(object_class_get_name(parent));
|
|
|
|
}
|
|
|
|
|
2020-11-13 04:13:37 +03:00
|
|
|
QAPI_LIST_PREPEND(*pret, info);
|
2019-06-19 23:10:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
|
|
|
|
const char *implements,
|
|
|
|
bool has_abstract,
|
|
|
|
bool abstract,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
ObjectTypeInfoList *ret = NULL;
|
|
|
|
|
2020-06-24 16:10:38 +03:00
|
|
|
module_load_qom_all();
|
2019-06-19 23:10:38 +03:00
|
|
|
object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
ObjectClass *klass;
|
|
|
|
Object *obj;
|
|
|
|
ObjectProperty *prop;
|
|
|
|
ObjectPropertyIterator iter;
|
|
|
|
ObjectPropertyInfoList *prop_list = NULL;
|
|
|
|
|
2020-06-24 16:10:38 +03:00
|
|
|
klass = module_object_class_by_name(typename);
|
2019-06-19 23:10:38 +03:00
|
|
|
if (klass == NULL) {
|
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", typename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:26:25 +03:00
|
|
|
if (!object_class_dynamic_cast(klass, TYPE_DEVICE)
|
|
|
|
|| object_class_is_abstract(klass)) {
|
2019-06-19 23:10:38 +03:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
|
2020-11-13 11:26:25 +03:00
|
|
|
"a non-abstract device type");
|
2019-06-19 23:10:38 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = object_new(typename);
|
|
|
|
|
|
|
|
object_property_iter_init(&iter, obj);
|
|
|
|
while ((prop = object_property_iter_next(&iter))) {
|
|
|
|
ObjectPropertyInfo *info;
|
|
|
|
|
|
|
|
/* Skip Object and DeviceState properties */
|
|
|
|
if (strcmp(prop->name, "type") == 0 ||
|
|
|
|
strcmp(prop->name, "realized") == 0 ||
|
|
|
|
strcmp(prop->name, "hotpluggable") == 0 ||
|
|
|
|
strcmp(prop->name, "hotplugged") == 0 ||
|
|
|
|
strcmp(prop->name, "parent_bus") == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip legacy properties since they are just string versions of
|
|
|
|
* properties that we already list.
|
|
|
|
*/
|
|
|
|
if (strstart(prop->name, "legacy-", NULL)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-01-23 14:17:13 +03:00
|
|
|
info = g_new0(ObjectPropertyInfo, 1);
|
|
|
|
info->name = g_strdup(prop->name);
|
|
|
|
info->type = g_strdup(prop->type);
|
|
|
|
info->has_description = !!prop->description;
|
|
|
|
info->description = g_strdup(prop->description);
|
2020-01-10 18:30:38 +03:00
|
|
|
info->default_value = qobject_ref(prop->defval);
|
|
|
|
info->has_default_value = !!info->default_value;
|
2019-06-19 23:10:38 +03:00
|
|
|
|
2020-11-13 04:13:37 +03:00
|
|
|
QAPI_LIST_PREPEND(prop_list, info);
|
2019-06-19 23:10:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
object_unref(obj);
|
|
|
|
|
|
|
|
return prop_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
ObjectClass *klass;
|
|
|
|
Object *obj = NULL;
|
|
|
|
ObjectProperty *prop;
|
|
|
|
ObjectPropertyIterator iter;
|
|
|
|
ObjectPropertyInfoList *prop_list = NULL;
|
|
|
|
|
|
|
|
klass = object_class_by_name(typename);
|
|
|
|
if (klass == NULL) {
|
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Class '%s' not found", typename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:26:25 +03:00
|
|
|
if (!object_class_dynamic_cast(klass, TYPE_OBJECT)) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
|
|
|
|
"a QOM type");
|
2019-06-19 23:10:38 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object_class_is_abstract(klass)) {
|
|
|
|
object_class_property_iter_init(&iter, klass);
|
|
|
|
} else {
|
|
|
|
obj = object_new(typename);
|
|
|
|
object_property_iter_init(&iter, obj);
|
|
|
|
}
|
|
|
|
while ((prop = object_property_iter_next(&iter))) {
|
|
|
|
ObjectPropertyInfo *info;
|
|
|
|
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->name = g_strdup(prop->name);
|
|
|
|
info->type = g_strdup(prop->type);
|
|
|
|
info->has_description = !!prop->description;
|
|
|
|
info->description = g_strdup(prop->description);
|
|
|
|
|
2020-11-13 04:13:37 +03:00
|
|
|
QAPI_LIST_PREPEND(prop_list, info);
|
2019-06-19 23:10:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
object_unref(obj);
|
|
|
|
|
|
|
|
return prop_list;
|
|
|
|
}
|
|
|
|
|
2020-10-20 14:27:22 +03:00
|
|
|
void qmp_object_add(ObjectOptions *options, Error **errp)
|
2019-06-19 23:10:38 +03:00
|
|
|
{
|
2021-02-17 14:06:20 +03:00
|
|
|
user_creatable_add_qapi(options, errp);
|
2019-06-19 23:10:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void qmp_object_del(const char *id, Error **errp)
|
|
|
|
{
|
|
|
|
user_creatable_del(id, errp);
|
|
|
|
}
|