diff options
| author | Anthony Liguori <aliguori@us.ibm.com> | 2011-12-12 14:29:35 -0600 |
|---|---|---|
| committer | Anthony Liguori <aliguori@us.ibm.com> | 2011-12-15 09:20:48 -0600 |
| commit | eb6e8ea5c38b47a3c6cf27f4780abd92bc079caa (patch) | |
| tree | 02cb9341c0ab3aefe309dd441b2a7c85829b6d97 /qmp.c | |
| parent | b4b12c6247d89b94e197891fbadb2699fd469ed6 (diff) | |
| download | focaccia-qemu-eb6e8ea5c38b47a3c6cf27f4780abd92bc079caa.tar.gz focaccia-qemu-eb6e8ea5c38b47a3c6cf27f4780abd92bc079caa.zip | |
qom: qom_{get, set} monitor commands (v2)
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 <aliguori@us.ibm.com>
Diffstat (limited to 'qmp.c')
| -rw-r--r-- | qmp.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/qmp.c b/qmp.c index 8e9a595398..5e09b4189e 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) { @@ -182,3 +184,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; +} |