summaryrefslogtreecommitdiff
path: root/qapi
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2026-07-06 14:58:20 +0100
committerMarkus Armbruster <armbru@redhat.com>2026-07-07 11:16:27 +0200
commit6c479e70e29f80bfd2b72c1ed760a1ddd9600281 (patch)
tree967b97a2f93c25e501ed6b3edf66d31a11fc415f /qapi
parentf091e8abd87157a634152489b0f580504a06d2cc (diff)
downloadqemu-6c479e70e29f80bfd2b72c1ed760a1ddd9600281.tar.gz
qemu-6c479e70e29f80bfd2b72c1ed760a1ddd9600281.zip
monitor: add support for auto-deleting monitors upon close
The default monitor is usually a long lived object that will exist for the entire lifetime of the VM. A monitor can only service a single client at a time though, and so it might be desirable to hotplug additional monitors at runtime for specific tasks. If doing that, however, there is a need to remove the monitor when it is no longer needed. A use case for hotplugging a monitor can involve a user wishing to spawn an ad hoc script that uses a temporary monitor. The script can ask the management application to hotplug a monitor and pass back a pre-opened FD using SCM_RIGHTS. In this case the lifetime of the script is not tied to the management application and thus it is desirable to have automatic cleanup when the script exits. Allowing a client to run "object-del" against its own monitor adds complex edge cases, as it would be desirable to send the QMP response despite the monitor sending it being deleted. Doing "object-del" alone will also result in orphaning a character device backend instance, as there is no opportunity to run the companion "chardev-del" command. A simpler way to ensure cleanup is to add the concept of auto-deleting monitor objects. Specifically when the "CHR_EVENT_CLOSED" event is emitted, the equivalent of "object-del" + "chardev-del" can be run internally. Since the transient client has already droppped its monitor connection, there is no synchronization to be concerned about with sending QMP replies. There is still some internal synchronization needed, however, between the character device event callback and the bottom-half that runs the delete. There is a chance that an incoming client connection may arise before the bottom-half runs, which has to be checked. Once the monitor object is deleted, the event callback is unregistered from the character device, eliminating any further races before the character device is fully deleted. This is implemented via a new "close-action=none|delete" property on the 'monitor-qmp' object. This concept could be extended with further actions in future, for example: * close-action=shutdown - graceful guest shutdown * close-action=terminate - immediate guest poweroff * close-action=stop - pause guest CPUs while the monitor is not connected to any client This is left as an exercise for future interested contributors. Tested-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Acked-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260706135824.2623960-33-berrange@redhat.com> [Commit message typos fixed] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'qapi')
-rw-r--r--qapi/qom.json22
1 files changed, 21 insertions, 1 deletions
diff --git a/qapi/qom.json b/qapi/qom.json
index 33a827b9fa..d96cc5aa21 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -1213,6 +1213,22 @@
'base': 'MonitorProperties',
'data': { '*readline': 'bool' } }
+
+##
+# @MonitorQMPCloseAction:
+#
+# Action to take when the character device backend is closed.
+#
+# @none: take no action
+#
+# @delete: delete both the 'monitor-qmp' object and its associated
+# character device backend object
+#
+# Since: 11.1
+##
+{ 'enum': 'MonitorQMPCloseAction',
+ 'data': ['none', 'delete'] }
+
##
# @MonitorQMPProperties:
#
@@ -1220,11 +1236,15 @@
#
# @pretty: whether to pretty print JSON responses (default: false)
#
+# @close-action: action to take when the character device backend is
+# closed (default: none)
+#
# Since: 11.1
##
{ 'struct': 'MonitorQMPProperties',
'base': 'MonitorProperties',
- 'data': { '*pretty': 'bool' } }
+ 'data': { '*pretty': 'bool',
+ '*close-action': 'MonitorQMPCloseAction' } }
##
# @ObjectType: