From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com, dgilbert@redhat.com
Subject: [PATCH 5/9] ui: Move QMP commands from monitor to new ui/ui-qmp-cmds.c
Date: Thu, 1 Dec 2022 07:13:07 +0100 [thread overview]
Message-ID: <20221201061311.3619052-6-armbru@redhat.com> (raw)
In-Reply-To: <20221201061311.3619052-1-armbru@redhat.com>
This moves these commands from MAINTAINERS section "Human
Monitor (HMP)" to "Graphics".
Command add-client applies to socket character devices in addition to
display devices. Move it anyway. Aside: the way @protocol character
device IDs and display types is bad design.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
monitor/qmp-cmds.c | 177 -----------------------------------------
ui/ui-qmp-cmds.c | 194 +++++++++++++++++++++++++++++++++++++++++++++
ui/meson.build | 1 +
3 files changed, 195 insertions(+), 177 deletions(-)
create mode 100644 ui/ui-qmp-cmds.c
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index a7c95e8e39..85b2089873 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -16,14 +16,9 @@
#include "qemu/osdep.h"
#include "qemu/cutils.h"
#include "qemu/option.h"
-#include "monitor/monitor.h"
#include "sysemu/sysemu.h"
#include "qemu/config-file.h"
#include "qemu/uuid.h"
-#include "chardev/char.h"
-#include "ui/qemu-spice.h"
-#include "ui/console.h"
-#include "ui/dbus-display.h"
#include "sysemu/kvm.h"
#include "sysemu/runstate.h"
#include "sysemu/runstate-action.h"
@@ -36,9 +31,7 @@
#include "qapi/qapi-commands-machine.h"
#include "qapi/qapi-commands-misc.h"
#include "qapi/qapi-commands-stats.h"
-#include "qapi/qapi-commands-ui.h"
#include "qapi/type-helpers.h"
-#include "qapi/qmp/qerror.h"
#include "exec/ramlist.h"
#include "hw/mem/memory-device.h"
#include "hw/acpi/acpi_dev_interface.h"
@@ -172,144 +165,6 @@ void qmp_system_wakeup(Error **errp)
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, errp);
}
-void qmp_set_password(SetPasswordOptions *opts, Error **errp)
-{
- int rc;
-
- if (opts->protocol == DISPLAY_PROTOCOL_SPICE) {
- if (!qemu_using_spice(errp)) {
- return;
- }
- rc = qemu_spice.set_passwd(opts->password,
- opts->connected == SET_PASSWORD_ACTION_FAIL,
- opts->connected == SET_PASSWORD_ACTION_DISCONNECT);
- } else {
- assert(opts->protocol == DISPLAY_PROTOCOL_VNC);
- if (opts->connected != SET_PASSWORD_ACTION_KEEP) {
- /* vnc supports "connected=keep" only */
- error_setg(errp, QERR_INVALID_PARAMETER, "connected");
- return;
- }
- /*
- * Note that setting an empty password will not disable login
- * through this interface.
- */
- rc = vnc_display_password(opts->u.vnc.display, opts->password);
- }
-
- if (rc != 0) {
- error_setg(errp, "Could not set password");
- }
-}
-
-void qmp_expire_password(ExpirePasswordOptions *opts, Error **errp)
-{
- time_t when;
- int rc;
- const char *whenstr = opts->time;
- const char *numstr = NULL;
- uint64_t num;
-
- if (strcmp(whenstr, "now") == 0) {
- when = 0;
- } else if (strcmp(whenstr, "never") == 0) {
- when = TIME_MAX;
- } else if (whenstr[0] == '+') {
- when = time(NULL);
- numstr = whenstr + 1;
- } else {
- when = 0;
- numstr = whenstr;
- }
-
- if (numstr) {
- if (qemu_strtou64(numstr, NULL, 10, &num) < 0) {
- error_setg(errp, "Parameter 'time' doesn't take value '%s'",
- whenstr);
- return;
- }
- when += num;
- }
-
- if (opts->protocol == DISPLAY_PROTOCOL_SPICE) {
- if (!qemu_using_spice(errp)) {
- return;
- }
- rc = qemu_spice.set_pw_expire(when);
- } else {
- assert(opts->protocol == DISPLAY_PROTOCOL_VNC);
- rc = vnc_display_pw_expire(opts->u.vnc.display, when);
- }
-
- if (rc != 0) {
- error_setg(errp, "Could not set password expire time");
- }
-}
-
-#ifdef CONFIG_VNC
-void qmp_change_vnc_password(const char *password, Error **errp)
-{
- if (vnc_display_password(NULL, password) < 0) {
- error_setg(errp, "Could not set password");
- }
-}
-#endif
-
-void qmp_add_client(const char *protocol, const char *fdname,
- bool has_skipauth, bool skipauth, bool has_tls, bool tls,
- Error **errp)
-{
- Chardev *s;
- int fd;
-
- fd = monitor_get_fd(monitor_cur(), fdname, errp);
- if (fd < 0) {
- return;
- }
-
- if (strcmp(protocol, "spice") == 0) {
- if (!qemu_using_spice(errp)) {
- 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);
- }
-#ifdef CONFIG_VNC
- } else if (strcmp(protocol, "vnc") == 0) {
- skipauth = has_skipauth ? skipauth : false;
- vnc_display_add_client(NULL, fd, skipauth);
-#endif
-#ifdef CONFIG_DBUS_DISPLAY
- } else if (strcmp(protocol, "@dbus-display") == 0) {
- if (!qemu_using_dbus_display(errp)) {
- close(fd);
- return;
- }
- if (!qemu_dbus_display.add_client(fd, errp)) {
- close(fd);
- return;
- }
-#endif
- } else {
- s = qemu_chr_find(protocol);
- if (!s) {
- error_setg(errp, "protocol '%s' is invalid", protocol);
- close(fd);
- return;
- }
- if (qemu_chr_add_client(s, fd) < 0) {
- error_setg(errp, "failed to add client");
- close(fd);
- return;
- }
- }
-}
-
-
MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
{
return qmp_memory_device_list();
@@ -348,38 +203,6 @@ MemoryInfo *qmp_query_memory_size_summary(Error **errp)
return mem_info;
}
-void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)
-{
- switch (arg->type) {
- case DISPLAY_RELOAD_TYPE_VNC:
-#ifdef CONFIG_VNC
- if (arg->u.vnc.has_tls_certs && arg->u.vnc.tls_certs) {
- vnc_display_reload_certs(NULL, errp);
- }
-#else
- error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
-#endif
- break;
- default:
- abort();
- }
-}
-
-void qmp_display_update(DisplayUpdateOptions *arg, Error **errp)
-{
- switch (arg->type) {
- case DISPLAY_UPDATE_TYPE_VNC:
-#ifdef CONFIG_VNC
- vnc_display_update(&arg->u.vnc, errp);
-#else
- error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
-#endif
- break;
- default:
- abort();
- }
-}
-
static int qmp_x_query_rdma_foreach(Object *obj, void *opaque)
{
RdmaProvider *rdma;
diff --git a/ui/ui-qmp-cmds.c b/ui/ui-qmp-cmds.c
new file mode 100644
index 0000000000..5d145c26f7
--- /dev/null
+++ b/ui/ui-qmp-cmds.c
@@ -0,0 +1,194 @@
+/*
+ * QMP commands related to UI
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+#include "chardev/char.h"
+#include "monitor/monitor.h"
+#include "qapi/qapi-commands-misc.h"
+#include "qapi/qapi-commands-ui.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/cutils.h"
+#include "ui/console.h"
+#include "ui/dbus-display.h"
+#include "ui/qemu-spice.h"
+
+void qmp_set_password(SetPasswordOptions *opts, Error **errp)
+{
+ int rc;
+
+ if (opts->protocol == DISPLAY_PROTOCOL_SPICE) {
+ if (!qemu_using_spice(errp)) {
+ return;
+ }
+ rc = qemu_spice.set_passwd(opts->password,
+ opts->connected == SET_PASSWORD_ACTION_FAIL,
+ opts->connected == SET_PASSWORD_ACTION_DISCONNECT);
+ } else {
+ assert(opts->protocol == DISPLAY_PROTOCOL_VNC);
+ if (opts->connected != SET_PASSWORD_ACTION_KEEP) {
+ /* vnc supports "connected=keep" only */
+ error_setg(errp, QERR_INVALID_PARAMETER, "connected");
+ return;
+ }
+ /*
+ * Note that setting an empty password will not disable login
+ * through this interface.
+ */
+ rc = vnc_display_password(opts->u.vnc.display, opts->password);
+ }
+
+ if (rc != 0) {
+ error_setg(errp, "Could not set password");
+ }
+}
+
+void qmp_expire_password(ExpirePasswordOptions *opts, Error **errp)
+{
+ time_t when;
+ int rc;
+ const char *whenstr = opts->time;
+ const char *numstr = NULL;
+ uint64_t num;
+
+ if (strcmp(whenstr, "now") == 0) {
+ when = 0;
+ } else if (strcmp(whenstr, "never") == 0) {
+ when = TIME_MAX;
+ } else if (whenstr[0] == '+') {
+ when = time(NULL);
+ numstr = whenstr + 1;
+ } else {
+ when = 0;
+ numstr = whenstr;
+ }
+
+ if (numstr) {
+ if (qemu_strtou64(numstr, NULL, 10, &num) < 0) {
+ error_setg(errp, "Parameter 'time' doesn't take value '%s'",
+ whenstr);
+ return;
+ }
+ when += num;
+ }
+
+ if (opts->protocol == DISPLAY_PROTOCOL_SPICE) {
+ if (!qemu_using_spice(errp)) {
+ return;
+ }
+ rc = qemu_spice.set_pw_expire(when);
+ } else {
+ assert(opts->protocol == DISPLAY_PROTOCOL_VNC);
+ rc = vnc_display_pw_expire(opts->u.vnc.display, when);
+ }
+
+ if (rc != 0) {
+ error_setg(errp, "Could not set password expire time");
+ }
+}
+
+#ifdef CONFIG_VNC
+void qmp_change_vnc_password(const char *password, Error **errp)
+{
+ if (vnc_display_password(NULL, password) < 0) {
+ error_setg(errp, "Could not set password");
+ }
+}
+#endif
+
+void qmp_add_client(const char *protocol, const char *fdname,
+ bool has_skipauth, bool skipauth, bool has_tls, bool tls,
+ Error **errp)
+{
+ Chardev *s;
+ int fd;
+
+ fd = monitor_get_fd(monitor_cur(), fdname, errp);
+ if (fd < 0) {
+ return;
+ }
+
+ if (strcmp(protocol, "spice") == 0) {
+ if (!qemu_using_spice(errp)) {
+ 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);
+ }
+#ifdef CONFIG_VNC
+ } else if (strcmp(protocol, "vnc") == 0) {
+ skipauth = has_skipauth ? skipauth : false;
+ vnc_display_add_client(NULL, fd, skipauth);
+#endif
+#ifdef CONFIG_DBUS_DISPLAY
+ } else if (strcmp(protocol, "@dbus-display") == 0) {
+ if (!qemu_using_dbus_display(errp)) {
+ close(fd);
+ return;
+ }
+ if (!qemu_dbus_display.add_client(fd, errp)) {
+ close(fd);
+ return;
+ }
+#endif
+ } else {
+ s = qemu_chr_find(protocol);
+ if (!s) {
+ error_setg(errp, "protocol '%s' is invalid", protocol);
+ close(fd);
+ return;
+ }
+ if (qemu_chr_add_client(s, fd) < 0) {
+ error_setg(errp, "failed to add client");
+ close(fd);
+ return;
+ }
+ }
+}
+
+void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)
+{
+ switch (arg->type) {
+ case DISPLAY_RELOAD_TYPE_VNC:
+#ifdef CONFIG_VNC
+ if (arg->u.vnc.has_tls_certs && arg->u.vnc.tls_certs) {
+ vnc_display_reload_certs(NULL, errp);
+ }
+#else
+ error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
+#endif
+ break;
+ default:
+ abort();
+ }
+}
+
+void qmp_display_update(DisplayUpdateOptions *arg, Error **errp)
+{
+ switch (arg->type) {
+ case DISPLAY_UPDATE_TYPE_VNC:
+#ifdef CONFIG_VNC
+ vnc_display_update(&arg->u.vnc, errp);
+#else
+ error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
+#endif
+ break;
+ default:
+ abort();
+ }
+}
diff --git a/ui/meson.build b/ui/meson.build
index c1b137bf33..9194ea335b 100644
--- a/ui/meson.build
+++ b/ui/meson.build
@@ -14,6 +14,7 @@ softmmu_ss.add(files(
'kbd-state.c',
'keymaps.c',
'qemu-pixman.c',
+ 'ui-qmp-cmds.c',
'util.c',
))
if dbus_display
--
2.37.3
next prev parent reply other threads:[~2022-12-01 6:16 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 6:13 [PATCH 0/9] ui: Move and clean up monitor command code Markus Armbruster
2022-12-01 6:13 ` [PATCH 1/9] ui: Check numeric part of expire_password argument @time properly Markus Armbruster
2022-12-01 8:13 ` Daniel P. Berrangé
2022-12-01 6:13 ` [PATCH 2/9] ui: Fix silent truncation of numeric keys in HMP sendkey Markus Armbruster
2022-12-01 8:14 ` Daniel P. Berrangé
2022-12-01 6:13 ` [PATCH 3/9] ui: Drop disabled code for SPICE_CHANNEL_WEBDAV Markus Armbruster
2022-12-01 8:49 ` Daniel P. Berrangé
2022-12-01 10:25 ` Markus Armbruster
2022-12-01 12:39 ` Markus Armbruster
2022-12-01 14:34 ` Daniel P. Berrangé
2022-12-01 15:49 ` Markus Armbruster
2022-12-01 18:34 ` Daniel P. Berrangé
2022-12-02 6:52 ` Markus Armbruster
2022-12-01 6:13 ` [PATCH 4/9] ui: Clean up a few things checkpatch.pl would flag later on Markus Armbruster
2022-12-01 8:50 ` Daniel P. Berrangé
2022-12-01 6:13 ` Markus Armbruster [this message]
2022-12-01 6:38 ` [PATCH 5/9] ui: Move QMP commands from monitor to new ui/ui-qmp-cmds.c Markus Armbruster
2022-12-11 16:48 ` Markus Armbruster
2022-12-01 8:51 ` Daniel P. Berrangé
2022-12-01 6:13 ` [PATCH 6/9] ui: Move HMP commands from monitor to new ui/ui-hmp-cmds.c Markus Armbruster
2022-12-01 7:14 ` Philippe Mathieu-Daudé
2022-12-01 10:26 ` Markus Armbruster
2022-12-01 8:53 ` Daniel P. Berrangé
2022-12-01 6:13 ` [PATCH 7/9] ui: Improve "change vnc" error reporting Markus Armbruster
2022-12-01 8:56 ` Daniel P. Berrangé
2022-12-01 10:27 ` Markus Armbruster
2022-12-01 6:13 ` [PATCH 8/9] ui: Factor out hmp_change_vnc(), and move to ui/ui-hmp-cmds.c Markus Armbruster
2022-12-01 8:57 ` Daniel P. Berrangé
2022-12-01 6:13 ` [PATCH 9/9] ui: Reduce nesting in hmp_change_vnc() slightly Markus Armbruster
2022-12-01 7:19 ` Philippe Mathieu-Daudé
2022-12-01 8:58 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221201061311.3619052-6-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).