Skip to contentSkip to conversation

Monitor patches for 2019-06-17

GIT PULL Markus Armbruster 5 participants 26 messages Jun 17, 2019 – Jun 19, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

The following changes since commit 076243ffe6c1b687e9e6d98348c3bf3398df78f3:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-docs-20190617' into staging (2019-06-17 16:41:25 +0100)

are available in the Git repository at:

git://repo.or.cz/qemu/armbru.git tags/pull-monitor-2019-06-17

for you to fetch changes up to 092b8737c5e7695c4b9caa3b4eedc66763632755:

vl: Deprecate -mon pretty=... for HMP monitors (2019-06-17 20:36:56 +0200)

----------------------------------------------------------------
Monitor patches for 2019-06-17

----------------------------------------------------------------
Kevin Wolf (15):
monitor: Remove unused password prompting fields
monitor: Split monitor_init in HMP and QMP function
monitor: Make MonitorQMP a child class of Monitor
monitor: Create MonitorHMP with readline state
monitor: Remove Monitor.cmd_table indirection
monitor: Rename HMP command type and tables
Move monitor.c to monitor/misc.c
monitor: Move {hmp, qmp}.c to monitor/{hmp, qmp}-cmds.c
monitor: Create monitor-internal.h with common definitions
monitor: Split out monitor/qmp.c
monitor: Split out monitor/hmp.c
monitor: Split out monitor/monitor.c
monitor: Split Monitor.flags into separate bools
monitor: Replace monitor_init() with monitor_init_{hmp, qmp}()
vl: Deprecate -mon pretty=... for HMP monitors

Yury Kotov (1):
monitor: Fix return type of monitor_fdset_dup_fd_find

 MAINTAINERS                         |   13 +-
 Makefile.objs                       |    4 +-
 Makefile.target                     |    3 +-
 chardev/char.c                      |    2 +-
 docs/devel/writing-qmp-commands.txt |   11 +-
 gdbstub.c                           |    2 +-
 hmp-commands.hx                     |    2 +-
 include/monitor/monitor.h           |   17 +-
 monitor.c                           | 4729 -----------------------------------
 monitor/Makefile.objs               |    3 +
 hmp.c => monitor/hmp-cmds.c         |    7 +-
 monitor/hmp.c                       | 1416 +++++++++++
 monitor/misc.c                      | 2353 +++++++++++++++++
 monitor/monitor-internal.h          |  183 ++
 monitor/monitor.c                   |  628 +++++
 qmp.c => monitor/qmp-cmds.c         |    2 +-
 monitor/qmp.c                       |  404 +++
 monitor/trace-events                |   15 +
 qemu-deprecated.texi                |    6 +
 stubs/fdset.c                       |    2 +-
 stubs/monitor.c                     |    6 +-
 tests/test-util-sockets.c           |    3 +-
 trace-events                        |   10 -
 vl.c                                |   28 +-
 24 files changed, 5072 insertions(+), 4777 deletions(-)
 delete mode 100644 monitor.c
 create mode 100644 monitor/Makefile.objs
 rename hmp.c => monitor/hmp-cmds.c (99%)
 create mode 100644 monitor/hmp.c
 create mode 100644 monitor/misc.c
 create mode 100644 monitor/monitor-internal.h
 create mode 100644 monitor/monitor.c
 rename qmp.c => monitor/qmp-cmds.c (99%)
 create mode 100644 monitor/qmp.c
 create mode 100644 monitor/trace-events
Signature · 1 line
2.21.0
#1 lore raw

[Qemu-devel] [PULL 02/16] monitor: Remove unused password prompting fields

From: Kevin Wolf <[email protected]>

Commit 788cf9f8c removed the code for password prompting from the monitor. Since then, the Monitor fields password_completion_cb and password_opaque have been unused. Remove them.

Message-Id: <[email protected]>

---
 monitor.c | 2 --
 1 file changed, 2 deletions(-)
monitor.c +0 -2
index dce3496920..8e9851ae15 100644
@@ -222,8 +222,6 @@ struct Monitor {
 
     MonitorQMP qmp;
     gchar *mon_cpu_path;
-    BlockCompletionFunc *password_completion_cb;
-    void *password_opaque;
     mon_cmd_t *cmd_table;
     QTAILQ_ENTRY(Monitor) entry;
 
Signature · 1 line
2.21.0
#2 lore raw

[Qemu-devel] [PULL 13/16] monitor: Split out monitor/monitor.c

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Move the monitor core infrastructure from monitor/misc.c to monitor/monitor.c. This is code that can be shared for all targets, so compile it only once.

What remains in monitor/misc.c after this patch is mostly monitor command implementations (which could move to hmp-cmds.c or qmp-cmds.c later) and code that requires a system emulator or is even target-dependent (including HMP command completion code).

The amount of function and particularly extern variables in monitor_int.h is probably a bit larger than it needs to be, but this way no non-trivial code modifications are needed. The interfaces between all monitor parts can be cleaned up later.

Message-Id: <[email protected]>

[Superfluous #include dropped]
---
 MAINTAINERS                |   2 +
 include/monitor/monitor.h  |   1 +
 monitor/Makefile.objs      |   2 +-
 monitor/misc.c             | 598 +----------------------------------
 monitor/monitor-internal.h |   1 +
 monitor/monitor.c          | 633 +++++++++++++++++++++++++++++++++++++
 monitor/trace-events       |   2 +-
 7 files changed, 640 insertions(+), 599 deletions(-)
 create mode 100644 monitor/monitor.c
MAINTAINERS +2 -0
index 15f21c35e0..d32c5c2313 100644
@@ -1920,6 +1920,7 @@ M: Dr. David Alan Gilbert <[email protected]>
 S: Maintained
 F: monitor/monitor-internal.h
 F: monitor/misc.c
+F: monitor/monitor.c
 F: monitor/hmp*
 F: hmp.h
 F: hmp-commands*.hx
@@ -2044,6 +2045,7 @@ S: Supported
 F: monitor/monitor-internal.h
 F: monitor/qmp*
 F: monitor/misc.c
+F: monitor/monitor.c
 F: docs/devel/*qmp-*
 F: docs/interop/*qmp-*
 F: scripts/qmp/
include/monitor/monitor.h +1 -0
index f9d30e1d78..44ac43df34 100644
@@ -19,6 +19,7 @@ typedef struct MonitorHMP MonitorHMP;
 bool monitor_cur_is_qmp(void);
 
 void monitor_init_globals(void);
+void monitor_init_globals_core(void);
 void monitor_init(Chardev *chr, int flags);
 void monitor_cleanup(void);
 
monitor/Makefile.objs +1 -1
index bea8838acc..e91a8581cd 100644
@@ -1,3 +1,3 @@
 obj-y += misc.o
-common-obj-y += qmp.o hmp.o
+common-obj-y += monitor.o qmp.o hmp.o
 common-obj-y += qmp-cmds.o hmp-cmds.o
monitor/misc.c +1 -597

644 lines not on this page · raw message

monitor/monitor-internal.h +1 -0
index 10fda7d97c..b4996c14ac 100644
@@ -167,6 +167,7 @@ void monitor_init_hmp(Chardev *chr, int flags);
 int monitor_puts(Monitor *mon, const char *str);
 void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
                        bool use_io_thread);
+void monitor_data_destroy(Monitor *mon);
 int monitor_can_read(void *opaque);
 void monitor_list_append(Monitor *mon);
 void monitor_fdsets_cleanup(void);
monitor/monitor.c new file +633 -0

633 lines not on this page · raw message

monitor/trace-events +1 -1
index 2285d26121..0365ac4d99 100644
@@ -3,7 +3,7 @@
 # hmp.c
 handle_hmp_command(void *mon, const char *cmdline) "mon %p cmdline: %s"
 
-# misc.c
+# monitor.c
 monitor_protocol_event_handler(uint32_t event, void *qdict) "event=%d data=%p"
 monitor_protocol_event_emit(uint32_t event, void *data) "event=%d data=%p"
 monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "event=%d data=%p rate=%" PRId64
Signature · 1 line
2.21.0
#3 lore raw

[Qemu-devel] [PULL 03/16] monitor: Split monitor_init in HMP and QMP function

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Instead of mixing HMP and QMP monitors in the same function, separate the monitor creation function for both.

While in theory, one could pass both MONITOR_USE_CONTROL and MONITOR_USE_READLINE before this patch and both flags would do something, readline support is tightly coupled with HMP: QMP never feeds its input to readline, and the tab completion function treats the input as an HMP command. Therefore, this configuration is useless.

After this patch, the QMP path asserts that MONITOR_USE_READLINE is not set. The HMP path can be used with or without MONITOR_USE_READLINE, like before.

Message-Id: <[email protected]> [Zero initialization of Monitor moved from monitor_data_init() to callers]

---
 monitor.c | 95 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 55 insertions(+), 40 deletions(-)
monitor.c +55 -40
index 8e9851ae15..261342a0f6 100644
@@ -704,13 +704,12 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline);
 
 static void monitor_iothread_init(void);
 
-static void monitor_data_init(Monitor *mon, bool skip_flush,
+static void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
                               bool use_io_thread)
 {
     if (use_io_thread && !mon_iothread) {
         monitor_iothread_init();
     }
-    memset(mon, 0, sizeof(Monitor));
     qemu_mutex_init(&mon->mon_lock);
     qemu_mutex_init(&mon->qmp.qmp_queue_lock);
     mon->outbuf = qstring_new();
@@ -719,6 +718,7 @@ static void monitor_data_init(Monitor *mon, bool skip_flush,
     mon->skip_flush = skip_flush;
     mon->use_io_thread = use_io_thread;
     mon->qmp.qmp_requests = g_queue_new();
+    mon->flags = flags;
 }
 
 static void monitor_data_destroy(Monitor *mon)
@@ -740,9 +740,10 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
                                 int64_t cpu_index, Error **errp)
 {
     char *output = NULL;
-    Monitor *old_mon, hmp;
+    Monitor *old_mon;
+    Monitor hmp = {};
 
-    monitor_data_init(&hmp, true, false);
+    monitor_data_init(&hmp, 0, true, false);
 
     old_mon = cur_mon;
     cur_mon = &hmp;
@@ -4605,19 +4606,51 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)
     monitor_list_append(mon);
 }
 
-void monitor_init(Chardev *chr, int flags)
+static void monitor_init_qmp(Chardev *chr, int flags)
 {
-    Monitor *mon = g_malloc(sizeof(*mon));
-    bool use_readline = flags & MONITOR_USE_READLINE;
+    Monitor *mon = g_new0(Monitor, 1);
+
+    /* Only HMP supports readline */
+    assert(!(flags & MONITOR_USE_READLINE));
 
     /* Note: we run QMP monitor in I/O thread when @chr supports that */
-    monitor_data_init(mon, false,
-                      (flags & MONITOR_USE_CONTROL)
-                      && qemu_chr_has_feature(chr,
-                                              QEMU_CHAR_FEATURE_GCONTEXT));
+    monitor_data_init(mon, flags, false,
+                      qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
 
     qemu_chr_fe_init(&mon->chr, chr, &error_abort);
-    mon->flags = flags;
+    qemu_chr_fe_set_echo(&mon->chr, true);
+
+    json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon, NULL);
+    if (mon->use_io_thread) {
+        /*
+         * Make sure the old iowatch is gone.  It's possible when
+         * e.g. the chardev is in client mode, with wait=on.
+         */
+        remove_fd_in_watch(chr);
+        /*
+         * We can't call qemu_chr_fe_set_handlers() directly here
+         * since chardev might be running in the monitor I/O
+         * thread.  Schedule a bottom half.
+         */
+        aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
+                                monitor_qmp_setup_handlers_bh, mon);
+        /* The bottom half will add @mon to @mon_list */
+    } else {
+        qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
+                                 monitor_qmp_read, monitor_qmp_event,
+                                 NULL, mon, NULL, true);
+        monitor_list_append(mon);
+    }
+}
+
+static void monitor_init_hmp(Chardev *chr, int flags)
+{
+    Monitor *mon = g_new0(Monitor, 1);
+    bool use_readline = flags & MONITOR_USE_READLINE;
+
+    monitor_data_init(mon, flags, false, false);
+    qemu_chr_fe_init(&mon->chr, chr, &error_abort);
+
     if (use_readline) {
         mon->rs = readline_init(monitor_readline_printf,
                                 monitor_readline_flush,
@@ -4626,36 +4659,18 @@ void monitor_init(Chardev *chr, int flags)
         monitor_read_command(mon, 0);
     }
 
-    if (monitor_is_qmp(mon)) {
-        qemu_chr_fe_set_echo(&mon->chr, true);
-        json_message_parser_init(&mon->qmp.parser, handle_qmp_command,
-                                 mon, NULL);
-        if (mon->use_io_thread) {
-            /*
-             * Make sure the old iowatch is gone.  It's possible when
-             * e.g. the chardev is in client mode, with wait=on.
-             */
-            remove_fd_in_watch(chr);
-            /*
-             * We can't call qemu_chr_fe_set_handlers() directly here
-             * since chardev might be running in the monitor I/O
-             * thread.  Schedule a bottom half.
-             */
-            aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
-                                    monitor_qmp_setup_handlers_bh, mon);
-            /* The bottom half will add @mon to @mon_list */
-            return;
-        } else {
-            qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
-                                     monitor_qmp_read, monitor_qmp_event,
-                                     NULL, mon, NULL, true);
-        }
+    qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read,
+                             monitor_event, NULL, mon, NULL, true);
+    monitor_list_append(mon);
+}
+
+void monitor_init(Chardev *chr, int flags)
+{
+    if (flags & MONITOR_USE_CONTROL) {
+        monitor_init_qmp(chr, flags);
     } else {
-        qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read,
-                                 monitor_event, NULL, mon, NULL, true);
+        monitor_init_hmp(chr, flags);
     }
-
-    monitor_list_append(mon);
 }
 
 void monitor_cleanup(void)
Signature · 1 line
2.21.0
#4 lore raw

[Qemu-devel] [PULL 12/16] monitor: Split out monitor/hmp.c

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Move HMP infrastructure from monitor/misc.c to monitor/hmp.c. This is code that can be shared for all targets, so compile it only once.

The amount of function and particularly extern variables in monitor_int.h is probably a bit larger than it needs to be, but this way no non-trivial code modifications are needed. The interfaces between HMP and the monitor core can be cleaned up later.

Message-Id: <[email protected]>

[Comment reformatted to make checkpatch.pl happy, superfluous #include dropped]

---
 monitor/Makefile.objs      |    2 +-
 monitor/hmp.c              | 1416 ++++++++++++++++++++++++++++++++++++
 monitor/misc.c             | 1368 +---------------------------------
 monitor/monitor-internal.h |    8 +
 monitor/trace-events       |    4 +-
 5 files changed, 1444 insertions(+), 1354 deletions(-)
 create mode 100644 monitor/hmp.c
monitor/Makefile.objs +1 -1
index 1037c09ff8..bea8838acc 100644
@@ -1,3 +1,3 @@
 obj-y += misc.o
-common-obj-y += qmp.o
+common-obj-y += qmp.o hmp.o
 common-obj-y += qmp-cmds.o hmp-cmds.o
monitor/hmp.c new file +1416 -0

1,416 lines not on this page · raw message

monitor/misc.c +16 -1352

1,487 lines not on this page · raw message

monitor/monitor-internal.h +8 -0
index d859bd3894..10fda7d97c 100644
@@ -159,7 +159,10 @@ extern QemuMutex monitor_lock;
 extern MonitorList mon_list;
 extern int mon_refcount;
 
+extern HMPCommand hmp_cmds[];
+
 void monitor_init_qmp(Chardev *chr, int flags);
+void monitor_init_hmp(Chardev *chr, int flags);
 
 int monitor_puts(Monitor *mon, const char *str);
 void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
@@ -172,4 +175,9 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
 void monitor_data_destroy_qmp(MonitorQMP *mon);
 void monitor_qmp_bh_dispatcher(void *data);
 
+int get_monitor_def(int64_t *pval, const char *name);
+void help_cmd(Monitor *mon, const char *name);
+void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
+int hmp_compare_cmd(const char *name, const char *list);
+
 #endif
monitor/trace-events +3 -1
index a06dde3fd3..2285d26121 100644
@@ -1,10 +1,12 @@
 # See docs/devel/tracing.txt for syntax documentation.
 
+# hmp.c
+handle_hmp_command(void *mon, const char *cmdline) "mon %p cmdline: %s"
+
 # misc.c
 monitor_protocol_event_handler(uint32_t event, void *qdict) "event=%d data=%p"
 monitor_protocol_event_emit(uint32_t event, void *data) "event=%d data=%p"
 monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "event=%d data=%p rate=%" PRId64
-handle_hmp_command(void *mon, const char *cmdline) "mon %p cmdline: %s"
 monitor_suspend(void *ptr, int cnt) "mon %p: %d"
 
 # qmp.c
Signature · 1 line
2.21.0
#5 lore raw

[Qemu-devel] [PULL 04/16] monitor: Make MonitorQMP a child class of Monitor

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Currently, struct Monitor mixes state that is only relevant for HMP, state that is only relevant for QMP, and some actually shared state. In particular, a MonitorQMP field is present in the state of any monitor, even if it's not a QMP monitor and therefore doesn't use the state.

As a first step towards a clean separation between QMP and HMP, let MonitorQMP extend Monitor and create a MonitorQMP object only when the monitor is actually a QMP monitor.

Some places accessed Monitor.qmp unconditionally, even for HMP monitors. They can't keep doing this now, so during the conversion, they are either changed to become conditional on monitor_is_qmp() or to assert() that they always get a QMP monitor.

Message-Id: <[email protected]>

[Superfluous variable in monitor_data_destroy() eliminated]
---
 monitor.c | 219 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 123 insertions(+), 96 deletions(-)
monitor.c +123 -96
index 261342a0f6..15f94fc41f 100644
@@ -168,26 +168,6 @@ struct MonFdset {
     QLIST_ENTRY(MonFdset) next;
 };
 
-typedef struct {
-    JSONMessageParser parser;
-    /*
-     * When a client connects, we're in capabilities negotiation mode.
-     * @commands is &qmp_cap_negotiation_commands then.  When command
-     * qmp_capabilities succeeds, we go into command mode, and
-     * @command becomes &qmp_commands.
-     */
-    QmpCommandList *commands;
-    bool capab_offered[QMP_CAPABILITY__MAX]; /* capabilities offered */
-    bool capab[QMP_CAPABILITY__MAX];         /* offered and accepted */
-    /*
-     * Protects qmp request/response queue.
-     * Take monitor_lock first when you need both.
-     */
-    QemuMutex qmp_queue_lock;
-    /* Input queue that holds all the parsed QMP requests */
-    GQueue *qmp_requests;
-} MonitorQMP;
-
 /*
  * To prevent flooding clients, events can be throttled. The
  * throttling is calculated globally, rather than per-Monitor
@@ -220,7 +200,6 @@ struct Monitor {
      */
     ReadLineState *rs;
 
-    MonitorQMP qmp;
     gchar *mon_cpu_path;
     mon_cmd_t *cmd_table;
     QTAILQ_ENTRY(Monitor) entry;
@@ -241,6 +220,27 @@ struct Monitor {
     int mux_out;
 };
 
+typedef struct {
+    Monitor common;
+    JSONMessageParser parser;
+    /*
+     * When a client connects, we're in capabilities negotiation mode.
+     * @commands is &qmp_cap_negotiation_commands then.  When command
+     * qmp_capabilities succeeds, we go into command mode, and
+     * @command becomes &qmp_commands.
+     */
+    QmpCommandList *commands;
+    bool capab_offered[QMP_CAPABILITY__MAX]; /* capabilities offered */
+    bool capab[QMP_CAPABILITY__MAX];         /* offered and accepted */
+    /*
+     * Protects qmp request/response queue.
+     * Take monitor_lock first when you need both.
+     */
+    QemuMutex qmp_queue_lock;
+    /* Input queue that holds all the parsed QMP requests */
+    GQueue *qmp_requests;
+} MonitorQMP;
+
 /* Shared monitor I/O thread */
 IOThread *mon_iothread;
 
@@ -249,7 +249,7 @@ QEMUBH *qmp_dispatcher_bh;
 
 struct QMPRequest {
     /* Owner of the request */
-    Monitor *mon;
+    MonitorQMP *mon;
     /*
      * Request object to be handled or Error to be reported
      * (exactly one of them is non-null)
@@ -357,18 +357,18 @@ static void qmp_request_free(QMPRequest *req)
 }
 
 /* Caller must hold mon->qmp.qmp_queue_lock */
-static void monitor_qmp_cleanup_req_queue_locked(Monitor *mon)
+static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon)
 {
-    while (!g_queue_is_empty(mon->qmp.qmp_requests)) {
-        qmp_request_free(g_queue_pop_head(mon->qmp.qmp_requests));
+    while (!g_queue_is_empty(mon->qmp_requests)) {
+        qmp_request_free(g_queue_pop_head(mon->qmp_requests));
     }
 }
 
-static void monitor_qmp_cleanup_queues(Monitor *mon)
+static void monitor_qmp_cleanup_queues(MonitorQMP *mon)
 {
-    qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
+    qemu_mutex_lock(&mon->qmp_queue_lock);
     monitor_qmp_cleanup_req_queue_locked(mon);
-    qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
+    qemu_mutex_unlock(&mon->qmp_queue_lock);
 }
 
 
@@ -480,17 +480,17 @@ int monitor_printf(Monitor *mon, const char *fmt, ...)
     return ret;
 }
 
-static void qmp_send_response(Monitor *mon, const QDict *rsp)
+static void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
 {
     const QObject *data = QOBJECT(rsp);
     QString *json;
 
-    json = mon->flags & MONITOR_USE_PRETTY ? qobject_to_json_pretty(data) :
-                                             qobject_to_json(data);
+    json = mon->common.flags & MONITOR_USE_PRETTY ?
+           qobject_to_json_pretty(data) : qobject_to_json(data);
     assert(json != NULL);
 
     qstring_append_chr(json, '\n');
-    monitor_puts(mon, qstring_get_str(json));
+    monitor_puts(&mon->common, qstring_get_str(json));
 
     qobject_unref(json);
 }
@@ -513,12 +513,17 @@ static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] = {
 static void monitor_qapi_event_emit(QAPIEvent event, QDict *qdict)
 {
     Monitor *mon;
+    MonitorQMP *qmp_mon;
 
     trace_monitor_protocol_event_emit(event, qdict);
     QTAILQ_FOREACH(mon, &mon_list, entry) {
-        if (monitor_is_qmp(mon)
-            && mon->qmp.commands != &qmp_cap_negotiation_commands) {
-            qmp_send_response(mon, qdict);
+        if (!monitor_is_qmp(mon)) {
+            continue;
+        }
+
+        qmp_mon = container_of(mon, MonitorQMP, common);
+        if (qmp_mon->commands != &qmp_cap_negotiation_commands) {
+            qmp_send_response(qmp_mon, qdict);
         }
     }
 }
@@ -711,29 +716,32 @@ static void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
         monitor_iothread_init();
     }
     qemu_mutex_init(&mon->mon_lock);
-    qemu_mutex_init(&mon->qmp.qmp_queue_lock);
     mon->outbuf = qstring_new();
     /* Use *mon_cmds by default. */
     mon->cmd_table = mon_cmds;
     mon->skip_flush = skip_flush;
     mon->use_io_thread = use_io_thread;
-    mon->qmp.qmp_requests = g_queue_new();
     mon->flags = flags;
 }
 
+static void monitor_data_destroy_qmp(MonitorQMP *mon)
+{
+    json_message_parser_destroy(&mon->parser);
+    qemu_mutex_destroy(&mon->qmp_queue_lock);
+    monitor_qmp_cleanup_req_queue_locked(mon);
+    g_queue_free(mon->qmp_requests);
+}
+
 static void monitor_data_destroy(Monitor *mon)
 {
     g_free(mon->mon_cpu_path);
     qemu_chr_fe_deinit(&mon->chr, false);
     if (monitor_is_qmp(mon)) {
-        json_message_parser_destroy(&mon->qmp.parser);
+        monitor_data_destroy_qmp(container_of(mon, MonitorQMP, common));
     }
     readline_free(mon->rs);
     qobject_unref(mon->outbuf);
     qemu_mutex_destroy(&mon->mon_lock);
-    qemu_mutex_destroy(&mon->qmp.qmp_queue_lock);
-    monitor_qmp_cleanup_req_queue_locked(mon);
-    g_queue_free(mon->qmp.qmp_requests);
 }
 
 char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
@@ -1087,8 +1095,12 @@ static void query_commands_cb(QmpCommand *cmd, void *opaque)
 CommandInfoList *qmp_query_commands(Error **errp)
 {
     CommandInfoList *list = NULL;
+    MonitorQMP *mon;
 
-    qmp_for_each_command(cur_mon->qmp.commands, query_commands_cb, &list);
+    assert(monitor_is_qmp(cur_mon));
+    mon = container_of(cur_mon, MonitorQMP, common);
+
+    qmp_for_each_command(mon->commands, query_commands_cb, &list);
 
     return list;
 }
@@ -1155,16 +1167,16 @@ static void monitor_init_qmp_commands(void)
                          qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG);
 }
 
-static bool qmp_oob_enabled(Monitor *mon)
+static bool qmp_oob_enabled(MonitorQMP *mon)
 {
-    return mon->qmp.capab[QMP_CAPABILITY_OOB];
+    return mon->capab[QMP_CAPABILITY_OOB];
 }
 
-static void monitor_qmp_caps_reset(Monitor *mon)
+static void monitor_qmp_caps_reset(MonitorQMP *mon)
 {
-    memset(mon->qmp.capab_offered, 0, sizeof(mon->qmp.capab_offered));
-    memset(mon->qmp.capab, 0, sizeof(mon->qmp.capab));
-    mon->qmp.capab_offered[QMP_CAPABILITY_OOB] = mon->use_io_thread;
+    memset(mon->capab_offered, 0, sizeof(mon->capab_offered));
+    memset(mon->capab, 0, sizeof(mon->capab));
+    mon->capab_offered[QMP_CAPABILITY_OOB] = mon->common.use_io_thread;
 }
 
 /*
@@ -1172,7 +1184,7 @@ static void monitor_qmp_caps_reset(Monitor *mon)
  * On success, set mon->qmp.capab[], and return true.
  * On error, set @errp, and return false.
  */
-static bool qmp_caps_accept(Monitor *mon, QMPCapabilityList *list,
+static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list,
                             Error **errp)
 {
     GString *unavailable = NULL;
@@ -1181,7 +1193,7 @@ static bool qmp_caps_accept(Monitor *mon, QMPCapabilityList *list,
     memset(capab, 0, sizeof(capab));
 
     for (; list; list = list->next) {
-        if (!mon->qmp.capab_offered[list->value]) {
+        if (!mon->capab_offered[list->value]) {
             if (!unavailable) {
                 unavailable = g_string_new(QMPCapability_str(list->value));
             } else {
@@ -1198,25 +1210,30 @@ static bool qmp_caps_accept(Monitor *mon, QMPCapabilityList *list,
         return false;
     }
 
-    memcpy(mon->qmp.capab, capab, sizeof(capab));
+    memcpy(mon->capab, capab, sizeof(capab));
     return true;
 }
 
 void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable,
                           Error **errp)
 {
-    if (cur_mon->qmp.commands == &qmp_commands) {
+    MonitorQMP *mon;
+
+    assert(monitor_is_qmp(cur_mon));
+    mon = container_of(cur_mon, MonitorQMP, common);
+
+    if (mon->commands == &qmp_commands) {
         error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
                   "Capabilities negotiation is already complete, command "
                   "ignored");
         return;
     }
 
-    if (!qmp_caps_accept(cur_mon, enable, errp)) {
+    if (!qmp_caps_accept(mon, enable, errp)) {
         return;
     }
 
-    cur_mon->qmp.commands = &qmp_commands;
+    mon->commands = &qmp_commands;
 }
 
 /* Set the current CPU defined by the user. Callers must hold BQL. */
@@ -4123,27 +4140,27 @@ static int monitor_can_read(void *opaque)
  * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP.
  * Nothing is emitted then.
  */
-static void monitor_qmp_respond(Monitor *mon, QDict *rsp)
+static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
 {
     if (rsp) {
         qmp_send_response(mon, rsp);
     }
 }
 
-static void monitor_qmp_dispatch(Monitor *mon, QObject *req)
+static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
 {
     Monitor *old_mon;
     QDict *rsp;
     QDict *error;
 
     old_mon = cur_mon;
-    cur_mon = mon;
+    cur_mon = &mon->common;
 
-    rsp = qmp_dispatch(mon->qmp.commands, req, qmp_oob_enabled(mon));
+    rsp = qmp_dispatch(mon->commands, req, qmp_oob_enabled(mon));
 
     cur_mon = old_mon;
 
-    if (mon->qmp.commands == &qmp_cap_negotiation_commands) {
+    if (mon->commands == &qmp_cap_negotiation_commands) {
         error = qdict_get_qdict(rsp, "error");
         if (error
             && !g_strcmp0(qdict_get_try_str(error, "class"),
@@ -4168,24 +4185,30 @@ static void monitor_qmp_dispatch(Monitor *mon, QObject *req)
  * monitor to the end of mon_list queue.
  *
  * Note: if the function returned with non-NULL, then the caller will
- * be with mon->qmp.qmp_queue_lock held, and the caller is responsible
+ * be with qmp_mon->qmp_queue_lock held, and the caller is responsible
  * to release it.
  */
 static QMPRequest *monitor_qmp_requests_pop_any_with_lock(void)
 {
     QMPRequest *req_obj = NULL;
     Monitor *mon;
+    MonitorQMP *qmp_mon;
 
     qemu_mutex_lock(&monitor_lock);
 
     QTAILQ_FOREACH(mon, &mon_list, entry) {
-        qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
-        req_obj = g_queue_pop_head(mon->qmp.qmp_requests);
+        if (!monitor_is_qmp(mon)) {
+            continue;
+        }
+
+        qmp_mon = container_of(mon, MonitorQMP, common);
+        qemu_mutex_lock(&qmp_mon->qmp_queue_lock);
+        req_obj = g_queue_pop_head(qmp_mon->qmp_requests);
         if (req_obj) {
             /* With the lock of corresponding queue held */
             break;
         }
-        qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
+        qemu_mutex_unlock(&qmp_mon->qmp_queue_lock);
     }
 
     if (req_obj) {
@@ -4207,7 +4230,7 @@ static void monitor_qmp_bh_dispatcher(void *data)
     QMPRequest *req_obj = monitor_qmp_requests_pop_any_with_lock();
     QDict *rsp;
     bool need_resume;
-    Monitor *mon;
+    MonitorQMP *mon;
 
     if (!req_obj) {
         return;
@@ -4216,8 +4239,8 @@ static void monitor_qmp_bh_dispatcher(void *data)
     mon = req_obj->mon;
     /*  qmp_oob_enabled() might change after "qmp_capabilities" */
     need_resume = !qmp_oob_enabled(mon) ||
-        mon->qmp.qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1;
-    qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
+        mon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1;
+    qemu_mutex_unlock(&mon->qmp_queue_lock);
     if (req_obj->req) {
         QDict *qdict = qobject_to(QDict, req_obj->req);
         QObject *id = qdict ? qdict_get(qdict, "id") : NULL;
@@ -4233,7 +4256,7 @@ static void monitor_qmp_bh_dispatcher(void *data)
 
     if (need_resume) {
         /* Pairs with the monitor_suspend() in handle_qmp_command() */
-        monitor_resume(mon);
+        monitor_resume(&mon->common);
     }
     qmp_request_free(req_obj);
 
@@ -4243,7 +4266,7 @@ static void monitor_qmp_bh_dispatcher(void *data)
 
 static void handle_qmp_command(void *opaque, QObject *req, Error *err)
 {
-    Monitor *mon = opaque;
+    MonitorQMP *mon = opaque;
     QObject *id = NULL;
     QDict *qdict;
     QMPRequest *req_obj;
@@ -4275,7 +4298,7 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
     req_obj->err = err;
 
     /* Protect qmp_requests and fetching its length. */
-    qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
+    qemu_mutex_lock(&mon->qmp_queue_lock);
 
     /*
      * Suspend the monitor when we can't queue more requests after
@@ -4284,8 +4307,8 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
      * command, for backward compatibility.
      */
     if (!qmp_oob_enabled(mon) ||
-        mon->qmp.qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1) {
-        monitor_suspend(mon);
+        mon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX - 1) {
+        monitor_suspend(&mon->common);
     }
 
     /*
@@ -4293,9 +4316,9 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
      * handled in time order.  Ownership for req_obj, req,
      * etc. will be delivered to the handler side.
      */
-    assert(mon->qmp.qmp_requests->length < QMP_REQ_QUEUE_LEN_MAX);
-    g_queue_push_tail(mon->qmp.qmp_requests, req_obj);
-    qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
+    assert(mon->qmp_requests->length < QMP_REQ_QUEUE_LEN_MAX);
+    g_queue_push_tail(mon->qmp_requests, req_obj);
+    qemu_mutex_unlock(&mon->qmp_queue_lock);
 
     /* Kick the dispatcher routine */
     qemu_bh_schedule(qmp_dispatcher_bh);
@@ -4303,9 +4326,9 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
 
 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
 {
-    Monitor *mon = opaque;
+    MonitorQMP *mon = opaque;
 
-    json_message_parser_feed(&mon->qmp.parser, (const char *) buf, size);
+    json_message_parser_feed(&mon->parser, (const char *) buf, size);
 }
 
 static void monitor_read(void *opaque, const uint8_t *buf, int size)
@@ -4391,7 +4414,7 @@ void monitor_resume(Monitor *mon)
     trace_monitor_suspend(mon, -1);
 }
 
-static QDict *qmp_greeting(Monitor *mon)
+static QDict *qmp_greeting(MonitorQMP *mon)
 {
     QList *cap_list = qlist_new();
     QObject *ver = NULL;
@@ -4400,7 +4423,7 @@ static QDict *qmp_greeting(Monitor *mon)
     qmp_marshal_query_version(NULL, &ver, NULL);
 
     for (cap = 0; cap < QMP_CAPABILITY__MAX; cap++) {
-        if (mon->qmp.capab_offered[cap]) {
+        if (mon->capab_offered[cap]) {
             qlist_append_str(cap_list, QMPCapability_str(cap));
         }
     }
@@ -4413,11 +4436,11 @@ static QDict *qmp_greeting(Monitor *mon)
 static void monitor_qmp_event(void *opaque, int event)
 {
     QDict *data;
-    Monitor *mon = opaque;
+    MonitorQMP *mon = opaque;
 
     switch (event) {
     case CHR_EVENT_OPENED:
-        mon->qmp.commands = &qmp_cap_negotiation_commands;
+        mon->commands = &qmp_cap_negotiation_commands;
         monitor_qmp_caps_reset(mon);
         data = qmp_greeting(mon);
         qmp_send_response(mon, data);
@@ -4432,8 +4455,8 @@ static void monitor_qmp_event(void *opaque, int event)
          * is closed.
          */
         monitor_qmp_cleanup_queues(mon);
-        json_message_parser_destroy(&mon->qmp.parser);
-        json_message_parser_init(&mon->qmp.parser, handle_qmp_command,
+        json_message_parser_destroy(&mon->parser);
+        json_message_parser_init(&mon->parser, handle_qmp_command,
                                  mon, NULL);
         mon_refcount--;
         monitor_fdsets_cleanup();
@@ -4595,33 +4618,37 @@ static void monitor_list_append(Monitor *mon)
 
 static void monitor_qmp_setup_handlers_bh(void *opaque)
 {
-    Monitor *mon = opaque;
+    MonitorQMP *mon = opaque;
     GMainContext *context;
 
-    assert(mon->use_io_thread);
+    assert(mon->common.use_io_thread);
     context = iothread_get_g_main_context(mon_iothread);
     assert(context);
-    qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_read,
-                             monitor_qmp_event, NULL, mon, context, true);
-    monitor_list_append(mon);
+    qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read,
+                             monitor_qmp_read, monitor_qmp_event,
+                             NULL, &mon->common, context, true);
+    monitor_list_append(&mon->common);
 }
 
 static void monitor_init_qmp(Chardev *chr, int flags)
 {
-    Monitor *mon = g_new0(Monitor, 1);
+    MonitorQMP *mon = g_new0(MonitorQMP, 1);
 
     /* Only HMP supports readline */
     assert(!(flags & MONITOR_USE_READLINE));
 
     /* Note: we run QMP monitor in I/O thread when @chr supports that */
-    monitor_data_init(mon, flags, false,
+    monitor_data_init(&mon->common, flags, false,
                       qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
 
-    qemu_chr_fe_init(&mon->chr, chr, &error_abort);
-    qemu_chr_fe_set_echo(&mon->chr, true);
+    qemu_mutex_init(&mon->qmp_queue_lock);
+    mon->qmp_requests = g_queue_new();
 
-    json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon, NULL);
-    if (mon->use_io_thread) {
+    qemu_chr_fe_init(&mon->common.chr, chr, &error_abort);
+    qemu_chr_fe_set_echo(&mon->common.chr, true);
+
+    json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL);
+    if (mon->common.use_io_thread) {
         /*
          * Make sure the old iowatch is gone.  It's possible when
          * e.g. the chardev is in client mode, with wait=on.
@@ -4636,10 +4663,10 @@ static void monitor_init_qmp(Chardev *chr, int flags)
                                 monitor_qmp_setup_handlers_bh, mon);
         /* The bottom half will add @mon to @mon_list */
     } else {
-        qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
+        qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read,
                                  monitor_qmp_read, monitor_qmp_event,
-                                 NULL, mon, NULL, true);
-        monitor_list_append(mon);
+                                 NULL, &mon->common, NULL, true);
+        monitor_list_append(&mon->common);
     }
 }
 
Signature · 1 line
2.21.0
#6 lore raw

[Qemu-devel] [PULL 10/16] monitor: Create monitor-internal.h with common definitions

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Before we can split monitor/misc.c, we need to create a header file that contains the common definitions that will be used by multiple source files.

For a start, add the type definitions for Monitor, MonitorHMP and MonitorQMP and their dependencies. We'll add functions as needed when splitting monitor/misc.c.

Message-Id: <[email protected]>

[Header guard symbol tidied up, superfluous #include dropped, FIXME in hmp_change() resolved]

---
 MAINTAINERS                |   2 +
 monitor/hmp-cmds.c         |   5 +-
 monitor/misc.c             | 114 +----------------------------
 monitor/monitor-internal.h | 145 +++++++++++++++++++++++++++++++++++++
 4 files changed, 150 insertions(+), 116 deletions(-)
 create mode 100644 monitor/monitor-internal.h
MAINTAINERS +2 -0
index 3c7d366727..15f21c35e0 100644
@@ -1918,6 +1918,7 @@ F: qapi/run-state.json
 Human Monitor (HMP)
 M: Dr. David Alan Gilbert <[email protected]>
 S: Maintained
+F: monitor/monitor-internal.h
 F: monitor/misc.c
 F: monitor/hmp*
 F: hmp.h
@@ -2040,6 +2041,7 @@ F: tests/check-qom-proplist.c
 QMP
 M: Markus Armbruster <[email protected]>
 S: Supported
+F: monitor/monitor-internal.h
 F: monitor/qmp*
 F: monitor/misc.c
 F: docs/devel/*qmp-*
monitor/hmp-cmds.c +2 -3
index c917e24d9c..c283dde0e9 100644
@@ -24,7 +24,7 @@
 #include "qemu/option.h"
 #include "qemu/timer.h"
 #include "qemu/sockets.h"
-#include "monitor/monitor.h"
+#include "monitor/monitor-internal.h"
 #include "monitor/qdev.h"
 #include "qapi/error.h"
 #include "qapi/opts-visitor.h"
@@ -1943,8 +1943,7 @@ static void hmp_change_read_arg(void *opaque, const char *password,
 
 void hmp_change(Monitor *mon, const QDict *qdict)
 {
-    /* FIXME Make MonitorHMP public and use container_of */
-    MonitorHMP *hmp_mon = (MonitorHMP *)mon;
+    MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
     const char *device = qdict_get_str(qdict, "device");
     const char *target = qdict_get_str(qdict, "target");
     const char *arg = qdict_get_try_str(qdict, "arg");
monitor/misc.c +1 -113

150 lines not on this page · raw message

monitor/monitor-internal.h new file +145 -0

145 lines not on this page · raw message

Signature · 1 line
2.21.0
#7 lore raw

[Qemu-devel] [PULL 01/16] monitor: Fix return type of monitor_fdset_dup_fd_find

In reply to Markus Armbruster

From: Yury Kotov <[email protected]>

monitor_fdset_dup_fd_find_remove() and monitor_fdset_dup_fd_find() return mon_fdset->id which is int64_t. Downcasting from int64_t to int leads to a bug with removing fd from fdset with id >= 2^32. So, fix return types for these function.

Message-Id: <[email protected]>

---
 include/monitor/monitor.h | 2 +-
 monitor.c                 | 4 ++--
 stubs/fdset.c             | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
include/monitor/monitor.h +1 -1
index 06cfcd8f36..1e1d6d2269 100644
@@ -44,6 +44,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
 int monitor_fdset_get_fd(int64_t fdset_id, int flags);
 int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
-int monitor_fdset_dup_fd_find(int dup_fd);
+int64_t monitor_fdset_dup_fd_find(int dup_fd);
 
 #endif /* MONITOR_H */
monitor.c +2 -2
index 5c5cbe254a..dce3496920 100644
@@ -2604,7 +2604,7 @@ err:
     return -1;
 }
 
-static int monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
+static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
 {
     MonFdset *mon_fdset;
     MonFdsetFd *mon_fdset_fd_dup;
@@ -2632,7 +2632,7 @@ err:
     return -1;
 }
 
-int monitor_fdset_dup_fd_find(int dup_fd)
+int64_t monitor_fdset_dup_fd_find(int dup_fd)
 {
     return monitor_fdset_dup_fd_find_remove(dup_fd, false);
 }
stubs/fdset.c +1 -1
index f3d9980b7e..67dd5e1d34 100644
@@ -6,7 +6,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd)
     return -1;
 }
 
-int monitor_fdset_dup_fd_find(int dup_fd)
+int64_t monitor_fdset_dup_fd_find(int dup_fd)
 {
     return -1;
 }
Signature · 1 line
2.21.0
#8 lore raw

[Qemu-devel] [PULL 09/16] monitor: Move {hmp, qmp}.c to monitor/{hmp, qmp}-cmds.c

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Now that we have a monitor/ subdirectory, let's move hmp.c and qmp.c from the root directory there. As they contain implementations of monitor commands, rename them to {hmp,qmp}-cmds.c, so that {hmp,qmp}.c are free for the HMP and QMP infrastructure.

Message-Id: <[email protected]>

---
 MAINTAINERS                         | 5 +++--
 Makefile.objs                       | 2 +-
 docs/devel/writing-qmp-commands.txt | 9 +++++----
 monitor/Makefile.objs               | 1 +
 hmp.c => monitor/hmp-cmds.c         | 2 +-
 qmp.c => monitor/qmp-cmds.c         | 2 +-
 6 files changed, 12 insertions(+), 9 deletions(-)
 rename hmp.c => monitor/hmp-cmds.c (99%)
 rename qmp.c => monitor/qmp-cmds.c (99%)
MAINTAINERS +3 -2
index 575ea6e68d..3c7d366727 100644
@@ -1919,7 +1919,8 @@ Human Monitor (HMP)
 M: Dr. David Alan Gilbert <[email protected]>
 S: Maintained
 F: monitor/misc.c
-F: hmp.[ch]
+F: monitor/hmp*
+F: hmp.h
 F: hmp-commands*.hx
 F: include/monitor/hmp-target.h
 F: tests/test-hmp.c
@@ -2039,7 +2040,7 @@ F: tests/check-qom-proplist.c
 QMP
 M: Markus Armbruster <[email protected]>
 S: Supported
-F: qmp.c
+F: monitor/qmp*
 F: monitor/misc.c
 F: docs/devel/*qmp-*
 F: docs/interop/*qmp-*
Makefile.objs +1 -1
index dd39a70b48..9495fcbc7e 100644
@@ -83,8 +83,8 @@ common-obj-$(CONFIG_FDT) += device_tree.o
 ######################################################################
 # qapi
 
-common-obj-y += qmp.o hmp.o
 common-obj-y += qapi/
+common-obj-y += monitor/
 endif
 
 #######################################################################
docs/devel/writing-qmp-commands.txt +5 -4
index cc6ecd6d5d..46a6c48683 100644
@@ -20,7 +20,7 @@ new QMP command.
 
 2. Write the QMP command itself, which is a regular C function. Preferably,
    the command should be exported by some QEMU subsystem. But it can also be
-   added to the qmp.c file
+   added to the monitor/qmp-cmds.c file
 
 3. At this point the command can be tested under the QMP protocol
 
@@ -101,7 +101,8 @@ protocol data.
 
 The next step is to write the "hello-world" implementation. As explained
 earlier, it's preferable for commands to live in QEMU subsystems. But
-"hello-world" doesn't pertain to any, so we put its implementation in qmp.c:
+"hello-world" doesn't pertain to any, so we put its implementation in
+monitor/qmp-cmds.c:
 
 void qmp_hello_world(Error **errp)
 {
@@ -146,7 +147,7 @@ for mandatory arguments). Finally, 'str' is the argument's type, which
 stands for "string". The QAPI also supports integers, booleans, enumerations
 and user defined types.
 
-Now, let's update our C implementation in qmp.c:
+Now, let's update our C implementation in monitor/qmp-cmds.c:
 
 void qmp_hello_world(bool has_message, const char *message, Error **errp)
 {
@@ -267,7 +268,7 @@ monitor (HMP).
 
 With the introduction of the QAPI, HMP commands make QMP calls. Most of the
 time HMP commands are simple wrappers. All HMP commands implementation exist in
-the hmp.c file.
+the monitor/hmp-cmds.c file.
 
 Here's the implementation of the "hello-world" HMP command:
 
monitor/Makefile.objs +1 -0
index e783b0616b..a7170af6e1 100644
@@ -1 +1,2 @@
 obj-y += misc.o
+common-obj-y += qmp-cmds.o hmp-cmds.o
monitor/hmp-cmds.c renamed from hmp.c +1 -1
similarity index 99%
rename from hmp.c
rename to monitor/hmp-cmds.c
index e6ea7cb9c2..c917e24d9c 100644
@@ -1,5 +1,5 @@
 /*
- * Human Monitor Interface
+ * Human Monitor Interface commands
  *
  * Copyright IBM, Corp. 2011
  *
monitor/qmp-cmds.c renamed from qmp.c +1 -1
similarity index 99%
rename from qmp.c
rename to monitor/qmp-cmds.c
index 6797568444..f1b1e4f08b 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU Management Protocol
+ * QEMU Management Protocol commands
  *
  * Copyright IBM, Corp. 2011
  *
Signature · 1 line
2.21.0
#9 lore raw
In reply to Markus Armbruster
Quoted 7 lines · Markus Armbruster

The following changes since commit 076243ffe6c1b687e9e6d98348c3bf3398df78f3:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-docs-20190617' into staging (2019-06-17 16:41:25 +0100)

are available in the Git repository at:

Quoted 9 lines

git://repo.or.cz/qemu/armbru.git tags/pull-monitor-2019-06-17

for you to fetch changes up to 092b8737c5e7695c4b9caa3b4eedc66763632755:

vl: Deprecate -mon pretty=... for HMP monitors (2019-06-17 20:36:56 +0200)

----------------------------------------------------------------
Monitor patches for 2019-06-17

Hi; I'm afraid this doesn't compile:

Most hosts (ppc64, s390, aarch64, aarch32, osx, and possibly the others too though they haven't failed immediately) fail something like this:

/home/pm215/qemu/monitor/misc.c: In function ‘netdev_del_completion’:
/home/pm215/qemu/monitor/misc.c:2165:9: error: implicit declaration of function ‘qemu_find_opts_err’ [-Werror=implicit-function-declaration]

         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
         ^

/home/pm215/qemu/monitor/misc.c:2165:9: error: nested extern declaration of ‘qemu_find_opts_err’ [-Werror=nested-externs] /home/pm215/qemu/monitor/misc.c:2165:9: error: passing argument 1 of ‘qemu_opts_find’ makes pointer from integer without a cast [-Werror] In file included from /home/pm215/qemu/monitor/misc.c:64:0:
/home/pm215/qemu/include/qemu/option.h:105:11: note: expected ‘struct QemuOptsList *’ but argument is of type ‘int’

 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
           ^

cc1: all warnings being treated as errors

windows is a bit different:

/home/petmay01/qemu-for-merges/monitor/hmp.c: In function 'file_completion':
/home/petmay01/qemu-for-merges/monitor/hmp.c:1113:5: error: unknown type name 'DIR'

     DIR *ffs;
     ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1135:11: error: implicit
declaration of function 'opendir'
[-Werror=implicit-function-declaration]
     ffs = opendir(path);
           ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1135:5: error: nested
extern declaration of 'opendir' [-Werror=nested-externs]
     ffs = opendir(path);
     ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1135:9: error: assignment
makes pointer from integer without a cast [-Werror=int-conversion]
     ffs = opendir(path);
         ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1141:13: error: implicit
declaration of function 'readdir'
[-Werror=implicit-function-declaration]
         d = readdir(ffs);
             ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1141:9: error: nested
extern declaration of 'readdir' [-Werror=nested-externs]
         d = readdir(ffs);
         ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1141:11: error:
assignment makes pointer from integer without a cast
[-Werror=int-conversion]
         d = readdir(ffs);
           ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1146:21: error:
dereferencing pointer to incomplete type 'struct dirent'
         if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) {
                     ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1166:5: error: implicit
declaration of function 'closedir'
[-Werror=implicit-function-declaration]
     closedir(ffs);
     ^

/home/petmay01/qemu-for-merges/monitor/hmp.c:1166:5: error: nested extern declaration of 'closedir' [-Werror=nested-externs]

thanks
-- PMM

#10 lore raw
Quoted 36 lines · Peter Maydell
Quoted 7 lines · Markus Armbruster

The following changes since commit 076243ffe6c1b687e9e6d98348c3bf3398df78f3:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-docs-20190617' into staging (2019-06-17 16:41:25 +0100)

are available in the Git repository at:

Quoted 9 lines

git://repo.or.cz/qemu/armbru.git tags/pull-monitor-2019-06-17

for you to fetch changes up to 092b8737c5e7695c4b9caa3b4eedc66763632755:

vl: Deprecate -mon pretty=... for HMP monitors (2019-06-17 20:36:56 +0200)

----------------------------------------------------------------
Monitor patches for 2019-06-17

Hi; I'm afraid this doesn't compile:

Most hosts (ppc64, s390, aarch64, aarch32, osx, and possibly the others too though they haven't failed immediately) fail something like this:

/home/pm215/qemu/monitor/misc.c: In function ‘netdev_del_completion’:
/home/pm215/qemu/monitor/misc.c:2165:9: error: implicit declaration of function ‘qemu_find_opts_err’ [-Werror=implicit-function-declaration]

         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
         ^

/home/pm215/qemu/monitor/misc.c:2165:9: error: nested extern declaration of ‘qemu_find_opts_err’ [-Werror=nested-externs] /home/pm215/qemu/monitor/misc.c:2165:9: error: passing argument 1 of ‘qemu_opts_find’ makes pointer from integer without a cast [-Werror] In file included from /home/pm215/qemu/monitor/misc.c:64:0:
/home/pm215/qemu/include/qemu/option.h:105:11: note: expected ‘struct QemuOptsList *’ but argument is of type ‘int’

Quoted 3 lines
 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
           ^

cc1: all warnings being treated as errors

Yup, my fault: I fell into the trap laid by include/ui/qemu-spice.h, which includes qemu/config-file.h only when CONFIG_SPICE.

Quoted 43 lines

windows is a bit different:

/home/petmay01/qemu-for-merges/monitor/hmp.c: In function 'file_completion':
/home/petmay01/qemu-for-merges/monitor/hmp.c:1113:5: error: unknown type name 'DIR'

     DIR *ffs;
     ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1135:11: error: implicit
declaration of function 'opendir'
[-Werror=implicit-function-declaration]
     ffs = opendir(path);
           ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1135:5: error: nested
extern declaration of 'opendir' [-Werror=nested-externs]
     ffs = opendir(path);
     ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1135:9: error: assignment
makes pointer from integer without a cast [-Werror=int-conversion]
     ffs = opendir(path);
         ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1141:13: error: implicit
declaration of function 'readdir'
[-Werror=implicit-function-declaration]
         d = readdir(ffs);
             ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1141:9: error: nested
extern declaration of 'readdir' [-Werror=nested-externs]
         d = readdir(ffs);
         ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1141:11: error:
assignment makes pointer from integer without a cast
[-Werror=int-conversion]
         d = readdir(ffs);
           ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1146:21: error:
dereferencing pointer to incomplete type 'struct dirent'
         if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) {
                     ^
/home/petmay01/qemu-for-merges/monitor/hmp.c:1166:5: error: implicit
declaration of function 'closedir'
[-Werror=implicit-function-declaration]
     closedir(ffs);
     ^
Quoted 2 lines

/home/petmay01/qemu-for-merges/monitor/hmp.c:1166:5: error: nested extern declaration of 'closedir' [-Werror=nested-externs]

Here, Kevin fell into the trap laid by GLib, which includes <dirent.h> only #ifdef G_OS_UNIX.

v2 coming up.

#11 lore raw

[Qemu-devel] [PULL 08/16] Move monitor.c to monitor/misc.c

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Create a new monitor/ subdirectory and move monitor.c there. As the plan is to move the monitor core into separate files, use the chance to rename it to misc.c.

Message-Id: <[email protected]>

---
 MAINTAINERS                         |  4 ++--
 Makefile.objs                       |  1 +
 Makefile.target                     |  3 ++-
 docs/devel/writing-qmp-commands.txt |  2 +-
 monitor/Makefile.objs               |  1 +
 monitor.c => monitor/misc.c         |  2 +-
 monitor/trace-events                | 11 +++++++++++
 trace-events                        | 10 ----------
 8 files changed, 19 insertions(+), 15 deletions(-)
 create mode 100644 monitor/Makefile.objs
 rename monitor.c => monitor/misc.c (99%)
 create mode 100644 monitor/trace-events
MAINTAINERS +2 -2
index acbad134ec..575ea6e68d 100644
@@ -1918,7 +1918,7 @@ F: qapi/run-state.json
 Human Monitor (HMP)
 M: Dr. David Alan Gilbert <[email protected]>
 S: Maintained
-F: monitor.c
+F: monitor/misc.c
 F: hmp.[ch]
 F: hmp-commands*.hx
 F: include/monitor/hmp-target.h
@@ -2040,7 +2040,7 @@ QMP
 M: Markus Armbruster <[email protected]>
 S: Supported
 F: qmp.c
-F: monitor.c
+F: monitor/misc.c
 F: docs/devel/*qmp-*
 F: docs/interop/*qmp-*
 F: scripts/qmp/
Makefile.objs +1 -0
index c8337fa34b..dd39a70b48 100644
@@ -130,6 +130,7 @@ trace-events-subdirs =
 trace-events-subdirs += accel/kvm
 trace-events-subdirs += accel/tcg
 trace-events-subdirs += crypto
+trace-events-subdirs += monitor
 ifeq ($(CONFIG_USER_ONLY),y)
 trace-events-subdirs += linux-user
 endif
Makefile.target +2 -1
index ecd856e3a3..72c267f7dc 100644
@@ -148,9 +148,10 @@ endif #CONFIG_BSD_USER
 #########################################################
 # System emulator target
 ifdef CONFIG_SOFTMMU
-obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o ioport.o numa.o
+obj-y += arch_init.o cpus.o gdbstub.o balloon.o ioport.o numa.o
 obj-y += qtest.o
 obj-y += hw/
+obj-y += monitor/
 obj-y += qapi/
 obj-y += memory.o
 obj-y += memory_mapping.o
docs/devel/writing-qmp-commands.txt +1 -1
index 9dfc62bf5a..cc6ecd6d5d 100644
@@ -470,7 +470,7 @@ it's good practice to always check for errors.
 
 Another important detail is that HMP's "info" commands don't go into the
 hmp-commands.hx. Instead, they go into the info_cmds[] table, which is defined
-in the monitor.c file. The entry for the "info alarmclock" follows:
+in the monitor/misc.c file. The entry for the "info alarmclock" follows:
 
     {
         .name       = "alarmclock",
monitor/Makefile.objs new file +1 -0
new file mode 100644
index 0000000000..e783b0616b
@@ -0,0 +1 @@
+obj-y += misc.o
monitor/misc.c renamed from monitor.c +1 -1
similarity index 99%
rename from monitor.c
rename to monitor/misc.c
index 3015b6e9c7..c5f8483b7e 100644
@@ -64,7 +64,7 @@
 #include "qapi/qmp/json-parser.h"
 #include "qapi/qmp/qlist.h"
 #include "qom/object_interfaces.h"
-#include "trace-root.h"
+#include "trace.h"
 #include "trace/control.h"
 #include "monitor/hmp-target.h"
 #ifdef CONFIG_TRACE_SIMPLE
monitor/trace-events new file +11 -0
new file mode 100644
index 0000000000..abfdf20b14
@@ -0,0 +1,11 @@
+# See docs/devel/tracing.txt for syntax documentation.
+
+# misc.c
+monitor_protocol_event_handler(uint32_t event, void *qdict) "event=%d data=%p"
+monitor_protocol_event_emit(uint32_t event, void *data) "event=%d data=%p"
+monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "event=%d data=%p rate=%" PRId64
+handle_hmp_command(void *mon, const char *cmdline) "mon %p cmdline: %s"
+handle_qmp_command(void *mon, const char *req) "mon %p req: %s"
+monitor_suspend(void *ptr, int cnt) "mon %p: %d"
+monitor_qmp_cmd_in_band(const char *id) "%s"
+monitor_qmp_cmd_out_of_band(const char *id) "%s"
trace-events +0 -10
index 844ee58dd9..aeea3c2bdb 100644
@@ -41,16 +41,6 @@ system_wakeup_request(int reason) "reason=%d"
 qemu_system_shutdown_request(int reason) "reason=%d"
 qemu_system_powerdown_request(void) ""
 
-# monitor.c
-monitor_protocol_event_handler(uint32_t event, void *qdict) "event=%d data=%p"
-monitor_protocol_event_emit(uint32_t event, void *data) "event=%d data=%p"
-monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "event=%d data=%p rate=%" PRId64
-handle_hmp_command(void *mon, const char *cmdline) "mon %p cmdline: %s"
-handle_qmp_command(void *mon, const char *req) "mon %p req: %s"
-monitor_suspend(void *ptr, int cnt) "mon %p: %d"
-monitor_qmp_cmd_in_band(const char *id) "%s"
-monitor_qmp_cmd_out_of_band(const char *id) "%s"
-
 # dma-helpers.c
 dma_blk_io(void *dbs, void *bs, int64_t offset, bool to_dev) "dbs=%p bs=%p offset=%" PRId64 " to_dev=%d"
 dma_aio_cancel(void *dbs) "dbs=%p"
Signature · 1 line
2.21.0
#12 lore raw

[Qemu-devel] [PULL 05/16] monitor: Create MonitorHMP with readline state

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

The ReadLineState in Monitor is only used for HMP monitors. Create MonitorHMP and move it there.

Can't use container_of() in hmp_change(). Cast instead, and mark FIXME. Will be cleaned up shortly.

Message-Id: <[email protected]>

[Superfluous variable in monitor_data_destroy() eliminated, whitespace tweaked in hmp_change(), commit message improved]

---
 hmp.c                     |   4 +-
 include/monitor/monitor.h |   5 +-
 monitor.c                 | 126 +++++++++++++++++++++-----------------
 3 files changed, 77 insertions(+), 58 deletions(-)
hmp.c +3 -1
index be5e345c6f..e6ea7cb9c2 100644
@@ -1943,6 +1943,8 @@ static void hmp_change_read_arg(void *opaque, const char *password,
 
 void hmp_change(Monitor *mon, const QDict *qdict)
 {
+    /* FIXME Make MonitorHMP public and use container_of */
+    MonitorHMP *hmp_mon = (MonitorHMP *)mon;
     const char *device = qdict_get_str(qdict, "device");
     const char *target = qdict_get_str(qdict, "target");
     const char *arg = qdict_get_try_str(qdict, "arg");
@@ -1960,7 +1962,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
         if (strcmp(target, "passwd") == 0 ||
             strcmp(target, "password") == 0) {
             if (!arg) {
-                monitor_read_password(mon, hmp_change_read_arg, NULL);
+                monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
                 return;
             }
         }
include/monitor/monitor.h +3 -2
index 1e1d6d2269..f9d30e1d78 100644
@@ -6,6 +6,7 @@
 #include "qemu/readline.h"
 
 extern __thread Monitor *cur_mon;
+typedef struct MonitorHMP MonitorHMP;
 
 /* flags for monitor_init */
 /* 0x01 unused */
@@ -34,8 +35,8 @@ void monitor_flush(Monitor *mon);
 int monitor_set_cpu(int cpu_index);
 int monitor_get_cpu_index(void);
 
-void monitor_read_command(Monitor *mon, int show_prompt);
-int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
+void monitor_read_command(MonitorHMP *mon, int show_prompt);
+int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func,
                           void *opaque);
 
 AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
monitor.c +71 -55

344 lines not on this page · raw message

Signature · 1 line
2.21.0
#13 lore raw

[Qemu-devel] [PULL 07/16] monitor: Rename HMP command type and tables

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

This renames the type for HMP monitor commands and the tables holding the commands to make clear that they are related to HMP and to allow making them public later:

* mon_cmd_t -> HMPCommand (fixing use of a reserved name, too)
* mon_cmds -> hmp_cmds
* info_cmds -> hmp_info_cmds

Message-Id: <[email protected]>

[sortcmdlist() cleaned up to make checkpatch.pl happy]
---
 hmp-commands.hx |  2 +-
 monitor.c       | 72 ++++++++++++++++++++++++-------------------------
 2 files changed, 36 insertions(+), 38 deletions(-)
hmp-commands.hx +1 -1
index a2c3ffc218..8b7aec3e8d 100644
@@ -1934,7 +1934,7 @@ ETEXI
         .params     = "[subcommand]",
         .help       = "show various information about the system state",
         .cmd        = hmp_info_help,
-        .sub_table  = info_cmds,
+        .sub_table  = hmp_info_cmds,
         .flags      = "p",
     },
 
monitor.c +35 -37

187 lines not on this page · raw message

Signature · 1 line
2.21.0
#14 lore raw

[Qemu-devel] [PULL 14/16] monitor: Split Monitor.flags into separate bools

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Monitor.flags contains three different flags: One to distinguish HMP from QMP; one specific to HMP (MONITOR_USE_READLINE) that is ignored with QMP; and another one specific to QMP (MONITOR_USE_PRETTY) that is ignored with HMP.

Split the flags field into three bools and move them to the right subclass. Flags are still in use for the monitor_init() interface.

Message-Id: <[email protected]>

---
 monitor/hmp.c              |  6 +++---
 monitor/misc.c             |  2 +-
 monitor/monitor-internal.h |  8 +++++---
 monitor/monitor.c          | 14 +++++++++-----
 monitor/qmp.c              |  7 ++++---
 5 files changed, 22 insertions(+), 15 deletions(-)
monitor/hmp.c +3 -3
index 86e86c1cf1..07f827c90c 100644
@@ -1397,12 +1397,12 @@ static void monitor_readline_flush(void *opaque)
 void monitor_init_hmp(Chardev *chr, int flags)
 {
     MonitorHMP *mon = g_new0(MonitorHMP, 1);
-    bool use_readline = flags & MONITOR_USE_READLINE;
 
-    monitor_data_init(&mon->common, flags, false, false);
+    monitor_data_init(&mon->common, false, false, false);
     qemu_chr_fe_init(&mon->common.chr, chr, &error_abort);
 
-    if (use_readline) {
+    mon->use_readline = flags & MONITOR_USE_READLINE;
+    if (mon->use_readline) {
         mon->rs = readline_init(monitor_readline_printf,
                                 monitor_readline_flush,
                                 mon,
monitor/misc.c +1 -1
index 002aba1030..10f24673f8 100644
@@ -121,7 +121,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
     Monitor *old_mon;
     MonitorHMP hmp = {};
 
-    monitor_data_init(&hmp.common, 0, true, false);
+    monitor_data_init(&hmp.common, false, true, false);
 
     old_mon = cur_mon;
     cur_mon = &hmp.common;
monitor/monitor-internal.h +5 -3
index b4996c14ac..03ea0239ef 100644
@@ -86,8 +86,8 @@ typedef struct HMPCommand {
 struct Monitor {
     CharBackend chr;
     int reset_seen;
-    int flags;
     int suspend_cnt;            /* Needs to be accessed atomically */
+    bool is_qmp;
     bool skip_flush;
     bool use_io_thread;
 
@@ -112,6 +112,7 @@ struct Monitor {
 
 struct MonitorHMP {
     Monitor common;
+    bool use_readline;
     /*
      * State used only in the thread "owning" the monitor.
      * If @use_io_thread, this is @mon_iothread. (This does not actually happen
@@ -125,6 +126,7 @@ struct MonitorHMP {
 typedef struct {
     Monitor common;
     JSONMessageParser parser;
+    bool pretty;
     /*
      * When a client connects, we're in capabilities negotiation mode.
      * @commands is &qmp_cap_negotiation_commands then.  When command
@@ -148,7 +150,7 @@ typedef struct {
  */
 static inline bool monitor_is_qmp(const Monitor *mon)
 {
-    return mon->flags & MONITOR_USE_CONTROL;
+    return mon->is_qmp;
 }
 
 typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList;
@@ -165,7 +167,7 @@ void monitor_init_qmp(Chardev *chr, int flags);
 void monitor_init_hmp(Chardev *chr, int flags);
 
 int monitor_puts(Monitor *mon, const char *str);
-void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
+void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
                        bool use_io_thread);
 void monitor_data_destroy(Monitor *mon);
 int monitor_can_read(void *opaque);
monitor/monitor.c +9 -5
index db3d5ece99..3f4808240a 100644
@@ -78,14 +78,18 @@ bool monitor_cur_is_qmp(void)
  * Note: not all HMP monitors use readline, e.g., gdbserver has a
  * non-interactive HMP monitor, so readline is not used there.
  */
-static inline bool monitor_uses_readline(const Monitor *mon)
+static inline bool monitor_uses_readline(const MonitorHMP *mon)
 {
-    return mon->flags & MONITOR_USE_READLINE;
+    return mon->use_readline;
 }
 
 static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)
 {
-    return !monitor_is_qmp(mon) && !monitor_uses_readline(mon);
+    if (monitor_is_qmp(mon)) {
+        return false;
+    }
+
+    return !monitor_uses_readline(container_of(mon, MonitorHMP, common));
 }
 
 static void monitor_flush_locked(Monitor *mon);
@@ -521,17 +525,17 @@ static void monitor_iothread_init(void)
     mon_iothread = iothread_create("mon_iothread", &error_abort);
 }
 
-void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
+void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
                        bool use_io_thread)
 {
     if (use_io_thread && !mon_iothread) {
         monitor_iothread_init();
     }
     qemu_mutex_init(&mon->mon_lock);
+    mon->is_qmp = is_qmp;
     mon->outbuf = qstring_new();
     mon->skip_flush = skip_flush;
     mon->use_io_thread = use_io_thread;
-    mon->flags = flags;
 }
 
 void monitor_data_destroy(Monitor *mon)
monitor/qmp.c +4 -3
index 7c3d081a72..940649f688 100644
@@ -87,8 +87,7 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
     const QObject *data = QOBJECT(rsp);
     QString *json;
 
-    json = mon->common.flags & MONITOR_USE_PRETTY ?
-           qobject_to_json_pretty(data) : qobject_to_json(data);
+    json = mon->pretty ? qobject_to_json_pretty(data) : qobject_to_json(data);
     assert(json != NULL);
 
     qstring_append_chr(json, '\n');
@@ -373,9 +372,11 @@ void monitor_init_qmp(Chardev *chr, int flags)
     assert(!(flags & MONITOR_USE_READLINE));
 
     /* Note: we run QMP monitor in I/O thread when @chr supports that */
-    monitor_data_init(&mon->common, flags, false,
+    monitor_data_init(&mon->common, true, false,
                       qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
 
+    mon->pretty = flags & MONITOR_USE_PRETTY;
+
     qemu_mutex_init(&mon->qmp_queue_lock);
     mon->qmp_requests = g_queue_new();
 
Signature · 1 line
2.21.0
#15 lore raw

[Qemu-devel] [PULL 06/16] monitor: Remove Monitor.cmd_table indirection

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Monitor.cmd_table is initialised to point to mon_cmds and never changed afterwards. We can remove the indirection and just reference mon_cmds directly instead.

Message-Id: <[email protected]>

---
 monitor.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
monitor.c +3 -6
index 7c57308e2a..6fb9fa285c 100644
@@ -193,7 +193,6 @@ struct Monitor {
     bool use_io_thread;
 
     gchar *mon_cpu_path;
-    mon_cmd_t *cmd_table;
     QTAILQ_ENTRY(Monitor) entry;
 
     /*
@@ -722,8 +721,6 @@ static void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
     }
     qemu_mutex_init(&mon->mon_lock);
     mon->outbuf = qstring_new();
-    /* Use *mon_cmds by default. */
-    mon->cmd_table = mon_cmds;
     mon->skip_flush = skip_flush;
     mon->use_io_thread = use_io_thread;
     mon->flags = flags;
@@ -1024,7 +1021,7 @@ static void help_cmd(Monitor *mon, const char *name)
     }
 
     /* 2. dump the contents according to parsed args */
-    help_cmd_dump(mon, mon->cmd_table, args, nb_args, 0);
+    help_cmd_dump(mon, mon_cmds, args, nb_args, 0);
 
     free_cmdline_args(args, nb_args);
 }
@@ -3485,7 +3482,7 @@ static void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
 
     trace_handle_hmp_command(mon, cmdline);
 
-    cmd = monitor_parse_command(mon, cmdline, &cmdline, mon->common.cmd_table);
+    cmd = monitor_parse_command(mon, cmdline, &cmdline, mon_cmds);
     if (!cmd) {
         return;
     }
@@ -4132,7 +4129,7 @@ static void monitor_find_completion(void *opaque,
     }
 
     /* 2. auto complete according to args */
-    monitor_find_completion_by_table(mon, mon->common.cmd_table, args, nb_args);
+    monitor_find_completion_by_table(mon, mon_cmds, args, nb_args);
 
 cleanup:
     free_cmdline_args(args, nb_args);
Signature · 1 line
2.21.0
#16 lore raw

[Qemu-devel] [PULL 11/16] monitor: Split out monitor/qmp.c

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Move QMP infrastructure from monitor/misc.c to monitor/qmp.c. This is code that can be shared for all targets, so compile it only once.

The amount of function and particularly extern variables in monitor_int.h is probably a bit larger than it needs to be, but this way no non-trivial code modifications are needed. The interfaces between QMP and the monitor core can be cleaned up later.

Message-Id: <[email protected]>

[monitor_is_qmp() tidied up to make checkpatch.pl happy, superfluous #include dropped]

---
 Makefile.objs              |   1 +
 monitor/Makefile.objs      |   1 +
 monitor/misc.c             | 401 +-----------------------------------
 monitor/monitor-internal.h |  30 +++
 monitor/qmp.c              | 406 +++++++++++++++++++++++++++++++++++++
 monitor/trace-events       |   4 +-
 6 files changed, 450 insertions(+), 393 deletions(-)
 create mode 100644 monitor/qmp.c
Makefile.objs +1 -0
index 9495fcbc7e..658cfc9d9f 100644
@@ -46,6 +46,7 @@ ifeq ($(CONFIG_SOFTMMU),y)
 common-obj-y = blockdev.o blockdev-nbd.o block/
 common-obj-y += bootdevice.o iothread.o
 common-obj-y += job-qmp.o
+common-obj-y += monitor/
 common-obj-y += net/
 common-obj-y += qdev-monitor.o device-hotplug.o
 common-obj-$(CONFIG_WIN32) += os-win32.o
monitor/Makefile.objs +1 -0
index a7170af6e1..1037c09ff8 100644
@@ -1,2 +1,3 @@
 obj-y += misc.o
+common-obj-y += qmp.o
 common-obj-y += qmp-cmds.o hmp-cmds.o
monitor/misc.c +9 -392

517 lines not on this page · raw message

monitor/monitor-internal.h +30 -0
index ebaf0201c8..d859bd3894 100644
@@ -31,6 +31,7 @@
 #include "qapi/qmp/dispatch.h"
 #include "qapi/qmp/json-parser.h"
 #include "qemu/readline.h"
+#include "sysemu/iothread.h"
 
 /*
  * Supported types:
@@ -142,4 +143,33 @@ typedef struct {
     GQueue *qmp_requests;
 } MonitorQMP;
 
+/**
+ * Is @mon a QMP monitor?
+ */
+static inline bool monitor_is_qmp(const Monitor *mon)
+{
+    return mon->flags & MONITOR_USE_CONTROL;
+}
+
+typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList;
+extern IOThread *mon_iothread;
+extern QEMUBH *qmp_dispatcher_bh;
+extern QmpCommandList qmp_commands, qmp_cap_negotiation_commands;
+extern QemuMutex monitor_lock;
+extern MonitorList mon_list;
+extern int mon_refcount;
+
+void monitor_init_qmp(Chardev *chr, int flags);
+
+int monitor_puts(Monitor *mon, const char *str);
+void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
+                       bool use_io_thread);
+int monitor_can_read(void *opaque);
+void monitor_list_append(Monitor *mon);
+void monitor_fdsets_cleanup(void);
+
+void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
+void monitor_data_destroy_qmp(MonitorQMP *mon);
+void monitor_qmp_bh_dispatcher(void *data);
+
 #endif
monitor/qmp.c new file +406 -0

406 lines not on this page · raw message

monitor/trace-events +3 -1
index abfdf20b14..a06dde3fd3 100644
@@ -5,7 +5,9 @@ monitor_protocol_event_handler(uint32_t event, void *qdict) "event=%d data=%p"
 monitor_protocol_event_emit(uint32_t event, void *data) "event=%d data=%p"
 monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "event=%d data=%p rate=%" PRId64
 handle_hmp_command(void *mon, const char *cmdline) "mon %p cmdline: %s"
-handle_qmp_command(void *mon, const char *req) "mon %p req: %s"
 monitor_suspend(void *ptr, int cnt) "mon %p: %d"
+
+# qmp.c
 monitor_qmp_cmd_in_band(const char *id) "%s"
 monitor_qmp_cmd_out_of_band(const char *id) "%s"
+handle_qmp_command(void *mon, const char *req) "mon %p req: %s"
Signature · 1 line
2.21.0
#17 lore raw

[Qemu-devel] [PULL 15/16] monitor: Replace monitor_init() with monitor_init_{hmp, qmp}()

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

Most callers know which monitor type they want to have. Instead of calling monitor_init() with flags that can describe both types of monitors, make monitor_init_{hmp,qmp}() public interfaces that take specific bools instead of flags and call these functions directly.

Message-Id: <[email protected]>

---
 chardev/char.c             |  2 +-
 gdbstub.c                  |  2 +-
 include/monitor/monitor.h  |  9 ++-------
 monitor/hmp.c              |  4 ++--
 monitor/monitor-internal.h |  3 ---
 monitor/monitor.c          |  9 ---------
 monitor/qmp.c              |  7 ++-----
 stubs/monitor.c            |  6 +++++-
 tests/test-util-sockets.c  |  3 ++-
 vl.c                       | 18 ++++++++++++------
 10 files changed, 27 insertions(+), 36 deletions(-)
chardev/char.c +1 -1
index e4887bcc82..7b6b2cb123 100644
@@ -731,7 +731,7 @@ Chardev *qemu_chr_new_noreplay(const char *label, const char *filename,
 
     if (qemu_opt_get_bool(opts, "mux", 0)) {
         assert(permit_mux_mon);
-        monitor_init(chr, MONITOR_USE_READLINE);
+        monitor_init_hmp(chr, true);
     }
 
 out:
gdbstub.c +1 -1
index d614a1f3c0..8618e34311 100644
@@ -3344,7 +3344,7 @@ int gdbserver_start(const char *device)
         /* Initialize a monitor terminal for gdb */
         mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB,
                                    NULL, NULL, &error_abort);
-        monitor_init(mon_chr, 0);
+        monitor_init_hmp(mon_chr, false);
     } else {
         qemu_chr_fe_deinit(&s->chr, true);
         mon_chr = s->mon_chr;
include/monitor/monitor.h +2 -7
index 44ac43df34..a81eeff5f8 100644
@@ -8,19 +8,14 @@
 extern __thread Monitor *cur_mon;
 typedef struct MonitorHMP MonitorHMP;
 
-/* flags for monitor_init */
-/* 0x01 unused */
-#define MONITOR_USE_READLINE  0x02
-#define MONITOR_USE_CONTROL   0x04
-#define MONITOR_USE_PRETTY    0x08
-
 #define QMP_REQ_QUEUE_LEN_MAX 8
 
 bool monitor_cur_is_qmp(void);
 
 void monitor_init_globals(void);
 void monitor_init_globals_core(void);
-void monitor_init(Chardev *chr, int flags);
+void monitor_init_qmp(Chardev *chr, bool pretty);
+void monitor_init_hmp(Chardev *chr, bool use_readline);
 void monitor_cleanup(void);
 
 int monitor_suspend(Monitor *mon);
monitor/hmp.c +2 -2
index 07f827c90c..5349a81307 100644
@@ -1394,14 +1394,14 @@ static void monitor_readline_flush(void *opaque)
     monitor_flush(&mon->common);
 }
 
-void monitor_init_hmp(Chardev *chr, int flags)
+void monitor_init_hmp(Chardev *chr, bool use_readline)
 {
     MonitorHMP *mon = g_new0(MonitorHMP, 1);
 
     monitor_data_init(&mon->common, false, false, false);
     qemu_chr_fe_init(&mon->common.chr, chr, &error_abort);
 
-    mon->use_readline = flags & MONITOR_USE_READLINE;
+    mon->use_readline = use_readline;
     if (mon->use_readline) {
         mon->rs = readline_init(monitor_readline_printf,
                                 monitor_readline_flush,
monitor/monitor-internal.h +0 -3
index 03ea0239ef..7760b22ba3 100644
@@ -163,9 +163,6 @@ extern int mon_refcount;
 
 extern HMPCommand hmp_cmds[];
 
-void monitor_init_qmp(Chardev *chr, int flags);
-void monitor_init_hmp(Chardev *chr, int flags);
-
 int monitor_puts(Monitor *mon, const char *str);
 void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
                        bool use_io_thread);
monitor/monitor.c +0 -9
index 3f4808240a..3ef28171c0 100644
@@ -551,15 +551,6 @@ void monitor_data_destroy(Monitor *mon)
     qemu_mutex_destroy(&mon->mon_lock);
 }
 
-void monitor_init(Chardev *chr, int flags)
-{
-    if (flags & MONITOR_USE_CONTROL) {
-        monitor_init_qmp(chr, flags);
-    } else {
-        monitor_init_hmp(chr, flags);
-    }
-}
-
 void monitor_cleanup(void)
 {
     /*
monitor/qmp.c +2 -5
index 940649f688..e1b196217d 100644
@@ -364,18 +364,15 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)
     monitor_list_append(&mon->common);
 }
 
-void monitor_init_qmp(Chardev *chr, int flags)
+void monitor_init_qmp(Chardev *chr, bool pretty)
 {
     MonitorQMP *mon = g_new0(MonitorQMP, 1);
 
-    /* Only HMP supports readline */
-    assert(!(flags & MONITOR_USE_READLINE));
-
     /* Note: we run QMP monitor in I/O thread when @chr supports that */
     monitor_data_init(&mon->common, true, false,
                       qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
 
-    mon->pretty = flags & MONITOR_USE_PRETTY;
+    mon->pretty = pretty;
 
     qemu_mutex_init(&mon->qmp_queue_lock);
     mon->qmp_requests = g_queue_new();
stubs/monitor.c +5 -1
index cdbf5c5f9a..c3e9a2e4dc 100644
@@ -16,7 +16,11 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
     return -1;
 }
 
-void monitor_init(Chardev *chr, int flags)
+void monitor_init_qmp(Chardev *chr, bool pretty)
+{
+}
+
+void monitor_init_hmp(Chardev *chr, bool use_readline)
 {
 }
 
tests/test-util-sockets.c +2 -1
index fd1ced058c..f1ebffee5a 100644
@@ -71,7 +71,8 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
  */
 __thread Monitor *cur_mon;
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
-void monitor_init(Chardev *chr, int flags) {}
+void monitor_init_qmp(Chardev *chr, bool pretty) {}
+void monitor_init_hmp(Chardev *chr, bool use_readline) {}
 
 
 static void test_socket_fd_pass_name_good(void)
vl.c +12 -6
index 005468cbfb..32daa434eb 100644
@@ -2299,25 +2299,27 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
 {
     Chardev *chr;
+    bool qmp;
+    bool pretty = false;
     const char *chardev;
     const char *mode;
-    int flags;
 
     mode = qemu_opt_get(opts, "mode");
     if (mode == NULL) {
         mode = "readline";
     }
     if (strcmp(mode, "readline") == 0) {
-        flags = MONITOR_USE_READLINE;
+        qmp = false;
     } else if (strcmp(mode, "control") == 0) {
-        flags = MONITOR_USE_CONTROL;
+        qmp = true;
     } else {
         error_setg(errp, "unknown monitor mode \"%s\"", mode);
         return -1;
     }
 
-    if (qemu_opt_get_bool(opts, "pretty", 0))
-        flags |= MONITOR_USE_PRETTY;
+    if (qemu_opt_get_bool(opts, "pretty", 0)) {
+        pretty = true;
+    }
 
     chardev = qemu_opt_get(opts, "chardev");
     if (!chardev) {
@@ -2330,7 +2332,11 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
         return -1;
     }
 
-    monitor_init(chr, flags);
+    if (qmp) {
+        monitor_init_qmp(chr, pretty);
+    } else {
+        monitor_init_hmp(chr, true);
+    }
     return 0;
 }
 
Signature · 1 line
2.21.0
#18 lore raw

[Qemu-devel] [PULL 16/16] vl: Deprecate -mon pretty=... for HMP monitors

In reply to Markus Armbruster

From: Kevin Wolf <[email protected]>

The -mon pretty=on|off switch of the -mon option applies only to QMP monitors. It's silently ignored for HMP. Deprecate this combination so that we can make it an error in future versions.

Message-Id: <[email protected]>

---
 qemu-deprecated.texi |  6 ++++++
 vl.c                 | 10 +++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
qemu-deprecated.texi +6 -0
index 50292d820b..df04f2840b 100644
@@ -72,6 +72,12 @@ backend settings instead of environment variables.  To ease migration to
 the new format, the ``-audiodev-help'' option can be used to convert
 the current values of the environment variables to ``-audiodev'' options.
 
+@subsection -mon ...,control=readline,pretty=on|off (since 4.1)
+
+The @code{pretty=on|off} switch has no effect for HMP monitors, but is
+silently ignored. Using the switch with HMP monitors will become an
+error in the future.
+
 @subsection -realtime (since 4.1)
 
 The @code{-realtime mlock=on|off} argument has been replaced by the
vl.c +9 -1
index 32daa434eb..99a56b5556 100644
@@ -2317,6 +2317,10 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
         return -1;
     }
 
+    if (!qmp && qemu_opt_get(opts, "pretty")) {
+        warn_report("'pretty' is deprecated for HMP monitors, it has no effect "
+                    "and will be removed in future versions");
+    }
     if (qemu_opt_get_bool(opts, "pretty", 0)) {
         pretty = true;
     }
@@ -2362,7 +2366,11 @@ static void monitor_parse(const char *optarg, const char *mode, bool pretty)
     opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
     qemu_opt_set(opts, "mode", mode, &error_abort);
     qemu_opt_set(opts, "chardev", label, &error_abort);
-    qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
     monitor_device_index++;
 }
 
Signature · 1 line
2.21.0
#19 lore raw

Re: [Qemu-devel] [PULL 16/16] vl: Deprecate -mon pretty=... for HMP monitors

Quoted 5 lines · Markus Armbruster

From: Kevin Wolf <[email protected]>

The -mon pretty=on|off switch of the -mon option applies only to QMP monitors. It's silently ignored for HMP. Deprecate this combination so that we can make it an error in future versions.

No objection to merging this PR as is, but how about we extend the deprecation to QMP too ?

I was responsible for adding this option back in 2010 and I don't think I've used it since 2012 when I added pretty printing support to scripts/qmp/qmp-shell. I struggle to imagine good reasons for using QMP directly with pretty printing, as opposed to doing it via qmp-shell or another wrapper tool.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#20 lore raw

Re: [Qemu-devel] [PULL 16/16] vl: Deprecate -mon pretty=... for HMP monitors

Am 18.06.2019 um 11:01 hat Daniel P. Berrangé geschrieben:

Quoted 7 lines · Markus Armbruster
Quoted 5 lines

From: Kevin Wolf <[email protected]>

The -mon pretty=on|off switch of the -mon option applies only to QMP monitors. It's silently ignored for HMP. Deprecate this combination so that we can make it an error in future versions.

Quoted 8 lines

No objection to merging this PR as is, but how about we extend the deprecation to QMP too ?

I was responsible for adding this option back in 2010 and I don't think I've used it since 2012 when I added pretty printing support to scripts/qmp/qmp-shell. I struggle to imagine good reasons for using QMP directly with pretty printing, as opposed to doing it via qmp-shell or another wrapper tool.

qemu-iotests uses it. It doesn't only make the output (and espeically diffs on failure) much more readable, but in fact also avoids very long lines in the refernce output that used to break patch emails when we didn't use pretty printing yet.

So let's keep it for QMP, please.

Kevin

#21 lore raw

Re: [Qemu-devel] [PULL 16/16] vl: Deprecate -mon pretty=... for HMP monitors

Quoted 17 lines · Kevin Wolf

Am 18.06.2019 um 11:01 hat Daniel P. Berrangé geschrieben:

Quoted 7 lines · Markus Armbruster
Quoted 5 lines

From: Kevin Wolf <[email protected]>

The -mon pretty=on|off switch of the -mon option applies only to QMP monitors. It's silently ignored for HMP. Deprecate this combination so that we can make it an error in future versions.

Quoted 8 lines

No objection to merging this PR as is, but how about we extend the deprecation to QMP too ?

I was responsible for adding this option back in 2010 and I don't think I've used it since 2012 when I added pretty printing support to scripts/qmp/qmp-shell. I struggle to imagine good reasons for using QMP directly with pretty printing, as opposed to doing it via qmp-shell or another wrapper tool.

Quoted 6 lines

qemu-iotests uses it. It doesn't only make the output (and espeically diffs on failure) much more readable, but in fact also avoids very long lines in the refernce output that used to break patch emails when we didn't use pretty printing yet.

So let's keep it for QMP, please.

Perhaps we can get rid of it if we find a suitable filter.

Hmm, Python comes with one: "python -m json.tool". It expects just one expression, and fails if anything follows:

    $ printf '{"execute": "qmp_capabilities"}\n{"execute": "query-version"}\n' | socat UNIX:/work/armbru/images/test-qmp STDIO | python3 -m json.tool
    Extra data: line 2 column 1 (char 134)

To pretty print a sequence of expressions, you have to wrap a loop around it:

    $ printf '{"execute": "qmp_capabilities"}\n{"execute": "query-version"}\n' | socat UNIX:/work/armbru/images/test-qmp STDIO | { while read line; do echo "$line" | python3 -m json.tool; done; }
    {
        "QMP": {
            "version": {
                "qemu": {
                    "micro": 50,
                    "minor": 0,
                    "major": 4
                },
                "package": "v4.0.0-1467-g6385dd6613"
            },
            "capabilities": [
                "oob"
            ]
        }
    }
    {
        "return": {}
    }
    {
        "return": {
            "qemu": {
                "micro": 50,
                "minor": 0,
                "major": 4
            },
            "package": "v4.0.0-1467-g6385dd6613"
        }
    }

I figure we'd want to loop in Python instead of shell.

My point is: pretty-printing is trivial in Python. The case for maintaining C code to do it seems weak.

#22 lore raw

Re: [Qemu-devel] [PULL 16/16] vl: Deprecate -mon pretty=... for HMP monitors

Am 19.06.2019 um 08:42 hat Markus Armbruster geschrieben:

Quoted 31 lines
Quoted 17 lines · Kevin Wolf

Am 18.06.2019 um 11:01 hat Daniel P. Berrangé geschrieben:

Quoted 7 lines · Markus Armbruster
Quoted 5 lines

From: Kevin Wolf <[email protected]>

The -mon pretty=on|off switch of the -mon option applies only to QMP monitors. It's silently ignored for HMP. Deprecate this combination so that we can make it an error in future versions.

Quoted 8 lines

No objection to merging this PR as is, but how about we extend the deprecation to QMP too ?

I was responsible for adding this option back in 2010 and I don't think I've used it since 2012 when I added pretty printing support to scripts/qmp/qmp-shell. I struggle to imagine good reasons for using QMP directly with pretty printing, as opposed to doing it via qmp-shell or another wrapper tool.

Quoted 6 lines

qemu-iotests uses it. It doesn't only make the output (and espeically diffs on failure) much more readable, but in fact also avoids very long lines in the refernce output that used to break patch emails when we didn't use pretty printing yet.

So let's keep it for QMP, please.

Perhaps we can get rid of it if we find a suitable filter.

Hmm, Python comes with one: "python -m json.tool". It expects just one expression, and fails if anything follows:

Quoted 7 lines
    $ printf '{"execute": "qmp_capabilities"}\n{"execute": "query-version"}\n' | socat UNIX:/work/armbru/images/test-qmp STDIO | python3 -m json.tool
    Extra data: line 2 column 1 (char 134)

To pretty print a sequence of expressions, you have to wrap a loop around it:

    $ printf '{"execute": "qmp_capabilities"}\n{"execute": "query-version"}\n' | socat UNIX:/work/armbru/images/test-qmp STDIO | { while read line; do echo "$line" | python3 -m json.tool; done; }

Yes, it's doable. It's not a very nice command line, but it does its job.

What do we win by removing pretty printing from qemu? We invest some work doing the patches, reviewing them, etc. and save the whole complexity of adding a few newlines and spaces to an already existing string buffer in a single place (qjson.c).

In exchange, we have to add the above overlong command line to every qemu-iotests case for which pretty printed QMP is useful, and lose the ability to just do -qmp-pretty stdio manually (which I do every now and then) instead of having to dig up the above line in some script to copy it.

It doesn't look like a net win to me.

Quoted 4 lines

I figure we'd want to loop in Python instead of shell.

My point is: pretty-printing is trivial in Python. The case for maintaining C code to do it seems weak.

The pretty printing is fairly trivial in C, too, when you already generate JSON. The code seems to have been last touched in 2014, and before that in 2010 when it was introduced. The maintenance burden doesn't seem to be that bad.

Removing features that have users can be justified sometimes, but it does need a justification, in my opinion.

Kevin

#23 lore raw

Re: [Qemu-devel] [PULL 16/16] vl: Deprecate -mon pretty=... for HMP monitors

Quoted 61 lines · Kevin Wolf

Am 19.06.2019 um 08:42 hat Markus Armbruster geschrieben:

Quoted 31 lines
Quoted 17 lines · Kevin Wolf

Am 18.06.2019 um 11:01 hat Daniel P. Berrangé geschrieben:

Quoted 7 lines · Markus Armbruster
Quoted 5 lines

From: Kevin Wolf <[email protected]>

The -mon pretty=on|off switch of the -mon option applies only to QMP monitors. It's silently ignored for HMP. Deprecate this combination so that we can make it an error in future versions.

Quoted 8 lines

No objection to merging this PR as is, but how about we extend the deprecation to QMP too ?

I was responsible for adding this option back in 2010 and I don't think I've used it since 2012 when I added pretty printing support to scripts/qmp/qmp-shell. I struggle to imagine good reasons for using QMP directly with pretty printing, as opposed to doing it via qmp-shell or another wrapper tool.

Quoted 6 lines

qemu-iotests uses it. It doesn't only make the output (and espeically diffs on failure) much more readable, but in fact also avoids very long lines in the refernce output that used to break patch emails when we didn't use pretty printing yet.

So let's keep it for QMP, please.

Perhaps we can get rid of it if we find a suitable filter.

Hmm, Python comes with one: "python -m json.tool". It expects just one expression, and fails if anything follows:

Quoted 7 lines
    $ printf '{"execute": "qmp_capabilities"}\n{"execute": "query-version"}\n' | socat UNIX:/work/armbru/images/test-qmp STDIO | python3 -m json.tool
    Extra data: line 2 column 1 (char 134)

To pretty print a sequence of expressions, you have to wrap a loop around it:

    $ printf '{"execute": "qmp_capabilities"}\n{"execute": "query-version"}\n' | socat UNIX:/work/armbru/images/test-qmp STDIO | { while read line; do echo "$line" | python3 -m json.tool; done; }

Yes, it's doable. It's not a very nice command line, but it does its job.

What do we win by removing pretty printing from qemu? We invest some work doing the patches, reviewing them, etc. and save the whole complexity of adding a few newlines and spaces to an already existing string buffer in a single place (qjson.c).

In exchange, we have to add the above overlong command line to every qemu-iotests case for which pretty printed QMP is useful, and lose the ability to just do -qmp-pretty stdio manually (which I do every now and then) instead of having to dig up the above line in some script to copy it.

It doesn't look like a net win to me.

Quoted 4 lines

I figure we'd want to loop in Python instead of shell.

My point is: pretty-printing is trivial in Python. The case for maintaining C code to do it seems weak.

Quoted 7 lines

The pretty printing is fairly trivial in C, too, when you already generate JSON. The code seems to have been last touched in 2014, and before that in 2010 when it was introduced. The maintenance burden doesn't seem to be that bad.

Removing features that have users can be justified sometimes, but it does need a justification, in my opinion.

I'm fine with keeping the print-printing in QEMU given that you illustrated an existing usage of it I wasn't aware of & its not difficult code to maintain.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#24 lore raw
In reply to Markus Armbruster
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Subject: [Qemu-devel] [PULL 00/16] Monitor patches for 2019-06-17
Type: series
Message-id: [email protected]

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
10cbb82 vl: Deprecate -mon pretty=... for HMP monitors c8d6357 monitor: Replace monitor_init() with monitor_init_{hmp, qmp}() add28d5 monitor: Split Monitor.flags into separate bools 61f535a monitor: Split out monitor/monitor.c
1f84df4 monitor: Split out monitor/hmp.c
7b0f436 monitor: Split out monitor/qmp.c
62fff9a monitor: Create monitor-internal.h with common definitions 0be87c8 monitor: Move {hmp, qmp}.c to monitor/{hmp, qmp}-cmds.c 9dc5b85 Move monitor.c to monitor/misc.c
32b2352 monitor: Rename HMP command type and tables
6259cf7 monitor: Remove Monitor.cmd_table indirection 4cc8716 monitor: Create MonitorHMP with readline state e28b9ba monitor: Make MonitorQMP a child class of Monitor 0032c2c monitor: Split monitor_init in HMP and QMP function 8ef4253 monitor: Remove unused password prompting fields f21701f monitor: Fix return type of monitor_fdset_dup_fd_find

=== OUTPUT BEGIN ===
1/16 Checking commit f21701f2afc2 (monitor: Fix return type of monitor_fdset_dup_fd_find) 2/16 Checking commit 8ef4253a4478 (monitor: Remove unused password prompting fields) 3/16 Checking commit 0032c2cf455d (monitor: Split monitor_init in HMP and QMP function) 4/16 Checking commit e28b9ba8e716 (monitor: Make MonitorQMP a child class of Monitor) 5/16 Checking commit 4cc8716de54a (monitor: Create MonitorHMP with readline state) 6/16 Checking commit 6259cf7f6c52 (monitor: Remove Monitor.cmd_table indirection) 7/16 Checking commit 32b235292bf6 (monitor: Rename HMP command type and tables) 8/16 Checking commit 9dc5b85526e4 (Move monitor.c to monitor/misc.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #82:
new file mode 100644

total: 0 errors, 1 warnings, 78 lines checked

Patch 8/16 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
9/16 Checking commit 0be87c866744 (monitor: Move {hmp, qmp}.c to monitor/{hmp, qmp}-cmds.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #106:
rename from hmp.c

total: 0 errors, 1 warnings, 73 lines checked

Patch 9/16 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
10/16 Checking commit 62fff9aeab3c (monitor: Create monitor-internal.h with common definitions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#227:
new file mode 100644

total: 0 errors, 1 warnings, 326 lines checked

Patch 10/16 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
11/16 Checking commit 7b0f43601c81 (monitor: Split out monitor/qmp.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #628:
new file mode 100644

total: 0 errors, 1 warnings, 984 lines checked

Patch 11/16 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
12/16 Checking commit 1f84df448bda (monitor: Split out monitor/hmp.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #33:
new file mode 100644

ERROR: consider using qemu_strtoull in preference to strtoull #436: FILE: monitor/hmp.c:399:
+ n = strtoull(pch, &p, 0);

total: 1 errors, 1 warnings, 2937 lines checked

Patch 12/16 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

13/16 Checking commit 61f535a02231 (monitor: Split out monitor/monitor.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #735:
new file mode 100644

WARNING: Block comments use a leading /* on a separate line #1370: FILE: monitor/monitor.c:631:
+ { /* end of list */ }

total: 0 errors, 2 warnings, 1317 lines checked

Patch 13/16 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
14/16 Checking commit add28d51ab77 (monitor: Split Monitor.flags into separate bools) 15/16 Checking commit c8d635777789 (monitor: Replace monitor_init() with monitor_init_{hmp, qmp}()) 16/16 Checking commit 10cbb82deaa5 (vl: Deprecate -mon pretty=... for HMP monitors) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#25 lore raw
In reply to Markus Armbruster
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed build test on s390x host. Please find the details below.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with # HEAD pointing to a commit that has the patches applied on top of "base"

# branch
set -e
CC=$HOME/bin/cc
INSTALL=$PWD/install
BUILD=$PWD/build
mkdir -p $BUILD $INSTALL
SRC=$PWD
cd $BUILD
$SRC/configure --cc=$CC --prefix=$INSTALL
make -j4
# XXX: we need reliable clean up
# make check -j4 V=1
make install

echo
echo "=== ENV ==="
env

echo
echo "=== PACKAGES ==="
rpm -qa
=== TEST SCRIPT END ===

CC arm-softmmu/hw/block/virtio-blk.o
CC alpha-softmmu/hw/char/virtio-serial-bus.o
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c: In function ‘netdev_del_completion’:
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: implicit declaration of function ‘qemu_find_opts_err’; did you mean ‘qemu_find_netdev’? [-Werror=implicit-function-declaration]

 2165 |         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
      |                               ^~~~~~~~~~~~~~~~~~
      |                               qemu_find_netdev
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: nested extern declaration of ‘qemu_find_opts_err’ [-Werror=nested-externs]
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: passing argument 1 of ‘qemu_opts_find’ makes pointer from integer without a cast [-Werror=int-conversion]
 2165 |         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |

---
CC aarch64-softmmu/hw/intc/arm_gicv3_cpuif.o
CC alpha-softmmu/qapi/qapi-introspect.o
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c: In function ‘netdev_del_completion’:
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: implicit declaration of function ‘qemu_find_opts_err’; did you mean ‘qemu_find_netdev’? [-Werror=implicit-function-declaration]

 2165 |         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
      |                               ^~~~~~~~~~~~~~~~~~
      |                               qemu_find_netdev
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: nested extern declaration of ‘qemu_find_opts_err’ [-Werror=nested-externs]
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: passing argument 1 of ‘qemu_opts_find’ makes pointer from integer without a cast [-Werror=int-conversion]
 2165 |         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |

---
CC arm-softmmu/hw/arm/msf2-soc.o
CC aarch64-softmmu/qapi/qapi-types.o
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c: In function ‘netdev_del_completion’:
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: implicit declaration of function ‘qemu_find_opts_err’; did you mean ‘qemu_find_netdev’? [-Werror=implicit-function-declaration]

 2165 |         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
      |                               ^~~~~~~~~~~~~~~~~~
      |                               qemu_find_netdev
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: nested extern declaration of ‘qemu_find_opts_err’ [-Werror=nested-externs]
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: passing argument 1 of ‘qemu_opts_find’ makes pointer from integer without a cast [-Werror=int-conversion]
 2165 |         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |

---
CC arm-softmmu/qapi/qapi-events.o
CC arm-softmmu/qapi/qapi-commands-target.o
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c: In function ‘netdev_del_completion’:
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: implicit declaration of function ‘qemu_find_opts_err’; did you mean ‘qemu_find_netdev’? [-Werror=implicit-function-declaration]

 2165 |         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
      |                               ^~~~~~~~~~~~~~~~~~
      |                               qemu_find_netdev
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: nested extern declaration of ‘qemu_find_opts_err’ [-Werror=nested-externs]
/var/tmp/patchew-tester-tmp-0lxd7r14/src/monitor/misc.c:2165:31: error: passing argument 1 of ‘qemu_opts_find’ makes pointer from integer without a cast [-Werror=int-conversion]
 2165 |         opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |

The full log is available at
http://patchew.org/logs/[email protected]/testing.s390x/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]