[PATCH RFC 00/17] monitor: turn QMP and HMP into QOM objects

Daniel P. Berrangé posted 17 patches 23 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260410160458.3778874-1-berrange@redhat.com
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, "Dr. David Alan Gilbert" <dave@treblig.org>, Markus Armbruster <armbru@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eric Blake <eblake@redhat.com>, Kevin Wolf <kwolf@redhat.com>
chardev/char.c                       |  10 +-
gdbstub/system.c                     |  10 +-
include/monitor/monitor.h            |  21 ++-
migration/migration-hmp-cmds.c       |   5 +-
monitor/hmp-cmds.c                   |   7 +-
monitor/hmp.c                        | 159 ++++++++++++++-----
monitor/monitor-internal.h           |  44 +++---
monitor/monitor.c                    | 222 +++++++++++++--------------
monitor/qmp-cmds-control.c           |  12 +-
monitor/qmp-cmds.c                   |  14 +-
monitor/qmp.c                        | 138 ++++++++++++-----
qapi/qom.json                        |  43 ++++++
storage-daemon/qemu-storage-daemon.c |   2 +-
stubs/monitor-core.c                 |   5 -
stubs/monitor-internal.c             |   4 -
system/vl.c                          |  10 +-
tests/unit/test-util-sockets.c       |   1 -
ui/ui-hmp-cmds.c                     |   2 +-
util/error-report.c                  |  13 +-
19 files changed, 465 insertions(+), 257 deletions(-)
[PATCH RFC 00/17] monitor: turn QMP and HMP into QOM objects
Posted by Daniel P. Berrangé 23 hours ago
Conceptually -object and object_add/object_del should be sufficient
for essentially all QEMU configuration....if only we ported all our
internal custom backends/devices/etc to QOM. That is of course a big
job which is why it hasn't happened.

This series started with the premise that the monitor is one of the
easier areas to convert since we have no more than three classes,
a common base, and QMP and HMP subclasses. So why not give it a go
and thus unlock the ability to dynamically create/delete monitors
in QMP/HMP.

This series does the conversion in as many small steps as I could
achieve. At the end it is possible to create HMP and QMP monitors
with -object and object_add.

In theory object_del is possible but is unsafe since there's no
synchronization wrt "in use" monitors. Christian Brauner sent
a proposal for monitor_add/monitor_del commands that address the
safety/synchronization issues, but I've not yet integrated the
relevent bits of that series with this proposal:

  https://lists.nongnu.org/archive/html/qemu-devel/2026-04/msg01349.html

My overall feeling is that we're better off turning monitors
into QOM classes, rather than inventing more type specific
QMP commands.

What's missing:

 - Integration of code for safe deletion of monitors
 - The existing -mon/-qmp/-monitor args should be turned
   into syntax sugar around -object & -chardev
 - The new approach must be documented
 - Functional tests are needed for the hot add/remove of
   monitors and new -object syntax. (The pre-existing
   test suites cover the static config with the traditional
   args).

Daniel P. Berrangé (17):
  monitor: replace 'common' with 'parent' in MonitorHMP
  monitor: replace 'common' with 'parent' in MonitorQMP
  monitor: rename monitor_init* to monitor_new*
  monitor: minimal conversion of monitors to QOM
  monitor: remove 'skip_flush' field
  monitor: move monitor_data_(init|destroy) into QOM init/finalize
  monitor: use class methods for monitor_vprintf
  monitor: use class methods for monitor_qapi_event_emit
  monitor: use class methods for monitor_accept_input
  monitor: use dynamic cast in monitor_qmp_requests_pop_any_with_lock
  util: use dynamic cast in error vreport
  monitor: drop unused monitor_cur_is_qmp
  monitor: use dynamic cast in QMP commands
  monitor: use dynamic cast in monitor_is_hmp_non_interactive
  monitor: drop unused monitor_is_qmp method
  monitor: eliminate monitor_is_hmp_non_interactive method
  FIXME: monitor: implement "user creatable" interface

 chardev/char.c                       |  10 +-
 gdbstub/system.c                     |  10 +-
 include/monitor/monitor.h            |  21 ++-
 migration/migration-hmp-cmds.c       |   5 +-
 monitor/hmp-cmds.c                   |   7 +-
 monitor/hmp.c                        | 159 ++++++++++++++-----
 monitor/monitor-internal.h           |  44 +++---
 monitor/monitor.c                    | 222 +++++++++++++--------------
 monitor/qmp-cmds-control.c           |  12 +-
 monitor/qmp-cmds.c                   |  14 +-
 monitor/qmp.c                        | 138 ++++++++++++-----
 qapi/qom.json                        |  43 ++++++
 storage-daemon/qemu-storage-daemon.c |   2 +-
 stubs/monitor-core.c                 |   5 -
 stubs/monitor-internal.c             |   4 -
 system/vl.c                          |  10 +-
 tests/unit/test-util-sockets.c       |   1 -
 ui/ui-hmp-cmds.c                     |   2 +-
 util/error-report.c                  |  13 +-
 19 files changed, 465 insertions(+), 257 deletions(-)

-- 
2.53.0