2011-09-02 19:34:48 +02: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-13 17:44:23 +01: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-02 19:34:48 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-29 18:50:05 +01:00
|
|
|
#include "qemu/osdep.h"
|
2016-06-01 11:44:21 +02:00
|
|
|
#include "qemu-version.h"
|
2016-03-20 18:16:19 +01:00
|
|
|
#include "qemu/cutils.h"
|
2018-02-01 12:18:46 +01:00
|
|
|
#include "qemu/option.h"
|
2015-03-17 18:16:21 +01:00
|
|
|
#include "monitor/monitor.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2016-12-12 18:22:24 +01:00
|
|
|
#include "qemu/config-file.h"
|
2016-09-21 06:27:14 +02:00
|
|
|
#include "qemu/uuid.h"
|
2017-01-26 14:19:46 +01:00
|
|
|
#include "chardev/char.h"
|
2011-12-07 14:17:51 +01:00
|
|
|
#include "ui/qemu-spice.h"
|
|
|
|
#include "ui/vnc.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/kvm.h"
|
|
|
|
#include "sysemu/arch_init.h"
|
2011-12-12 21:29:34 +01:00
|
|
|
#include "hw/qdev.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/blockdev.h"
|
2015-10-19 17:53:22 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2012-12-17 18:19:50 +01:00
|
|
|
#include "qom/qom-qobject.h"
|
2018-02-01 12:18:31 +01:00
|
|
|
#include "qapi/error.h"
|
2018-02-27 00:13:27 +01:00
|
|
|
#include "qapi/qapi-commands-block-core.h"
|
|
|
|
#include "qapi/qapi-commands-misc.h"
|
|
|
|
#include "qapi/qapi-commands-ui.h"
|
2018-02-01 12:18:39 +01:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2015-03-17 17:22:46 +01:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2016-09-30 16:45:27 +02:00
|
|
|
#include "qapi/qobject-input-visitor.h"
|
2013-04-30 15:41:25 +02:00
|
|
|
#include "hw/boards.h"
|
2014-01-16 17:34:38 +01:00
|
|
|
#include "qom/object_interfaces.h"
|
2018-04-23 18:51:16 +02:00
|
|
|
#include "hw/mem/memory-device.h"
|
2014-06-16 19:12:28 +02:00
|
|
|
#include "hw/acpi/acpi_dev_interface.h"
|
2011-09-02 19:34:48 +02: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-26 22:38:13 +02:00
|
|
|
|
2014-05-02 13:26:31 +02:00
|
|
|
VersionInfo *qmp_query_version(Error **errp)
|
2011-08-26 22:38:13 +02:00
|
|
|
{
|
2015-05-04 17:05:31 +02:00
|
|
|
VersionInfo *info = g_new0(VersionInfo, 1);
|
2011-08-26 22:38:13 +02:00
|
|
|
|
2015-05-04 17:05:31 +02:00
|
|
|
info->qemu = g_new0(VersionTriple, 1);
|
2016-09-12 11:18:56 +02:00
|
|
|
info->qemu->major = QEMU_VERSION_MAJOR;
|
|
|
|
info->qemu->minor = QEMU_VERSION_MINOR;
|
|
|
|
info->qemu->micro = QEMU_VERSION_MICRO;
|
2011-08-26 22:38:13 +02:00
|
|
|
info->package = g_strdup(QEMU_PKGVERSION);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2011-09-12 20:10:53 +02: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-13 22:16:25 +02:00
|
|
|
UuidInfo *qmp_query_uuid(Error **errp)
|
|
|
|
{
|
|
|
|
UuidInfo *info = g_malloc0(sizeof(*info));
|
|
|
|
|
2016-09-21 06:27:22 +02:00
|
|
|
info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid);
|
2011-09-13 22:16:25 +02:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:31 +02:00
|
|
|
void qmp_quit(Error **errp)
|
2011-09-15 19:20:28 +02:00
|
|
|
{
|
|
|
|
no_shutdown = 0;
|
2018-12-05 12:01:31 +01:00
|
|
|
qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT);
|
2011-09-15 19:20:28 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 19:34:39 +02:00
|
|
|
void qmp_stop(Error **errp)
|
|
|
|
{
|
2016-02-18 06:16:49 +01:00
|
|
|
/* if there is a dump in background, we should wait until the dump
|
|
|
|
* finished */
|
|
|
|
if (dump_in_progress()) {
|
|
|
|
error_setg(errp, "There is a dump in process, please wait.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:54:21 +02:00
|
|
|
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
|
|
|
autostart = 0;
|
|
|
|
} else {
|
|
|
|
vm_stop(RUN_STATE_PAUSED);
|
|
|
|
}
|
2011-09-15 19:34:39 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 19:41:46 +02:00
|
|
|
void qmp_system_reset(Error **errp)
|
|
|
|
{
|
2018-12-05 12:01:31 +01:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP_SYSTEM_RESET);
|
2011-09-15 19:41:46 +02:00
|
|
|
}
|
2011-09-28 16:06:15 +02:00
|
|
|
|
|
|
|
void qmp_system_powerdown(Error **erp)
|
|
|
|
{
|
|
|
|
qemu_system_powerdown_request();
|
|
|
|
}
|
2011-10-06 19:31:39 +02:00
|
|
|
|
2013-04-30 15:41:25 +02:00
|
|
|
void qmp_cpu_add(int64_t id, Error **errp)
|
|
|
|
{
|
2014-03-05 18:30:47 +01:00
|
|
|
MachineClass *mc;
|
|
|
|
|
|
|
|
mc = MACHINE_GET_CLASS(current_machine);
|
2014-04-09 19:34:53 +02:00
|
|
|
if (mc->hot_add_cpu) {
|
|
|
|
mc->hot_add_cpu(id, errp);
|
2013-04-30 15:41:25 +02:00
|
|
|
} else {
|
|
|
|
error_setg(errp, "Not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 11:14:02 +02:00
|
|
|
void qmp_x_exit_preconfig(Error **errp)
|
2018-05-11 19:24:43 +02:00
|
|
|
{
|
|
|
|
if (!runstate_check(RUN_STATE_PRECONFIG)) {
|
|
|
|
error_setg(errp, "The command is permitted only in '%s' state",
|
|
|
|
RunState_str(RUN_STATE_PRECONFIG));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qemu_exit_preconfig_request();
|
|
|
|
}
|
|
|
|
|
2011-11-22 20:58:31 +01:00
|
|
|
void qmp_cont(Error **errp)
|
|
|
|
{
|
2015-10-19 17:53:22 +02:00
|
|
|
BlockBackend *blk;
|
2017-06-23 18:24:15 +02:00
|
|
|
Error *local_err = NULL;
|
2011-11-22 20:58:31 +01:00
|
|
|
|
2016-02-18 06:16:49 +01:00
|
|
|
/* if there is a dump in background, we should wait until the dump
|
|
|
|
* finished */
|
|
|
|
if (dump_in_progress()) {
|
|
|
|
error_setg(errp, "There is a dump in process, please wait.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-26 05:24:40 +02:00
|
|
|
if (runstate_needs_reset()) {
|
2014-03-22 00:42:26 +01:00
|
|
|
error_setg(errp, "Resetting the Virtual Machine is required");
|
2011-11-22 20:58:31 +01:00
|
|
|
return;
|
2012-04-27 18:33:36 +02:00
|
|
|
} else if (runstate_check(RUN_STATE_SUSPENDED)) {
|
|
|
|
return;
|
2011-11-22 20:58:31 +01:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:53:22 +02:00
|
|
|
for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
|
|
|
|
blk_iostatus_reset(blk);
|
2014-05-02 13:26:42 +02:00
|
|
|
}
|
2016-03-22 18:58:50 +01:00
|
|
|
|
2015-12-22 14:07:08 +01:00
|
|
|
/* Continuing after completed migration. Images have been inactivated to
|
2017-05-04 18:52:36 +02:00
|
|
|
* allow the destination to take control. Need to get control back now.
|
|
|
|
*
|
|
|
|
* If there are no inactive block nodes (e.g. because the VM was just
|
|
|
|
* paused rather than completing a migration), bdrv_inactivate_all() simply
|
|
|
|
* doesn't do anything. */
|
|
|
|
bdrv_invalidate_cache_all(&local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
2015-12-22 14:07:08 +01:00
|
|
|
}
|
|
|
|
|
2012-10-23 14:54:21 +02:00
|
|
|
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
|
|
|
autostart = 1;
|
|
|
|
} else {
|
|
|
|
vm_start();
|
|
|
|
}
|
2011-11-22 20:58:31 +01:00
|
|
|
}
|
2011-12-12 21:29:34 +01:00
|
|
|
|
2012-02-23 13:45:21 +01:00
|
|
|
void qmp_system_wakeup(Error **errp)
|
|
|
|
{
|
qmp hmp: Make system_wakeup check wake-up support and run state
The qmp/hmp command 'system_wakeup' is simply a direct call to
'qemu_system_wakeup_request' from vl.c. This function verifies if
runstate is SUSPENDED and if the wake up reason is valid before
proceeding. However, no error or warning is thrown if any of those
pre-requirements isn't met. There is no way for the caller to
differentiate between a successful wakeup or an error state caused
when trying to wake up a guest that wasn't suspended.
This means that system_wakeup is silently failing, which can be
considered a bug. Adding error handling isn't an API break in this
case - applications that didn't check the result will remain broken,
the ones that check it will have a chance to deal with it.
Adding to that, the commit before previous created a new QMP API called
query-current-machine, with a new flag called wakeup-suspend-support,
that indicates if the guest has the capability of waking up from suspended
state. Although such guest will never reach SUSPENDED state and erroring
it out in this scenario would suffice, it is more informative for the user
to differentiate between a failure because the guest isn't suspended versus
a failure because the guest does not have support for wake up at all.
All this considered, this patch changes qmp_system_wakeup to check if
the guest is capable of waking up from suspend, and if it is suspended.
After this patch, this is the output of system_wakeup in a guest that
does not have wake-up from suspend support (ppc64):
(qemu) system_wakeup
wake-up from suspend is not supported by this guest
(qemu)
And this is the output of system_wakeup in a x86 guest that has the
support but isn't suspended:
(qemu) system_wakeup
Unable to wake up: guest is not in suspended state
(qemu)
Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20181205194701.17836-4-danielhb413@gmail.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-12-05 20:47:01 +01:00
|
|
|
if (!qemu_wakeup_suspend_enabled()) {
|
|
|
|
error_setg(errp,
|
|
|
|
"wake-up from suspend is not supported by this guest");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, errp);
|
2012-02-23 13:45:21 +01:00
|
|
|
}
|
|
|
|
|
2012-01-30 15:55:55 +01:00
|
|
|
ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
|
2011-12-12 21:29:34 +01:00
|
|
|
{
|
2012-01-30 15:55:55 +01:00
|
|
|
Object *obj;
|
2011-12-12 21:29:34 +01:00
|
|
|
bool ambiguous = false;
|
2012-01-30 15:55:55 +01:00
|
|
|
ObjectPropertyInfoList *props = NULL;
|
|
|
|
ObjectProperty *prop;
|
2015-12-09 13:34:02 +01:00
|
|
|
ObjectPropertyIterator iter;
|
2011-12-12 21:29:34 +01:00
|
|
|
|
2012-01-30 15:55:55 +01:00
|
|
|
obj = object_resolve_path(path, &ambiguous);
|
|
|
|
if (obj == NULL) {
|
2014-05-04 10:23:59 +02:00
|
|
|
if (ambiguous) {
|
|
|
|
error_setg(errp, "Path '%s' is ambiguous", path);
|
|
|
|
} else {
|
2015-03-16 08:57:47 +01:00
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", path);
|
2014-05-04 10:23:59 +02:00
|
|
|
}
|
2011-12-12 21:29:34 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-09 13:34:02 +01:00
|
|
|
object_property_iter_init(&iter, obj);
|
|
|
|
while ((prop = object_property_iter_next(&iter))) {
|
2012-01-30 15:55:55 +01:00
|
|
|
ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
|
2011-12-12 21:29:34 +01:00
|
|
|
|
2012-01-30 15:55:55 +01:00
|
|
|
entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
|
2011-12-12 21:29:34 +01:00
|
|
|
entry->next = props;
|
|
|
|
props = entry;
|
|
|
|
|
|
|
|
entry->value->name = g_strdup(prop->name);
|
|
|
|
entry->value->type = g_strdup(prop->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return props;
|
|
|
|
}
|
2011-12-12 21:29:35 +01:00
|
|
|
|
2015-09-16 13:06:25 +02:00
|
|
|
void qmp_qom_set(const char *path, const char *property, QObject *value,
|
|
|
|
Error **errp)
|
2011-12-12 21:29:35 +01:00
|
|
|
{
|
2012-01-30 15:55:55 +01:00
|
|
|
Object *obj;
|
2011-12-12 21:29:35 +01:00
|
|
|
|
2012-01-30 15:55:55 +01: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-13 17:25:50 +01:00
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
2015-03-16 08:57:47 +01: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-13 17:25:50 +01:00
|
|
|
return;
|
2011-12-12 21:29:35 +01: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-13 17:25:50 +01:00
|
|
|
object_property_set_qobject(obj, value, property, errp);
|
2011-12-12 21:29:35 +01:00
|
|
|
}
|
|
|
|
|
2015-09-16 13:06:25 +02:00
|
|
|
QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
|
2011-12-12 21:29:35 +01:00
|
|
|
{
|
2012-01-30 15:55:55 +01:00
|
|
|
Object *obj;
|
2011-12-12 21:29:35 +01:00
|
|
|
|
2012-01-30 15:55:55 +01: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-13 17:25:50 +01:00
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
2015-03-16 08:57:47 +01:00
|
|
|
"Device '%s' not found", path);
|
2015-09-16 13:06:25 +02:00
|
|
|
return NULL;
|
2011-12-12 21:29:35 +01:00
|
|
|
}
|
|
|
|
|
2015-09-16 13:06:25 +02:00
|
|
|
return object_property_get_qobject(obj, property, errp);
|
2011-12-12 21:29:35 +01:00
|
|
|
}
|
2011-12-07 14:17:51 +01: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 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER, "connected");
|
2011-12-07 14:17:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "spice") == 0) {
|
2015-01-13 17:07:15 +01:00
|
|
|
if (!qemu_using_spice(errp)) {
|
2011-12-07 14:17:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
rc = qemu_spice_set_passwd(password, fail_if_connected,
|
|
|
|
disconnect_if_connected);
|
|
|
|
if (rc != 0) {
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-07 14:17:51 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "vnc") == 0) {
|
|
|
|
if (fail_if_connected || disconnect_if_connected) {
|
|
|
|
/* vnc supports "connected=keep" only */
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER, "connected");
|
2011-12-07 14:17:51 +01: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 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-07 14:17:51 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
|
2011-12-07 14:17:51 +01:00
|
|
|
}
|
2011-12-07 14:47:57 +01: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-13 17:07:15 +01:00
|
|
|
if (!qemu_using_spice(errp)) {
|
2011-12-07 14:47:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
rc = qemu_spice_set_pw_expire(when);
|
|
|
|
if (rc != 0) {
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-07 14:47:57 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "vnc") == 0) {
|
|
|
|
rc = vnc_display_pw_expire(NULL, when);
|
|
|
|
if (rc != 0) {
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-07 14:47:57 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
|
2011-12-07 14:47:57 +01:00
|
|
|
}
|
2011-12-08 14:45:55 +01:00
|
|
|
|
2011-12-08 14:13:50 +01:00
|
|
|
#ifdef CONFIG_VNC
|
2011-12-08 14:45:55 +01:00
|
|
|
void qmp_change_vnc_password(const char *password, Error **errp)
|
|
|
|
{
|
|
|
|
if (vnc_display_password(NULL, password) < 0) {
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_SET_PASSWD_FAILED);
|
2011-12-08 14:45:55 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-08 14:13:50 +01:00
|
|
|
|
2012-10-18 09:01:01 +02:00
|
|
|
static void qmp_change_vnc_listen(const char *target, Error **errp)
|
2011-12-08 14:13:50 +01:00
|
|
|
{
|
2014-09-16 12:33:03 +02: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 12:50:26 +01:00
|
|
|
opts = vnc_parse(target, errp);
|
2015-02-05 10:43:35 +01:00
|
|
|
if (!opts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-16 12:33:03 +02:00
|
|
|
vnc_display_open("default", errp);
|
2011-12-08 14:13:50 +01: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 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_MISSING_PARAMETER, "password");
|
2011-12-08 14:13:50 +01:00
|
|
|
} else {
|
|
|
|
qmp_change_vnc_password(arg, errp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qmp_change_vnc_listen(target, errp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* !CONFIG_VNC */
|
|
|
|
|
|
|
|
void qmp_change(const char *device, const char *target,
|
2014-05-02 13:26:31 +02:00
|
|
|
bool has_arg, const char *arg, Error **errp)
|
2011-12-08 14:13:50 +01:00
|
|
|
{
|
|
|
|
if (strcmp(device, "vnc") == 0) {
|
qapi: add conditions to VNC type/commands/events on the schema
Add #if defined(CONFIG_VNC) in generated code, and adjust the
qmp/hmp code accordingly.
query-qmp-schema no longer reports the command/events etc as
available when disabled at compile.
Commands made conditional:
* query-vnc, query-vnc-servers, change-vnc-password
Before the patch, the commands for !CONFIG_VNC are stubs that fail
like this:
{"error": {"class": "GenericError",
"desc": "The feature 'vnc' is not enabled"}}
Afterwards, they fail like this:
{"error": {"class": "CommandNotFound",
"desc": "The command FOO has not been found"}}
I call that an improvement, because it lets clients distinguish
between command unavailable (class CommandNotFound) and command failed
(class GenericError).
Events made conditional:
* VNC_CONNECTED, VNC_INITIALIZED, VNC_DISCONNECTED
HMP change:
* info vnc
Will return "unknown command: 'info vnc'" when VNC is compiled
out (same as error for spice when --disable-spice)
Occurrences of VNC (case insensitive) in the schema that aren't
covered by this change:
* add_client
Command has other uses, including "socket bases character devices".
These are unconditional as far as I can tell.
* set_password, expire_password
In theory, these commands could be used for managing any service's
password. In practice, they're used for VNC and SPICE services.
They're documented for "remote display session" / "remote display
server".
The service is selected by argument @protocol. The code special-cases
protocol-specific argument checking, then calls a protocol-specific
function to do the work. If it fails, the command fails with "Could
not set password". It does when the service isn't compiled in (it's a
stub then).
We could make these commands conditional on the conjunction of all
services [currently: defined(CONFIG_VNC) || defined(CONFIG_SPICE)],
but I doubt it's worthwhile.
* change
Command has other uses, namely changing media.
This patch inlines a stub; no functional change.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20180703155648.11933-14-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-07-03 17:56:47 +02:00
|
|
|
#ifdef CONFIG_VNC
|
2014-05-02 13:26:31 +02:00
|
|
|
qmp_change_vnc(target, has_arg, arg, errp);
|
qapi: add conditions to VNC type/commands/events on the schema
Add #if defined(CONFIG_VNC) in generated code, and adjust the
qmp/hmp code accordingly.
query-qmp-schema no longer reports the command/events etc as
available when disabled at compile.
Commands made conditional:
* query-vnc, query-vnc-servers, change-vnc-password
Before the patch, the commands for !CONFIG_VNC are stubs that fail
like this:
{"error": {"class": "GenericError",
"desc": "The feature 'vnc' is not enabled"}}
Afterwards, they fail like this:
{"error": {"class": "CommandNotFound",
"desc": "The command FOO has not been found"}}
I call that an improvement, because it lets clients distinguish
between command unavailable (class CommandNotFound) and command failed
(class GenericError).
Events made conditional:
* VNC_CONNECTED, VNC_INITIALIZED, VNC_DISCONNECTED
HMP change:
* info vnc
Will return "unknown command: 'info vnc'" when VNC is compiled
out (same as error for spice when --disable-spice)
Occurrences of VNC (case insensitive) in the schema that aren't
covered by this change:
* add_client
Command has other uses, including "socket bases character devices".
These are unconditional as far as I can tell.
* set_password, expire_password
In theory, these commands could be used for managing any service's
password. In practice, they're used for VNC and SPICE services.
They're documented for "remote display session" / "remote display
server".
The service is selected by argument @protocol. The code special-cases
protocol-specific argument checking, then calls a protocol-specific
function to do the work. If it fails, the command fails with "Could
not set password". It does when the service isn't compiled in (it's a
stub then).
We could make these commands conditional on the conjunction of all
services [currently: defined(CONFIG_VNC) || defined(CONFIG_SPICE)],
but I doubt it's worthwhile.
* change
Command has other uses, namely changing media.
This patch inlines a stub; no functional change.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20180703155648.11933-14-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-07-03 17:56:47 +02:00
|
|
|
#else
|
|
|
|
error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
|
|
|
|
#endif
|
2011-12-08 14:13:50 +01:00
|
|
|
} else {
|
2016-09-20 13:38:47 +02:00
|
|
|
qmp_blockdev_change_medium(true, device, false, NULL, target,
|
|
|
|
has_arg, arg, false, 0, errp);
|
2011-12-08 14:13:50 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-22 21:40:54 +01:00
|
|
|
|
|
|
|
static void qom_list_types_tramp(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
ObjectTypeInfoList *e, **pret = data;
|
|
|
|
ObjectTypeInfo *info;
|
2017-07-07 14:22:15 +02:00
|
|
|
ObjectClass *parent = object_class_get_parent(klass);
|
2011-12-22 21:40:54 +01:00
|
|
|
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->name = g_strdup(object_class_get_name(klass));
|
2017-07-07 14:22:14 +02:00
|
|
|
info->has_abstract = info->abstract = object_class_is_abstract(klass);
|
2017-07-07 14:22:15 +02:00
|
|
|
if (parent) {
|
|
|
|
info->has_parent = true;
|
|
|
|
info->parent = g_strdup(object_class_get_name(parent));
|
|
|
|
}
|
2011-12-22 21:40:54 +01:00
|
|
|
|
|
|
|
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-10 18:04:09 +02:00
|
|
|
|
2014-05-20 14:29:01 +02: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.
|
|
|
|
*/
|
2018-03-01 14:09:38 +01:00
|
|
|
static ObjectPropertyInfo *make_device_property_info(ObjectClass *klass,
|
|
|
|
const char *name,
|
|
|
|
const char *default_type,
|
|
|
|
const char *description)
|
2014-05-20 14:29:01 +02:00
|
|
|
{
|
2018-03-01 14:09:38 +01:00
|
|
|
ObjectPropertyInfo *info;
|
2014-05-20 14:29:01 +02:00
|
|
|
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.
|
|
|
|
*/
|
2017-07-14 04:14:51 +02:00
|
|
|
if (!prop->info->set && !prop->info->create) {
|
2014-05-20 14:29:01 +02:00
|
|
|
return NULL; /* no way to set it, don't show */
|
|
|
|
}
|
|
|
|
|
|
|
|
info = g_malloc0(sizeof(*info));
|
|
|
|
info->name = g_strdup(prop->name);
|
2017-07-14 04:14:53 +02:00
|
|
|
info->type = default_type ? g_strdup(default_type)
|
|
|
|
: g_strdup(prop->info->name);
|
2014-10-07 08:33:23 +02:00
|
|
|
info->has_description = !!prop->info->description;
|
|
|
|
info->description = g_strdup(prop->info->description);
|
2014-05-20 14:29:01 +02: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 08:33:23 +02:00
|
|
|
info->has_description = !!description;
|
|
|
|
info->description = g_strdup(description);
|
|
|
|
|
2014-05-20 14:29:01 +02:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:09:38 +01:00
|
|
|
ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
|
|
|
|
Error **errp)
|
2012-08-10 18:04:09 +02:00
|
|
|
{
|
|
|
|
ObjectClass *klass;
|
2014-05-20 14:29:01 +02:00
|
|
|
Object *obj;
|
|
|
|
ObjectProperty *prop;
|
2015-12-09 13:34:02 +01:00
|
|
|
ObjectPropertyIterator iter;
|
2018-03-01 14:09:38 +01:00
|
|
|
ObjectPropertyInfoList *prop_list = NULL;
|
2012-08-10 18:04:09 +02:00
|
|
|
|
|
|
|
klass = object_class_by_name(typename);
|
|
|
|
if (klass == NULL) {
|
2015-03-16 08:57:47 +01:00
|
|
|
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
|
|
"Device '%s' not found", typename);
|
2012-08-10 18:04:09 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
|
|
|
|
if (klass == NULL) {
|
2017-01-25 06:27:03 +01:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE);
|
2012-08-10 18:04:09 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 10:59:57 +02:00
|
|
|
if (object_class_is_abstract(klass)) {
|
2017-01-25 06:27:03 +01:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
|
2015-10-01 10:59:57 +02:00
|
|
|
"non-abstract device type");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-20 14:29:01 +02:00
|
|
|
obj = object_new(typename);
|
2012-08-10 18:04:09 +02:00
|
|
|
|
2015-12-09 13:34:02 +01:00
|
|
|
object_property_iter_init(&iter, obj);
|
|
|
|
while ((prop = object_property_iter_next(&iter))) {
|
2018-03-01 14:09:38 +01:00
|
|
|
ObjectPropertyInfo *info;
|
|
|
|
ObjectPropertyInfoList *entry;
|
2014-05-20 14:29:01 +02:00
|
|
|
|
|
|
|
/* Skip Object and DeviceState properties */
|
|
|
|
if (strcmp(prop->name, "type") == 0 ||
|
|
|
|
strcmp(prop->name, "realized") == 0 ||
|
|
|
|
strcmp(prop->name, "hotpluggable") == 0 ||
|
2014-07-09 14:01:31 +02:00
|
|
|
strcmp(prop->name, "hotplugged") == 0 ||
|
2014-05-20 14:29:01 +02:00
|
|
|
strcmp(prop->name, "parent_bus") == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-10 18:04:09 +02:00
|
|
|
|
2014-05-20 14:29:01 +02: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-10 18:04:09 +02:00
|
|
|
|
2014-10-07 08:33:23 +02:00
|
|
|
info = make_device_property_info(klass, prop->name, prop->type,
|
|
|
|
prop->description);
|
2014-05-20 14:29:01 +02:00
|
|
|
if (!info) {
|
|
|
|
continue;
|
2012-08-10 18:04:09 +02:00
|
|
|
}
|
2014-05-20 14:29:01 +02:00
|
|
|
|
|
|
|
entry = g_malloc0(sizeof(*entry));
|
2018-03-01 14:09:39 +01:00
|
|
|
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));
|
2014-05-20 14:29:01 +02:00
|
|
|
entry->value = info;
|
|
|
|
entry->next = prop_list;
|
|
|
|
prop_list = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_unref(obj);
|
2012-08-10 18:04:09 +02:00
|
|
|
|
|
|
|
return prop_list;
|
|
|
|
}
|
2012-08-10 18:04:13 +02:00
|
|
|
|
2012-09-13 21:52:20 +02:00
|
|
|
void qmp_add_client(const char *protocol, const char *fdname,
|
|
|
|
bool has_skipauth, bool skipauth, bool has_tls, bool tls,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2016-12-07 14:20:22 +01:00
|
|
|
Chardev *s;
|
2012-09-13 21:52:20 +02:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = monitor_get_fd(cur_mon, fdname, errp);
|
|
|
|
if (fd < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(protocol, "spice") == 0) {
|
2015-01-13 17:07:15 +01:00
|
|
|
if (!qemu_using_spice(errp)) {
|
2012-09-13 21:52:20 +02: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-20 23:21:09 +01:00
|
|
|
|
2013-12-20 23:21:10 +01:00
|
|
|
|
2015-09-16 13:06:25 +02:00
|
|
|
void qmp_object_add(const char *type, const char *id,
|
|
|
|
bool has_props, QObject *props, Error **errp)
|
2013-12-20 23:21:10 +01:00
|
|
|
{
|
2016-09-22 22:39:25 +02:00
|
|
|
QDict *pdict;
|
qmp-input-visitor: Favor new visit_free() function
Now that we have a polymorphic visit_free(), we no longer need
qmp_input_visitor_cleanup(); which in turn means we no longer
need to return a subtype from qmp_input_visitor_new() nor a
public upcast function.
Generated code changes to qmp-marshal.c look like:
|@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb
| {
| Error *err = NULL;
| AddfdInfo *retval;
|- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
| Visitor *v;
| q_obj_add_fd_arg arg = {0};
|
|- v = qmp_input_get_visitor(qiv);
|+ v = qmp_input_visitor_new(QOBJECT(args), true);
| visit_start_struct(v, NULL, NULL, 0, &err);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 18:48:38 +02:00
|
|
|
Visitor *v;
|
2016-02-10 19:40:59 +01:00
|
|
|
Object *obj;
|
2013-12-20 23:21:10 +01:00
|
|
|
|
|
|
|
if (props) {
|
2018-02-24 16:40:29 +01:00
|
|
|
pdict = qobject_to(QDict, props);
|
2013-12-20 23:21:10 +01:00
|
|
|
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-13 17:25:50 +01:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
|
|
|
|
return;
|
2013-12-20 23:21:10 +01:00
|
|
|
}
|
2018-04-19 17:01:43 +02:00
|
|
|
qobject_ref(pdict);
|
2016-09-22 22:39:25 +02:00
|
|
|
} else {
|
|
|
|
pdict = qdict_new();
|
2013-12-20 23:21:10 +01:00
|
|
|
}
|
|
|
|
|
2017-03-03 13:32:39 +01:00
|
|
|
v = qobject_input_visitor_new(QOBJECT(pdict));
|
qmp-input-visitor: Favor new visit_free() function
Now that we have a polymorphic visit_free(), we no longer need
qmp_input_visitor_cleanup(); which in turn means we no longer
need to return a subtype from qmp_input_visitor_new() nor a
public upcast function.
Generated code changes to qmp-marshal.c look like:
|@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb
| {
| Error *err = NULL;
| AddfdInfo *retval;
|- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
| Visitor *v;
| q_obj_add_fd_arg arg = {0};
|
|- v = qmp_input_get_visitor(qiv);
|+ v = qmp_input_visitor_new(QOBJECT(args), true);
| visit_start_struct(v, NULL, NULL, 0, &err);
| if (err) {
| goto out;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-06-09 18:48:38 +02:00
|
|
|
obj = user_creatable_add_type(type, id, pdict, v, errp);
|
|
|
|
visit_free(v);
|
2016-02-10 19:40:59 +01:00
|
|
|
if (obj) {
|
|
|
|
object_unref(obj);
|
|
|
|
}
|
2018-04-19 17:01:43 +02:00
|
|
|
qobject_unref(pdict);
|
2013-12-20 23:21:10 +01:00
|
|
|
}
|
|
|
|
|
2013-12-20 23:21:09 +01:00
|
|
|
void qmp_object_del(const char *id, Error **errp)
|
|
|
|
{
|
2016-02-10 19:40:59 +01:00
|
|
|
user_creatable_del(id, errp);
|
2013-12-20 23:21:09 +01:00
|
|
|
}
|
2014-06-16 19:12:25 +02:00
|
|
|
|
|
|
|
MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
|
|
|
|
{
|
2018-04-23 18:51:16 +02:00
|
|
|
return qmp_memory_device_list();
|
2014-06-16 19:12:25 +02:00
|
|
|
}
|
2014-06-16 19:12:28 +02: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;
|
|
|
|
}
|
2017-08-29 17:30:21 +02:00
|
|
|
|
|
|
|
MemoryInfo *qmp_query_memory_size_summary(Error **errp)
|
|
|
|
{
|
|
|
|
MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
|
|
|
|
|
|
|
|
mem_info->base_memory = ram_size;
|
|
|
|
|
|
|
|
mem_info->plugged_memory = get_plugged_memory_size();
|
|
|
|
mem_info->has_plugged_memory =
|
|
|
|
mem_info->plugged_memory != (uint64_t)-1;
|
|
|
|
|
|
|
|
return mem_info;
|
|
|
|
}
|