2011-09-03 01:34:48 +08:00
|
|
|
/*
|
|
|
|
* QEMU Management Protocol
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2012-01-14 00:44:23 +08:00
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2011-09-03 01:34:48 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu-common.h"
|
2015-03-18 01:16:21 +08:00
|
|
|
#include "monitor/monitor.h"
|
2012-12-18 01:20:04 +08:00
|
|
|
#include "sysemu/sysemu.h"
|
2011-09-03 01:34:48 +08:00
|
|
|
#include "qmp-commands.h"
|
2013-04-08 22:55:25 +08:00
|
|
|
#include "sysemu/char.h"
|
2011-12-07 21:17:51 +08:00
|
|
|
#include "ui/qemu-spice.h"
|
|
|
|
#include "ui/vnc.h"
|
2012-12-18 01:20:04 +08:00
|
|
|
#include "sysemu/kvm.h"
|
|
|
|
#include "sysemu/arch_init.h"
|
2011-12-13 04:29:34 +08:00
|
|
|
#include "hw/qdev.h"
|
2012-12-18 01:20:04 +08:00
|
|
|
#include "sysemu/blockdev.h"
|
2012-12-18 01:19:50 +08:00
|
|
|
#include "qom/qom-qobject.h"
|
2015-03-18 00:22:46 +08:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2013-12-21 06:21:10 +08:00
|
|
|
#include "qapi/qmp/qobject.h"
|
|
|
|
#include "qapi/qmp-input-visitor.h"
|
2013-04-30 21:41:25 +08:00
|
|
|
#include "hw/boards.h"
|
2014-01-17 00:34:38 +08:00
|
|
|
#include "qom/object_interfaces.h"
|
2014-06-17 01:12:25 +08:00
|
|
|
#include "hw/mem/pc-dimm.h"
|
2014-06-17 01:12:28 +08:00
|
|
|
#include "hw/acpi/acpi_dev_interface.h"
|
2011-09-03 01:34:48 +08:00
|
|
|
|
|
|
|
NameInfo *qmp_query_name(Error **errp)
|
|
|
|
{
|
|
|
|
NameInfo *info = g_malloc0(sizeof(*info));
|
|
|
|
|
|
|
|
if (qemu_name) {
|
|
|
|
info->has_name = true;
|
|
|
|
info->name = g_strdup(qemu_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2011-08-27 04:38:13 +08:00
|
|
|
|
2014-05-02 19:26:31 +08:00
|
|
|
VersionInfo *qmp_query_version(Error **errp)
|
2011-08-27 04:38:13 +08:00
|
|
|
{
|
2015-05-04 23:05:31 +08:00
|
|
|
VersionInfo *info = g_new0(VersionInfo, 1);
|
2011-08-27 04:38:13 +08:00
|
|
|
const char *version = QEMU_VERSION;
|
|
|
|
char *tmp;
|
|
|
|
|
2015-05-04 23:05:31 +08:00
|
|
|
info->qemu = g_new0(VersionTriple, 1);
|
|
|
|
info->qemu->major = strtol(version, &tmp, 10);
|
2011-08-27 04:38:13 +08:00
|
|
|
tmp++;
|
2015-05-04 23:05:31 +08:00
|
|
|
info->qemu->minor = strtol(tmp, &tmp, 10);
|
2011-08-27 04:38:13 +08:00
|
|
|
tmp++;
|
2015-05-04 23:05:31 +08:00
|
|
|
info->qemu->micro = strtol(tmp, &tmp, 10);
|
2011-08-27 04:38:13 +08:00
|
|
|
info->package = g_strdup(QEMU_PKGVERSION);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2011-09-13 02:10:53 +08:00
|
|
|
|
|
|
|
KvmInfo *qmp_query_kvm(Error **errp)
|
|
|
|
{
|
|
|
|
KvmInfo *info = g_malloc0(sizeof(*info));
|
|
|
|
|
|
|
|
info->enabled = kvm_enabled();
|
|
|
|
info->present = kvm_available();
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2011-09-14 04:16:25 +08:00
|
|
|
UuidInfo *qmp_query_uuid(Error **errp)
|
|
|
|
{
|
|
|
|
UuidInfo *info = g_malloc0(sizeof(*info));
|
|
|
|
char uuid[64];
|
|
|
|
|
|
|
|
snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
|
|
|
|
qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
|
|
|
|
qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
|
|
|
|
qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
|
|
|
|
qemu_uuid[14], qemu_uuid[15]);
|
|
|
|
|
|
|
|
info->UUID = g_strdup(uuid);
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2014-05-02 19:26:31 +08:00
|
|
|
void qmp_quit(Error **errp)
|
2011-09-16 01:20:28 +08:00
|
|
|
{
|
|
|
|
no_shutdown = 0;
|
|
|
|
qemu_system_shutdown_request();
|
|
|
|
}
|
|
|
|
|
2011-09-16 01:34:39 +08:00
|
|
|
void qmp_stop(Error **errp)
|
|
|
|
{
|
2012-10-23 20:54:21 +08:00
|
|
|
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
|
|
|
autostart = 0;
|
|
|
|
} else {
|
|
|
|
vm_stop(RUN_STATE_PAUSED);
|
|
|
|
}
|
2011-09-16 01:34:39 +08:00
|
|
|
}
|
|
|
|
|
2011-09-16 01:41:46 +08:00
|
|
|
void qmp_system_reset(Error **errp)
|
|
|
|
{
|
|
|
|
qemu_system_reset_request();
|
|
|
|
}
|
2011-09-28 22:06:15 +08:00
|
|
|
|
|
|
|
void qmp_system_powerdown(Error **erp)
|
|
|
|
{
|
|
|
|
qemu_system_powerdown_request();
|
|
|
|
}
|
2011-10-07 01:31:39 +08:00
|
|
|
|
|
|
|
void qmp_cpu(int64_t index, Error **errp)
|
|
|
|
{
|
|
|
|
/* Just do nothing */
|
|
|
|
}
|
2011-10-18 02:41:22 +08:00
|
|
|
|
2013-04-30 21:41:25 +08:00
|
|
|
void qmp_cpu_add(int64_t id, Error **errp)
|
|
|
|
{
|
2014-03-06 01:30:47 +08:00
|
|
|
MachineClass *mc;
|
|
|
|
|
|
|
|
mc = MACHINE_GET_CLASS(current_machine);
|
2014-04-10 01:34:53 +08:00
|
|
|
if (mc->hot_add_cpu) {
|
|
|
|
mc->hot_add_cpu(id, errp);
|
2013-04-30 21:41:25 +08:00
|
|
|
} else {
|
|
|
|
error_setg(errp, "Not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 02:41:22 +08:00
|
|
|
#ifndef CONFIG_VNC
|
|
|
|
/* If VNC support is enabled, the "true" query-vnc command is
|
|
|
|
defined in the VNC subsystem */
|
|
|
|
VncInfo *qmp_query_vnc(Error **errp)
|
|
|
|
{
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
|
2011-10-18 02:41:22 +08:00
|
|
|
return NULL;
|
|
|
|
};
|
2015-02-02 13:08:51 +08:00
|
|
|
|
|
|
|
VncInfo2List *qmp_query_vnc_servers(Error **errp)
|
|
|
|
{
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
|
2015-02-02 13:08:51 +08:00
|
|
|
return NULL;
|
|
|
|
};
|
2011-10-18 02:41:22 +08:00
|
|
|
#endif
|
2011-10-21 03:01:33 +08:00
|
|
|
|
|
|
|
#ifndef CONFIG_SPICE
|
2015-01-13 22:56:11 +08:00
|
|
|
/*
|
|
|
|
* qmp-commands.hx ensures that QMP command query-spice exists only
|
|
|
|
* #ifdef CONFIG_SPICE. Necessary for an accurate query-commands
|
|
|
|
* result. However, the QAPI schema is blissfully unaware of that,
|
|
|
|
* and the QAPI code generator happily generates a dead
|
|
|
|
* qmp_marshal_input_query_spice() that calls qmp_query_spice().
|
|
|
|
* Provide it one, or else linking fails.
|
|
|
|
* FIXME Educate the QAPI schema on CONFIG_SPICE.
|
|
|
|
*/
|
2011-10-21 03:01:33 +08:00
|
|
|
SpiceInfo *qmp_query_spice(Error **errp)
|
|
|
|
{
|
2015-01-13 22:56:11 +08:00
|
|
|
abort();
|
2011-10-21 03:01:33 +08:00
|
|
|
};
|
|
|
|
#endif
|
2011-11-23 03:58:31 +08:00
|
|
|
|
|
|
|
void qmp_cont(Error **errp)
|
|
|
|
{
|
2015-01-29 17:37:00 +08:00
|
|
|
Error *local_err = NULL;
|
2014-05-02 19:26:42 +08:00
|
|
|
BlockDriverState *bs;
|
2011-11-23 03:58:31 +08:00
|
|
|
|
2013-04-26 11:24:40 +08:00
|
|
|
if (runstate_needs_reset()) {
|
2014-03-22 07:42:26 +08:00
|
|
|
error_setg(errp, "Resetting the Virtual Machine is required");
|
2011-11-23 03:58:31 +08:00
|
|
|
return;
|
2012-04-28 00:33:36 +08:00
|
|
|
} else if (runstate_check(RUN_STATE_SUSPENDED)) {
|
|
|
|
return;
|
2011-11-23 03:58:31 +08:00
|
|
|
}
|
|
|
|
|
2014-05-02 19:26:42 +08:00
|
|
|
for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
|
|
|
|
bdrv_iostatus_reset(bs);
|
|
|
|
}
|
|
|
|
for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
|
2015-01-29 17:37:00 +08:00
|
|
|
bdrv_add_key(bs, NULL, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
2014-05-02 19:26:42 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-11-23 03:58:31 +08:00
|
|
|
}
|
|
|
|
|
2012-10-23 20:54:21 +08:00
|
|
|
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
|
|
|
autostart = 1;
|
|
|
|
} else {
|
|
|
|
vm_start();
|
|
|
|
}
|
2011-11-23 03:58:31 +08:00
|
|
|
}
|
2011-12-13 04:29:34 +08:00
|
|
|
|
2012-02-23 20:45:21 +08:00
|
|
|
void qmp_system_wakeup(Error **errp)
|
|
|
|
{
|
|
|
|
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
|
|
|
|
}
|
|
|
|
|
2012-01-30 22:55:55 +08:00
|
|
|
ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
|
2011-12-13 04:29:34 +08:00
|
|
|
{
|
2012-01-30 22:55:55 +08:00
|
|
|
Object *obj;
|
2011-12-13 04:29:34 +08:00
|
|
|
bool ambiguous = false;
|
2012-01-30 22:55:55 +08:00
|
|
|
ObjectPropertyInfoList *props = NULL;
|
|
|
|
ObjectProperty *prop;
|
2011-12-13 04:29:34 +08:00
|
|
|
|
2012-01-30 22:55:55 +08:00
|
|
|
obj = object_resolve_path(path, &ambiguous);
|
|
|
|
if (obj == NULL) {
|
2014-05-04 16:23:59 +08:00
|
|
|
if (ambiguous) {
|
|
|
|
error_setg(errp, "Path '%s' is ambiguous", path);
|
|
|
|
} else {
|
2015-03-16 15:57:47 +08:00
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", path);
|
2014-05-04 16:23:59 +08:00
|
|
|
}
|
2011-12-13 04:29:34 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-30 22:55:55 +08:00
|
|
|
QTAILQ_FOREACH(prop, &obj->properties, node) {
|
|
|
|
ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
|
2011-12-13 04:29:34 +08:00
|
|
|
|
2012-01-30 22:55:55 +08:00
|
|
|
entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
|
2011-12-13 04:29:34 +08:00
|
|
|
entry->next = props;
|
|
|
|
props = entry;
|
|
|
|
|
|
|
|
entry->value->name = g_strdup(prop->name);
|
|
|
|
entry->value->type = g_strdup(prop->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return props;
|
|
|
|
}
|
2011-12-13 04:29:35 +08:00
|
|
|
|
|
|
|
/* FIXME: teach qapi about how to pass through Visitors */
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
void qmp_qom_set(QDict *qdict, QObject **ret, Error **errp)
|
2011-12-13 04:29:35 +08:00
|
|
|
{
|
|
|
|
const char *path = qdict_get_str(qdict, "path");
|
|
|
|
const char *property = qdict_get_str(qdict, "property");
|
|
|
|
QObject *value = qdict_get(qdict, "value");
|
2012-01-30 22:55:55 +08:00
|
|
|
Object *obj;
|
2011-12-13 04:29:35 +08:00
|
|
|
|
2012-01-30 22:55:55 +08:00
|
|
|
obj = object_resolve_path(path, NULL);
|
|
|
|
if (!obj) {
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
2015-03-16 15:57:47 +08:00
|
|
|
"Device '%s' not found", path);
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
return;
|
2011-12-13 04:29:35 +08:00
|
|
|
}
|
|
|
|
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
object_property_set_qobject(obj, value, property, errp);
|
2011-12-13 04:29:35 +08:00
|
|
|
}
|
|
|
|
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
void qmp_qom_get(QDict *qdict, QObject **ret, Error **errp)
|
2011-12-13 04:29:35 +08:00
|
|
|
{
|
|
|
|
const char *path = qdict_get_str(qdict, "path");
|
|
|
|
const char *property = qdict_get_str(qdict, "property");
|
2012-01-30 22:55:55 +08:00
|
|
|
Object *obj;
|
2011-12-13 04:29:35 +08:00
|
|
|
|
2012-01-30 22:55:55 +08:00
|
|
|
obj = object_resolve_path(path, NULL);
|
|
|
|
if (!obj) {
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
2015-03-16 15:57:47 +08:00
|
|
|
"Device '%s' not found", path);
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
return;
|
2011-12-13 04:29:35 +08:00
|
|
|
}
|
|
|
|
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
*ret = object_property_get_qobject(obj, property, errp);
|
2011-12-13 04:29:35 +08:00
|
|
|
}
|
2011-12-07 21:17:51 +08:00
|
|
|
|
|
|
|
void qmp_set_password(const char *protocol, const char *password,
|
|
|
|
bool has_connected, const char *connected, Error **errp)
|
|
|
|
{
|
|
|
|
int disconnect_if_connected = 0;
|
|
|
|
int fail_if_connected = 0;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (has_connected) {
|
|
|
|
if (strcmp(connected, "fail") == 0) {
|
|
|
|
fail_if_connected = 1;
|
|
|
|
} else if (strcmp(connected, "disconnect") == 0) {
|
|
|
|
disconnect_if_connected = 1;
|
|
|
|
} else if (strcmp(connected, "keep") == 0) {
|
|
|
|
/* nothing */
|
|
|
|
} else {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER, "connected");
|
2011-12-07 21:17:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "spice") == 0) {
|
2015-01-14 00:07:15 +08:00
|
|
|
if (!qemu_using_spice(errp)) {
|
2011-12-07 21:17:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
rc = qemu_spice_set_passwd(password, fail_if_connected,
|
|
|
|
disconnect_if_connected);
|
|
|
|
if (rc != 0) {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-07 21:17:51 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "vnc") == 0) {
|
|
|
|
if (fail_if_connected || disconnect_if_connected) {
|
|
|
|
/* vnc supports "connected=keep" only */
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER, "connected");
|
2011-12-07 21:17:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Note that setting an empty password will not disable login through
|
|
|
|
* this interface. */
|
|
|
|
rc = vnc_display_password(NULL, password);
|
|
|
|
if (rc < 0) {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-07 21:17:51 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
|
2011-12-07 21:17:51 +08:00
|
|
|
}
|
2011-12-07 21:47:57 +08:00
|
|
|
|
|
|
|
void qmp_expire_password(const char *protocol, const char *whenstr,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
time_t when;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (strcmp(whenstr, "now") == 0) {
|
|
|
|
when = 0;
|
|
|
|
} else if (strcmp(whenstr, "never") == 0) {
|
|
|
|
when = TIME_MAX;
|
|
|
|
} else if (whenstr[0] == '+') {
|
|
|
|
when = time(NULL) + strtoull(whenstr+1, NULL, 10);
|
|
|
|
} else {
|
|
|
|
when = strtoull(whenstr, NULL, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "spice") == 0) {
|
2015-01-14 00:07:15 +08:00
|
|
|
if (!qemu_using_spice(errp)) {
|
2011-12-07 21:47:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
rc = qemu_spice_set_pw_expire(when);
|
|
|
|
if (rc != 0) {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-07 21:47:57 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "vnc") == 0) {
|
|
|
|
rc = vnc_display_pw_expire(NULL, when);
|
|
|
|
if (rc != 0) {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-07 21:47:57 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
|
2011-12-07 21:47:57 +08:00
|
|
|
}
|
2011-12-08 21:45:55 +08:00
|
|
|
|
2011-12-08 21:13:50 +08:00
|
|
|
#ifdef CONFIG_VNC
|
2011-12-08 21:45:55 +08:00
|
|
|
void qmp_change_vnc_password(const char *password, Error **errp)
|
|
|
|
{
|
|
|
|
if (vnc_display_password(NULL, password) < 0) {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-08 21:45:55 +08:00
|
|
|
}
|
|
|
|
}
|
2011-12-08 21:13:50 +08:00
|
|
|
|
2012-10-18 15:01:01 +08:00
|
|
|
static void qmp_change_vnc_listen(const char *target, Error **errp)
|
2011-12-08 21:13:50 +08:00
|
|
|
{
|
2014-09-16 18:33:03 +08:00
|
|
|
QemuOptsList *olist = qemu_find_opts("vnc");
|
|
|
|
QemuOpts *opts;
|
|
|
|
|
|
|
|
if (strstr(target, "id=")) {
|
|
|
|
error_setg(errp, "id not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts = qemu_opts_find(olist, "default");
|
|
|
|
if (opts) {
|
|
|
|
qemu_opts_del(opts);
|
|
|
|
}
|
QemuOpts: Wean off qerror_report_err()
qerror_report_err() is a transitional interface to help with
converting existing monitor commands to QMP. It should not be used
elsewhere.
The only remaining user in qemu-option.c is qemu_opts_parse(). Is it
used in QMP context? If not, we can simply replace
qerror_report_err() by error_report_err().
The uses in qemu-img.c, qemu-io.c, qemu-nbd.c and under tests/ are
clearly not in QMP context.
The uses in vl.c aren't either, because the only QMP command handlers
there are qmp_query_status() and qmp_query_machines(), and they don't
call it.
Remaining uses:
* drive_def(): Command line -drive and such, HMP drive_add and pci_add
* hmp_chardev_add(): HMP chardev-add
* monitor_parse_command(): HMP core
* tmp_config_parse(): Command line -tpmdev
* net_host_device_add(): HMP host_net_add
* net_client_parse(): Command line -net and -netdev
* qemu_global_option(): Command line -global
* vnc_parse_func(): Command line -display, -vnc, default display, HMP
change, QMP change. Bummer.
* qemu_pci_hot_add_nic(): HMP pci_add
* usb_net_init(): Command line -usbdevice, HMP usb_add
Propagate errors through qemu_opts_parse(). Create a convenience
function qemu_opts_parse_noisily() that passes errors to
error_report_err(). Switch all non-QMP users outside tests to it.
That leaves vnc_parse_func(). Propagate errors through it. Since I'm
touching it anyway, rename it to vnc_parse().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-02-13 19:50:26 +08:00
|
|
|
opts = vnc_parse(target, errp);
|
2015-02-05 17:43:35 +08:00
|
|
|
if (!opts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-16 18:33:03 +08:00
|
|
|
vnc_display_open("default", errp);
|
2011-12-08 21:13:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
|
|
|
|
if (!has_arg) {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_MISSING_PARAMETER, "password");
|
2011-12-08 21:13:50 +08:00
|
|
|
} else {
|
|
|
|
qmp_change_vnc_password(arg, errp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qmp_change_vnc_listen(target, errp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void qmp_change_vnc_password(const char *password, Error **errp)
|
|
|
|
{
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
|
2011-12-08 21:13:50 +08:00
|
|
|
}
|
|
|
|
static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
|
2011-12-08 21:13:50 +08:00
|
|
|
}
|
|
|
|
#endif /* !CONFIG_VNC */
|
|
|
|
|
|
|
|
void qmp_change(const char *device, const char *target,
|
2014-05-02 19:26:31 +08:00
|
|
|
bool has_arg, const char *arg, Error **errp)
|
2011-12-08 21:13:50 +08:00
|
|
|
{
|
|
|
|
if (strcmp(device, "vnc") == 0) {
|
2014-05-02 19:26:31 +08:00
|
|
|
qmp_change_vnc(target, has_arg, arg, errp);
|
2011-12-08 21:13:50 +08:00
|
|
|
} else {
|
2014-05-02 19:26:31 +08:00
|
|
|
qmp_change_blockdev(device, target, arg, errp);
|
2011-12-08 21:13:50 +08:00
|
|
|
}
|
|
|
|
}
|
2011-12-23 04:40:54 +08:00
|
|
|
|
|
|
|
static void qom_list_types_tramp(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
ObjectTypeInfoList *e, **pret = data;
|
|
|
|
ObjectTypeInfo *info;
|
|
|
|
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->name = g_strdup(object_class_get_name(klass));
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-08-11 00:04:09 +08:00
|
|
|
|
2014-05-20 20:29:01 +08:00
|
|
|
/* Return a DevicePropertyInfo for a qdev property.
|
|
|
|
*
|
|
|
|
* If a qdev property with the given name does not exist, use the given default
|
|
|
|
* type. If the qdev property info should not be shown, return NULL.
|
|
|
|
*
|
|
|
|
* The caller must free the return value.
|
|
|
|
*/
|
|
|
|
static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
|
|
|
|
const char *name,
|
2014-10-07 14:33:23 +08:00
|
|
|
const char *default_type,
|
|
|
|
const char *description)
|
2014-05-20 20:29:01 +08:00
|
|
|
{
|
|
|
|
DevicePropertyInfo *info;
|
|
|
|
Property *prop;
|
|
|
|
|
|
|
|
do {
|
|
|
|
for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
|
|
|
|
if (strcmp(name, prop->name) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO Properties without a parser are just for dirty hacks.
|
|
|
|
* qdev_prop_ptr is the only such PropertyInfo. It's marked
|
|
|
|
* for removal. This conditional should be removed along with
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
if (!prop->info->set) {
|
|
|
|
return NULL; /* no way to set it, don't show */
|
|
|
|
}
|
|
|
|
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->name = g_strdup(prop->name);
|
2014-10-07 14:33:23 +08:00
|
|
|
info->type = g_strdup(prop->info->name);
|
|
|
|
info->has_description = !!prop->info->description;
|
|
|
|
info->description = g_strdup(prop->info->description);
|
2014-05-20 20:29:01 +08:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
klass = object_class_get_parent(klass);
|
|
|
|
} while (klass != object_class_by_name(TYPE_DEVICE));
|
|
|
|
|
|
|
|
/* Not a qdev property, use the default type */
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->name = g_strdup(name);
|
|
|
|
info->type = g_strdup(default_type);
|
2014-10-07 14:33:23 +08:00
|
|
|
info->has_description = !!description;
|
|
|
|
info->description = g_strdup(description);
|
|
|
|
|
2014-05-20 20:29:01 +08:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2012-08-11 00:04:09 +08:00
|
|
|
DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
ObjectClass *klass;
|
2014-05-20 20:29:01 +08:00
|
|
|
Object *obj;
|
|
|
|
ObjectProperty *prop;
|
2012-08-11 00:04:09 +08:00
|
|
|
DevicePropertyInfoList *prop_list = NULL;
|
|
|
|
|
|
|
|
klass = object_class_by_name(typename);
|
|
|
|
if (klass == NULL) {
|
2015-03-16 15:57:47 +08:00
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", typename);
|
2012-08-11 00:04:09 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
|
|
|
|
if (klass == NULL) {
|
2015-03-17 18:54:50 +08:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "name", TYPE_DEVICE);
|
2012-08-11 00:04:09 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-20 20:29:01 +08:00
|
|
|
obj = object_new(typename);
|
2012-08-11 00:04:09 +08:00
|
|
|
|
2014-05-20 20:29:01 +08:00
|
|
|
QTAILQ_FOREACH(prop, &obj->properties, node) {
|
|
|
|
DevicePropertyInfo *info;
|
|
|
|
DevicePropertyInfoList *entry;
|
|
|
|
|
|
|
|
/* Skip Object and DeviceState properties */
|
|
|
|
if (strcmp(prop->name, "type") == 0 ||
|
|
|
|
strcmp(prop->name, "realized") == 0 ||
|
|
|
|
strcmp(prop->name, "hotpluggable") == 0 ||
|
2014-07-09 20:01:31 +08:00
|
|
|
strcmp(prop->name, "hotplugged") == 0 ||
|
2014-05-20 20:29:01 +08:00
|
|
|
strcmp(prop->name, "parent_bus") == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-11 00:04:09 +08:00
|
|
|
|
2014-05-20 20:29:01 +08:00
|
|
|
/* Skip legacy properties since they are just string versions of
|
|
|
|
* properties that we already list.
|
|
|
|
*/
|
|
|
|
if (strstart(prop->name, "legacy-", NULL)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-11 00:04:09 +08:00
|
|
|
|
2014-10-07 14:33:23 +08:00
|
|
|
info = make_device_property_info(klass, prop->name, prop->type,
|
|
|
|
prop->description);
|
2014-05-20 20:29:01 +08:00
|
|
|
if (!info) {
|
|
|
|
continue;
|
2012-08-11 00:04:09 +08:00
|
|
|
}
|
2014-05-20 20:29:01 +08:00
|
|
|
|
|
|
|
entry = g_malloc0(sizeof(*entry));
|
|
|
|
entry->value = info;
|
|
|
|
entry->next = prop_list;
|
|
|
|
prop_list = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_unref(obj);
|
2012-08-11 00:04:09 +08:00
|
|
|
|
|
|
|
return prop_list;
|
|
|
|
}
|
2012-08-11 00:04:13 +08:00
|
|
|
|
2012-08-15 11:17:36 +08:00
|
|
|
CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
|
|
|
|
{
|
|
|
|
return arch_query_cpu_definitions(errp);
|
|
|
|
}
|
|
|
|
|
2012-09-14 03:52:20 +08:00
|
|
|
void qmp_add_client(const char *protocol, const char *fdname,
|
|
|
|
bool has_skipauth, bool skipauth, bool has_tls, bool tls,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
CharDriverState *s;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = monitor_get_fd(cur_mon, fdname, errp);
|
|
|
|
if (fd < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "spice") == 0) {
|
2015-01-14 00:07:15 +08:00
|
|
|
if (!qemu_using_spice(errp)) {
|
2012-09-14 03:52:20 +08:00
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
skipauth = has_skipauth ? skipauth : false;
|
|
|
|
tls = has_tls ? tls : false;
|
|
|
|
if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
|
|
|
|
error_setg(errp, "spice failed to add client");
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
#ifdef CONFIG_VNC
|
|
|
|
} else if (strcmp(protocol, "vnc") == 0) {
|
|
|
|
skipauth = has_skipauth ? skipauth : false;
|
|
|
|
vnc_display_add_client(NULL, fd, skipauth);
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
} else if ((s = qemu_chr_find(protocol)) != NULL) {
|
|
|
|
if (qemu_chr_add_client(s, fd) < 0) {
|
|
|
|
error_setg(errp, "failed to add client");
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_setg(errp, "protocol '%s' is invalid", protocol);
|
|
|
|
close(fd);
|
|
|
|
}
|
2013-12-21 06:21:09 +08:00
|
|
|
|
2013-12-21 06:21:10 +08:00
|
|
|
void object_add(const char *type, const char *id, const QDict *qdict,
|
|
|
|
Visitor *v, Error **errp)
|
|
|
|
{
|
|
|
|
Object *obj;
|
2014-04-17 01:39:38 +08:00
|
|
|
ObjectClass *klass;
|
2013-12-21 06:21:10 +08:00
|
|
|
const QDictEntry *e;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
2014-04-17 01:39:38 +08:00
|
|
|
klass = object_class_by_name(type);
|
|
|
|
if (!klass) {
|
2014-05-14 17:43:13 +08:00
|
|
|
error_setg(errp, "invalid object type: %s", type);
|
2013-12-21 06:21:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-17 01:39:38 +08:00
|
|
|
if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
|
|
|
|
error_setg(errp, "object type '%s' isn't supported by object-add",
|
|
|
|
type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object_class_is_abstract(klass)) {
|
|
|
|
error_setg(errp, "object type '%s' is abstract", type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-21 06:21:10 +08:00
|
|
|
obj = object_new(type);
|
|
|
|
if (qdict) {
|
|
|
|
for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
|
|
|
|
object_property_set(obj, v, e->key, &local_err);
|
|
|
|
if (local_err) {
|
2014-01-17 00:34:36 +08:00
|
|
|
goto out;
|
2013-12-21 06:21:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-14 00:14:05 +08:00
|
|
|
object_property_add_child(object_get_objects_root(),
|
2014-06-02 21:24:59 +08:00
|
|
|
id, obj, &local_err);
|
2014-01-17 00:34:38 +08:00
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-06-02 21:24:59 +08:00
|
|
|
user_creatable_complete(obj, &local_err);
|
|
|
|
if (local_err) {
|
2015-05-14 00:14:05 +08:00
|
|
|
object_property_del(object_get_objects_root(),
|
2014-06-02 21:24:59 +08:00
|
|
|
id, &error_abort);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-01-17 00:34:36 +08:00
|
|
|
out:
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
}
|
2013-12-21 06:21:10 +08:00
|
|
|
object_unref(obj);
|
|
|
|
}
|
|
|
|
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
void qmp_object_add(QDict *qdict, QObject **ret, Error **errp)
|
2013-12-21 06:21:10 +08:00
|
|
|
{
|
|
|
|
const char *type = qdict_get_str(qdict, "qom-type");
|
|
|
|
const char *id = qdict_get_str(qdict, "id");
|
|
|
|
QObject *props = qdict_get(qdict, "props");
|
|
|
|
const QDict *pdict = NULL;
|
|
|
|
QmpInputVisitor *qiv;
|
|
|
|
|
|
|
|
if (props) {
|
|
|
|
pdict = qobject_to_qdict(props);
|
|
|
|
if (!pdict) {
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
|
|
|
|
return;
|
2013-12-21 06:21:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qiv = qmp_input_visitor_new(props);
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-14 00:25:50 +08:00
|
|
|
object_add(type, id, pdict, qmp_input_get_visitor(qiv), errp);
|
2013-12-21 06:21:10 +08:00
|
|
|
qmp_input_visitor_cleanup(qiv);
|
|
|
|
}
|
|
|
|
|
2013-12-21 06:21:09 +08:00
|
|
|
void qmp_object_del(const char *id, Error **errp)
|
|
|
|
{
|
|
|
|
Object *container;
|
|
|
|
Object *obj;
|
|
|
|
|
2015-05-14 00:14:05 +08:00
|
|
|
container = object_get_objects_root();
|
2013-12-21 06:21:09 +08:00
|
|
|
obj = object_resolve_path_component(container, id);
|
|
|
|
if (!obj) {
|
|
|
|
error_setg(errp, "object id not found");
|
|
|
|
return;
|
|
|
|
}
|
2015-03-30 16:36:28 +08:00
|
|
|
|
|
|
|
if (!user_creatable_can_be_deleted(USER_CREATABLE(obj), errp)) {
|
|
|
|
error_setg(errp, "%s is in use, can not be deleted", id);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-21 06:21:09 +08:00
|
|
|
object_unparent(obj);
|
|
|
|
}
|
2014-06-17 01:12:25 +08:00
|
|
|
|
|
|
|
MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
|
|
|
|
{
|
|
|
|
MemoryDeviceInfoList *head = NULL;
|
|
|
|
MemoryDeviceInfoList **prev = &head;
|
|
|
|
|
|
|
|
qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
2014-06-17 01:12:28 +08:00
|
|
|
|
|
|
|
ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
|
|
|
|
{
|
|
|
|
bool ambig;
|
|
|
|
ACPIOSTInfoList *head = NULL;
|
|
|
|
ACPIOSTInfoList **prev = &head;
|
|
|
|
Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
|
|
|
|
|
|
|
|
if (obj) {
|
|
|
|
AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
|
|
|
|
AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
|
|
|
|
|
|
|
|
adevc->ospm_status(adev, &prev);
|
|
|
|
} else {
|
|
|
|
error_setg(errp, "command is not supported, missing ACPI device");
|
|
|
|
}
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|