[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 011/197] qom: qom_{get, set} monitor commands (v2
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH v3 011/197] qom: qom_{get, set} monitor commands (v2) |
Date: |
Mon, 12 Dec 2011 14:18:07 -0600 |
This allows clients to read and write device model properties through QMP. QAPI
doesn't support Visitor types yet and these commands are special in that they
don't work with fixed types.
I've added a documentation stub to qapi-schema.json so we can keep consistency
there.
Signed-off-by: Anthony Liguori <address@hidden>
---
v1 -> v2
- comments (Stefan)
---
monitor.h | 4 +++
qapi-schema.json | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
qmp-commands.hx | 12 ++++++++++
qmp.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 140 insertions(+), 0 deletions(-)
diff --git a/monitor.h b/monitor.h
index e76795f..efc76c7 100644
--- a/monitor.h
+++ b/monitor.h
@@ -64,4 +64,8 @@ typedef void (MonitorCompletion)(void *opaque, QObject
*ret_data);
void monitor_set_error(Monitor *mon, QError *qerror);
+int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret);
+
+int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret);
+
#endif /* !MONITOR_H */
diff --git a/qapi-schema.json b/qapi-schema.json
index 276b7c3..76a8a53 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -935,3 +935,62 @@
{ 'command': 'qom-list',
'data': { 'path': 'str' },
'returns': [ 'DevicePropertyInfo' ] }
+
+##
+# @qom-get:
+#
+# This command will get a property from a device model path and return the
+# value.
+#
+# @path: The path within the device model. There are two forms of supported
+# paths--absolute and partial paths.
+#
+# Absolute paths are derived from the root device and can follow child<>
+# or link<> properties. Since they can follow link<> properties, they
+# can be arbitrarily long. Absolute paths look like absolute filenames
+# and are prefixed with a leading slash.
+#
+# Partial paths look like relative filenames. They do not begin
+# with a prefix. The matching rules for partial paths are subtle but
+# designed to make specifying devices easy. At each level of the
+# composition tree, the partial path is matched as an absolute path.
+# The first match is not returned. At least two matches are searched
+# for. A successful result is only returned if only one match is
+# found. If more than one match is found, a flag is return to
+# indicate that the match was ambiguous.
+#
+# @property: The property name to read
+#
+# Returns: The property value. The type depends on the property type.
legacy<>
+# properties are returned as #str. child<> and link<> properties are
+# returns as #str pathnames. All integer property types (u8, u16,
etc)
+# are returned as #int.
+#
+# Since: 1.1
+#
+# Notes: This command is experimental and may change syntax in future releases.
+##
+{ 'command': 'qom-get',
+ 'data': { 'path': 'str', 'property': 'str' },
+ 'returns': 'visitor',
+ 'gen': 'no' }
+
+##
+# @qom-set:
+#
+# This command will set a property from a device model path.
+#
+# @path: see @qom-get for a description of this parameter
+#
+# @property: the property name to set
+#
+# @value: a value who's type is appropriate for the property type. See
@qom-get
+# for a description of type mapping.
+#
+# Since: 1.1
+#
+# Notes: This command is experimental and may change syntax in future releases.
+##
+{ 'command': 'qom-set',
+ 'data': { 'path': 'str', 'property': 'str', 'value': 'visitor' },
+ 'gen': 'no' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index d6ff466..027189a 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2007,3 +2007,15 @@ EQMP
.args_type = "path:s",
.mhandler.cmd_new = qmp_marshal_input_qom_list,
},
+
+ {
+ .name = "qom-set",
+ .args_type = "path:s,property:s,opts:O",
+ .mhandler.cmd_new = qmp_qom_set,
+ },
+
+ {
+ .name = "qom-get",
+ .args_type = "path:s,property:s",
+ .mhandler.cmd_new = qmp_qom_get,
+ },
diff --git a/qmp.c b/qmp.c
index 06ae569..641761e 100644
--- a/qmp.c
+++ b/qmp.c
@@ -17,6 +17,8 @@
#include "kvm.h"
#include "arch_init.h"
#include "hw/qdev.h"
+#include "qapi/qmp-input-visitor.h"
+#include "qapi/qmp-output-visitor.h"
NameInfo *qmp_query_name(Error **errp)
{
@@ -145,3 +147,66 @@ DevicePropertyInfoList *qmp_qom_list(const char *path,
Error **errp)
return props;
}
+
+/* FIXME: teach qapi about how to pass through Visitors */
+int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret)
+{
+ const char *path = qdict_get_str(qdict, "path");
+ const char *property = qdict_get_str(qdict, "property");
+ QObject *value = qdict_get(qdict, "value");
+ Error *local_err = NULL;
+ QmpInputVisitor *mi;
+ DeviceState *dev;
+
+ dev = qdev_resolve_path(path, NULL);
+ if (!dev) {
+ error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
+ goto out;
+ }
+
+ mi = qmp_input_visitor_new(value);
+ qdev_property_set(dev, qmp_input_get_visitor(mi), property, &local_err);
+
+ qmp_input_visitor_cleanup(mi);
+
+out:
+ if (local_err) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ return -1;
+ }
+
+ return 0;
+}
+
+int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret)
+{
+ const char *path = qdict_get_str(qdict, "path");
+ const char *property = qdict_get_str(qdict, "property");
+ Error *local_err = NULL;
+ QmpOutputVisitor *mo;
+ DeviceState *dev;
+
+ dev = qdev_resolve_path(path, NULL);
+ if (!dev) {
+ error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
+ goto out;
+ }
+
+ mo = qmp_output_visitor_new();
+ qdev_property_get(dev, qmp_output_get_visitor(mo), property, &local_err);
+ if (!local_err) {
+ *ret = qmp_output_get_qobject(mo);
+ }
+
+ qmp_output_visitor_cleanup(mo);
+
+out:
+ if (local_err) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ return -1;
+ }
+
+ return 0;
+}
--
1.7.4.1
- [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects, (continued)
- [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 003/197] qom: register legacy properties as new style properties (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 002/197] qom: add new dynamic property infrastructure based on Visitors (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 005/197] qdev: provide an interface to return canonical path from root (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 006/197] qdev: provide a path resolution (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 007/197] qom: add child properties (composition) (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 008/197] qom: add link properties (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 009/197] qapi: allow a 'gen' key to suppress code generation, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 010/197] qmp: add qom-list command, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 011/197] qom: qom_{get, set} monitor commands (v2),
Anthony Liguori <=
- [Qemu-devel] [PATCH v3 015/197] rtc: add a dynamic property for retrieving the date, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 016/197] qom: optimize qdev_get_canonical_path using a parent link, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 017/197] qmp: make qmp.py easier to use, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 018/197] qom: add test tools (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 020/197] qom: add vga node to the pc composition tree, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 021/197] qom: add string property type, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 022/197] qdev: add a qdev_get_type() function and expose as a 'type' property, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 023/197] pc: fill out most of the composition tree, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 024/197] i440fx: split out piix3 device, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 025/197] i440fx: rename piix_pci -> i440fx, Anthony Liguori, 2011/12/12