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"
|
|
|
|
#include "qapi/qmp/qdict.h"
|
|
|
|
#include "qapi/qmp/qerror.h"
|
|
|
|
#include "qapi/qobject-input-visitor.h"
|
|
|
|
#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))) {
|
|
|
|
ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
|
|
|
|
|
|
|
|
entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
|
|
|
|
entry->next = props;
|
|
|
|
props = entry;
|
|
|
|
|
|
|
|
entry->value->name = g_strdup(prop->name);
|
|
|
|
entry->value->type = g_strdup(prop->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_property_set_qobject(obj, value, property, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ObjectTypeInfoList *e, **pret = data;
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
e = g_malloc0(sizeof(*e));
|
|
|
|
e->value = info;
|
|
|
|
e->next = *pret;
|
|
|
|
*pret = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
|
|
|
|
const char *implements,
|
|
|
|
bool has_abstract,
|
|
|
|
bool abstract,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
ObjectTypeInfoList *ret = NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
klass = object_class_by_name(typename);
|
|
|
|
if (klass == NULL) {
|
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", typename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
|
|
|
|
if (klass == NULL) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object_class_is_abstract(klass)) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
|
|
|
|
"non-abstract device type");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = object_new(typename);
|
|
|
|
|
|
|
|
object_property_iter_init(&iter, obj);
|
|
|
|
while ((prop = object_property_iter_next(&iter))) {
|
|
|
|
ObjectPropertyInfo *info;
|
|
|
|
ObjectPropertyInfoList *entry;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
entry = g_malloc0(sizeof(*entry));
|
|
|
|
entry->value = info;
|
|
|
|
entry->next = prop_list;
|
|
|
|
prop_list = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
klass = object_class_dynamic_cast(klass, TYPE_OBJECT);
|
|
|
|
if (klass == NULL) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_OBJECT);
|
|
|
|
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;
|
|
|
|
ObjectPropertyInfoList *entry;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
entry = g_malloc0(sizeof(*entry));
|
|
|
|
entry->value = info;
|
|
|
|
entry->next = prop_list;
|
|
|
|
prop_list = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_unref(obj);
|
|
|
|
|
|
|
|
return prop_list;
|
|
|
|
}
|
|
|
|
|
2020-02-24 17:29:55 +03:00
|
|
|
void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
|
2019-06-19 23:10:38 +03:00
|
|
|
{
|
2020-02-24 17:29:55 +03:00
|
|
|
QObject *props;
|
2019-06-19 23:10:38 +03:00
|
|
|
QDict *pdict;
|
|
|
|
Visitor *v;
|
|
|
|
Object *obj;
|
2020-03-10 09:46:40 +03:00
|
|
|
g_autofree char *type = NULL;
|
|
|
|
g_autofree char *id = NULL;
|
2019-06-19 23:10:38 +03:00
|
|
|
|
2020-03-10 09:46:40 +03:00
|
|
|
type = g_strdup(qdict_get_try_str(qdict, "qom-type"));
|
2020-02-24 17:29:55 +03:00
|
|
|
if (!type) {
|
|
|
|
error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
|
|
|
|
return;
|
|
|
|
}
|
2020-03-10 09:46:40 +03:00
|
|
|
qdict_del(qdict, "qom-type");
|
2020-02-24 17:29:55 +03:00
|
|
|
|
2020-03-10 09:46:40 +03:00
|
|
|
id = g_strdup(qdict_get_try_str(qdict, "id"));
|
2020-02-24 17:29:55 +03:00
|
|
|
if (!id) {
|
|
|
|
error_setg(errp, QERR_MISSING_PARAMETER, "id");
|
|
|
|
return;
|
|
|
|
}
|
2020-03-10 09:46:40 +03:00
|
|
|
qdict_del(qdict, "id");
|
2020-02-24 17:29:55 +03:00
|
|
|
|
|
|
|
props = qdict_get(qdict, "props");
|
2019-06-19 23:10:38 +03:00
|
|
|
if (props) {
|
|
|
|
pdict = qobject_to(QDict, props);
|
|
|
|
if (!pdict) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qobject_ref(pdict);
|
2020-02-24 17:29:55 +03:00
|
|
|
qdict_del(qdict, "props");
|
|
|
|
qdict_join(qdict, pdict, false);
|
|
|
|
if (qdict_size(pdict) != 0) {
|
|
|
|
error_setg(errp, "Option in 'props' conflicts with top level");
|
|
|
|
qobject_unref(pdict);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qobject_unref(pdict);
|
2019-06-19 23:10:38 +03:00
|
|
|
}
|
|
|
|
|
2020-02-24 17:29:55 +03:00
|
|
|
v = qobject_input_visitor_new(QOBJECT(qdict));
|
|
|
|
obj = user_creatable_add_type(type, id, qdict, v, errp);
|
2019-06-19 23:10:38 +03:00
|
|
|
visit_free(v);
|
|
|
|
if (obj) {
|
|
|
|
object_unref(obj);
|
|
|
|
}
|
2020-02-24 17:29:55 +03:00
|
|
|
*ret_data = QOBJECT(qdict_new());
|
2019-06-19 23:10:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void qmp_object_del(const char *id, Error **errp)
|
|
|
|
{
|
|
|
|
user_creatable_del(id, errp);
|
|
|
|
}
|