From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346409; cv=none; d=zohomail.com; s=zohoarc; b=MzEsXDeSW0hfce2vw+sLduxGPATSXB9SLd5SQ6CGhoKAlL45xUOc6cgeElvYyb5BtbqfgBUE4f7IotjtbZDnVd4D5VUMdjNp2dPf4D5wX7n8Ed/NAmTTFcJ3arrguInSxQ7oNnvPZTciuyxb5J8ZCz4oBPoIW3D1sQQVunOzJLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346409; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RJaemyZMLbnYGTOQypoBxU3iM/bBc6eUkFNZBg8L8g8=; b=XKJgcrhzOapesbgPEr671xDjWy/6CF/hq46pRGhYRXOILO/dGPCesAmoCxm6AyX0rrp7dyCxMz93YZiklxbsUPIpW1NrcTlbziL8DEbd68GXqQd9BrKWuuQXiHujkhKw9ftQrNZyP22rUDh1RUNSkEDobg+e6wiWLO/SkPZ2XS4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346409438168.03534543786657; Mon, 6 Jul 2026 07:00:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjqR-0001pA-2s; Mon, 06 Jul 2026 09:58:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqM-0001oj-Tg for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqK-0001Y3-NW for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:42 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-dk97D9JxOJOAg9pAPKHfpg-1; Mon, 06 Jul 2026 09:58:36 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 425501955F3B; Mon, 6 Jul 2026 13:58:35 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 82F323000B54; Mon, 6 Jul 2026 13:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346320; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RJaemyZMLbnYGTOQypoBxU3iM/bBc6eUkFNZBg8L8g8=; b=eNPxJUTRMLtANVJPfaildiRfjz0gitdYS45xYrPDeUDpwHNXcyif/N/K61SQI7r1MqAev+ XIsciJkdc5k8m5qVhKu4U2FmkTVu/R3bshyihIcP18BkPoZBwD9N236faUQSTtG9IYloYt /Dr2jlAtM386nmyen2fDUTtDFqtsrBY= X-MC-Unique: dk97D9JxOJOAg9pAPKHfpg-1 X-Mimecast-MFC-AGG-ID: dk97D9JxOJOAg9pAPKHfpg_1783346315 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 01/35] qom: replace 'can_be_deleted' with 'prepare_delete' Date: Mon, 6 Jul 2026 14:57:49 +0100 Message-ID: <20260706135824.2623960-2-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346411600158502 While most objects can perform all their cleanup in the finalizer method, there can be interactions with other resources / subsystems / threads which require that some cleanup be performed on an user creatable object before unparenting it and entering finalization. The current 'can_be_deleted' method runs in the deletion path and is intended to be used to block deletion. While it could be used to perform cleanup tasks, its name suggests it should be free of side-effects. Generalize this by renaming it to 'prepare_delete', explicitly allowing for cleanup to be provided. Existing users of 'can_be_deleted' are re-written, which provides them with more detailed/tailored error messages. Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster Reviewed-by: Markus Armbruster --- backends/cryptodev.c | 12 +++++++++--- backends/hostmem.c | 7 +++++-- backends/iommufd.c | 11 ++++++++--- block/throttle-groups.c | 12 +++++++++--- event-loop-base.c | 8 ++++---- include/qom/object_interfaces.h | 26 +++++++++++++++++--------- include/system/event-loop-base.h | 2 +- net/can/can_core.c | 6 ++++-- qom/object_interfaces.c | 13 +++++-------- tests/qemu-iotests/245 | 4 ++-- util/main-loop.c | 6 ++++-- 11 files changed, 68 insertions(+), 39 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 79f8882d3b..e8f2b18f20 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -454,9 +454,15 @@ bool cryptodev_backend_is_ready(CryptoDevBackend *back= end) } =20 static bool -cryptodev_backend_can_be_deleted(UserCreatable *uc) +cryptodev_backend_prepare_delete(UserCreatable *uc, Error **errp) { - return !cryptodev_backend_is_used(CRYPTODEV_BACKEND(uc)); + if (cryptodev_backend_is_used(CRYPTODEV_BACKEND(uc))) { + error_setg(errp, + "Cannot delete cryptodev backend '%s' that is in use", + object_get_canonical_path_component(OBJECT(uc))); + return false; + } + return true; } =20 static void cryptodev_backend_instance_init(Object *obj) @@ -613,7 +619,7 @@ cryptodev_backend_class_init(ObjectClass *oc, const voi= d *data) UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); =20 ucc->complete =3D cryptodev_backend_complete; - ucc->can_be_deleted =3D cryptodev_backend_can_be_deleted; + ucc->prepare_delete =3D cryptodev_backend_prepare_delete; =20 QTAILQ_INIT(&crypto_clients); object_class_property_add(oc, "queues", "uint32", diff --git a/backends/hostmem.c b/backends/hostmem.c index cd2085fb3c..5dd5fb155c 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -434,9 +434,12 @@ host_memory_backend_memory_complete(UserCreatable *uc,= Error **errp) } =20 static bool -host_memory_backend_can_be_deleted(UserCreatable *uc) +host_memory_backend_prepare_delete(UserCreatable *uc, Error **errp) { if (host_memory_backend_is_mapped(MEMORY_BACKEND(uc))) { + error_setg(errp, + "Cannot delete host memory backend '%s' which is mapped= ", + object_get_canonical_path_component(OBJECT(uc))); return false; } else { return true; @@ -508,7 +511,7 @@ host_memory_backend_class_init(ObjectClass *oc, const v= oid *data) UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); =20 ucc->complete =3D host_memory_backend_memory_complete; - ucc->can_be_deleted =3D host_memory_backend_can_be_deleted; + ucc->prepare_delete =3D host_memory_backend_prepare_delete; =20 object_class_property_add_bool(oc, "merge", host_memory_backend_get_merge, diff --git a/backends/iommufd.c b/backends/iommufd.c index 09624cd652..0643947140 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -63,11 +63,16 @@ static void iommufd_backend_set_fd(Object *obj, const c= har *str, Error **errp) trace_iommu_backend_set_fd(be->fd); } =20 -static bool iommufd_backend_can_be_deleted(UserCreatable *uc) +static bool iommufd_backend_prepare_delete(UserCreatable *uc, Error **errp) { IOMMUFDBackend *be =3D IOMMUFD_BACKEND(uc); =20 - return !be->users; + if (be->users) { + error_setg(errp, "Can not delete IOMMUFD backend '%s' with %d user= s", + object_get_canonical_path_component(OBJECT(uc)), be->us= ers); + return false; + } + return true; } =20 static void iommufd_backend_complete(UserCreatable *uc, Error **errp) @@ -92,7 +97,7 @@ static void iommufd_backend_class_init(ObjectClass *oc, c= onst void *data) { UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); =20 - ucc->can_be_deleted =3D iommufd_backend_can_be_deleted; + ucc->prepare_delete =3D iommufd_backend_prepare_delete; ucc->complete =3D iommufd_backend_complete; =20 object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd); diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 4b1b1944c2..805e47270c 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -960,9 +960,15 @@ static void throttle_group_get_limits(Object *obj, Vis= itor *v, visit_type_ThrottleLimits(v, name, &argp, errp); } =20 -static bool throttle_group_can_be_deleted(UserCreatable *uc) +static bool throttle_group_prepare_delete(UserCreatable *uc, Error **errp) { - return OBJECT(uc)->ref =3D=3D 1; + if (OBJECT(uc)->ref > 1) { + error_setg(errp, + "Cannot delete throttle group '%s' with active referenc= es", + object_get_canonical_path_component(OBJECT(uc))); + return false; + } + return true; } =20 static void throttle_group_obj_class_init(ObjectClass *klass, @@ -972,7 +978,7 @@ static void throttle_group_obj_class_init(ObjectClass *= klass, UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); =20 ucc->complete =3D throttle_group_obj_complete; - ucc->can_be_deleted =3D throttle_group_can_be_deleted; + ucc->prepare_delete =3D throttle_group_prepare_delete; =20 /* individual properties */ for (i =3D 0; i < sizeof(properties) / sizeof(ThrottleParamInfo); i++)= { diff --git a/event-loop-base.c b/event-loop-base.c index 8ca143bea4..ee5987ddbf 100644 --- a/event-loop-base.c +++ b/event-loop-base.c @@ -85,13 +85,13 @@ static void event_loop_base_complete(UserCreatable *uc,= Error **errp) } } =20 -static bool event_loop_base_can_be_deleted(UserCreatable *uc) +static bool event_loop_base_prepare_delete(UserCreatable *uc, Error **errp) { EventLoopBaseClass *bc =3D EVENT_LOOP_BASE_GET_CLASS(uc); EventLoopBase *backend =3D EVENT_LOOP_BASE(uc); =20 - if (bc->can_be_deleted) { - return bc->can_be_deleted(backend); + if (bc->prepare_delete) { + return bc->prepare_delete(backend, errp); } =20 return true; @@ -102,7 +102,7 @@ static void event_loop_base_class_init(ObjectClass *kla= ss, { UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); ucc->complete =3D event_loop_base_complete; - ucc->can_be_deleted =3D event_loop_base_can_be_deleted; + ucc->prepare_delete =3D event_loop_base_prepare_delete; =20 object_class_property_add(klass, "aio-max-batch", "int", event_loop_base_get_param, diff --git a/include/qom/object_interfaces.h b/include/qom/object_interface= s.h index e2b8615617..afd0fb93b2 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -20,8 +20,10 @@ typedef struct UserCreatable UserCreatable; * UserCreatableClass: * @parent_class: the base class * @complete: callback to be called after @obj's properties are set. - * @can_be_deleted: callback to be called before an object is removed - * to check if @obj can be removed safely. + * @prepare_delete: to be called before an attempt to delete @obj + * to validate whether the object can be deleted and trigger any + * cleanup of any resources which have to be dealt with before the + * object is unparented and enters finalization. * * Interface is designed to work with -object/object-add/object_add * commands. @@ -36,7 +38,9 @@ typedef struct UserCreatable UserCreatable; * For objects created without using -object/object-add/object_add, * @user_creatable_complete() wrapper should be called manually if * object's type implements USER_CREATABLE interface and needs - * complete() callback to be called. + * complete() callback to be called. Similarly @user_creatable_prepare_del= ete() + * should be called manually prior to an attempt to the delete the + * object. */ struct UserCreatableClass { /* */ @@ -44,7 +48,7 @@ struct UserCreatableClass { =20 /* */ void (*complete)(UserCreatable *uc, Error **errp); - bool (*can_be_deleted)(UserCreatable *uc); + bool (*prepare_delete)(UserCreatable *uc, Error **errp); }; =20 /** @@ -61,13 +65,17 @@ struct UserCreatableClass { bool user_creatable_complete(UserCreatable *uc, Error **errp); =20 /** - * user_creatable_can_be_deleted: - * @uc: the object whose can_be_deleted() method is called if implemented + * user_creatable_prepare_delete: + * @uc: the user-creatable object whose prepare_delete() method is called + * @errp: if an error occurs, a pointer to an area to store the error + * + * Wrapper to call prepare_delete() class method if defined, otherwise + * does nothing. * - * Wrapper to call can_be_deleted() method if one of types it's inherited - * from implements USER_CREATABLE interface. + * Returns: %true on success or if prepare_delete() is not defined, + * %false on failure. */ -bool user_creatable_can_be_deleted(UserCreatable *uc); +bool user_creatable_prepare_delete(UserCreatable *uc, Error **errp); =20 /** * user_creatable_add_qapi: diff --git a/include/system/event-loop-base.h b/include/system/event-loop-b= ase.h index 130629e7f3..1e1e427ac7 100644 --- a/include/system/event-loop-base.h +++ b/include/system/event-loop-base.h @@ -24,7 +24,7 @@ struct EventLoopBaseClass { =20 void (*init)(EventLoopBase *base, Error **errp); void (*update_params)(EventLoopBase *base, Error **errp); - bool (*can_be_deleted)(EventLoopBase *base); + bool (*prepare_delete)(EventLoopBase *base, Error **errp); }; =20 struct EventLoopBase { diff --git a/net/can/can_core.c b/net/can/can_core.c index 77fe2b8ba4..6a56b33251 100644 --- a/net/can/can_core.c +++ b/net/can/can_core.c @@ -143,8 +143,10 @@ int can_bus_client_set_filters(CanBusClientState *clie= nt, } =20 =20 -static bool can_bus_can_be_deleted(UserCreatable *uc) +static bool can_bus_prepare_delete(UserCreatable *uc, Error **errp) { + error_setg(errp, "Deleting CAN bus device '%s' is not supported", + object_get_canonical_path_component(OBJECT(uc))); return false; } =20 @@ -153,7 +155,7 @@ static void can_bus_class_init(ObjectClass *klass, { UserCreatableClass *uc_klass =3D USER_CREATABLE_CLASS(klass); =20 - uc_klass->can_be_deleted =3D can_bus_can_be_deleted; + uc_klass->prepare_delete =3D can_bus_prepare_delete; } =20 static const TypeInfo can_bus_info =3D { diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 7080f85f95..3216a754ed 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -32,16 +32,14 @@ bool user_creatable_complete(UserCreatable *uc, Error *= *errp) return !*errp; } =20 -bool user_creatable_can_be_deleted(UserCreatable *uc) +bool user_creatable_prepare_delete(UserCreatable *uc, Error **errp) { - UserCreatableClass *ucc =3D USER_CREATABLE_GET_CLASS(uc); =20 - if (ucc->can_be_deleted) { - return ucc->can_be_deleted(uc); - } else { - return true; + if (ucc->prepare_delete) { + return ucc->prepare_delete(uc, errp); } + return true; } =20 void user_creatable_add_qapi(ObjectOptions *options, Error **errp) @@ -253,8 +251,7 @@ bool user_creatable_del(const char *id, Error **errp) return false; } =20 - if (!user_creatable_can_be_deleted(USER_CREATABLE(obj))) { - error_setg(errp, "object '%s' is in use, can not be deleted", id); + if (!user_creatable_prepare_delete(USER_CREATABLE(obj), errp)) { return false; } =20 diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index f96610f510..03550b9971 100755 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -801,7 +801,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): # Now group1 is in use, it cannot be deleted result =3D self.vm.qmp('object-del', id =3D 'group1') self.assert_qmp(result, 'error/class', 'GenericError') - self.assert_qmp(result, 'error/desc', "object 'group1' is in use, = can not be deleted") + self.assert_qmp(result, 'error/desc', "Cannot delete throttle grou= p 'group1' with active references") =20 # Default options, this switches the group back to group0 self.reopen(opts) @@ -809,7 +809,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): # So now we cannot delete group0 result =3D self.vm.qmp('object-del', id =3D 'group0') self.assert_qmp(result, 'error/class', 'GenericError') - self.assert_qmp(result, 'error/desc', "object 'group0' is in use, = can not be deleted") + self.assert_qmp(result, 'error/desc', "Cannot delete throttle grou= p 'group0' with active references") =20 # But group1 is free this time, and it can be deleted self.vm.cmd('object-del', id =3D 'group1') diff --git a/util/main-loop.c b/util/main-loop.c index ad8645c30a..65e5dbcc94 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -218,8 +218,10 @@ static void main_loop_init(EventLoopBase *base, Error = **errp) mloop =3D m; } =20 -static bool main_loop_can_be_deleted(EventLoopBase *base) +static bool main_loop_prepare_delete(EventLoopBase *base, Error **errp) { + error_setg(errp, "Deleting main loop '%s' is not supported", + object_get_canonical_path_component(OBJECT(base))); return false; } =20 @@ -229,7 +231,7 @@ static void main_loop_class_init(ObjectClass *oc, const= void *class_data) =20 bc->init =3D main_loop_init; bc->update_params =3D main_loop_update_params; - bc->can_be_deleted =3D main_loop_can_be_deleted; + bc->prepare_delete =3D main_loop_prepare_delete; } =20 static const TypeInfo main_loop_info =3D { --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346371; cv=none; d=zohomail.com; s=zohoarc; b=P8QDLKHs+VVUd/Gg4Y2Kz5rboTKXhCHGLuepaWHM35MSCLu+6CLDXSUKd10iWHGszseKGV4RKETt7tUHTkdl849LMx9rTIIjbiYuaDS7iC3iJIF31bwl7UGA7jR4xPGTbxR6mB2NYT1bwVJka958UkcyzCcRwX9jXMJPYmgna0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346371; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ghdqZMUGeCj/f6yTinvRaBunSm0yhHUhP+zeygbRb+w=; b=M8KpL1ZBupWkYXsKqNcxzCheaerAtvJ9/ly0bS8hVRi++8S2T+5cwsR4GWm4p6sKBroF6Ozj6iNTW1KMo3tyLH+qMhNb+0gh65Wx9nays9webb7a9zHTEvk6iJRCtaEoYVX+7DhU9coid+31sNPq60shhev2JJpd1QAFPFE1j8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346371980401.18198621669376; Mon, 6 Jul 2026 06:59:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjqS-0001pi-Um; Mon, 06 Jul 2026 09:58:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqQ-0001p5-FZ for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqO-0001YK-9F for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:45 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-a1xcGSQKMqa0WNhQMt6sjw-1; Mon, 06 Jul 2026 09:58:40 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A2F971955F3F; Mon, 6 Jul 2026 13:58:39 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C99DA3000B4C; Mon, 6 Jul 2026 13:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ghdqZMUGeCj/f6yTinvRaBunSm0yhHUhP+zeygbRb+w=; b=cx30OU9JhjgKIiEWo5fZu4jt608/ahsZyIVl9iJmiN99HwEQy8/c9XrvMuPYsXbHnBvW6D 9a7SqlAajy57vMnkXDJpyqPXT2K1i1OvrHHDjdp2Unj/HlNesiuBDiZohDUb4A/NEJs6s+ KMZnmT+xEG8+aefkR/WgR2JrufOkY3k= X-MC-Unique: a1xcGSQKMqa0WNhQMt6sjw-1 X-Mimecast-MFC-AGG-ID: a1xcGSQKMqa0WNhQMt6sjw_1783346319 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 02/35] monitor: replace 'common' with 'parent_obj' in MonitorHMP Date: Mon, 6 Jul 2026 14:57:50 +0100 Message-ID: <20260706135824.2623960-3-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346375197158500 The field name 'parent_obj' is standard practice for QOM structs so align the HMP monitor. Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Dr. David Alan Gilbert Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/hmp-cmds.c | 2 +- monitor/hmp.c | 43 ++++++++++++++++++++------------------ monitor/monitor-internal.h | 2 +- monitor/monitor.c | 6 +++--- monitor/qmp-cmds.c | 10 ++++----- ui/ui-hmp-cmds.c | 2 +- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 443b8c785d..e139caeba9 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -287,7 +287,7 @@ void hmp_info_sync_profile(Monitor *mon, const QDict *q= dict) =20 void hmp_info_history(Monitor *mon, const QDict *qdict) { - MonitorHMP *hmp_mon =3D container_of(mon, MonitorHMP, common); + MonitorHMP *hmp_mon =3D container_of(mon, MonitorHMP, parent_obj); int i; const char *str; =20 diff --git a/monitor/hmp.c b/monitor/hmp.c index cc4390486e..3dde52ddbe 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -48,9 +48,9 @@ static void monitor_command_cb(void *opaque, const char *= cmdline, { MonitorHMP *mon =3D opaque; =20 - monitor_suspend(&mon->common); + monitor_suspend(&mon->parent_obj); handle_hmp_command(mon, cmdline); - monitor_resume(&mon->common); + monitor_resume(&mon->parent_obj); } =20 void monitor_read_command(MonitorHMP *mon, int show_prompt) @@ -73,7 +73,7 @@ int monitor_read_password(MonitorHMP *mon, ReadLineFunc *= readline_func, /* prompt is printed on return from the command handler */ return 0; } else { - monitor_printf(&mon->common, + monitor_printf(&mon->parent_obj, "terminal does not support password prompting\n"); return -ENOTTY; } @@ -695,7 +695,7 @@ static const HMPCommand *monitor_parse_command(MonitorH= MP *hmp_mon, const char **cmdp, HMPCommand *table) { - Monitor *mon =3D &hmp_mon->common; + Monitor *mon =3D &hmp_mon->parent_obj; const char *p; const HMPCommand *cmd; char cmdname[256]; @@ -1188,35 +1188,37 @@ void handle_hmp_command(MonitorHMP *mon, const char= *cmdline) =20 if (!cmd->cmd && !cmd->cmd_info_hrt) { /* FIXME: is it useful to try autoload modules here ??? */ - monitor_printf(&mon->common, "Command \"%.*s\" is not available.\n= ", + monitor_printf(&mon->parent_obj, "Command \"%.*s\" is not availabl= e.\n", (int)(cmdline - cmd_start), cmd_start); return; } =20 - qdict =3D monitor_parse_arguments(&mon->common, &cmdline, cmd); + qdict =3D monitor_parse_arguments(&mon->parent_obj, &cmdline, cmd); if (!qdict) { while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) { cmdline--; } - monitor_printf(&mon->common, "Try \"help %.*s\" for more informati= on\n", + monitor_printf(&mon->parent_obj, + "Try \"help %.*s\" for more information\n", (int)(cmdline - cmd_start), cmd_start); return; } =20 if (!cmd->coroutine) { /* old_mon is non-NULL when called from qmp_human_monitor_command(= ) */ - Monitor *old_mon =3D monitor_set_cur(qemu_coroutine_self(), &mon->= common); - handle_hmp_command_exec(&mon->common, cmd, qdict); + Monitor *old_mon =3D monitor_set_cur(qemu_coroutine_self(), + &mon->parent_obj); + handle_hmp_command_exec(&mon->parent_obj, cmd, qdict); monitor_set_cur(qemu_coroutine_self(), old_mon); } else { HandleHmpCommandCo data =3D { - .mon =3D &mon->common, + .mon =3D &mon->parent_obj, .cmd =3D cmd, .qdict =3D qdict, .done =3D false, }; Coroutine *co =3D qemu_coroutine_create(handle_hmp_command_co, &da= ta); - monitor_set_cur(co, &mon->common); + monitor_set_cur(co, &mon->parent_obj); aio_co_enter(qemu_get_aio_context(), co); AIO_WAIT_WHILE_UNLOCKED(NULL, !data.done); } @@ -1434,7 +1436,7 @@ cleanup: =20 static void monitor_read(void *opaque, const uint8_t *buf, int size) { - MonitorHMP *mon =3D container_of(opaque, MonitorHMP, common); + MonitorHMP *mon =3D container_of(opaque, MonitorHMP, parent_obj); int i; =20 if (mon->rs) { @@ -1443,7 +1445,7 @@ static void monitor_read(void *opaque, const uint8_t = *buf, int size) } } else { if (size =3D=3D 0 || buf[size - 1] !=3D 0) { - monitor_printf(&mon->common, "corrupted command\n"); + monitor_printf(&mon->parent_obj, "corrupted command\n"); } else { handle_hmp_command(mon, (char *)buf); } @@ -1512,26 +1514,26 @@ static void G_GNUC_PRINTF(2, 3) monitor_readline_pr= intf(void *opaque, MonitorHMP *mon =3D opaque; va_list ap; va_start(ap, fmt); - monitor_vprintf(&mon->common, fmt, ap); + monitor_vprintf(&mon->parent_obj, fmt, ap); va_end(ap); } =20 static void monitor_readline_flush(void *opaque) { MonitorHMP *mon =3D opaque; - monitor_flush(&mon->common); + monitor_flush(&mon->parent_obj); } =20 void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) { MonitorHMP *mon =3D g_new0(MonitorHMP, 1); =20 - if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) { + if (!qemu_chr_fe_init(&mon->parent_obj.chr, chr, errp)) { g_free(mon); return; } =20 - monitor_data_init(&mon->common, false, false, false); + monitor_data_init(&mon->parent_obj, false, false, false); =20 mon->use_readline =3D use_readline; if (mon->use_readline) { @@ -1542,9 +1544,10 @@ void monitor_init_hmp(Chardev *chr, bool use_readlin= e, Error **errp) monitor_read_command(mon, 0); } =20 - qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read, monitor_r= ead, - monitor_event, NULL, &mon->common, NULL, true= ); - monitor_list_append(&mon->common); + qemu_chr_fe_set_handlers(&mon->parent_obj.chr, + monitor_can_read, monitor_read, monitor_event, + NULL, &mon->parent_obj, NULL, true); + monitor_list_append(&mon->parent_obj); } =20 /** diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index a5c4aba306..eb301ea796 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -128,7 +128,7 @@ struct Monitor { }; =20 struct MonitorHMP { - Monitor common; + Monitor parent_obj; bool use_readline; /* * State used only in the thread "owning" the monitor. diff --git a/monitor/monitor.c b/monitor/monitor.c index 00b93ed612..2a1b511ff4 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -132,7 +132,7 @@ static inline bool monitor_is_hmp_non_interactive(const= Monitor *mon) return false; } =20 - return !monitor_uses_readline(container_of(mon, MonitorHMP, common)); + return !monitor_uses_readline(container_of(mon, MonitorHMP, parent_obj= )); } =20 static gboolean monitor_unblocked(void *do_not_use, GIOCondition cond, @@ -542,7 +542,7 @@ static void monitor_accept_input(void *opaque) =20 qemu_mutex_lock(&mon->mon_lock); if (!monitor_is_qmp(mon) && mon->reset_seen) { - MonitorHMP *hmp_mon =3D container_of(mon, MonitorHMP, common); + MonitorHMP *hmp_mon =3D container_of(mon, MonitorHMP, parent_obj); assert(hmp_mon->rs); readline_restart(hmp_mon->rs); qemu_mutex_unlock(&mon->mon_lock); @@ -627,7 +627,7 @@ void monitor_data_destroy(Monitor *mon) if (monitor_is_qmp(mon)) { monitor_data_destroy_qmp(container_of(mon, MonitorQMP, common)); } else { - readline_free(container_of(mon, MonitorHMP, common)->rs); + readline_free(container_of(mon, MonitorHMP, parent_obj)->rs); } g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 0c409c27dc..aa9ee8a391 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -168,10 +168,10 @@ char *qmp_human_monitor_command(const char *command_l= ine, bool has_cpu_index, char *output =3D NULL; MonitorHMP hmp =3D {}; =20 - monitor_data_init(&hmp.common, false, true, false); + monitor_data_init(&hmp.parent_obj, false, true, false); =20 if (has_cpu_index) { - int ret =3D monitor_set_cpu(&hmp.common, cpu_index); + int ret =3D monitor_set_cpu(&hmp.parent_obj, cpu_index); if (ret < 0) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", "a CPU number"); @@ -181,12 +181,12 @@ char *qmp_human_monitor_command(const char *command_l= ine, bool has_cpu_index, =20 handle_hmp_command(&hmp, command_line); =20 - WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) { - output =3D g_strdup(hmp.common.outbuf->str); + WITH_QEMU_LOCK_GUARD(&hmp.parent_obj.mon_lock) { + output =3D g_strdup(hmp.parent_obj.outbuf->str); } =20 out: - monitor_data_destroy(&hmp.common); + monitor_data_destroy(&hmp.parent_obj); return output; } =20 diff --git a/ui/ui-hmp-cmds.c b/ui/ui-hmp-cmds.c index ee3e731d07..06f4030ce4 100644 --- a/ui/ui-hmp-cmds.c +++ b/ui/ui-hmp-cmds.c @@ -343,7 +343,7 @@ void hmp_change_vnc(Monitor *mon, const char *device, c= onst char *target, return; } if (!arg) { - MonitorHMP *hmp_mon =3D container_of(mon, MonitorHMP, common); + MonitorHMP *hmp_mon =3D container_of(mon, MonitorHMP, parent_obj); monitor_read_password(hmp_mon, hmp_change_read_arg, NULL); } else { qmp_change_vnc_password(arg, errp); --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346372; cv=none; d=zohomail.com; s=zohoarc; b=MX9mNBfO5kZ1sCq10nqq71SZaJZTA2mETmmjf13Ft1ffGlIEezZVYa+NYxz+iMbADS0nF0ufOZxmoAhfLrntZzP49+/oS3kjS7hN5sRQuhIE7uYrvEISCd6Q5PBDfPtbd4Axs0y0SHagQnKUjdxai5gEF2Gafwd+k3myF9ZATuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346372; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=37XqEPVLaqN3uXaHAM0S35ezrejH2eJdteA2q96Y5/I=; b=K95CtITIXdruaEbACe4uYS++mGnzBXFIzWOkEx75mLfFXsMJ+/1Z6llv6R90jcL5Ly4MnRQp1mmrLU9PnAWSYBZZHmFihe26r6QkVAoMMspsO8weyJG1/Cl0RFQmwmcLFccVYn/1B00pNCU8luvGPcRwWZimd16oUykQHGKbASw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346372119696.550549981026; Mon, 6 Jul 2026 06:59:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjqX-0001qI-J6; Mon, 06 Jul 2026 09:58:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqV-0001q8-Hw for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqT-0001bb-4E for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:51 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-61-hQxjyMiJNy-arDCtnbsTow-1; Mon, 06 Jul 2026 09:58:44 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 34B2F1955F18; Mon, 6 Jul 2026 13:58:43 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1DBC63000B56; Mon, 6 Jul 2026 13:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346328; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=37XqEPVLaqN3uXaHAM0S35ezrejH2eJdteA2q96Y5/I=; b=XkpTGytYgulK4lT7u6fszZnv670+WwlD4x53KzoU2m+QJeLXy02bSqKP7poBkATOMB4NA2 s5BTCfrlmJwu1TdZ/pX6x3n0ZX/b0bzUoU8WfOaL6Ip7WPLqZNqIlzHE2VFbpuGFT8/BzB upzUoeZoTkcI+aK6uJO9iesX6jytUos= X-MC-Unique: hQxjyMiJNy-arDCtnbsTow-1 X-Mimecast-MFC-AGG-ID: hQxjyMiJNy-arDCtnbsTow_1783346323 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 03/35] monitor: replace 'common' with 'parent_obj' in MonitorQMP Date: Mon, 6 Jul 2026 14:57:51 +0100 Message-ID: <20260706135824.2623960-4-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346375158158500 The field name 'parent_obj' is standard practice for QOM structs so align the QMP monitor. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/monitor-internal.h | 2 +- monitor/monitor.c | 4 ++-- monitor/qmp-cmds-control.c | 4 ++-- monitor/qmp.c | 40 +++++++++++++++++++------------------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index eb301ea796..4da2b2a677 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -141,7 +141,7 @@ struct MonitorHMP { }; =20 typedef struct { - Monitor common; + Monitor parent_obj; JSONMessageParser parser; bool pretty; /* diff --git a/monitor/monitor.c b/monitor/monitor.c index 2a1b511ff4..0b7b464ebe 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -308,7 +308,7 @@ static void monitor_qapi_event_emit(QAPIEvent event, QD= ict *qdict) continue; } =20 - qmp_mon =3D container_of(mon, MonitorQMP, common); + qmp_mon =3D container_of(mon, MonitorQMP, parent_obj); { QEMU_LOCK_GUARD(&mon->mon_lock); if (qmp_mon->commands =3D=3D &qmp_cap_negotiation_commands) { @@ -625,7 +625,7 @@ void monitor_data_destroy(Monitor *mon) g_free(mon->mon_cpu_path); qemu_chr_fe_deinit(&mon->chr, false); if (monitor_is_qmp(mon)) { - monitor_data_destroy_qmp(container_of(mon, MonitorQMP, common)); + monitor_data_destroy_qmp(container_of(mon, MonitorQMP, parent_obj)= ); } else { readline_free(container_of(mon, MonitorHMP, parent_obj)->rs); } diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c index 150ca9f5cb..af6a2a118b 100644 --- a/monitor/qmp-cmds-control.c +++ b/monitor/qmp-cmds-control.c @@ -76,7 +76,7 @@ void qmp_qmp_capabilities(bool has_enable, QMPCapabilityL= ist *enable, MonitorQMP *mon; =20 assert(monitor_is_qmp(cur_mon)); - mon =3D container_of(cur_mon, MonitorQMP, common); + mon =3D container_of(cur_mon, MonitorQMP, parent_obj); =20 if (mon->commands =3D=3D &qmp_commands) { error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, @@ -126,7 +126,7 @@ CommandInfoList *qmp_query_commands(Error **errp) MonitorQMP *mon; =20 assert(monitor_is_qmp(cur_mon)); - mon =3D container_of(cur_mon, MonitorQMP, common); + mon =3D container_of(cur_mon, MonitorQMP, parent_obj); =20 qmp_for_each_command(mon->commands, query_commands_cb, &list); =20 diff --git a/monitor/qmp.c b/monitor/qmp.c index 687019811f..27934206db 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -80,7 +80,7 @@ static void monitor_qmp_caps_reset(MonitorQMP *mon) { memset(mon->capab_offered, 0, sizeof(mon->capab_offered)); memset(mon->capab, 0, sizeof(mon->capab)); - mon->capab_offered[QMP_CAPABILITY_OOB] =3D mon->common.use_io_thread; + mon->capab_offered[QMP_CAPABILITY_OOB] =3D mon->parent_obj.use_io_thre= ad; } =20 static void qmp_request_free(QMPRequest *req) @@ -124,7 +124,7 @@ static void monitor_qmp_cleanup_queue_and_resume(Monito= rQMP *mon) * when we get here while the monitor is suspended. An * unfortunately timed CHR_EVENT_CLOSED can do the trick. */ - monitor_resume(&mon->common); + monitor_resume(&mon->parent_obj); } =20 } @@ -139,7 +139,7 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rs= p) trace_monitor_qmp_respond(mon, json->str); =20 g_string_append_c(json, '\n'); - monitor_puts(&mon->common, json->str); + monitor_puts(&mon->parent_obj, json->str); =20 g_string_free(json, true); } @@ -166,7 +166,7 @@ static void monitor_qmp_dispatch(MonitorQMP *mon, QObje= ct *req) QDict *error; =20 rsp =3D qmp_dispatch(mon->commands, req, qmp_oob_enabled(mon), - &mon->common); + &mon->parent_obj); =20 if (mon->commands =3D=3D &qmp_cap_negotiation_commands) { error =3D qdict_get_qdict(rsp, "error"); @@ -207,7 +207,7 @@ static QMPRequest *monitor_qmp_requests_pop_any_with_lo= ck(void) continue; } =20 - qmp_mon =3D container_of(mon, MonitorQMP, common); + qmp_mon =3D container_of(mon, MonitorQMP, parent_obj); qemu_mutex_lock(&qmp_mon->qmp_queue_lock); req_obj =3D g_queue_pop_head(qmp_mon->qmp_requests); if (req_obj) { @@ -302,7 +302,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data) oob_enabled =3D qmp_oob_enabled(mon); if (oob_enabled && mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1)= { - monitor_resume(&mon->common); + monitor_resume(&mon->parent_obj); } =20 /* @@ -343,7 +343,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data) } =20 if (!oob_enabled) { - monitor_resume(&mon->common); + monitor_resume(&mon->parent_obj); } =20 qmp_request_free(req_obj); @@ -408,7 +408,7 @@ static void handle_qmp_command(void *opaque, QObject *r= eq, Error *err) */ if (!qmp_oob_enabled(mon) || mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1) { - monitor_suspend(&mon->common); + monitor_suspend(&mon->parent_obj); } =20 /* @@ -462,7 +462,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEven= t event) =20 switch (event) { case CHR_EVENT_OPENED: - WITH_QEMU_LOCK_GUARD(&mon->common.mon_lock) { + WITH_QEMU_LOCK_GUARD(&mon->parent_obj.mon_lock) { mon->commands =3D &qmp_cap_negotiation_commands; monitor_qmp_caps_reset(mon); } @@ -504,27 +504,27 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) MonitorQMP *mon =3D opaque; GMainContext *context; =20 - assert(mon->common.use_io_thread); + assert(mon->parent_obj.use_io_thread); context =3D iothread_get_g_main_context(mon_iothread); assert(context); - qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read, + qemu_chr_fe_set_handlers(&mon->parent_obj.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, - NULL, &mon->common, context, true); - monitor_list_append(&mon->common); + NULL, &mon->parent_obj, context, true); + monitor_list_append(&mon->parent_obj); } =20 void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) { MonitorQMP *mon =3D g_new0(MonitorQMP, 1); =20 - if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) { + if (!qemu_chr_fe_init(&mon->parent_obj.chr, chr, errp)) { g_free(mon); return; } - qemu_chr_fe_set_echo(&mon->common.chr, true); + qemu_chr_fe_set_echo(&mon->parent_obj.chr, true); =20 /* Note: we run QMP monitor in I/O thread when @chr supports that */ - monitor_data_init(&mon->common, true, false, + monitor_data_init(&mon->parent_obj, true, false, qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT= )); =20 mon->pretty =3D pretty; @@ -533,7 +533,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error = **errp) mon->qmp_requests =3D g_queue_new(); =20 json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); - if (mon->common.use_io_thread) { + if (mon->parent_obj.use_io_thread) { /* * Make sure the old iowatch is gone. It's possible when * e.g. the chardev is in client mode, with wait=3Don. @@ -553,9 +553,9 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error = **errp) monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ } else { - qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read, + qemu_chr_fe_set_handlers(&mon->parent_obj.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, - NULL, &mon->common, NULL, true); - monitor_list_append(&mon->common); + NULL, &mon->parent_obj, NULL, true); + monitor_list_append(&mon->parent_obj); } } --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346357; cv=none; d=zohomail.com; s=zohoarc; b=XQ95k9YnYd3yCqWUisurSECdod2tuoCuRdZJjfPXqIyMh+Ne5y/4rzjPLmRDgzX7d0d5UMTbUCFUIJeHP5YyVW+cEvP1u6gBCcYsM942xKHz/f6BB0XngeBMUm1rsE6rX2Wm+7a92chZkRDriEHwqKjBoL/DvcihpGvorKywc5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346357; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jE64+S1b/0EW8c3nML1wCg3pvL+b2QrainJxyp8eUPU=; b=AtC07VQ/pHESog9u0eJTnADJjV6FLZvTY08ZrPzIn4d8sYiDsxB15EQNvDz7KjDbnvqIanbzBzMwmrg7b+O1yHsSlD/Csw8z4FVAHL7/nafz4mTGeZKKkchow2X4W/i5A2f+adMmU+k7juRqModnbzmvODDFq2Qc4RmlEP6fZ3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346357132736.6163722225596; Mon, 6 Jul 2026 06:59:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjqc-0001qr-Gt; Mon, 06 Jul 2026 09:58:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqY-0001qZ-8G for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqW-0001bq-HB for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:53 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-87YTds1DO5uuNujEDxvf3w-1; Mon, 06 Jul 2026 09:58:48 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 419E51955DDA; Mon, 6 Jul 2026 13:58:47 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A25013000B4D; Mon, 6 Jul 2026 13:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jE64+S1b/0EW8c3nML1wCg3pvL+b2QrainJxyp8eUPU=; b=dr1xesesFAG0WkCvmHm1HVhcI5yGS6yhAN+qwWpYiNJbynEKqaJ15O8aw15zQH1xb7Kw+a 966fVfru4eQrmXWtFYrcRZ52xM+eZEjZhZYaJ2Gom38P15W1dTkoGfGBhxegg3dQK7nqPo 3tTSO1hVb43BVyXqInKNZQsg81r3NXc= X-MC-Unique: 87YTds1DO5uuNujEDxvf3w-1 X-Mimecast-MFC-AGG-ID: 87YTds1DO5uuNujEDxvf3w_1783346327 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 04/35] monitor: rename monitor_init* to monitor_new* Date: Mon, 6 Jul 2026 14:57:52 +0100 Message-ID: <20260706135824.2623960-5-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346358934158500 The current "monitor_init" functions will clash with the methods of the same name that are required by QOM. To ease the transition to QOM, rename them out of the way. Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Dr. David Alan Gilbert Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- chardev/char.c | 2 +- gdbstub/system.c | 2 +- include/monitor/monitor.h | 8 ++++---- monitor/hmp.c | 2 +- monitor/monitor.c | 10 +++++----- monitor/qmp.c | 2 +- storage-daemon/qemu-storage-daemon.c | 2 +- stubs/monitor-internal.c | 2 +- system/vl.c | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index ca8b37ed8d..813c04d953 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -805,7 +805,7 @@ static Chardev *qemu_chr_new_from_name(const char *labe= l, const char *filename, =20 if (qemu_opt_get_bool(opts, "mux", 0)) { assert(permit_mux_mon); - monitor_init_hmp(chr, true, &err); + monitor_new_hmp(chr, true, &err); if (err) { error_report_err(err); object_unparent(OBJECT(chr)); diff --git a/gdbstub/system.c b/gdbstub/system.c index 2063b63b2f..18f6a62b2e 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -389,7 +389,7 @@ bool gdbserver_start(const char *device, Error **errp) /* Initialize a monitor terminal for gdb */ mon_chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_GDB, NULL, NULL, &error_abort); - monitor_init_hmp(mon_chr, false, &error_abort); + monitor_new_hmp(mon_chr, false, &error_abort); } else { qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); mon_chr =3D gdbserver_system_state.mon_chr; diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 55649a8664..b9642b58ba 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -19,10 +19,10 @@ bool monitor_cur_is_qmp(void); =20 void monitor_init_globals(void); void monitor_init_globals_core(void); -void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp); -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp); -int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp); -int monitor_init_opts(QemuOpts *opts, Error **errp); +void monitor_new_qmp(Chardev *chr, bool pretty, Error **errp); +void monitor_new_hmp(Chardev *chr, bool use_readline, Error **errp); +int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp); +int monitor_new_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); =20 int monitor_suspend(Monitor *mon); diff --git a/monitor/hmp.c b/monitor/hmp.c index 3dde52ddbe..4e4468424a 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1524,7 +1524,7 @@ static void monitor_readline_flush(void *opaque) monitor_flush(&mon->parent_obj); } =20 -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) +void monitor_new_hmp(Chardev *chr, bool use_readline, Error **errp) { MonitorHMP *mon =3D g_new0(MonitorHMP, 1); =20 diff --git a/monitor/monitor.c b/monitor/monitor.c index 0b7b464ebe..a87597e606 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -715,7 +715,7 @@ void monitor_init_globals(void) aio_co_schedule(iohandler_get_aio_context(), qmp_dispatcher_co); } =20 -int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp) +int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) { ERRP_GUARD(); Chardev *chr; @@ -732,7 +732,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, = Error **errp) =20 switch (opts->mode) { case MONITOR_MODE_CONTROL: - monitor_init_qmp(chr, opts->pretty, errp); + monitor_new_qmp(chr, opts->pretty, errp); break; case MONITOR_MODE_READLINE: if (!allow_hmp) { @@ -743,7 +743,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, = Error **errp) error_setg(errp, "'pretty' is not compatible with HMP monitors= "); return -1; } - monitor_init_hmp(chr, true, errp); + monitor_new_hmp(chr, true, errp); break; default: g_assert_not_reached(); @@ -752,7 +752,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, = Error **errp) return *errp ? -1 : 0; } =20 -int monitor_init_opts(QemuOpts *opts, Error **errp) +int monitor_new_opts(QemuOpts *opts, Error **errp) { Visitor *v; MonitorOptions *options; @@ -765,7 +765,7 @@ int monitor_init_opts(QemuOpts *opts, Error **errp) return -1; } =20 - ret =3D monitor_init(options, true, errp); + ret =3D monitor_new(options, true, errp); qapi_free_MonitorOptions(options); return ret; } diff --git a/monitor/qmp.c b/monitor/qmp.c index 27934206db..cb28a95efd 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -513,7 +513,7 @@ static void monitor_qmp_setup_handlers_bh(void *opaque) monitor_list_append(&mon->parent_obj); } =20 -void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) +void monitor_new_qmp(Chardev *chr, bool pretty, Error **errp) { MonitorQMP *mon =3D g_new0(MonitorQMP, 1); =20 diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-sto= rage-daemon.c index eb72561358..50dbfbd97a 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -330,7 +330,7 @@ static void process_options(int argc, char *argv[], boo= l pre_init_pass) visit_free(v); =20 /* TODO Catch duplicate monitor IDs */ - monitor_init(monitor, false, &error_fatal); + monitor_new(monitor, false, &error_fatal); qapi_free_MonitorOptions(monitor); break; } diff --git a/stubs/monitor-internal.c b/stubs/monitor-internal.c index 4fece49d53..23d58da184 100644 --- a/stubs/monitor-internal.c +++ b/stubs/monitor-internal.c @@ -8,6 +8,6 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **= errp) return -1; } =20 -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) +void monitor_new_hmp(Chardev *chr, bool use_readline, Error **errp) { } diff --git a/system/vl.c b/system/vl.c index 1d14e2e207..6643242729 100644 --- a/system/vl.c +++ b/system/vl.c @@ -1247,7 +1247,7 @@ static int fsdev_init_func(void *opaque, QemuOpts *op= ts, Error **errp) =20 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) { - return monitor_init_opts(opts, errp); + return monitor_new_opts(opts, errp); } =20 static void monitor_parse(const char *str, const char *mode, bool pretty) --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346388; cv=none; d=zohomail.com; s=zohoarc; b=M1ZgH0pXAchi2HtNx8ohe0mY/3DJO6Kzef0ye0CtJ87N/Ez6HDwARWsVyiQXOvpVXrskEmbc6fhZ1TxG7urAk2Kc/Kw/5exlPtzwBGkWDzrtHCboFxIuV4Mou8/mazuSL1PU/p9Te7vQ4VKGSiu+IL4/EpXTzs2CrW0A3bAM5qU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346388; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mdRa+WMDJzs94P7dfeKgJO/oz2Qr9F9EFzV2D0i3XCU=; b=cc7dUbzoYf/IInW7J+RsDhaJ+ACmTsiNoR/KgUWePDrpBvgdlusQ+Uvfiom1l8fWQJ/cvfmlFu4WxLU19W7pS+VaoXY7ajlpblpejNLjNrlmLiY+mvM3bkEDwBZ8hbYCFLHBDwmZVT0veBIMM6aztcuQ3hR3OVaGYzucz425u4w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346388385798.6991045650203; Mon, 6 Jul 2026 06:59:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjqm-0001rf-Hz; Mon, 06 Jul 2026 09:59:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqd-0001r8-TI for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqb-0001cC-NM for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:58:59 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-335-1vHwdu8oOlKuiLxt6oKKmg-1; Mon, 06 Jul 2026 09:58:52 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 394271955F2D; Mon, 6 Jul 2026 13:58:51 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B14303000B4E; Mon, 6 Jul 2026 13:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mdRa+WMDJzs94P7dfeKgJO/oz2Qr9F9EFzV2D0i3XCU=; b=im51FB51eXiMxOlWAfFze8gN6uDPxVGBTJy2V6yQ7x/oNPtbDqVQRshOHuDGcoPlcCRRP2 i6nXYnIgg8Ykrr56usDi5RqSCw0Hrhn3kaobXhmzrG/Lmv6q+zTKcKK1PdmNKbJXqXX872 FFW/jGXuP0etyZuHmMQB3lKLHU8GSA8= X-MC-Unique: 1vHwdu8oOlKuiLxt6oKKmg-1 X-Mimecast-MFC-AGG-ID: 1vHwdu8oOlKuiLxt6oKKmg_1783346331 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 05/35] monitor: minimal conversion of monitors to QOM Date: Mon, 6 Jul 2026 14:57:53 +0100 Message-ID: <20260706135824.2623960-6-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346389166158500 This introduces abstract QOM type "monitor", with concrete subtypes "monitor-hmp" and "monitor-qmp". This is the bare minimum conversion of just the type declarations and replacing g_new/g_free with object_new/object_unref. Command line option "-monitor" now creates a "monitor-hmp" object "/objects/compat_monitorNNN" in addition to the character device "/chardevs/compat_monitorNNN". NNN counts up from zero. Exception: "-monitor chardev:ID" creates a "monitor-hmp" object "/objects/ID", and does not create a character device. "-qmp" and "-qmp-pretty" work the same, except they create a "monitor-qmp" object. "-mon" now creates either a "monitor-hmp" or "monitor-qmp" object "/objects/ID" if the option argument provides an ID, else "/objects/compat_monitorNNN". "-gdbstub" and "-serial mon:..." now create a "monitor-hmp" object "/objects/compat_monitorNNN". Note that the object's name in "/objects/" matches the QemuOpts ID when it exists. The only cases where it doesn't exist are "-mon" without ID, "-gdbstub" and "-serial mon:". A future patch will make "monitor-hmp" and "monitor-qmp" work with "-object" and "object-add". Note: there is a slight change in the NNN values assigned. The old code would increment the counter for every monitor added, regardless of whether it needed a "compat_monitorNNN" ID assignment. Now it is only incremented when an automatic ID assigned is needed, from any of -mon, -gdbstub or -serial. Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster Reviewed-by: Markus Armbruster --- chardev/char.c | 2 +- gdbstub/system.c | 2 +- include/monitor/monitor.h | 18 +++++++++++++++--- monitor/hmp.c | 31 ++++++++++++++++++++++++++++--- monitor/monitor-internal.h | 18 ++++++++++++++++-- monitor/monitor.c | 31 +++++++++++++++++++++++++++---- monitor/qmp-cmds.c | 15 ++++++++------- monitor/qmp.c | 31 ++++++++++++++++++++++++++++--- stubs/monitor-internal.c | 3 ++- system/vl.c | 7 +++---- 10 files changed, 129 insertions(+), 29 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index 813c04d953..c71ffa7963 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -805,7 +805,7 @@ static Chardev *qemu_chr_new_from_name(const char *labe= l, const char *filename, =20 if (qemu_opt_get_bool(opts, "mux", 0)) { assert(permit_mux_mon); - monitor_new_hmp(chr, true, &err); + monitor_new_hmp(NULL, chr, true, &err); if (err) { error_report_err(err); object_unparent(OBJECT(chr)); diff --git a/gdbstub/system.c b/gdbstub/system.c index 18f6a62b2e..fda8ef9352 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -389,7 +389,7 @@ bool gdbserver_start(const char *device, Error **errp) /* Initialize a monitor terminal for gdb */ mon_chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_GDB, NULL, NULL, &error_abort); - monitor_new_hmp(mon_chr, false, &error_abort); + monitor_new_hmp(NULL, mon_chr, false, &error_abort); } else { qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); mon_chr =3D gdbserver_system_state.mon_chr; diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index b9642b58ba..83723f705a 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -5,8 +5,17 @@ #include "qapi/qapi-types-misc.h" #include "qemu/readline.h" #include "exec/hwaddr.h" +#include "qom/object.h" + +#define TYPE_MONITOR "monitor" +OBJECT_DECLARE_TYPE(Monitor, MonitorClass, MONITOR); + +#define TYPE_MONITOR_HMP "monitor-hmp" +OBJECT_DECLARE_TYPE(MonitorHMP, MonitorHMPClass, MONITOR_HMP); + +#define TYPE_MONITOR_QMP "monitor-qmp" +OBJECT_DECLARE_TYPE(MonitorQMP, MonitorQMPClass, MONITOR_QMP); =20 -typedef struct MonitorHMP MonitorHMP; typedef struct MonitorOptions MonitorOptions; =20 #define QMP_REQ_QUEUE_LEN_MAX 8 @@ -19,8 +28,11 @@ bool monitor_cur_is_qmp(void); =20 void monitor_init_globals(void); void monitor_init_globals_core(void); -void monitor_new_qmp(Chardev *chr, bool pretty, Error **errp); -void monitor_new_hmp(Chardev *chr, bool use_readline, Error **errp); +char *monitor_compat_id(void); +void monitor_new_qmp(const char *id, Chardev *chr, + bool pretty, Error **errp); +void monitor_new_hmp(const char *id, Chardev *chr, + bool use_readline, Error **errp); int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp); int monitor_new_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); diff --git a/monitor/hmp.c b/monitor/hmp.c index 4e4468424a..da11e56854 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -43,6 +43,20 @@ #include "system/block-backend.h" #include "trace.h" =20 +OBJECT_DEFINE_TYPE(MonitorHMP, monitor_hmp, MONITOR_HMP, MONITOR); + +static void monitor_hmp_finalize(Object *obj) +{ +} + +static void monitor_hmp_class_init(ObjectClass *cls, const void *data) +{ +} + +static void monitor_hmp_init(Object *obj) +{ +} + static void monitor_command_cb(void *opaque, const char *cmdline, void *readline_opaque) { @@ -1524,12 +1538,23 @@ static void monitor_readline_flush(void *opaque) monitor_flush(&mon->parent_obj); } =20 -void monitor_new_hmp(Chardev *chr, bool use_readline, Error **errp) +void monitor_new_hmp(const char *id, Chardev *chr, + bool use_readline, Error **errp) { - MonitorHMP *mon =3D g_new0(MonitorHMP, 1); + MonitorHMP *mon; + g_autofree char *autoid =3D id ? NULL : monitor_compat_id(); + Object *obj =3D object_new_with_props(TYPE_MONITOR_HMP, + object_get_objects_root(), + id ? id : autoid, + errp, + NULL); + if (!obj) { + return; + } + mon =3D MONITOR_HMP(obj); =20 if (!qemu_chr_fe_init(&mon->parent_obj.chr, chr, errp)) { - g_free(mon); + object_unparent(OBJECT(mon)); return; } =20 diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 4da2b2a677..05c1f2f5e0 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -101,7 +101,13 @@ typedef struct HMPCommand { bool coroutine; } HMPCommand; =20 + +struct MonitorClass { + ObjectClass parent_class; +}; + struct Monitor { + Object parent; CharFrontend chr; int suspend_cnt; /* Needs to be accessed atomically */ bool is_qmp; @@ -127,6 +133,10 @@ struct Monitor { int reset_seen; }; =20 +struct MonitorHMPClass { + MonitorClass parent_class; +}; + struct MonitorHMP { Monitor parent_obj; bool use_readline; @@ -140,7 +150,11 @@ struct MonitorHMP { ReadLineState *rs; }; =20 -typedef struct { +struct MonitorQMPClass { + MonitorClass parent_class; +}; + +struct MonitorQMP { Monitor parent_obj; JSONMessageParser parser; bool pretty; @@ -160,7 +174,7 @@ typedef struct { QemuMutex qmp_queue_lock; /* Input queue that holds all the parsed QMP requests */ GQueue *qmp_requests; -} MonitorQMP; +}; =20 /** * Is @mon a QMP monitor? diff --git a/monitor/monitor.c b/monitor/monitor.c index a87597e606..18a1d8ddde 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -73,6 +73,22 @@ static GHashTable *coroutine_mon; /* Maps Coroutine* to = Monitor* */ MonitorList mon_list; static bool monitor_destroyed; =20 +int monitor_device_index; + +OBJECT_DEFINE_ABSTRACT_TYPE(Monitor, monitor, MONITOR, OBJECT); + +static void monitor_finalize(Object *obj) +{ +} + +static void monitor_class_init(ObjectClass *cls, const void *data) +{ +} + +static void monitor_init(Object *obj) +{ +} + Monitor *monitor_cur(void) { Monitor *mon; @@ -598,7 +614,7 @@ void monitor_list_append(Monitor *mon) =20 if (mon) { monitor_data_destroy(mon); - g_free(mon); + object_unparent(OBJECT(mon)); } } =20 @@ -680,7 +696,7 @@ void monitor_cleanup(void) monitor_flush(mon); monitor_data_destroy(mon); qemu_mutex_lock(&monitor_lock); - g_free(mon); + object_unparent(OBJECT(mon)); } qemu_mutex_unlock(&monitor_lock); =20 @@ -715,6 +731,13 @@ void monitor_init_globals(void) aio_co_schedule(iohandler_get_aio_context(), qmp_dispatcher_co); } =20 +char *monitor_compat_id(void) +{ + static int monitor_device_index; + + return g_strdup_printf("compat_monitor%d", monitor_device_index++); +} + int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) { ERRP_GUARD(); @@ -732,7 +755,7 @@ int monitor_new(MonitorOptions *opts, bool allow_hmp, E= rror **errp) =20 switch (opts->mode) { case MONITOR_MODE_CONTROL: - monitor_new_qmp(chr, opts->pretty, errp); + monitor_new_qmp(opts->id, chr, opts->pretty, errp); break; case MONITOR_MODE_READLINE: if (!allow_hmp) { @@ -743,7 +766,7 @@ int monitor_new(MonitorOptions *opts, bool allow_hmp, E= rror **errp) error_setg(errp, "'pretty' is not compatible with HMP monitors= "); return -1; } - monitor_new_hmp(chr, true, errp); + monitor_new_hmp(opts->id, chr, true, errp); break; default: g_assert_not_reached(); diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index aa9ee8a391..bfde769ef0 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -166,12 +166,12 @@ char *qmp_human_monitor_command(const char *command_l= ine, bool has_cpu_index, int64_t cpu_index, Error **errp) { char *output =3D NULL; - MonitorHMP hmp =3D {}; + MonitorHMP *hmp =3D MONITOR_HMP(object_new(TYPE_MONITOR_HMP)); =20 - monitor_data_init(&hmp.parent_obj, false, true, false); + monitor_data_init(&hmp->parent_obj, false, true, false); =20 if (has_cpu_index) { - int ret =3D monitor_set_cpu(&hmp.parent_obj, cpu_index); + int ret =3D monitor_set_cpu(&hmp->parent_obj, cpu_index); if (ret < 0) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", "a CPU number"); @@ -179,14 +179,15 @@ char *qmp_human_monitor_command(const char *command_l= ine, bool has_cpu_index, } } =20 - handle_hmp_command(&hmp, command_line); + handle_hmp_command(hmp, command_line); =20 - WITH_QEMU_LOCK_GUARD(&hmp.parent_obj.mon_lock) { - output =3D g_strdup(hmp.parent_obj.outbuf->str); + WITH_QEMU_LOCK_GUARD(&hmp->parent_obj.mon_lock) { + output =3D g_strdup(hmp->parent_obj.outbuf->str); } =20 out: - monitor_data_destroy(&hmp.parent_obj); + monitor_data_destroy(&hmp->parent_obj); + object_unref(hmp); return output; } =20 diff --git a/monitor/qmp.c b/monitor/qmp.c index cb28a95efd..1ef09352fc 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -71,6 +71,20 @@ typedef struct QMPRequest QMPRequest; =20 QmpCommandList qmp_commands, qmp_cap_negotiation_commands; =20 +OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR); + +static void monitor_qmp_finalize(Object *obj) +{ +} + +static void monitor_qmp_class_init(ObjectClass *cls, const void *data) +{ +} + +static void monitor_qmp_init(Object *obj) +{ +} + static bool qmp_oob_enabled(MonitorQMP *mon) { return mon->capab[QMP_CAPABILITY_OOB]; @@ -513,12 +527,23 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) monitor_list_append(&mon->parent_obj); } =20 -void monitor_new_qmp(Chardev *chr, bool pretty, Error **errp) +void monitor_new_qmp(const char *id, Chardev *chr, + bool pretty, Error **errp) { - MonitorQMP *mon =3D g_new0(MonitorQMP, 1); + MonitorQMP *mon; + g_autofree char *autoid =3D id ? NULL : monitor_compat_id(); + Object *obj =3D object_new_with_props(TYPE_MONITOR_QMP, + object_get_objects_root(), + id ? id : autoid, + errp, + NULL); + if (!obj) { + return; + } + mon =3D MONITOR_QMP(obj); =20 if (!qemu_chr_fe_init(&mon->parent_obj.chr, chr, errp)) { - g_free(mon); + object_unparent(OBJECT(mon)); return; } qemu_chr_fe_set_echo(&mon->parent_obj.chr, true); diff --git a/stubs/monitor-internal.c b/stubs/monitor-internal.c index 23d58da184..20367b7e9a 100644 --- a/stubs/monitor-internal.c +++ b/stubs/monitor-internal.c @@ -8,6 +8,7 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **= errp) return -1; } =20 -void monitor_new_hmp(Chardev *chr, bool use_readline, Error **errp) +void monitor_new_hmp(const char *id, Chardev *chr, + bool use_readline, Error **errp) { } diff --git a/system/vl.c b/system/vl.c index 6643242729..4737c03872 100644 --- a/system/vl.c +++ b/system/vl.c @@ -1252,7 +1252,6 @@ static int mon_init_func(void *opaque, QemuOpts *opts= , Error **errp) =20 static void monitor_parse(const char *str, const char *mode, bool pretty) { - static int monitor_device_index =3D 0; QemuOpts *opts; const char *p; char label[32]; @@ -1260,8 +1259,9 @@ static void monitor_parse(const char *str, const char= *mode, bool pretty) if (strstart(str, "chardev:", &p)) { snprintf(label, sizeof(label), "%s", p); } else { - snprintf(label, sizeof(label), "compat_monitor%d", - monitor_device_index); + g_autofree char *id =3D monitor_compat_id(); + assert(strlen(id) < sizeof(label)); + memcpy(label, id, strlen(id) + 1); opts =3D qemu_chr_parse_compat(label, str, true); if (!opts) { error_report("parse error: %s", str); @@ -1277,7 +1277,6 @@ static void monitor_parse(const char *str, const char= *mode, bool pretty) } else { assert(pretty =3D=3D false); } - monitor_device_index++; } =20 struct device_config { --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346412; cv=none; d=zohomail.com; s=zohoarc; b=MCOfndSTxbjHDIiMKrSMnOeMbW4mdKOpEoG7rBUH2BviRr8mFN4+qbh01EIZPOzRbaieBHjJZ7OVnVMQp0xRvswKcLSSo6EPm5jq6iUsAMF5OKHn8IpJ/cB0fq3eZ1rjvpA/H7ggQlTJJQTW6sBj9/v89VpXyv02+HxAq+TdTs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346412; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mo8+0CeBpO/xq8m33uq8yDSNPTo4TkPck571PuAEanc=; b=SIJ6t/8JMJenrDs993me8Vml7r4urjPbE0KtSAgWR7AL3wJJUZv59qOPg3lmiwNtj2PQ5FKSzlz1WkstoLq9FkOT4Ss3rmELfbWOoAkYFF5SylGT/03FKmWdnIfs3HZ0tHg6NZ2Cd8tkcEmvHvLgSLTmnJalVctoRs4/GqQiB04= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178334641236366.82353597803387; Mon, 6 Jul 2026 07:00:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjqq-0001sI-FF; Mon, 06 Jul 2026 09:59:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqj-0001rN-7X for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqf-0001cL-N0 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:04 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-zYx_4-tlOPWrLAgP7_YNaw-1; Mon, 06 Jul 2026 09:58:56 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8ABF21955E74; Mon, 6 Jul 2026 13:58:55 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CE9313000B4D; Mon, 6 Jul 2026 13:58:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mo8+0CeBpO/xq8m33uq8yDSNPTo4TkPck571PuAEanc=; b=XdW7Y0DmvJylwXxdtJmE3zTwNECDvsABbAbWyfEeU/CEvIfT1rTiNA51MUJVoHvwKsSb4n zTbEznO+5EKDjMjPUcqzpOPzUYMJjQG8bVGiX5cUb/TmEMaZ9MAr8KS1Hdv15x/CBitc5C d76w3emK61kNttzPavrSrh9g43slY+A= X-MC-Unique: zYx_4-tlOPWrLAgP7_YNaw-1 X-Mimecast-MFC-AGG-ID: zYx_4-tlOPWrLAgP7_YNaw_1783346335 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 06/35] monitor: pass chardev ID into monitor constructor instead of object Date: Mon, 6 Jul 2026 14:57:54 +0100 Message-ID: <20260706135824.2623960-7-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346413525158500 Current the monitor_new_hmp/monitor_new_qmp constructors accept a Chardev object pointer. To facilitate the next commit which will introduce a QOM property for the character device ID, switch to accepting an chardev ID in the constructor. Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Marc-Andr=C3=A9 Lureau Acked-by: Markus Armbruster --- chardev/char.c | 3 ++- gdbstub/system.c | 2 +- include/monitor/monitor.h | 4 ++-- monitor/hmp.c | 22 ++++++++++++++++------ monitor/monitor.c | 11 ++--------- monitor/qmp.c | 21 +++++++++++++++------ stubs/monitor-internal.c | 2 +- 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index c71ffa7963..22e5bae388 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -804,8 +804,9 @@ static Chardev *qemu_chr_new_from_name(const char *labe= l, const char *filename, } =20 if (qemu_opt_get_bool(opts, "mux", 0)) { + const char *chardev_id =3D qemu_opts_id(opts); assert(permit_mux_mon); - monitor_new_hmp(NULL, chr, true, &err); + monitor_new_hmp(NULL, chardev_id, true, &err); if (err) { error_report_err(err); object_unparent(OBJECT(chr)); diff --git a/gdbstub/system.c b/gdbstub/system.c index fda8ef9352..fd754e5664 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -389,7 +389,7 @@ bool gdbserver_start(const char *device, Error **errp) /* Initialize a monitor terminal for gdb */ mon_chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_GDB, NULL, NULL, &error_abort); - monitor_new_hmp(NULL, mon_chr, false, &error_abort); + monitor_new_hmp(NULL, mon_chr->label, false, &error_abort); } else { qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); mon_chr =3D gdbserver_system_state.mon_chr; diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 83723f705a..bfbeedec9b 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -29,9 +29,9 @@ bool monitor_cur_is_qmp(void); void monitor_init_globals(void); void monitor_init_globals_core(void); char *monitor_compat_id(void); -void monitor_new_qmp(const char *id, Chardev *chr, +void monitor_new_qmp(const char *id, const char *chardev_id, bool pretty, Error **errp); -void monitor_new_hmp(const char *id, Chardev *chr, +void monitor_new_hmp(const char *id, const char *chardev_id, bool use_readline, Error **errp); int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp); int monitor_new_opts(QemuOpts *opts, Error **errp); diff --git a/monitor/hmp.c b/monitor/hmp.c index da11e56854..1704166326 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -39,6 +39,7 @@ #include "qemu/base-arch-defs.h" #include "qemu/target-info.h" #include "qemu/units.h" +#include "qapi/error.h" #include "exec/gdbstub.h" #include "system/block-backend.h" #include "trace.h" @@ -1538,16 +1539,25 @@ static void monitor_readline_flush(void *opaque) monitor_flush(&mon->parent_obj); } =20 -void monitor_new_hmp(const char *id, Chardev *chr, +void monitor_new_hmp(const char *id, const char *chardev_id, bool use_readline, Error **errp) { MonitorHMP *mon; g_autofree char *autoid =3D id ? NULL : monitor_compat_id(); - Object *obj =3D object_new_with_props(TYPE_MONITOR_HMP, - object_get_objects_root(), - id ? id : autoid, - errp, - NULL); + Chardev *chr; + Object *obj; + + chr =3D qemu_chr_find(chardev_id); + if (chr =3D=3D NULL) { + error_setg(errp, "chardev \"%s\" not found", chardev_id); + return; + } + + obj =3D object_new_with_props(TYPE_MONITOR_HMP, + object_get_objects_root(), + id ? id : autoid, + errp, + NULL); if (!obj) { return; } diff --git a/monitor/monitor.c b/monitor/monitor.c index 18a1d8ddde..cb0299a2f7 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -741,13 +741,6 @@ char *monitor_compat_id(void) int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) { ERRP_GUARD(); - Chardev *chr; - - chr =3D qemu_chr_find(opts->chardev); - if (chr =3D=3D NULL) { - error_setg(errp, "chardev \"%s\" not found", opts->chardev); - return -1; - } =20 if (!opts->has_mode) { opts->mode =3D allow_hmp ? MONITOR_MODE_READLINE : MONITOR_MODE_CO= NTROL; @@ -755,7 +748,7 @@ int monitor_new(MonitorOptions *opts, bool allow_hmp, E= rror **errp) =20 switch (opts->mode) { case MONITOR_MODE_CONTROL: - monitor_new_qmp(opts->id, chr, opts->pretty, errp); + monitor_new_qmp(opts->id, opts->chardev, opts->pretty, errp); break; case MONITOR_MODE_READLINE: if (!allow_hmp) { @@ -766,7 +759,7 @@ int monitor_new(MonitorOptions *opts, bool allow_hmp, E= rror **errp) error_setg(errp, "'pretty' is not compatible with HMP monitors= "); return -1; } - monitor_new_hmp(opts->id, chr, true, errp); + monitor_new_hmp(opts->id, opts->chardev, true, errp); break; default: g_assert_not_reached(); diff --git a/monitor/qmp.c b/monitor/qmp.c index 1ef09352fc..e2f841212b 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -527,16 +527,25 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) monitor_list_append(&mon->parent_obj); } =20 -void monitor_new_qmp(const char *id, Chardev *chr, +void monitor_new_qmp(const char *id, const char *chardev_id, bool pretty, Error **errp) { MonitorQMP *mon; g_autofree char *autoid =3D id ? NULL : monitor_compat_id(); - Object *obj =3D object_new_with_props(TYPE_MONITOR_QMP, - object_get_objects_root(), - id ? id : autoid, - errp, - NULL); + Chardev *chr; + Object *obj; + + chr =3D qemu_chr_find(chardev_id); + if (chr =3D=3D NULL) { + error_setg(errp, "chardev \"%s\" not found", chardev_id); + return; + } + + obj =3D object_new_with_props(TYPE_MONITOR_QMP, + object_get_objects_root(), + id ? id : autoid, + errp, + NULL); if (!obj) { return; } diff --git a/stubs/monitor-internal.c b/stubs/monitor-internal.c index 20367b7e9a..f94b5e5c21 100644 --- a/stubs/monitor-internal.c +++ b/stubs/monitor-internal.c @@ -8,7 +8,7 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **= errp) return -1; } =20 -void monitor_new_hmp(const char *id, Chardev *chr, +void monitor_new_hmp(const char *id, const char *chardev_id, bool use_readline, Error **errp) { } --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346442; cv=none; d=zohomail.com; s=zohoarc; b=gVJF1ICjpnM3VGp0w4QkZhjKqTG0eCv+64v3U8a7wu119KH+Eha7tGCfaML2/36xah6jTnzqhIxuckLZRlgvSHqbIjZQQmoRwlYEfKjWa/Ye7CPkjC7SAwijz5Tkyl9JfkQNrNYI8t7vzNBVviFOxWRXxHGeqO9FxVExEObu1Ck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346442; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iK6bDC7EaRdOs5PB/8RxC28zOLfBXwEkty0qN8zTwRE=; b=NXLY5eNz0f5svp2nJPMlbCioqaud2oyJ2bE8p9X5VbDg7bcDkRYP4uZspJyzXnQ7HsuRloKQ0iYPnJeUdd5+K5apbIeXE8yZt/0zwbUqkJUmzoKtKO0F1vkj9dqXdh9v/FEF0uN34FOs8COZBcnL+fcD2jz405GLm2kuOp/vybg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346442800517.6600435286039; Mon, 6 Jul 2026 07:00:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjr3-00020z-Bp; Mon, 06 Jul 2026 09:59:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjql-0001rd-5I for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqj-0001cg-5t for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:06 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-297-Zsc1bMUbMueK1PPDsJuwAA-1; Mon, 06 Jul 2026 09:59:01 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 54DA118052D9; Mon, 6 Jul 2026 13:58:59 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0ACCD3000B4E; Mon, 6 Jul 2026 13:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iK6bDC7EaRdOs5PB/8RxC28zOLfBXwEkty0qN8zTwRE=; b=RNGyrsdmN9+7XdovJbM5qRUhjzHlgn1iB6T30ieIlibP/uWtZTzXlCahLU2TXUtESeyMSj p5Vm4zS4mBWMxwEn23HIP4MuJWStEAvqaeX+XlQPciPQ98uRTveN0rOD1HlbNmxO0Y7C15 g9cIWFnQ5NprurrT8gAyZKI5pcUWMqE= X-MC-Unique: Zsc1bMUbMueK1PPDsJuwAA-1 X-Mimecast-MFC-AGG-ID: Zsc1bMUbMueK1PPDsJuwAA_1783346339 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 07/35] monitor: add 'chardev' property to Monitor base class Date: Mon, 6 Jul 2026 14:57:55 +0100 Message-ID: <20260706135824.2623960-8-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346443756158500 This is associates both QMP and HMP monitors with a character device backend. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/hmp.c | 24 ++++++++++-------------- monitor/monitor-internal.h | 2 ++ monitor/monitor.c | 36 ++++++++++++++++++++++++++++++++++++ monitor/qmp.c | 33 +++++++++++++++------------------ 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index 1704166326..34a39b071c 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1542,28 +1542,24 @@ static void monitor_readline_flush(void *opaque) void monitor_new_hmp(const char *id, const char *chardev_id, bool use_readline, Error **errp) { + ERRP_GUARD(); MonitorHMP *mon; g_autofree char *autoid =3D id ? NULL : monitor_compat_id(); - Chardev *chr; - Object *obj; + Object *obj =3D object_new_with_props(TYPE_MONITOR_HMP, + object_get_objects_root(), + id ? id : autoid, + errp, + "chardev", chardev_id, + NULL); =20 - chr =3D qemu_chr_find(chardev_id); - if (chr =3D=3D NULL) { - error_setg(errp, "chardev \"%s\" not found", chardev_id); - return; - } - - obj =3D object_new_with_props(TYPE_MONITOR_HMP, - object_get_objects_root(), - id ? id : autoid, - errp, - NULL); if (!obj) { return; } + mon =3D MONITOR_HMP(obj); =20 - if (!qemu_chr_fe_init(&mon->parent_obj.chr, chr, errp)) { + monitor_complete(MONITOR(mon), errp); + if (*errp) { object_unparent(OBJECT(mon)); return; } diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 05c1f2f5e0..145d52fd71 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -108,6 +108,7 @@ struct MonitorClass { =20 struct Monitor { Object parent; + char *chardev_id; CharFrontend chr; int suspend_cnt; /* Needs to be accessed atomically */ bool is_qmp; @@ -192,6 +193,7 @@ extern QmpCommandList qmp_commands, qmp_cap_negotiation= _commands; extern QemuMutex monitor_lock; extern MonitorList mon_list; =20 +void monitor_complete(Monitor *mon, Error **errp); void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush, bool use_io_thread); void monitor_data_destroy(Monitor *mon); diff --git a/monitor/monitor.c b/monitor/monitor.c index cb0299a2f7..1648946c92 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -79,10 +79,31 @@ OBJECT_DEFINE_ABSTRACT_TYPE(Monitor, monitor, MONITOR, = OBJECT); =20 static void monitor_finalize(Object *obj) { + Monitor *mon =3D MONITOR(obj); + + g_free(mon->chardev_id); +} + +static char *monitor_get_chardev_id(Object *obj, Error **errp) +{ + Monitor *mon =3D MONITOR(obj); + + return g_strdup(mon->chardev_id); +} + +static void monitor_set_chardev_id(Object *obj, const char *str, Error **e= rrp) +{ + Monitor *mon =3D MONITOR(obj); + + g_free(mon->chardev_id); + mon->chardev_id =3D g_strdup(str); } =20 static void monitor_class_init(ObjectClass *cls, const void *data) { + object_class_property_add_str(cls, "chardev", + monitor_get_chardev_id, + monitor_set_chardev_id); } =20 static void monitor_init(Object *obj) @@ -738,6 +759,21 @@ char *monitor_compat_id(void) return g_strdup_printf("compat_monitor%d", monitor_device_index++); } =20 +void monitor_complete(Monitor *mon, Error **errp) +{ + if (mon->chardev_id) { + Chardev *chr =3D qemu_chr_find(mon->chardev_id); + if (chr =3D=3D NULL) { + error_setg(errp, "chardev \"%s\" not found", mon->chardev_id); + return; + } + + if (!qemu_chr_fe_init(&mon->chr, chr, errp)) { + return; + } + } +} + int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) { ERRP_GUARD(); diff --git a/monitor/qmp.c b/monitor/qmp.c index e2f841212b..df35b530ed 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -530,36 +530,33 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) void monitor_new_qmp(const char *id, const char *chardev_id, bool pretty, Error **errp) { + ERRP_GUARD(); MonitorQMP *mon; g_autofree char *autoid =3D id ? NULL : monitor_compat_id(); - Chardev *chr; - Object *obj; + Object *obj =3D object_new_with_props(TYPE_MONITOR_QMP, + object_get_objects_root(), + id ? id : autoid, + errp, + "chardev", chardev_id, + NULL); =20 - chr =3D qemu_chr_find(chardev_id); - if (chr =3D=3D NULL) { - error_setg(errp, "chardev \"%s\" not found", chardev_id); - return; - } - - obj =3D object_new_with_props(TYPE_MONITOR_QMP, - object_get_objects_root(), - id ? id : autoid, - errp, - NULL); if (!obj) { return; } - mon =3D MONITOR_QMP(obj); =20 - if (!qemu_chr_fe_init(&mon->parent_obj.chr, chr, errp)) { + mon =3D MONITOR_QMP(obj); + monitor_complete(MONITOR(mon), errp); + if (*errp) { object_unparent(OBJECT(mon)); return; } + qemu_chr_fe_set_echo(&mon->parent_obj.chr, true); =20 /* Note: we run QMP monitor in I/O thread when @chr supports that */ monitor_data_init(&mon->parent_obj, true, false, - qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT= )); + qemu_chr_has_feature(mon->parent_obj.chr.chr, + QEMU_CHAR_FEATURE_GCONTEXT)); =20 mon->pretty =3D pretty; =20 @@ -572,12 +569,12 @@ void monitor_new_qmp(const char *id, const char *char= dev_id, * Make sure the old iowatch is gone. It's possible when * e.g. the chardev is in client mode, with wait=3Don. */ - remove_fd_in_watch(chr); + remove_fd_in_watch(mon->parent_obj.chr.chr); /* * Clean up listener IO sources early to prevent racy fd * handling between the main thread and the I/O thread. */ - remove_listener_fd_in_watch(chr); + remove_listener_fd_in_watch(mon->parent_obj.chr.chr); /* * We can't call qemu_chr_fe_set_handlers() directly here * since chardev might be running in the monitor I/O --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346465; cv=none; d=zohomail.com; s=zohoarc; b=FUDvBeyVUIoo7eE2hufnYQzt4PX4G0JADeui+MZxZbC73TdJFH1RTK9rq+ND5SsteE1BDPCQHEi3EzYzhMEYcnOJzP6q3F4+SELkpJ9HUWpFOFe98XdN7uMhpguTttOtCsxOq23FSEyHeK/QY3rSSJF4yGmVjfoFzPqlo6/y9b8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346465; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zkjdrI725VspPVbuz3o4rBqZpOogPffuMLbDQ9eM+wg=; b=OWOQTdZdfu9KqEl+KqDctXvBfkbpMqxOaH5OmTOactAxgXLegI71WpPQyS+7p/SRpz9tG1n1rhGNcBnfjnfjl/i8oJH5I4puN1W5NBYYmQHA2XPTr78qiIcmore0TiPDcsyIOI+WQFG9j6f9wNpyHtQie2WkoCSZW641I9AlKE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178334646521375.68830541742727; Mon, 6 Jul 2026 07:01:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjqu-0001sZ-8U; Mon, 06 Jul 2026 09:59:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqm-0001ri-6N for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqk-0001cv-LD for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:07 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-Zlxv7Q1LNYm56ZXJmd5V5Q-1; Mon, 06 Jul 2026 09:59:04 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 50C6F1805A0C; Mon, 6 Jul 2026 13:59:03 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 000B93000B4E; Mon, 6 Jul 2026 13:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zkjdrI725VspPVbuz3o4rBqZpOogPffuMLbDQ9eM+wg=; b=PqPaLib1eh3ZZzQQeLaTkBKWi4vwv58e0ZnlAONwe/rcaDhK+i3QLVh5hTlB1v3fcH+QnF ZikGesUN9B7QTCXPPVsHe0BqyqrZJugXcqhZgHfsZ1QYX4bBhIup3YwEQ5LAnTdSBHmbBN jXef1a18Kdp2/FFNUGBET2kU41wvG28= X-MC-Unique: Zlxv7Q1LNYm56ZXJmd5V5Q-1 X-Mimecast-MFC-AGG-ID: Zlxv7Q1LNYm56ZXJmd5V5Q_1783346343 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 08/35] monitor: add 'readline' property to HMP Monitor class Date: Mon, 6 Jul 2026 14:57:56 +0100 Message-ID: <20260706135824.2623960-9-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346466253158500 This determines whether a human monitor runs with readline for interactive use, or without readline for non-interactive use by the GDB stub. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/hmp.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index 34a39b071c..54fd25f220 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -50,12 +50,37 @@ static void monitor_hmp_finalize(Object *obj) { } =20 +static bool monitor_hmp_get_readline(Object *obj, Error **errp) +{ + MonitorHMP *mon =3D MONITOR_HMP(obj); + + return mon->use_readline; +} + +static void monitor_hmp_set_readline(Object *obj, bool val, Error **errp) +{ + MonitorHMP *mon =3D MONITOR_HMP(obj); + + mon->use_readline =3D val; +} + static void monitor_hmp_class_init(ObjectClass *cls, const void *data) { + object_class_property_add_bool(cls, "readline", + monitor_hmp_get_readline, + monitor_hmp_set_readline); } =20 static void monitor_hmp_init(Object *obj) { + MonitorHMP *hmp =3D MONITOR_HMP(obj); + + /* + * Default to common case for external HMP use, + * as opposed to non-interactive internal use + * from gdbstub + */ + hmp->use_readline =3D true; } =20 static void monitor_command_cb(void *opaque, const char *cmdline, @@ -1550,6 +1575,7 @@ void monitor_new_hmp(const char *id, const char *char= dev_id, id ? id : autoid, errp, "chardev", chardev_id, + "readline", use_readline ? "yes" := "no", NULL); =20 if (!obj) { @@ -1566,7 +1592,6 @@ void monitor_new_hmp(const char *id, const char *char= dev_id, =20 monitor_data_init(&mon->parent_obj, false, false, false); =20 - mon->use_readline =3D use_readline; if (mon->use_readline) { mon->rs =3D readline_init(monitor_readline_printf, monitor_readline_flush, --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346449; cv=none; d=zohomail.com; s=zohoarc; b=iL0gV9UQ2gNoa9RLtRp2qwTfhHEDMfC6vSXq1Zj1M6s/n+pVprPfn2Zk3Yakrv25tIeHCDiuOZtJvE37UtMKEucZpCNIVqj4ycnyufot8t0+ZdIpE0f0zhcCgQICOXmG9t/QArf7fexC4VXv6vxOfU6ro0gtXGe8g1a88vYcIKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346449; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=C1RqUNgK820J1VsbQdPIkj5w625+FjzSLT7CeElSeqQ=; b=UFCAwp1o7U6EzOND0UI5eiMgiZK0AmDNXAOPQhJ4LPH8EzvnmtuQx6/7dyYJjjCH+Pe9n/e6TG1tO9Z35BK3tngry4CgHHIsvzCH4vdObj3FqbzXQAQ1l4/z5ppuf9Cf4jXDnPcShuDkIDoNOUHRmLL7ODnbHhfJmBud/nCFgZs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17833464492191.5996054572364073; Mon, 6 Jul 2026 07:00:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjr4-00028H-Tz; Mon, 06 Jul 2026 09:59:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr0-0001zp-A6 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjqu-0001de-5f for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:17 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-cgUERvFPP-GnpNm2Hh0d3Q-1; Mon, 06 Jul 2026 09:59:11 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3AA9E1955EAE; Mon, 6 Jul 2026 13:59:07 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2A473000B4D; Mon, 6 Jul 2026 13:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C1RqUNgK820J1VsbQdPIkj5w625+FjzSLT7CeElSeqQ=; b=KYqY/Er2qGq0j6cIZBfm9rsWodu9mlJwu0BnqlRO+e59cXqzZ7BTwRWmXPOexLZWhh/TQq YVfE717tWdJ1CL70Acy8kWOY2lpsvy/u8X77OpmlFKmWiVRY7FBHq0F13sWEGgGfI1IY2d wnaw2+IeO5MrcNJsIr5fy6o8LXTx93M= X-MC-Unique: cgUERvFPP-GnpNm2Hh0d3Q-1 X-Mimecast-MFC-AGG-ID: cgUERvFPP-GnpNm2Hh0d3Q_1783346347 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 09/35] monitor: add 'pretty' property to QMP Monitor class Date: Mon, 6 Jul 2026 14:57:57 +0100 Message-ID: <20260706135824.2623960-10-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346451803158500 This determines whether the QMP JSON responses are pretty printed with newlines and indentation, or compact with no extra whitespace. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/qmp.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index df35b530ed..d7adb9ba8b 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -77,8 +77,25 @@ static void monitor_qmp_finalize(Object *obj) { } =20 +static bool monitor_qmp_get_pretty(Object *obj, Error **errp) +{ + MonitorQMP *mon =3D MONITOR_QMP(obj); + + return mon->pretty; +} + +static void monitor_qmp_set_pretty(Object *obj, bool val, Error **errp) +{ + MonitorQMP *mon =3D MONITOR_QMP(obj); + + mon->pretty =3D val; +} + static void monitor_qmp_class_init(ObjectClass *cls, const void *data) { + object_class_property_add_bool(cls, "pretty", + monitor_qmp_get_pretty, + monitor_qmp_set_pretty); } =20 static void monitor_qmp_init(Object *obj) @@ -538,6 +555,7 @@ void monitor_new_qmp(const char *id, const char *charde= v_id, id ? id : autoid, errp, "chardev", chardev_id, + "pretty", pretty ? "yes" : "no", NULL); =20 if (!obj) { @@ -558,8 +576,6 @@ void monitor_new_qmp(const char *id, const char *charde= v_id, qemu_chr_has_feature(mon->parent_obj.chr.chr, QEMU_CHAR_FEATURE_GCONTEXT)); =20 - mon->pretty =3D pretty; - qemu_mutex_init(&mon->qmp_queue_lock); mon->qmp_requests =3D g_queue_new(); =20 --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346482; cv=none; d=zohomail.com; s=zohoarc; b=IGWX8cDXxQjLutkq3aIg0pk+qC8WLcGs8PU9wgjl4pA0NiA6uJrKZBnyc/O9LHK2sOmeEnr66v2IvNRWd4Y8j5Hg1ZYHzaIwA3cqAs886MXByiszRNcK27PLAnoea70OjuLVbv41ffldVvO2swvlQvcRJTJU5OtrvJsy0Scrfjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346482; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eRbPc5V5zSOjentT24jeonMImAhJp7fdi+bBT794jZo=; b=Cuj4aKQeRSZFI17RWZDhuha5l9vDaNDdhi6VPYdnnlUR8w8xP2cRRDEdufL1Z73xYEI38vD+GUiev091skfuliu37vXrfXgAg33Xmr87eW46/npoVd+H+uGMYmkg7Oev4btNA+sHnZgyp8RLJAQCsG/ylfI/xfL7fcuIENjjbns= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346482634173.82592197285578; Mon, 6 Jul 2026 07:01:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjr4-00028O-UF; Mon, 06 Jul 2026 09:59:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr1-00020b-Ru for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr0-0001gp-8B for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:23 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-172-7d1uV8BjMLyrxqoxf5NgfQ-1; Mon, 06 Jul 2026 09:59:13 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D14A11955E9A; Mon, 6 Jul 2026 13:59:10 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A80903000B4D; Mon, 6 Jul 2026 13:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346360; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eRbPc5V5zSOjentT24jeonMImAhJp7fdi+bBT794jZo=; b=RI/y9yLKI0GmrlPZGAYSzGcZY0NVqvvu85vAtmZxxbIEyAJ3RllFYzr5cjNH5fmcBYv/6W ttD3a0XrV50pYc6IP+zeUrLrVzCTbdoLVnyyDm42odOKAAxQ9tB/a8o77rqgHQy6C8jStn PboQO9oT2xgnPxB73ioZkMssoJ2Fv5M= X-MC-Unique: 7d1uV8BjMLyrxqoxf5NgfQ-1 X-Mimecast-MFC-AGG-ID: 7d1uV8BjMLyrxqoxf5NgfQ_1783346351 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 10/35] monitor: remove 'skip_flush' field Date: Mon, 6 Jul 2026 14:57:58 +0100 Message-ID: <20260706135824.2623960-11-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346484302158500 The 'skip_flush' field is set on the dummy throwaway HMP monitor object created by QMP's 'human-monitor-command', as an indication not to try to write data to the chardev. Instead the QMP command impl will grab the data straight out of the in-memory buffer. The flag is redundant, however, as the monitor code could instead simply check the 'fe_is_open' field on the CharFrontend, which will be false in the same scenarios that 'skip_flush' is true. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/hmp.c | 2 +- monitor/monitor-internal.h | 4 +--- monitor/monitor.c | 11 +++++++---- monitor/qmp-cmds.c | 2 +- monitor/qmp.c | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index 54fd25f220..5644c9c4f5 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1590,7 +1590,7 @@ void monitor_new_hmp(const char *id, const char *char= dev_id, return; } =20 - monitor_data_init(&mon->parent_obj, false, false, false); + monitor_data_init(&mon->parent_obj, false, false); =20 if (mon->use_readline) { mon->rs =3D readline_init(monitor_readline_printf, diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 145d52fd71..d34f9be139 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -112,7 +112,6 @@ struct Monitor { CharFrontend chr; int suspend_cnt; /* Needs to be accessed atomically */ bool is_qmp; - bool skip_flush; bool use_io_thread; =20 char *mon_cpu_path; @@ -194,8 +193,7 @@ extern QemuMutex monitor_lock; extern MonitorList mon_list; =20 void monitor_complete(Monitor *mon, Error **errp); -void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush, - bool use_io_thread); +void monitor_data_init(Monitor *mon, bool is_qmp, bool use_io_thread); void monitor_data_destroy(Monitor *mon); int monitor_can_read(void *opaque); void monitor_list_append(Monitor *mon); diff --git a/monitor/monitor.c b/monitor/monitor.c index 1648946c92..db9243410a 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -190,7 +190,12 @@ void monitor_flush_locked(Monitor *mon) size_t len; const char *buf; =20 - if (mon->skip_flush) { + /* + * When used by QMP human-monitor-command, no chardev + * will be connected, as we want to just collect the + * output in the buffer + */ + if (!mon->chr.fe_is_open) { return; } =20 @@ -644,8 +649,7 @@ static void monitor_iothread_init(void) mon_iothread =3D iothread_create("mon_iothread", &error_abort); } =20 -void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush, - bool use_io_thread) +void monitor_data_init(Monitor *mon, bool is_qmp, bool use_io_thread) { if (use_io_thread && !mon_iothread) { monitor_iothread_init(); @@ -653,7 +657,6 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool = skip_flush, qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; mon->outbuf =3D g_string_new(NULL); - mon->skip_flush =3D skip_flush; mon->use_io_thread =3D use_io_thread; } =20 diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index bfde769ef0..0d9adad288 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -168,7 +168,7 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, char *output =3D NULL; MonitorHMP *hmp =3D MONITOR_HMP(object_new(TYPE_MONITOR_HMP)); =20 - monitor_data_init(&hmp->parent_obj, false, true, false); + monitor_data_init(&hmp->parent_obj, false, false); =20 if (has_cpu_index) { int ret =3D monitor_set_cpu(&hmp->parent_obj, cpu_index); diff --git a/monitor/qmp.c b/monitor/qmp.c index d7adb9ba8b..b300886f33 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -572,7 +572,7 @@ void monitor_new_qmp(const char *id, const char *charde= v_id, qemu_chr_fe_set_echo(&mon->parent_obj.chr, true); =20 /* Note: we run QMP monitor in I/O thread when @chr supports that */ - monitor_data_init(&mon->parent_obj, true, false, + monitor_data_init(&mon->parent_obj, true, qemu_chr_has_feature(mon->parent_obj.chr.chr, QEMU_CHAR_FEATURE_GCONTEXT)); =20 --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346462; cv=none; d=zohomail.com; s=zohoarc; b=W80GXjHAltMAvWq+5LwwVZSFMiXx979yBe/cWYfFUh7BnmHPAZE4YJpxmMSW0zk92fAfN3XUMqtWpD7FD5gp3GqK2GS3DCv9aKdJGZChLYrk2DdM6cEAUmDOBHFzbgmNILDg/sMP2QePVJDO4JTZMMEAHQIvrGkG8l8gN1By1+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346462; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mt29ZQVUbe2Up6s5sG/8Pmks6U5SihHYd6xs+0JEVQA=; b=ICYO2DwodYKo6uvmCO5mWkTJeKQfAY6RNdf/YbSsE/Lau25Npo7cewa0E42+EQYDvCuXFxeijUNvlI3tCZAc/HvotExmSkgs2tjgxm0cRkgJxa4Pyc78h6UFq+91UR89jQsgnGa1n4NrGJJighHK1Gtym/Ndn0Zeb5Z/Xhn6GZc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346462670165.9630919596393; Mon, 6 Jul 2026 07:01:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjr4-00024x-8A; Mon, 06 Jul 2026 09:59:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr2-00020d-50 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr0-0001gP-7m for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:23 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-f8Ze6XeDOpeiB0CXJ2b3lQ-1; Mon, 06 Jul 2026 09:59:16 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C8A291802673; Mon, 6 Jul 2026 13:59:14 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 62D803000B4D; Mon, 6 Jul 2026 13:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mt29ZQVUbe2Up6s5sG/8Pmks6U5SihHYd6xs+0JEVQA=; b=XYRAXp6wfpOW09wV3LGi1btkUwLIWuDUS0Vq1kPatzGIHjxD7ByLuzQegGzVT3wT0T+Sbv jvkphniKMddExMPdcavQP6ogAKzdWVbq+3eFNtmz2K3xpYXfBbqQVlVP12ImaSO8rBEjvh bGKGNse0YHfSEcKFdVwmsrLdFtRm2cA= X-MC-Unique: f8Ze6XeDOpeiB0CXJ2b3lQ-1 X-Mimecast-MFC-AGG-ID: f8Ze6XeDOpeiB0CXJ2b3lQ_1783346354 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 11/35] monitor: move monitor_data_(init|destroy) into QOM init/finalize Date: Mon, 6 Jul 2026 14:57:59 +0100 Message-ID: <20260706135824.2623960-12-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346464126158500 Start to take advantage of QOM, by using object init and finalize methods to replace monitor_data_init and monitor_data_destroy. A standalone helper is provided to enable the I/O thread for QMP where appropriate for the chardev backend. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/hmp.c | 6 +++-- monitor/monitor-internal.h | 3 +-- monitor/monitor.c | 46 +++++++++++++------------------------- monitor/qmp-cmds.c | 3 --- monitor/qmp.c | 34 +++++++++++++++------------- 5 files changed, 40 insertions(+), 52 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index 5644c9c4f5..c03b91782c 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -48,6 +48,10 @@ OBJECT_DEFINE_TYPE(MonitorHMP, monitor_hmp, MONITOR_HMP,= MONITOR); =20 static void monitor_hmp_finalize(Object *obj) { + MonitorHMP *mon =3D MONITOR_HMP(obj); + if (mon->rs) { + readline_free(mon->rs); + } } =20 static bool monitor_hmp_get_readline(Object *obj, Error **errp) @@ -1590,8 +1594,6 @@ void monitor_new_hmp(const char *id, const char *char= dev_id, return; } =20 - monitor_data_init(&mon->parent_obj, false, false); - if (mon->use_readline) { mon->rs =3D readline_init(monitor_readline_printf, monitor_readline_flush, diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index d34f9be139..6a4c3b0f37 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -193,8 +193,7 @@ extern QemuMutex monitor_lock; extern MonitorList mon_list; =20 void monitor_complete(Monitor *mon, Error **errp); -void monitor_data_init(Monitor *mon, bool is_qmp, bool use_io_thread); -void monitor_data_destroy(Monitor *mon); +void monitor_iothread_init(Monitor *mon); int monitor_can_read(void *opaque); void monitor_list_append(Monitor *mon); void monitor_fdsets_cleanup(void); diff --git a/monitor/monitor.c b/monitor/monitor.c index db9243410a..9fe131983d 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -82,6 +82,10 @@ static void monitor_finalize(Object *obj) Monitor *mon =3D MONITOR(obj); =20 g_free(mon->chardev_id); + g_free(mon->mon_cpu_path); + qemu_chr_fe_deinit(&mon->chr, false); + g_string_free(mon->outbuf, true); + qemu_mutex_destroy(&mon->mon_lock); } =20 static char *monitor_get_chardev_id(Object *obj, Error **errp) @@ -108,6 +112,11 @@ static void monitor_class_init(ObjectClass *cls, const= void *data) =20 static void monitor_init(Object *obj) { + Monitor *mon =3D MONITOR(obj); + + qemu_mutex_init(&mon->mon_lock); + mon->is_qmp =3D !!object_dynamic_cast(obj, TYPE_MONITOR_QMP); + mon->outbuf =3D g_string_new(NULL); } =20 Monitor *monitor_cur(void) @@ -639,38 +648,16 @@ void monitor_list_append(Monitor *mon) qemu_mutex_unlock(&monitor_lock); =20 if (mon) { - monitor_data_destroy(mon); object_unparent(OBJECT(mon)); } } =20 -static void monitor_iothread_init(void) -{ - mon_iothread =3D iothread_create("mon_iothread", &error_abort); -} - -void monitor_data_init(Monitor *mon, bool is_qmp, bool use_io_thread) +void monitor_iothread_init(Monitor *mon) { - if (use_io_thread && !mon_iothread) { - monitor_iothread_init(); + if (!mon_iothread) { + mon_iothread =3D iothread_create("mon_iothread", &error_abort); } - qemu_mutex_init(&mon->mon_lock); - mon->is_qmp =3D is_qmp; - mon->outbuf =3D g_string_new(NULL); - mon->use_io_thread =3D use_io_thread; -} - -void monitor_data_destroy(Monitor *mon) -{ - g_free(mon->mon_cpu_path); - qemu_chr_fe_deinit(&mon->chr, false); - if (monitor_is_qmp(mon)) { - monitor_data_destroy_qmp(container_of(mon, MonitorQMP, parent_obj)= ); - } else { - readline_free(container_of(mon, MonitorHMP, parent_obj)->rs); - } - g_string_free(mon->outbuf, true); - qemu_mutex_destroy(&mon->mon_lock); + mon->use_io_thread =3D true; } =20 void monitor_cleanup(void) @@ -688,7 +675,7 @@ void monitor_cleanup(void) * Letting the iothread continue while shutting down the dispatcher * means that new requests may still be coming in. This is okay, * we'll just leave them in the queue without sending a response - * and monitor_data_destroy() will free them. + * and object finalization will free them. */ WITH_QEMU_LOCK_GUARD(&monitor_lock) { qmp_dispatcher_co_shutdown =3D true; @@ -702,8 +689,8 @@ void monitor_cleanup(void) /* * We need to explicitly stop the I/O thread (but not destroy it), * clean up the monitor resources, then destroy the I/O thread since - * we need to unregister from chardev below in - * monitor_data_destroy(), and chardev is not thread-safe yet + * we need to unregister from chardev below in object + * finalization, and chardev is not thread-safe yet */ if (mon_iothread) { iothread_stop(mon_iothread); @@ -718,7 +705,6 @@ void monitor_cleanup(void) /* Permit QAPI event emission from character frontend release */ qemu_mutex_unlock(&monitor_lock); monitor_flush(mon); - monitor_data_destroy(mon); qemu_mutex_lock(&monitor_lock); object_unparent(OBJECT(mon)); } diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 0d9adad288..6cb0b587fb 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -168,8 +168,6 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, char *output =3D NULL; MonitorHMP *hmp =3D MONITOR_HMP(object_new(TYPE_MONITOR_HMP)); =20 - monitor_data_init(&hmp->parent_obj, false, false); - if (has_cpu_index) { int ret =3D monitor_set_cpu(&hmp->parent_obj, cpu_index); if (ret < 0) { @@ -186,7 +184,6 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, } =20 out: - monitor_data_destroy(&hmp->parent_obj); object_unref(hmp); return output; } diff --git a/monitor/qmp.c b/monitor/qmp.c index b300886f33..3574b9a339 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -73,8 +73,16 @@ QmpCommandList qmp_commands, qmp_cap_negotiation_command= s; =20 OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR); =20 +static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon); + static void monitor_qmp_finalize(Object *obj) { + MonitorQMP *mon =3D MONITOR_QMP(obj); + + 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); } =20 static bool monitor_qmp_get_pretty(Object *obj, Error **errp) @@ -98,8 +106,15 @@ static void monitor_qmp_class_init(ObjectClass *cls, co= nst void *data) monitor_qmp_set_pretty); } =20 +static void handle_qmp_command(void *opaque, QObject *req, Error *err); static void monitor_qmp_init(Object *obj) { + MonitorQMP *mon =3D MONITOR_QMP(obj); + + qemu_mutex_init(&mon->qmp_queue_lock); + mon->qmp_requests =3D g_queue_new(); + + json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); } =20 static bool qmp_oob_enabled(MonitorQMP *mon) @@ -522,14 +537,6 @@ static void monitor_qmp_event(void *opaque, QEMUChrEve= nt event) } } =20 -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_qmp_setup_handlers_bh(void *opaque) { MonitorQMP *mon =3D opaque; @@ -572,14 +579,11 @@ void monitor_new_qmp(const char *id, const char *char= dev_id, qemu_chr_fe_set_echo(&mon->parent_obj.chr, true); =20 /* Note: we run QMP monitor in I/O thread when @chr supports that */ - monitor_data_init(&mon->parent_obj, true, - qemu_chr_has_feature(mon->parent_obj.chr.chr, - QEMU_CHAR_FEATURE_GCONTEXT)); - - qemu_mutex_init(&mon->qmp_queue_lock); - mon->qmp_requests =3D g_queue_new(); + if (qemu_chr_has_feature(mon->parent_obj.chr.chr, + QEMU_CHAR_FEATURE_GCONTEXT)) { + monitor_iothread_init(&mon->parent_obj); + } =20 - json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); if (mon->parent_obj.use_io_thread) { /* * Make sure the old iowatch is gone. It's possible when --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346415; cv=none; d=zohomail.com; s=zohoarc; b=ho2d1BkIIJILVHP8EIdObnyjindeptYe2lQsAsveT9cTK/Hbtb31Jt9bvG8I9dy/o2+5lN8JgdqJ+VmrPLDv5s6RRhWT97Zrz9bZ5OxvN+kFMo3B88VYzpT/RO1xBe3DIaJ3+U7CEdxtJ4wnMvEzBcpxiVXw7CrSYOyfAqV8Vj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346415; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cFqLl0XSXy5NW+XCKDEsJTGn9IdS3//n42bsxOkXo78=; b=arqUF26DhmVxoIIrSvmQ6QrygTNgR0hKhy/MAH0GkBsqI6umSJ5DlhGOeenl5HsNiW1GjRlvhAmI8CnejaPU6AsN06CGUG+Fy+N5G35E+FeFMNAyBRLdVEv/bGvp59Mic6wc/CdQBRaAiWK+eMKgzjAkxTlx+Xz6BNL0AQU1NFU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346415228445.3407352447708; Mon, 6 Jul 2026 07:00:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjr9-0002Lm-J0; Mon, 06 Jul 2026 09:59:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr4-00026V-G8 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr2-0001jD-W8 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:26 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-569-1SNmDFWlPpO9s-PdXCJ18g-1; Mon, 06 Jul 2026 09:59:20 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9473F1955F38; Mon, 6 Jul 2026 13:59:18 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 513CC3000B4D; Mon, 6 Jul 2026 13:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cFqLl0XSXy5NW+XCKDEsJTGn9IdS3//n42bsxOkXo78=; b=J5UaRqVd+7TYWouuRNDoPWyZ2ZHQI522hVVFtSNx4G+eK6FZ0BZEo5aj4G13U422jHh4Xb 0W6rJqtDmbDrODmz+/+KRYCEc8BpDSOWhjC2R5kHAl/nbiiCNAygBajC3UBXURYi2RTZQG 4vMJO1dwujhHTOtxMb+RsoWx+PjuODA= X-MC-Unique: 1SNmDFWlPpO9s-PdXCJ18g-1 X-Mimecast-MFC-AGG-ID: 1SNmDFWlPpO9s-PdXCJ18g_1783346358 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 12/35] monitor: use class methods for monitor_vprintf Date: Mon, 6 Jul 2026 14:58:00 +0100 Message-ID: <20260706135824.2623960-13-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346417378158500 This removes the need for using monitor_is_qmp() to check the subclass type, which is an anti-pattern. Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Dr. David Alan Gilbert Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/hmp.c | 13 +++++++++++++ monitor/monitor-internal.h | 7 +++++++ monitor/monitor.c | 11 ++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index c03b91782c..f9252387c4 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -68,11 +68,18 @@ static void monitor_hmp_set_readline(Object *obj, bool = val, Error **errp) mon->use_readline =3D val; } =20 +int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap) + G_GNUC_PRINTF(2, 0); + static void monitor_hmp_class_init(ObjectClass *cls, const void *data) { + MonitorClass *moncls =3D MONITOR_CLASS(cls); + object_class_property_add_bool(cls, "readline", monitor_hmp_get_readline, monitor_hmp_set_readline); + + moncls->vprintf =3D monitor_hmp_vprintf; } =20 static void monitor_hmp_init(Object *obj) @@ -87,6 +94,12 @@ static void monitor_hmp_init(Object *obj) hmp->use_readline =3D true; } =20 +int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap) +{ + g_autofree char *buf =3D g_strdup_vprintf(fmt, ap); + return monitor_puts(mon, buf); +} + static void monitor_command_cb(void *opaque, const char *cmdline, void *readline_opaque) { diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 6a4c3b0f37..23cef68153 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -104,6 +104,13 @@ typedef struct HMPCommand { =20 struct MonitorClass { ObjectClass parent_class; + + /* + * If non-NULL, the monitor is able to print messages + * for attention of the client user + */ + int (*vprintf)(Monitor *mon, const char *fmt, va_list ap) + G_GNUC_PRINTF(2, 0); }; =20 struct Monitor { diff --git a/monitor/monitor.c b/monitor/monitor.c index 9fe131983d..0cb0930bf4 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -264,21 +264,18 @@ int monitor_puts(Monitor *mon, const char *str) =20 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { - char *buf; - int n; + MonitorClass *moncls; =20 if (!mon) { return -1; } =20 - if (monitor_is_qmp(mon)) { + moncls =3D MONITOR_GET_CLASS(mon); + if (!moncls->vprintf) { return -1; } =20 - buf =3D g_strdup_vprintf(fmt, ap); - n =3D monitor_puts(mon, buf); - g_free(buf); - return n; + return moncls->vprintf(mon, fmt, ap); } =20 int monitor_printf(Monitor *mon, const char *fmt, ...) --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346414; cv=none; d=zohomail.com; s=zohoarc; b=lbYXHxm8fYUDSeo6J4ErI0M/LEKMnJJDLFqYvQilRS7zkPimHBiGwc0clOA2GFRk/2stxXp5/vYlSCM5SMKkH/N3ZSIvHwwh9aVvQEXqKzQQJh3kxk5F+fePCj57w4LC+p7l2dUaIUaNtHXEqtujO14TRu03UAWbEeIgXDBA8lE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346414; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yXxQHOnsd1hcOE9VsGUlLt1+bI1bqLhQR5bgSfzdQK4=; b=PP3kYH87Cru4n5wzo69L5+4kVxwgKkN1G8gWXVi6xXNWNv6hfLSjDMuVf0n3bAiuPdjAchW4CtJ6joWacQtAO2ANajl9/CL5pzQC9P4urT/IkDQf7hOBrBMRvyF6sobwiOK0qBWTUIfTY6dxgmn4ibX/cRKOuNyRmbZnKizsWCE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346414745594.4489686605532; Mon, 6 Jul 2026 07:00:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjr7-0002Hp-C3; Mon, 06 Jul 2026 09:59:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr5-0002Cq-T0 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjr3-0001kT-RG for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:27 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-Fa79yf6aN9KWGmrpdm5NJQ-1; Mon, 06 Jul 2026 09:59:23 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 631381800847; Mon, 6 Jul 2026 13:59:22 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 14BE43000B4D; Mon, 6 Jul 2026 13:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yXxQHOnsd1hcOE9VsGUlLt1+bI1bqLhQR5bgSfzdQK4=; b=Ks9Rvgh+Z937xigzpfT0nvs6vN/Z3wpLk9sFMw4TryXNjYHCUnTVPfdmjVIBECCt3Gqp3f qrSbmdiIO8lA+YUhGXu6vHpTZYaUdd6chQK9LkgyKudOPKsRH1V5rytwBBfauAdSeljyKX iMRpY4VOVuXOAmYOEyCdeivfoOgt8ek= X-MC-Unique: Fa79yf6aN9KWGmrpdm5NJQ-1 X-Mimecast-MFC-AGG-ID: Fa79yf6aN9KWGmrpdm5NJQ_1783346362 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 13/35] monitor: use class methods for monitor_qapi_event_emit Date: Mon, 6 Jul 2026 14:58:01 +0100 Message-ID: <20260706135824.2623960-14-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346415495158500 This removes the need for using monitor_is_qmp() to check the subclass type, which is an anti-pattern. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- include/monitor/monitor.h | 1 + monitor/monitor-internal.h | 5 +++++ monitor/monitor.c | 15 +++------------ monitor/qmp.c | 20 ++++++++++++++++++++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index bfbeedec9b..821465f17e 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -3,6 +3,7 @@ =20 #include "block/block.h" #include "qapi/qapi-types-misc.h" +#include "qapi/qapi-emit-events.h" #include "qemu/readline.h" #include "exec/hwaddr.h" #include "qom/object.h" diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 23cef68153..763b5c9625 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -111,6 +111,11 @@ struct MonitorClass { */ int (*vprintf)(Monitor *mon, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); + /* + * If non-NULL, the monitor is able to send event + * notifications back to the client + */ + void (*emit_event)(Monitor *mon, QAPIEvent event, QDict *qdict); }; =20 struct Monitor { diff --git a/monitor/monitor.c b/monitor/monitor.c index 0cb0930bf4..90cfb59c66 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -348,22 +348,13 @@ static inline QEMUClockType monitor_get_event_clock(v= oid) static void monitor_qapi_event_emit(QAPIEvent event, QDict *qdict) { Monitor *mon; - MonitorQMP *qmp_mon; =20 trace_monitor_protocol_event_emit(event, qdict); QTAILQ_FOREACH(mon, &mon_list, entry) { - if (!monitor_is_qmp(mon)) { - continue; + MonitorClass *cls =3D MONITOR_GET_CLASS(mon); + if (cls->emit_event) { + cls->emit_event(mon, event, qdict); } - - qmp_mon =3D container_of(mon, MonitorQMP, parent_obj); - { - QEMU_LOCK_GUARD(&mon->mon_lock); - if (qmp_mon->commands =3D=3D &qmp_cap_negotiation_commands) { - continue; - } - } - qmp_send_response(qmp_mon, qdict); } } =20 diff --git a/monitor/qmp.c b/monitor/qmp.c index 3574b9a339..d732fff9a3 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -99,11 +99,17 @@ static void monitor_qmp_set_pretty(Object *obj, bool va= l, Error **errp) mon->pretty =3D val; } =20 +static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *q= dict); + static void monitor_qmp_class_init(ObjectClass *cls, const void *data) { + MonitorClass *moncls =3D MONITOR_CLASS(cls); + object_class_property_add_bool(cls, "pretty", monitor_qmp_get_pretty, monitor_qmp_set_pretty); + + moncls->emit_event =3D monitor_qmp_emit_event; } =20 static void handle_qmp_command(void *opaque, QObject *req, Error *err); @@ -117,6 +123,20 @@ static void monitor_qmp_init(Object *obj) json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); } =20 +static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *q= dict) +{ + MonitorQMP *qmp =3D MONITOR_QMP(mon); + + WITH_QEMU_LOCK_GUARD(&mon->mon_lock) { + if (qmp->commands =3D=3D &qmp_cap_negotiation_commands) { + return; + } + } + + qmp_send_response(qmp, qdict); +} + + static bool qmp_oob_enabled(MonitorQMP *mon) { return mon->capab[QMP_CAPABILITY_OOB]; --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346523; cv=none; d=zohomail.com; s=zohoarc; b=gvr1wuBc6IcngL1wIi9HXiAuXQGA72wx3pwG9tVKi3w5OgKRl65r4VvT0hPD+xeB+e6KAez0y7OxW5Mh8TQ03ry+RXj4qC7I3hRpVPQBiUBemeRsWThbQg0a1MzGSFZTS1vupwIA+AIQdOD1lYfSEuJDYxwAkRDZTr3fnayPvxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346523; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H3K0yxJ+DLWAz4JBbbb8x+22vd/NRNKXNGRidiJnYfs=; b=UfvVZ0GjY5l2hq9nJjHDHxRYg8aYrYc7jHaaTKFHrDlIeW3AI0RSTJGnjGn2PENaQLgw25+J/fDfwZoAjRqD3tj6G0C38qBTOd/9PgUEePgE2mtJ/SYJojTK6AxoHV4Ds+Ff1CRCzz2Uqr2AR7KM0X+YBPVm5hJhq4G95nDyojU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346523285463.5540333373384; Mon, 6 Jul 2026 07:02:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrH-0002VA-6c; Mon, 06 Jul 2026 09:59:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrE-0002Ro-J5 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrC-0001mb-GR for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:35 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-w_3VZOmsPm-JeycT-CK9ZA-1; Mon, 06 Jul 2026 09:59:28 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 14A451955D84; Mon, 6 Jul 2026 13:59:26 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D1BA73000B4D; Mon, 6 Jul 2026 13:59:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H3K0yxJ+DLWAz4JBbbb8x+22vd/NRNKXNGRidiJnYfs=; b=NTTTtqvNN96lmkcSao7fvbQ99FjJ2YTkIMgdbVEGTqYhp5fKCO/Dyr/+Dvtlk4R5vq9No6 +o8cxRXJjzujRr/06zP6GwRvA63h5aVb5F+Zh7WtV8Knjv0rUOWaN1foWb1GQ12Peb+1Rz JGc13Yq/ay9m4+kHkKE9W79kZtnlrWw= X-MC-Unique: w_3VZOmsPm-JeycT-CK9ZA-1 X-Mimecast-MFC-AGG-ID: w_3VZOmsPm-JeycT-CK9ZA_1783346366 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 14/35] monitor: use class methods for monitor_accept_input Date: Mon, 6 Jul 2026 14:58:02 +0100 Message-ID: <20260706135824.2623960-15-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346524828158500 This removes the need for using monitor_is_qmp() to check the subclass type, which is an anti-pattern. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/hmp.c | 16 ++++++++++++++++ monitor/monitor-internal.h | 5 +++++ monitor/monitor.c | 12 +++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index f9252387c4..4636165d0b 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -70,6 +70,7 @@ static void monitor_hmp_set_readline(Object *obj, bool va= l, Error **errp) =20 int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); +static void monitor_hmp_accept_input(Monitor *mon); =20 static void monitor_hmp_class_init(ObjectClass *cls, const void *data) { @@ -80,6 +81,7 @@ static void monitor_hmp_class_init(ObjectClass *cls, cons= t void *data) monitor_hmp_set_readline); =20 moncls->vprintf =3D monitor_hmp_vprintf; + moncls->accept_input =3D monitor_hmp_accept_input; } =20 static void monitor_hmp_init(Object *obj) @@ -100,6 +102,20 @@ int monitor_hmp_vprintf(Monitor *mon, const char *fmt,= va_list ap) return monitor_puts(mon, buf); } =20 +static void monitor_hmp_accept_input(Monitor *mon) +{ + qemu_mutex_lock(&mon->mon_lock); + if (mon->reset_seen) { + MonitorHMP *hmp =3D MONITOR_HMP(mon); + assert(hmp->rs); + readline_restart(hmp->rs); + qemu_mutex_unlock(&mon->mon_lock); + readline_show_prompt(hmp->rs); + } else { + qemu_mutex_unlock(&mon->mon_lock); + } +} + static void monitor_command_cb(void *opaque, const char *cmdline, void *readline_opaque) { diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 763b5c9625..592f146331 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -116,6 +116,11 @@ struct MonitorClass { * notifications back to the client */ void (*emit_event)(Monitor *mon, QAPIEvent event, QDict *qdict); + /* + * If non-NULL, perform any actions needed to prepare + * the monitor to accept further client input + */ + void (*accept_input)(Monitor *mon); }; =20 struct Monitor { diff --git a/monitor/monitor.c b/monitor/monitor.c index 90cfb59c66..6e63e7a5c7 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -578,16 +578,10 @@ int monitor_suspend(Monitor *mon) static void monitor_accept_input(void *opaque) { Monitor *mon =3D opaque; + MonitorClass *cls =3D MONITOR_GET_CLASS(mon); =20 - qemu_mutex_lock(&mon->mon_lock); - if (!monitor_is_qmp(mon) && mon->reset_seen) { - MonitorHMP *hmp_mon =3D container_of(mon, MonitorHMP, parent_obj); - assert(hmp_mon->rs); - readline_restart(hmp_mon->rs); - qemu_mutex_unlock(&mon->mon_lock); - readline_show_prompt(hmp_mon->rs); - } else { - qemu_mutex_unlock(&mon->mon_lock); + if (cls->accept_input) { + cls->accept_input(mon); } =20 qemu_chr_fe_accept_input(&mon->chr); --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346488; cv=none; d=zohomail.com; s=zohoarc; b=Eb/BDNvj+RU66sJpiZoukpfepsuPgEKYVLyl2vK6CqRjqNTwmz8OcJIYjsGFtoOWfxTZH41eLhNRjavZ/i75GHXj7NPxqosmaIxxwny4a3GHYIetl5YiAikKGzvJA22G//LHd8PpvERiXfGRE8x4fHWeY46BjcGN9CN1ZBkafmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346488; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aekispRBE71bK8cj0hULuFEvR+XWf6HWVh3460aRpsM=; b=eRGc4hk2mlTH7Xi+DSrKJBm/J3nRKEdwQP2N90M/h3acE5Tdvar9pkjeB9Gtscbp3RnjTmQMWkTIs+VeQUuTUsSH8ye9afzMBUUcQpnrVlPGJDLMlXAu879Qn7xWoBlo/gVgKspMOluMfHLnR6ch4xFHC93956URr6aq3BCii1M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346488082437.790900191564; Mon, 6 Jul 2026 07:01:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrL-0002cI-4S; Mon, 06 Jul 2026 09:59:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrH-0002WS-Pe for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrF-0001of-KB for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:39 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-99fFQ5drNjWYERTa-hUQdw-1; Mon, 06 Jul 2026 09:59:31 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A37F71955E72; Mon, 6 Jul 2026 13:59:30 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 916753000B4D; Mon, 6 Jul 2026 13:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aekispRBE71bK8cj0hULuFEvR+XWf6HWVh3460aRpsM=; b=MrFD7aNmIH74BKceQMdnl1ZprEIaFjiQ6gP44RcL5dsuPtTG9jNFFzz7VQYZ/VHGfGe40z /daSdLP24Sdgo4B0/vae6V/Bs2X4pRW+I1PlkczQlkfCcrABVwaqYYCJNa9ofycw2HVx8s 41RTp3WxVdMibXKqXyQ/YtIl060PQbA= X-MC-Unique: 99fFQ5drNjWYERTa-hUQdw-1 X-Mimecast-MFC-AGG-ID: 99fFQ5drNjWYERTa-hUQdw_1783346370 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 15/35] monitor: use class method for I/O thread request Date: Mon, 6 Jul 2026 14:58:03 +0100 Message-ID: <20260706135824.2623960-16-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346488431158500 Introducing a virtual "requires_iothread" method allows the code to automatically initialize the I/O thread during object completion. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/monitor-internal.h | 14 +++++++++----- monitor/monitor.c | 22 ++++++++++++---------- monitor/qmp.c | 20 +++++++++++--------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 592f146331..efd21b8912 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -121,6 +121,12 @@ struct MonitorClass { * the monitor to accept further client input */ void (*accept_input)(Monitor *mon); + + /* + * If non-NULL and returns true, then an I/O thread + * is required for processing the monitor + */ + bool (*requires_iothread)(const Monitor *mon); }; =20 struct Monitor { @@ -129,7 +135,6 @@ struct Monitor { CharFrontend chr; int suspend_cnt; /* Needs to be accessed atomically */ bool is_qmp; - bool use_io_thread; =20 char *mon_cpu_path; QTAILQ_ENTRY(Monitor) entry; @@ -159,9 +164,8 @@ struct MonitorHMP { bool use_readline; /* * State used only in the thread "owning" the monitor. - * If @use_io_thread, this is @mon_iothread. (This does not actually h= appen - * in the current state of the code.) - * Else, it's the main thread. + * This is currently always the main thread, since + * HMP does not allow use of the I/O thread at this time. * These members can be safely accessed without locks. */ ReadLineState *rs; @@ -210,7 +214,7 @@ extern QemuMutex monitor_lock; extern MonitorList mon_list; =20 void monitor_complete(Monitor *mon, Error **errp); -void monitor_iothread_init(Monitor *mon); +bool monitor_requires_iothread(const Monitor *mon); int monitor_can_read(void *opaque); void monitor_list_append(Monitor *mon); void monitor_fdsets_cleanup(void); diff --git a/monitor/monitor.c b/monitor/monitor.c index 6e63e7a5c7..1b2bdcf68f 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -162,6 +162,12 @@ bool monitor_cur_is_qmp(void) return cur_mon && monitor_is_qmp(cur_mon); } =20 +bool monitor_requires_iothread(const Monitor *mon) +{ + MonitorClass *cls =3D MONITOR_GET_CLASS(mon); + return cls->requires_iothread && cls->requires_iothread(mon); +} + /** * Is @mon is using readline? * Note: not all HMP monitors use readline, e.g., gdbserver has a @@ -563,7 +569,7 @@ int monitor_suspend(Monitor *mon) =20 qatomic_inc(&mon->suspend_cnt); =20 - if (mon->use_io_thread) { + if (monitor_requires_iothread(mon)) { /* * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. @@ -596,7 +602,7 @@ void monitor_resume(Monitor *mon) if (qatomic_dec_fetch(&mon->suspend_cnt) =3D=3D 0) { AioContext *ctx; =20 - if (mon->use_io_thread) { + if (monitor_requires_iothread(mon)) { ctx =3D iothread_get_aio_context(mon_iothread); } else { ctx =3D qemu_get_aio_context(); @@ -634,14 +640,6 @@ void monitor_list_append(Monitor *mon) } } =20 -void monitor_iothread_init(Monitor *mon) -{ - if (!mon_iothread) { - mon_iothread =3D iothread_create("mon_iothread", &error_abort); - } - mon->use_io_thread =3D true; -} - void monitor_cleanup(void) { /* @@ -743,6 +741,10 @@ void monitor_complete(Monitor *mon, Error **errp) return; } } + + if (monitor_requires_iothread(mon) && !mon_iothread) { + mon_iothread =3D iothread_create("mon_iothread", &error_abort); + } } =20 int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) diff --git a/monitor/qmp.c b/monitor/qmp.c index d732fff9a3..8bbe25d8de 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -100,6 +100,7 @@ static void monitor_qmp_set_pretty(Object *obj, bool va= l, Error **errp) } =20 static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *q= dict); +static bool monitor_qmp_requires_iothread(const Monitor *mon); =20 static void monitor_qmp_class_init(ObjectClass *cls, const void *data) { @@ -110,6 +111,7 @@ static void monitor_qmp_class_init(ObjectClass *cls, co= nst void *data) monitor_qmp_set_pretty); =20 moncls->emit_event =3D monitor_qmp_emit_event; + moncls->requires_iothread =3D monitor_qmp_requires_iothread; } =20 static void handle_qmp_command(void *opaque, QObject *req, Error *err); @@ -136,6 +138,11 @@ static void monitor_qmp_emit_event(Monitor *mon, QAPIE= vent event, QDict *qdict) qmp_send_response(qmp, qdict); } =20 +static bool monitor_qmp_requires_iothread(const Monitor *mon) +{ + return qemu_chr_has_feature(mon->chr.chr, + QEMU_CHAR_FEATURE_GCONTEXT); +} =20 static bool qmp_oob_enabled(MonitorQMP *mon) { @@ -146,7 +153,8 @@ static void monitor_qmp_caps_reset(MonitorQMP *mon) { memset(mon->capab_offered, 0, sizeof(mon->capab_offered)); memset(mon->capab, 0, sizeof(mon->capab)); - mon->capab_offered[QMP_CAPABILITY_OOB] =3D mon->parent_obj.use_io_thre= ad; + mon->capab_offered[QMP_CAPABILITY_OOB] =3D + monitor_requires_iothread(MONITOR(mon)); } =20 static void qmp_request_free(QMPRequest *req) @@ -562,7 +570,7 @@ static void monitor_qmp_setup_handlers_bh(void *opaque) MonitorQMP *mon =3D opaque; GMainContext *context; =20 - assert(mon->parent_obj.use_io_thread); + assert(monitor_requires_iothread(MONITOR(mon))); context =3D iothread_get_g_main_context(mon_iothread); assert(context); qemu_chr_fe_set_handlers(&mon->parent_obj.chr, monitor_can_read, @@ -598,13 +606,7 @@ void monitor_new_qmp(const char *id, const char *chard= ev_id, =20 qemu_chr_fe_set_echo(&mon->parent_obj.chr, true); =20 - /* Note: we run QMP monitor in I/O thread when @chr supports that */ - if (qemu_chr_has_feature(mon->parent_obj.chr.chr, - QEMU_CHAR_FEATURE_GCONTEXT)) { - monitor_iothread_init(&mon->parent_obj); - } - - if (mon->parent_obj.use_io_thread) { + if (monitor_requires_iothread(MONITOR(mon))) { /* * Make sure the old iowatch is gone. It's possible when * e.g. the chardev is in client mode, with wait=3Don. --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346426; cv=none; d=zohomail.com; s=zohoarc; b=J69SJCAo3W/CZmQtf9TVjt+jeUueWV2sjnQtniWgzkRXh+J+WoblrVToCq3hbmNjujH2tP+Y/VKR8AT3tJ1Z2Pi2POiBzf/KiXNV907ubQS18Nwu4PgOoy6yP6BFq+4EHLa1lMUduKQCxscMdSAhoKAG3IE4NKtYDysSO3UiAS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346426; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nROEUf3PvmRHPNyGA0w6n/7txBCJ5/vbb7RhTBeB9rI=; b=iAb15dj6N4ec8fmxFLxx8qhHTlBKxt72kTJcPnSxqoUlhPVvOHFpUlbBTjUi8sCZKTJb12R9g5CGyTTvylgQxqFZc8bIjdez+YVOJ77cf5K5sInQQHseh56nzOzW2LywKWuoJSbDxJxN3srsCdnm+mZynYtrN+KV0uMzafVt6qE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346426253815.5356402040754; Mon, 6 Jul 2026 07:00:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrM-0002e6-R7; Mon, 06 Jul 2026 09:59:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrK-0002cF-Ua for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrJ-0001qL-C2 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:42 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-5AfYMrt3PTGKSvstP7p5iQ-1; Mon, 06 Jul 2026 09:59:36 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 73A8C1955D8E; Mon, 6 Jul 2026 13:59:34 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 18D383000B52; Mon, 6 Jul 2026 13:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nROEUf3PvmRHPNyGA0w6n/7txBCJ5/vbb7RhTBeB9rI=; b=fQEDD7gQAxiqbtTw11MUy1k5YNFsUtSDNTwPFEnukpWwRXicrubIjOarErplOreIvmVaBI RQzoec/qDDpM3LxUUJTiz5bhtyOw1GO++19k6HX6/4fTKoZZ44dpk+p/i1m+KnzsFKVrif QZeYuj/1wG+WsygSWhjqgKTLJUGlvE8= X-MC-Unique: 5AfYMrt3PTGKSvstP7p5iQ-1 X-Mimecast-MFC-AGG-ID: 5AfYMrt3PTGKSvstP7p5iQ_1783346374 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 16/35] monitor: use dynamic cast in monitor_qmp_requests_pop_any_with_lock Date: Mon, 6 Jul 2026 14:58:04 +0100 Message-ID: <20260706135824.2623960-17-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346427514158500 This eliminates a use of monitor_is_qmp() from the QMP coroutine dispatch path. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/qmp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index 8bbe25d8de..bd3e6f8375 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -277,11 +277,12 @@ static QMPRequest *monitor_qmp_requests_pop_any_with_= lock(void) MonitorQMP *qmp_mon; =20 QTAILQ_FOREACH(mon, &mon_list, entry) { - if (!monitor_is_qmp(mon)) { + qmp_mon =3D MONITOR_QMP( + object_dynamic_cast(OBJECT(mon), TYPE_MONITOR_QMP)); + if (!qmp_mon) { continue; } =20 - qmp_mon =3D container_of(mon, MonitorQMP, parent_obj); qemu_mutex_lock(&qmp_mon->qmp_queue_lock); req_obj =3D g_queue_pop_head(qmp_mon->qmp_requests); if (req_obj) { --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346498; cv=none; d=zohomail.com; s=zohoarc; b=OhYTf6clfxVqDfkb9p2hiW17kkswf9NGonvZPS9RldilNPhzp+B7upo2f4d0Ddsl7hE3Y/78TOcl1GQyj6LN5KORgtNLwwwQmxhkNgR9MT5wmJNgQzgktlBd1FpvQSjgWd+lif/ni1Cg3mqE7zLCmd5UNEvKXtcgl6AlZ17Dtxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346498; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ngWS4mS2Dbs0LC3jR4MV80BABTanbGb13zaqwTqo5ms=; b=hXXZJSg5ScduFE3EuWUxmjDQV99S63yXt1iIKfyoOdv2nFC5d/RDa7B+HrmWm7UJa07ZP2pmp7R5lTvwnU862yncF+qR+zyL6aXsBW4ENGWrKHSj7USmSJottqJinJthSDniH1HWr0U4KU6WX/mfFM9aElzsrpultsLW5dJknB0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346498404313.4063573230676; Mon, 6 Jul 2026 07:01:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrO-0002qN-Ko; Mon, 06 Jul 2026 09:59:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrM-0002eK-Rs for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrL-0001qY-IR for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:44 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-oUcR_YIiPj2X0c0cgyoWFA-1; Mon, 06 Jul 2026 09:59:39 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8A4D018009D3; Mon, 6 Jul 2026 13:59:38 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E29AB3000B4D; Mon, 6 Jul 2026 13:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ngWS4mS2Dbs0LC3jR4MV80BABTanbGb13zaqwTqo5ms=; b=iHHDHR6UIKcALVkqqf0vYZISG7vfW/sQukfgTB2/ai0mt9lzWnzbxMutFjI9A0ogxYUoiP l0UIQ35nYpIAIA+ObFyuXOo/FUOmi7xAJ5JC507cmFicW52VmEsXRUhhAqo7c0UoKVf4mT XIzdtenea61yS288hNhP5kfg8fIl0f8= X-MC-Unique: oUcR_YIiPj2X0c0cgyoWFA-1 X-Mimecast-MFC-AGG-ID: oUcR_YIiPj2X0c0cgyoWFA_1783346378 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 17/35] util: use dynamic cast in error vreport Date: Mon, 6 Jul 2026 14:58:05 +0100 Message-ID: <20260706135824.2623960-18-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346500377158500 This eliminates a use of monitor_is_qmp() from the error reporting path. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- util/error-report.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/util/error-report.c b/util/error-report.c index f832ad9b6b..f333af9249 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -231,16 +231,15 @@ char *real_time_iso8601(void) G_GNUC_PRINTF(2, 0) static void vreport(report_type type, const char *fmt, va_list ap) { - Monitor *cur =3D monitor_cur(); - gchar *timestr; - /* * When current monitor is QMP, messages must go to stderr - * and have prefixes added + * and have prefixes added, so we cast to HMP, leaving 'cur' + * as NULL in QMP case */ - if (monitor_cur_is_qmp()) { - cur =3D NULL; - } + Monitor *cur =3D MONITOR( + object_dynamic_cast(OBJECT(monitor_cur()), TYPE_MONITOR_HMP)); + gchar *timestr; + if (!cur) { qemu_flockfile(stderr); } --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346398; cv=none; d=zohomail.com; s=zohoarc; b=U1vz3HQWmx7/bAeqhXB/X4LIqXbBsQL7l1mcTvqzZU+XYw94a+HFuSyFwJpakvq4UOj3q8d+hiOxOWlApezVrmjirbSLQ8+4oSnGNUhkB/ir0dcOZwxzJw4jvTZTR0XCX+81NPkTsDyoO0pK5t7/MFuq7MbM6WhYdAlibOgjuuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346398; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=n/ohhfMEcAmdnbkUbO/K4y2OAcZrsM+LilLyeGrmrEM=; b=camWTxKx2Dg2xGKSriHLeam/tiQfFxbwi0+FXdwZYGeSx8k8VNkwzGxaUcLNs28LzoxkuHQfz3r8jR7Z1c/yWUZ5WJtokiyH/MGWp+jRZ2eMrZp/ousD5WwYWdlj/FF0iPIdyMXRpP+v+PjMxd2TPiRUJY+cpaAET6oO2U1fqec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346398650450.5666589086892; Mon, 6 Jul 2026 06:59:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrS-0003Kb-PK; Mon, 06 Jul 2026 09:59:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrR-0003Be-DA for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrP-0001qo-UE for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:49 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-EezwHVAeOk2DCTLOOLJkNA-1; Mon, 06 Jul 2026 09:59:43 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3AF091955DC1; Mon, 6 Jul 2026 13:59:42 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0CB723000B4D; Mon, 6 Jul 2026 13:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346387; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n/ohhfMEcAmdnbkUbO/K4y2OAcZrsM+LilLyeGrmrEM=; b=gYv9+W2vKzl855ajE4Dzw0gLUMISd3v5LaAeL9PiE3P+1YQ0Gs3tY9Y9wC+M6A7Jagq9Ce MtlP3g2/kjekiKdx7tDrDt4FFQQdgq5nQM7Y5miN2Vi+rfuv7I6Qh+OTqgLN4WLYwzQ7gW 1G1qprZW2dSrBO0D6fDHjQnRkDHCxd4= X-MC-Unique: EezwHVAeOk2DCTLOOLJkNA-1 X-Mimecast-MFC-AGG-ID: EezwHVAeOk2DCTLOOLJkNA_1783346382 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 18/35] monitor: drop unused monitor_cur_is_qmp Date: Mon, 6 Jul 2026 14:58:06 +0100 Message-ID: <20260706135824.2623960-19-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346398847158500 The previous patch dropped the only remaining use of monitor_cur_is_qmp. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- include/monitor/monitor.h | 1 - monitor/monitor.c | 10 ---------- stubs/monitor-core.c | 5 ----- tests/unit/test-util-sockets.c | 1 - tools/qemu-vnc/stubs.c | 5 ----- 5 files changed, 22 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 821465f17e..e802e8dfb2 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -25,7 +25,6 @@ extern QemuOptsList qemu_mon_opts; =20 Monitor *monitor_cur(void); Monitor *monitor_set_cur(Coroutine *co, Monitor *mon); -bool monitor_cur_is_qmp(void); =20 void monitor_init_globals(void); void monitor_init_globals_core(void); diff --git a/monitor/monitor.c b/monitor/monitor.c index 1b2bdcf68f..a818659392 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -152,16 +152,6 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) return old_monitor; } =20 -/** - * Is the current monitor, if any, a QMP monitor? - */ -bool monitor_cur_is_qmp(void) -{ - Monitor *cur_mon =3D monitor_cur(); - - return cur_mon && monitor_is_qmp(cur_mon); -} - bool monitor_requires_iothread(const Monitor *mon) { MonitorClass *cls =3D MONITOR_GET_CLASS(mon); diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index 078a5012e9..a7c32297c9 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -7,11 +7,6 @@ Monitor *monitor_cur(void) return NULL; } =20 -bool monitor_cur_is_qmp(void) -{ - return false; -} - Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { return NULL; diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index b9f2453e29..ee66d727c3 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -74,7 +74,6 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Erro= r **errp) Monitor *monitor_cur(void) { return cur_mon; } Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); } int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } -bool monitor_cur_is_qmp(void) { abort(); }; =20 #ifndef _WIN32 static void test_socket_fd_pass_name_good(void) diff --git a/tools/qemu-vnc/stubs.c b/tools/qemu-vnc/stubs.c index a865ce85f0..1c82d8cff4 100644 --- a/tools/qemu-vnc/stubs.c +++ b/tools/qemu-vnc/stubs.c @@ -36,11 +36,6 @@ Monitor *monitor_cur(void) return NULL; } =20 -bool monitor_cur_is_qmp(void) -{ - return false; -} - Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { return NULL; --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346564; cv=none; d=zohomail.com; s=zohoarc; b=FGXfRWIjUVO+APhnxV0cvo0ZTlZv7LoVylYb36seCkHvBmdKxuTJgui4M4o9OdJTaFPflVe5yrr0khgjYv1pmc7SfqVffBsS8FneIt33sn+OqPkRRIIyrqxXauRA+SIEdZDkHv+9O2084TXO8WjaT2gm5AGEfQkAUBDYK/tzNPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346564; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9kJWkeAnC6/S4dnkIZ3f9RMRIl1fKjT975v/SJttVzU=; b=CBMEqV3pDMW2cUJeN4OTYZoCkh0HS2lIG6301ZT8qeSlpXKzi8eXyf6D17R8LER0rBLRRqK+7s9rnOAxr1V4elzBIqDzo1dRKDL5Fwz4nKrn7aTtf8RO9Qu2dB0nq2wmehJ3zljRvgwCqa//MoA8IWUIiUtm7WIsvA0RxEq6F/E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346564731818.5258089326261; Mon, 6 Jul 2026 07:02:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrX-0003dT-42; Mon, 06 Jul 2026 09:59:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrU-0003XP-Sp for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrT-0001rE-Hp for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:52 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-2u_MnhipPnavZVh2W7O7lg-1; Mon, 06 Jul 2026 09:59:47 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 116701955F73; Mon, 6 Jul 2026 13:59:46 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AAA283000B52; Mon, 6 Jul 2026 13:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9kJWkeAnC6/S4dnkIZ3f9RMRIl1fKjT975v/SJttVzU=; b=RRNWuyNAY9VYv5Zqxb5w5uWfOCe9tn8ibSxYpg4Ls50FosUbcVuo9iqmH3YQQ0d7PbAxvo AhAzFgXzvvB/b1PNEKCEU3C6RdxR7eWoWhkwbsGjpP6EKPJqlGFJW+14F7MI+VYpTwRDdj ep/8ahwmnnY8XAhqmKfER6SIO54oT7s= X-MC-Unique: 2u_MnhipPnavZVh2W7O7lg-1 X-Mimecast-MFC-AGG-ID: 2u_MnhipPnavZVh2W7O7lg_1783346386 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 19/35] monitor: use dynamic cast in QMP commands Date: Mon, 6 Jul 2026 14:58:07 +0100 Message-ID: <20260706135824.2623960-20-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346567355158500 Rather than asserting monitor_is_qmp(), use a QOM cast via MONITOR_QMP which performs an assert already. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/qmp-cmds-control.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c index af6a2a118b..8fe0876a3d 100644 --- a/monitor/qmp-cmds-control.c +++ b/monitor/qmp-cmds-control.c @@ -72,11 +72,7 @@ static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabili= tyList *list, void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, Error **errp) { - Monitor *cur_mon =3D monitor_cur(); - MonitorQMP *mon; - - assert(monitor_is_qmp(cur_mon)); - mon =3D container_of(cur_mon, MonitorQMP, parent_obj); + MonitorQMP *mon =3D MONITOR_QMP(monitor_cur()); =20 if (mon->commands =3D=3D &qmp_commands) { error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, @@ -122,11 +118,7 @@ static void query_commands_cb(const QmpCommand *cmd, v= oid *opaque) CommandInfoList *qmp_query_commands(Error **errp) { CommandInfoList *list =3D NULL; - Monitor *cur_mon =3D monitor_cur(); - MonitorQMP *mon; - - assert(monitor_is_qmp(cur_mon)); - mon =3D container_of(cur_mon, MonitorQMP, parent_obj); + MonitorQMP *mon =3D MONITOR_QMP(monitor_cur()); =20 qmp_for_each_command(mon->commands, query_commands_cb, &list); =20 --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346593; cv=none; d=zohomail.com; s=zohoarc; b=QH+i/JwTjzCrQwktoi5qR/D0IV5XPDUpu1t1Fla/0+uCX4rXUP1eu4O/3NItK1MXCMEV4sjJcjb1K9VEzpBHd3m/3W83BrGHAfAHB+YhN2FJPck/tw3lyGAQj0ir/Riqh/djZQq7H5dxvcvoH2l6GY/auUb0GXTm/C7HuQ6pD90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346593; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TW/rdLiT5KRos71GuuR+uqTbFv+v1Hjm4MO15NjhpIk=; b=NbJPKjJOtUBoNv5WWzX/ej2/Vwo8/f+I7foAXu1ptmlklqItJitmkhPojAbmltpDsKGcfdjAW2pgos2HZ42L5z41H/dKkW9M3hM85Gj66AJn+eGq5ca/o9bRJ7K5SYpMjvpWE4onRu2B2aV1J8zhlpRfJSJzpRaosFDbJ/RHn3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178334659358515.068574590527987; Mon, 6 Jul 2026 07:03:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjra-0003m2-IV; Mon, 06 Jul 2026 09:59:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrW-0003d9-Bz for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrU-0001rL-RV for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:53 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-422-CyOSYZCeMgWMR0crFzU8OA-1; Mon, 06 Jul 2026 09:59:51 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D3A1D1955F21; Mon, 6 Jul 2026 13:59:49 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7FC423000B4D; Mon, 6 Jul 2026 13:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TW/rdLiT5KRos71GuuR+uqTbFv+v1Hjm4MO15NjhpIk=; b=c5ZbBrkCqb6B9DiDkDJUl/3hyNRzu8CLQC254WPRmTUMGJ+kfXHhjiOoZhXLw1712+6A6z x3mjhooi5nWZt1hZTjMX7PweAM4h853LGh6HMj6dJ1xl2ZG9Al/37Y6je4UiI13gWJch36 1s3tPH6y9A292/veY2lVCaogNJ6sWwk= X-MC-Unique: CyOSYZCeMgWMR0crFzU8OA-1 X-Mimecast-MFC-AGG-ID: CyOSYZCeMgWMR0crFzU8OA_1783346390 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 20/35] monitor: use dynamic cast in monitor_is_hmp_non_interactive Date: Mon, 6 Jul 2026 14:58:08 +0100 Message-ID: <20260706135824.2623960-21-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346599695158500 Rather than checking !monitor_is_qmp(), use a dynamic cast to check for HMP. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index a818659392..6fdd0255f4 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -170,7 +170,7 @@ static inline bool monitor_uses_readline(const MonitorH= MP *mon) =20 static inline bool monitor_is_hmp_non_interactive(const Monitor *mon) { - if (monitor_is_qmp(mon)) { + if (!object_dynamic_cast(OBJECT(mon), TYPE_MONITOR_HMP)) { return false; } =20 --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346488; cv=none; d=zohomail.com; s=zohoarc; b=aGUOhL7tGDcpef3YXjCb4lIUkWiKM49BA2ZpO8w0QmngCNaHar3UbfCOSPZg9o8w2BWnvTx67JqgqUMCJWGrM7i7Fqp/aZTvfcFEU2QzwV+ALV+wS7fNYDqcj+6V7YeTISKSyFTbILMIo2kV30oX4f3FE7aNclU62OdfsL4LTDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346488; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=y28CSpmW1jNzutZHRxm20fpsqrVzW0jO0kbnzgUdCmE=; b=VBK3ppJY/C3wVIh5ba5QH94aWj14pz547BZ58MDJaNQW1a1KKKbp3n0HJAWvBeHEaajRnVROOpLjUqspCI7CrQnX9x+2ygx3n11PVIDACDm2g3URXemT4oMThZi+5KyJXVK/dE4clZKmlLpH01A1MIM9FA7NZwSHLfVNKOJUZLk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346488066434.1883344360043; Mon, 6 Jul 2026 07:01:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrc-0003oT-4I; Mon, 06 Jul 2026 10:00:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjra-0003lX-6c for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrY-0001rd-R9 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 09:59:57 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-gSzZgF2PN9-39Hup25PHvQ-1; Mon, 06 Jul 2026 09:59:55 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ABA931955DE9; Mon, 6 Jul 2026 13:59:53 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4F2CE3000B4D; Mon, 6 Jul 2026 13:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y28CSpmW1jNzutZHRxm20fpsqrVzW0jO0kbnzgUdCmE=; b=DtkzWXaD7LRRFYDjEGkU304voMTe/dduQK8S0l9Ot4GjxC8AzFMdeSU2+Bcm/h3ed666Ol Zs7jvu9dwg3MCNnIywd1rIfnAlaZLdysh/FLCQoVvFLH/NpIwfgDXPrBt0tOgoTWaUBQ6W XpGgaWAFLLEu/qaTFM20WmEj0VjCWJE= X-MC-Unique: gSzZgF2PN9-39Hup25PHvQ-1 X-Mimecast-MFC-AGG-ID: gSzZgF2PN9-39Hup25PHvQ_1783346393 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 21/35] monitor: drop unused monitor_is_qmp method Date: Mon, 6 Jul 2026 14:58:09 +0100 Message-ID: <20260706135824.2623960-22-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346488352158500 The previous patch dropped the only remaining use of monitor_is_qmp. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/monitor-internal.h | 9 --------- monitor/monitor.c | 1 - 2 files changed, 10 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index efd21b8912..fe5703af6d 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -134,7 +134,6 @@ struct Monitor { char *chardev_id; CharFrontend chr; int suspend_cnt; /* Needs to be accessed atomically */ - bool is_qmp; =20 char *mon_cpu_path; QTAILQ_ENTRY(Monitor) entry; @@ -197,14 +196,6 @@ struct MonitorQMP { GQueue *qmp_requests; }; =20 -/** - * Is @mon a QMP monitor? - */ -static inline bool monitor_is_qmp(const Monitor *mon) -{ - return mon->is_qmp; -} - typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList; extern IOThread *mon_iothread; extern Coroutine *qmp_dispatcher_co; diff --git a/monitor/monitor.c b/monitor/monitor.c index 6fdd0255f4..9b62716033 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -115,7 +115,6 @@ static void monitor_init(Object *obj) Monitor *mon =3D MONITOR(obj); =20 qemu_mutex_init(&mon->mon_lock); - mon->is_qmp =3D !!object_dynamic_cast(obj, TYPE_MONITOR_QMP); mon->outbuf =3D g_string_new(NULL); } =20 --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346486; cv=none; d=zohomail.com; s=zohoarc; b=PxEBElFoflGqSb88N7iF59oXvx4wAacpE2F27plE4L7787z9C7HJV3IkiXLy3ADimb2aRcVv3SWBf52eXTEuZT6qe5+0+sNM7opr+ESFEdc7wce4agq0g/t/MFO6W+EEtQTMyDVfCKdjkRM6P8M2WgvTBKHmfgyRmdeOigFZFQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346486; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5bXxssTyYnkBlVt7qMbDcqHrgRdotP9+q0aAJz51+aM=; b=VwA0n53lWSWvIhkflm0gUX6B3GhBDGObc5dV1tyKT1i1aRiXzEQn3iMxgbHI998DO7/K3yY4JVoehzjQ69XbLy9uygSAs92rx/v6UwB6ezC7guiZhToUb2IOcG3OE9Ut28N9wSZPi/Ul7Enbjo7XU+wwhEHS2ACZ6LX4iNccdrI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346486516191.77912940432896; Mon, 6 Jul 2026 07:01:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrn-00040y-0V; Mon, 06 Jul 2026 10:00:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrh-0003wL-5L for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrf-0001vU-0g for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:04 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-414-TUQ63APWPAGadHFHiPRw3A-1; Mon, 06 Jul 2026 09:59:58 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 940EA1800844; Mon, 6 Jul 2026 13:59:57 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2714C3000B50; Mon, 6 Jul 2026 13:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5bXxssTyYnkBlVt7qMbDcqHrgRdotP9+q0aAJz51+aM=; b=Zqv7/vHKCXCoqLBc/L7qT1Cq5o+REKPzC+ALP0X/m4f6R1UOfAdCvf5SdbHzklFwB49T36 D7EXqMiOqpRx7IhHGlgqoDAkONRwhMqNB3jL1zQIKsTJROOPLiaAV4tpTynoSt+2B5OdTf xTYsaHfLAP834QKZuzUhDMKdoae6SOw= X-MC-Unique: TUQ63APWPAGadHFHiPRw3A-1 X-Mimecast-MFC-AGG-ID: TUQ63APWPAGadHFHiPRw3A_1783346397 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 22/35] monitor: eliminate monitor_is_hmp_non_interactive method Date: Mon, 6 Jul 2026 14:58:10 +0100 Message-ID: <20260706135824.2623960-23-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346488401158500 The monitor_is_hmp_non_interactive method is used by monitor_suspend and monitor_resume, to make them a no-op if the HMP does not use readline. There are only a handful of callers of suspend/resume and they can be made to skip the call when readline is not present. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- include/monitor/monitor.h | 2 +- migration/migration-hmp-cmds.c | 5 ++++- monitor/hmp-cmds.c | 5 ++++- monitor/hmp.c | 11 ++++++++--- monitor/monitor.c | 30 +----------------------------- 5 files changed, 18 insertions(+), 35 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index e802e8dfb2..890497b0d2 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -37,7 +37,7 @@ int monitor_new(MonitorOptions *opts, bool allow_hmp, Err= or **errp); int monitor_new_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); =20 -int monitor_suspend(Monitor *mon); +void monitor_suspend(Monitor *mon); void monitor_resume(Monitor *mon); =20 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp); diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 8b385f560e..502ca704da 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -19,6 +19,7 @@ #include "monitor/hmp.h" #include "monitor/hmp-completion.h" #include "monitor/monitor.h" +#include "monitor/monitor-internal.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-visit-migration.h" @@ -853,12 +854,14 @@ void hmp_migrate(Monitor *mon, const QDict *qdict) =20 if (!detach) { HMPMigrationStatus *status; + MonitorHMP *hmp =3D MONITOR_HMP(mon); =20 - if (monitor_suspend(mon) < 0) { + if (!hmp->use_readline) { monitor_printf(mon, "terminal does not allow synchronous " "migration, continuing detached\n"); return; } + monitor_suspend(mon); =20 status =3D g_malloc0(sizeof(*status)); status->mon =3D mon; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index e139caeba9..e9fb8d827a 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -129,7 +129,10 @@ void hmp_info_version(Monitor *mon, const QDict *qdict) =20 void hmp_quit(Monitor *mon, const QDict *qdict) { - monitor_suspend(mon); + MonitorHMP *hmp =3D MONITOR_HMP(mon); + if (hmp->use_readline) { + monitor_suspend(mon); + } qmp_quit(NULL); } =20 diff --git a/monitor/hmp.c b/monitor/hmp.c index 4636165d0b..a51de8e467 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1528,13 +1528,16 @@ static void monitor_read(void *opaque, const uint8_= t *buf, int size) static void monitor_event(void *opaque, QEMUChrEvent event) { Monitor *mon =3D opaque; + MonitorHMP *hmp =3D MONITOR_HMP(mon); =20 switch (event) { case CHR_EVENT_MUX_IN: qemu_mutex_lock(&mon->mon_lock); if (mon->mux_out) { mon->mux_out =3D 0; - monitor_resume(mon); + if (hmp->use_readline) { + monitor_resume(mon); + } } qemu_mutex_unlock(&mon->mon_lock); break; @@ -1547,7 +1550,9 @@ static void monitor_event(void *opaque, QEMUChrEvent = event) } else { monitor_flush_locked(mon); } - monitor_suspend(mon); + if (hmp->use_readline) { + monitor_suspend(mon); + } mon->mux_out =3D 1; } qemu_mutex_unlock(&mon->mon_lock); @@ -1558,7 +1563,7 @@ static void monitor_event(void *opaque, QEMUChrEvent = event) "information\n", QEMU_VERSION); qemu_mutex_lock(&mon->mon_lock); mon->reset_seen =3D 1; - if (!mon->mux_out) { + if (!mon->mux_out && hmp->use_readline) { /* Suspend-resume forces the prompt to be printed. */ monitor_suspend(mon); monitor_resume(mon); diff --git a/monitor/monitor.c b/monitor/monitor.c index 9b62716033..f1b189c1c2 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -157,25 +157,6 @@ bool monitor_requires_iothread(const Monitor *mon) return cls->requires_iothread && cls->requires_iothread(mon); } =20 -/** - * Is @mon is using readline? - * 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 MonitorHMP *mon) -{ - return mon->use_readline; -} - -static inline bool monitor_is_hmp_non_interactive(const Monitor *mon) -{ - if (!object_dynamic_cast(OBJECT(mon), TYPE_MONITOR_HMP)) { - return false; - } - - return !monitor_uses_readline(container_of(mon, MonitorHMP, parent_obj= )); -} - static gboolean monitor_unblocked(void *do_not_use, GIOCondition cond, void *opaque) { @@ -550,12 +531,8 @@ static gboolean qapi_event_throttle_equal(const void *= a, const void *b) return TRUE; } =20 -int monitor_suspend(Monitor *mon) +void monitor_suspend(Monitor *mon) { - if (monitor_is_hmp_non_interactive(mon)) { - return -ENOTTY; - } - qatomic_inc(&mon->suspend_cnt); =20 if (monitor_requires_iothread(mon)) { @@ -567,7 +544,6 @@ int monitor_suspend(Monitor *mon) } =20 trace_monitor_suspend(mon, 1); - return 0; } =20 static void monitor_accept_input(void *opaque) @@ -584,10 +560,6 @@ static void monitor_accept_input(void *opaque) =20 void monitor_resume(Monitor *mon) { - if (monitor_is_hmp_non_interactive(mon)) { - return; - } - if (qatomic_dec_fetch(&mon->suspend_cnt) =3D=3D 0) { AioContext *ctx; =20 --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346547; cv=none; d=zohomail.com; s=zohoarc; b=GwcoCk4ezFYyWET/H1BgsxVOkNocTDEFfmyxI3JzlVpy/78dhv7wmU2Wj/Ex3Alhh10TWepIUIwTa70MDOwzsc1/6jk/BK8ErNEWGBeSMZyuVQ/ofehp2Y47944+vEOUgdeoODuiDlSnMWoC4rMmabqfDx9x+E5A6Wp9L4rk1gg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346547; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VRhm9zwicQZsZCfNMqVWgq8ASge64+TA94rEiQoqnh4=; b=O+wuurwoXVT5W0DCcx95XwU6J6LQOu9qjYahK9OG84hkl9VFmad/D78auKtdfa/oQCx3ri4UlsDOFmZW6Y8UOiw2F7n6crf/DJ2UYdCTBPCGoJXI096YtMhFoXFKo0GMOYgNy3qjuzTG8KNZHZgZRw4CPwD08RSz3AF7YZFBQJI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346547088114.79096530854952; Mon, 6 Jul 2026 07:02:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjro-00048J-Ku; Mon, 06 Jul 2026 10:00:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrl-00040u-5X for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjri-00027Z-Q3 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:08 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-532-How7tDndOAujxVSmWcYogA-1; Mon, 06 Jul 2026 10:00:02 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9153A1955F3B; Mon, 6 Jul 2026 14:00:01 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 207693000B50; Mon, 6 Jul 2026 13:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VRhm9zwicQZsZCfNMqVWgq8ASge64+TA94rEiQoqnh4=; b=AWXeV7/67BNBZGjlEvGvc+xEmA9YC+H7orwGzcDAzBs2RKW45OazWy7mUqb7dda1BP5jJE 2Wk6PpF7EUqqEE2ZeZPX99SDo9m44DtWFt4UxPx+GJHeW46FMMGnEA2HbHu6IqCcUaDRiS Uz6G2xWrQJoupgT1gmdxuHRiW7Unn8M= X-MC-Unique: How7tDndOAujxVSmWcYogA-1 X-Mimecast-MFC-AGG-ID: How7tDndOAujxVSmWcYogA_1783346401 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 23/35] monitor: implement "user creatable" interface for adding monitors Date: Mon, 6 Jul 2026 14:58:11 +0100 Message-ID: <20260706135824.2623960-24-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346549314158500 Implement the user creatable QOM interface and define the monitor-qmp and monitor-hmp types in QAPI. This unlocks the ability to create them on the command line with -object or in HMP/QMP with object_add. For example: $QEMU -chardev stdio,id=3Dmonchr0 -object monitor-hmp,id=3Dmon0,chrdev=3D= monchr0 Initially the "prepare_delete" callback is hardcoded to return an error which means -object and object_add can be used, but object_del will fail. Support for deleting monitors will be introduced in subsequent commits. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Acked-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- monitor/hmp.c | 70 ++++++++++++++++++++++++-------------- monitor/monitor-internal.h | 1 - monitor/monitor.c | 14 ++++++-- monitor/qmp.c | 47 ++++++++++++++++--------- qapi/qom.json | 43 +++++++++++++++++++++++ stubs/monitor-internal.c | 1 + system/vl.c | 8 ++++- 7 files changed, 138 insertions(+), 46 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index a51de8e467..75b93f29a3 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -40,6 +40,7 @@ #include "qemu/target-info.h" #include "qemu/units.h" #include "qapi/error.h" +#include "qom/object_interfaces.h" #include "exec/gdbstub.h" #include "system/block-backend.h" #include "trace.h" @@ -71,10 +72,13 @@ static void monitor_hmp_set_readline(Object *obj, bool = val, Error **errp) int monitor_hmp_vprintf(Monitor *mon, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); static void monitor_hmp_accept_input(Monitor *mon); +static void monitor_hmp_complete(UserCreatable *uc, Error **errp); +static bool monitor_hmp_prepare_delete(UserCreatable *uc, Error **errp); =20 static void monitor_hmp_class_init(ObjectClass *cls, const void *data) { MonitorClass *moncls =3D MONITOR_CLASS(cls); + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(cls); =20 object_class_property_add_bool(cls, "readline", monitor_hmp_get_readline, @@ -82,6 +86,9 @@ static void monitor_hmp_class_init(ObjectClass *cls, cons= t void *data) =20 moncls->vprintf =3D monitor_hmp_vprintf; moncls->accept_input =3D monitor_hmp_accept_input; + + ucc->complete =3D monitor_hmp_complete; + ucc->prepare_delete =3D monitor_hmp_prepare_delete; } =20 static void monitor_hmp_init(Object *obj) @@ -1605,41 +1612,52 @@ static void monitor_readline_flush(void *opaque) void monitor_new_hmp(const char *id, const char *chardev_id, bool use_readline, Error **errp) { - ERRP_GUARD(); - MonitorHMP *mon; g_autofree char *autoid =3D id ? NULL : monitor_compat_id(); - Object *obj =3D object_new_with_props(TYPE_MONITOR_HMP, - object_get_objects_root(), - id ? id : autoid, - errp, - "chardev", chardev_id, - "readline", use_readline ? "yes" := "no", - NULL); - - if (!obj) { - return; - } + object_new_with_props(TYPE_MONITOR_HMP, + object_get_objects_root(), + id ? id : autoid, + errp, + "chardev", chardev_id, + "readline", use_readline ? "yes" : "no", + NULL); +} =20 - mon =3D MONITOR_HMP(obj); +static void monitor_hmp_complete(UserCreatable *uc, Error **errp) +{ + MonitorHMP *mon =3D MONITOR_HMP(uc); + UserCreatableClass *ucc_parent =3D + USER_CREATABLE_CLASS( + object_class_get_parent( + OBJECT_CLASS(MONITOR_HMP_GET_CLASS(mon)))); + ERRP_GUARD(); =20 - monitor_complete(MONITOR(mon), errp); + ucc_parent->complete(uc, errp); if (*errp) { - object_unparent(OBJECT(mon)); return; } =20 - if (mon->use_readline) { - mon->rs =3D readline_init(monitor_readline_printf, - monitor_readline_flush, - mon, - monitor_find_completion); - monitor_read_command(mon, 0); + if (mon->parent_obj.chardev_id) { + if (mon->use_readline) { + mon->rs =3D readline_init(monitor_readline_printf, + monitor_readline_flush, + mon, + monitor_find_completion); + monitor_read_command(mon, 0); + } + + qemu_chr_fe_set_handlers(&mon->parent_obj.chr, + monitor_can_read, + monitor_read, + monitor_event, NULL, + &mon->parent_obj, NULL, true); + monitor_list_append(&mon->parent_obj); } +} =20 - qemu_chr_fe_set_handlers(&mon->parent_obj.chr, - monitor_can_read, monitor_read, monitor_event, - NULL, &mon->parent_obj, NULL, true); - monitor_list_append(&mon->parent_obj); +static bool monitor_hmp_prepare_delete(UserCreatable *uc, Error **errp) +{ + error_setg(errp, "Deleting HMP monitors is not supported"); + return false; } =20 /** diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index fe5703af6d..012d442a20 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -204,7 +204,6 @@ extern QmpCommandList qmp_commands, qmp_cap_negotiation= _commands; extern QemuMutex monitor_lock; extern MonitorList mon_list; =20 -void monitor_complete(Monitor *mon, Error **errp); bool monitor_requires_iothread(const Monitor *mon); int monitor_can_read(void *opaque); void monitor_list_append(Monitor *mon); diff --git a/monitor/monitor.c b/monitor/monitor.c index f1b189c1c2..f0ca6b04ed 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -29,6 +29,7 @@ #include "qapi/qapi-emit-events.h" #include "qapi/qapi-visit-control.h" #include "qobject/qdict.h" +#include "qom/object_interfaces.h" #include "qemu/error-report.h" #include "qemu/option.h" #include "system/qtest.h" @@ -75,7 +76,8 @@ static bool monitor_destroyed; =20 int monitor_device_index; =20 -OBJECT_DEFINE_ABSTRACT_TYPE(Monitor, monitor, MONITOR, OBJECT); +OBJECT_DEFINE_TYPE_EXTENDED(Monitor, monitor, MONITOR, OBJECT, true, + { TYPE_USER_CREATABLE }, {}); =20 static void monitor_finalize(Object *obj) { @@ -103,11 +105,17 @@ static void monitor_set_chardev_id(Object *obj, const= char *str, Error **errp) mon->chardev_id =3D g_strdup(str); } =20 +static void monitor_complete(UserCreatable *uc, Error **errp); + static void monitor_class_init(ObjectClass *cls, const void *data) { + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(cls); + object_class_property_add_str(cls, "chardev", monitor_get_chardev_id, monitor_set_chardev_id); + + ucc->complete =3D monitor_complete; } =20 static void monitor_init(Object *obj) @@ -689,8 +697,10 @@ char *monitor_compat_id(void) return g_strdup_printf("compat_monitor%d", monitor_device_index++); } =20 -void monitor_complete(Monitor *mon, Error **errp) +static void monitor_complete(UserCreatable *uc, Error **errp) { + Monitor *mon =3D MONITOR(uc); + if (mon->chardev_id) { Chardev *chr =3D qemu_chr_find(mon->chardev_id); if (chr =3D=3D NULL) { diff --git a/monitor/qmp.c b/monitor/qmp.c index bd3e6f8375..67ee491f5a 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -31,6 +31,7 @@ #include "qobject/qdict.h" #include "qobject/qjson.h" #include "qobject/qlist.h" +#include "qom/object_interfaces.h" #include "trace.h" =20 /* @@ -101,10 +102,13 @@ static void monitor_qmp_set_pretty(Object *obj, bool = val, Error **errp) =20 static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *q= dict); static bool monitor_qmp_requires_iothread(const Monitor *mon); +static void monitor_qmp_complete(UserCreatable *uc, Error **errp); +static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp); =20 static void monitor_qmp_class_init(ObjectClass *cls, const void *data) { MonitorClass *moncls =3D MONITOR_CLASS(cls); + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(cls); =20 object_class_property_add_bool(cls, "pretty", monitor_qmp_get_pretty, @@ -112,6 +116,9 @@ static void monitor_qmp_class_init(ObjectClass *cls, co= nst void *data) =20 moncls->emit_event =3D monitor_qmp_emit_event; moncls->requires_iothread =3D monitor_qmp_requires_iothread; + + ucc->complete =3D monitor_qmp_complete; + ucc->prepare_delete =3D monitor_qmp_prepare_delete; } =20 static void handle_qmp_command(void *opaque, QObject *req, Error *err); @@ -583,25 +590,27 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) void monitor_new_qmp(const char *id, const char *chardev_id, bool pretty, Error **errp) { - ERRP_GUARD(); - MonitorQMP *mon; g_autofree char *autoid =3D id ? NULL : monitor_compat_id(); - Object *obj =3D object_new_with_props(TYPE_MONITOR_QMP, - object_get_objects_root(), - id ? id : autoid, - errp, - "chardev", chardev_id, - "pretty", pretty ? "yes" : "no", - NULL); - - if (!obj) { - return; - } + object_new_with_props(TYPE_MONITOR_QMP, + object_get_objects_root(), + id ? id : autoid, + errp, + "chardev", chardev_id, + "pretty", pretty ? "yes" : "no", + NULL); +} =20 - mon =3D MONITOR_QMP(obj); - monitor_complete(MONITOR(mon), errp); +static void monitor_qmp_complete(UserCreatable *uc, Error **errp) +{ + MonitorQMP *mon =3D MONITOR_QMP(uc); + UserCreatableClass *ucc_parent =3D + USER_CREATABLE_CLASS( + object_class_get_parent( + OBJECT_CLASS(MONITOR_QMP_GET_CLASS(mon)))); + ERRP_GUARD(); + + ucc_parent->complete(uc, errp); if (*errp) { - object_unparent(OBJECT(mon)); return; } =20 @@ -633,3 +642,9 @@ void monitor_new_qmp(const char *id, const char *charde= v_id, monitor_list_append(&mon->parent_obj); } } + +static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp) +{ + error_setg(errp, "Deleting QMP monitors is not supported"); + return false; +} diff --git a/qapi/qom.json b/qapi/qom.json index dd45ac1087..33a827b9fa 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1187,6 +1187,45 @@ 'data': { '*cpu-affinity': ['uint16'], '*node-affinity': ['uint16'] } } =20 +## +# @MonitorProperties: +# +# Properties for all monitors +# +# @chardev: ID of the character device providing the monitor transport +# +# Since: 11.1 +## +{ 'struct': 'MonitorProperties', + 'data': { 'chardev': 'str' }} + +## +# @MonitorHMPProperties: +# +# Properties for the HMP monitor +# +# @readline: whether to enable readline for line editing +# (default: true) +# +# Since: 11.1 +## +{ 'struct': 'MonitorHMPProperties', + 'base': 'MonitorProperties', + 'data': { '*readline': 'bool' } } + +## +# @MonitorQMPProperties: +# +# Properties for the QMP monitor +# +# @pretty: whether to pretty print JSON responses (default: false) +# +# Since: 11.1 +## +{ 'struct': 'MonitorQMPProperties', + 'base': 'MonitorProperties', + 'data': { '*pretty': 'bool' } } + ## # @ObjectType: # @@ -1237,6 +1276,8 @@ 'memory-backend-ram', { 'name': 'memory-backend-shm', 'if': 'CONFIG_POSIX' }, + 'monitor-hmp', + 'monitor-qmp', 'pef-guest', { 'name': 'pr-manager-helper', 'if': 'CONFIG_LINUX' }, @@ -1315,6 +1356,8 @@ 'memory-backend-ram': 'MemoryBackendProperties', 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', 'if': 'CONFIG_POSIX' }, + 'monitor-hmp': 'MonitorHMPProperties', + 'monitor-qmp': 'MonitorQMPProperties', 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties', diff --git a/stubs/monitor-internal.c b/stubs/monitor-internal.c index f94b5e5c21..731fad221e 100644 --- a/stubs/monitor-internal.c +++ b/stubs/monitor-internal.c @@ -11,4 +11,5 @@ int monitor_get_fd(Monitor *mon, const char *name, Error = **errp) void monitor_new_hmp(const char *id, const char *chardev_id, bool use_readline, Error **errp) { + g_assert_not_reached(); } diff --git a/system/vl.c b/system/vl.c index 4737c03872..63bdd06dfa 100644 --- a/system/vl.c +++ b/system/vl.c @@ -1829,6 +1829,10 @@ static void object_option_add_visitor(Visitor *v) { ObjectOption *opt =3D g_new0(ObjectOption, 1); visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal); + if (opt->opts->qom_type =3D=3D OBJECT_TYPE_MONITOR_HMP || + opt->opts->qom_type =3D=3D OBJECT_TYPE_MONITOR_QMP) { + default_monitor =3D 0; + } QTAILQ_INSERT_TAIL(&object_opts, opt, next); } =20 @@ -1970,7 +1974,9 @@ static bool object_create_early(const char *type) =20 /* Reason: property "chardev" */ if (g_str_equal(type, "rng-egd") || - g_str_equal(type, "qtest")) { + g_str_equal(type, "qtest") || + g_str_equal(type, "monitor-hmp") || + g_str_equal(type, "monitor-qmp")) { return false; } =20 --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346520; cv=none; d=zohomail.com; s=zohoarc; b=IhKBMI/2eYIFVN08mMtPxge43kBGwAthmzjSVJq3yc/Uuxhi6eyhbcuFHkqGDU2iGeN7W0R6dhgZnGMI/Jne4jmG2NYyBR/USDYL1ttOtudUb49+CXLUqSDXvU+krD8VZQLnrgl4wUbwSTzv21RBFvv6P+X+YavksMFf0IcyG+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346520; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bKaf1G62jkNrohllvF71Q/jzAmAi/tWYP5jrT7rBBJ0=; b=ipDldmZKGPS0Q7pA9E6P6guqmMkglVX/vewnF5gMyy8zvUD9OOqGEf/JMXceCO5kPk0OjEg3Nh7KsPuYMhbXc5U3dt9lYxnVGNu9w6x9SrwQEPHaOTlBTQRYRcMDGRDboBhNmvf8RkAQlDRlQ3mI9WbeDq1zBGqU+PU761du8Dg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346520404860.1832619535386; Mon, 6 Jul 2026 07:02:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrq-0004Ik-G2; Mon, 06 Jul 2026 10:00:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjro-00048o-Oz for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrn-0002Br-18 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:12 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-533-TDNayGcfPe-tkgnX-KhfOw-1; Mon, 06 Jul 2026 10:00:06 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EDFD18052FE; Mon, 6 Jul 2026 14:00:05 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C37A3000B4D; Mon, 6 Jul 2026 14:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bKaf1G62jkNrohllvF71Q/jzAmAi/tWYP5jrT7rBBJ0=; b=HhErrFF7UEj7Lg6BkrR3E3zJeYhHI1RLw1sIKLKhOey4+7kaznrQUAdMWcgrsGLoO1fhfk L+wEMIqY0Ku3ArbZO3ZS2XG0JDygVM/tVirTexo90lxlSzRwJdrgdMcS7LFZQFuHVrBdgg ddonXB6/0HivXYzFDmL87NvzDfr7Mac= X-MC-Unique: TDNayGcfPe-tkgnX-KhfOw-1 X-Mimecast-MFC-AGG-ID: TDNayGcfPe-tkgnX-KhfOw_1783346405 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 24/35] monitor: convert from oneshot BH to persistent BH Date: Mon, 6 Jul 2026 14:58:12 +0100 Message-ID: <20260706135824.2623960-25-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346522846158500 From: Christian Brauner Convert monitor_accept_input from a oneshot BH (aio_bh_schedule_oneshot) to a persistent BH (aio_bh_new + qemu_bh_schedule). Oneshot BHs cannot be cancelled, so monitor_resume() racing with destruction would schedule a callback against memory that monitor_qmp_destroy() is about to free. A persistent BH can be deleted during destruction, cancelling any pending schedule. Signed-off-by: Christian Brauner (Amutable) [DB: extracted oneshot BH conversion from larger commit] Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/monitor-internal.h | 2 +- monitor/monitor.c | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 012d442a20..a82e1aacb6 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -134,7 +134,7 @@ struct Monitor { char *chardev_id; CharFrontend chr; int suspend_cnt; /* Needs to be accessed atomically */ - + QEMUBH *accept_input_bh; /* persistent BH for monitor_accept_input = */ char *mon_cpu_path; QTAILQ_ENTRY(Monitor) entry; =20 diff --git a/monitor/monitor.c b/monitor/monitor.c index f0ca6b04ed..de1f761041 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -83,6 +83,9 @@ static void monitor_finalize(Object *obj) { Monitor *mon =3D MONITOR(obj); =20 + if (mon->accept_input_bh) { + qemu_bh_delete(mon->accept_input_bh); + } g_free(mon->chardev_id); g_free(mon->mon_cpu_path); qemu_chr_fe_deinit(&mon->chr, false); @@ -569,15 +572,7 @@ static void monitor_accept_input(void *opaque) void monitor_resume(Monitor *mon) { if (qatomic_dec_fetch(&mon->suspend_cnt) =3D=3D 0) { - AioContext *ctx; - - if (monitor_requires_iothread(mon)) { - ctx =3D iothread_get_aio_context(mon_iothread); - } else { - ctx =3D qemu_get_aio_context(); - } - - aio_bh_schedule_oneshot(ctx, monitor_accept_input, mon); + qemu_bh_schedule(mon->accept_input_bh); } =20 trace_monitor_suspend(mon, -1); @@ -700,6 +695,7 @@ char *monitor_compat_id(void) static void monitor_complete(UserCreatable *uc, Error **errp) { Monitor *mon =3D MONITOR(uc); + AioContext *ctx; =20 if (mon->chardev_id) { Chardev *chr =3D qemu_chr_find(mon->chardev_id); @@ -713,9 +709,16 @@ static void monitor_complete(UserCreatable *uc, Error = **errp) } } =20 - if (monitor_requires_iothread(mon) && !mon_iothread) { - mon_iothread =3D iothread_create("mon_iothread", &error_abort); + if (monitor_requires_iothread(mon)) { + if (!mon_iothread) { + mon_iothread =3D iothread_create("mon_iothread", &error_abort); + } + + ctx =3D iothread_get_aio_context(mon_iothread); + } else { + ctx =3D qemu_get_aio_context(); } + mon->accept_input_bh =3D aio_bh_new(ctx, monitor_accept_input, mon); } =20 int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346624; cv=none; d=zohomail.com; s=zohoarc; b=XAiwuJpiJ1w3nUm1VInbH877X53+b3uxzMZFzLX1g75BPm+vAaTh9TvN7ZGVUhIyAlRCGJfsXeaCQXfHfSQfBULaCgeI20PyrEAY378Tg4DXJfZb273ZwgVstEFA7ZXKWQgqoQfn8WdpVbrVlHymAuooKvHJCwa3ndOIeu/RfDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346624; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RNSaQHktR+A/MgrymT5azxZ5ZUePYKqL0lOeXeit0N8=; b=DOtbgtjXE3nxuPYDY2jLfjE0NH6vvIla4jKqZSZu9RR9EVOlq0j3HvwQ5T0PUetMIyWFzUkKg2eZBclR5sOmZBxjWtaRtzokOpQZSKqG9fPPEHxLt8GQw9/Vq/JwHIf1EhLKQXDHGi1/ivZMjNTTmlXGdLIPIk6uLn+2nIrrZlA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346624608975.5637269982511; Mon, 6 Jul 2026 07:03:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjrx-0004j9-SB; Mon, 06 Jul 2026 10:00:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrs-0004VN-9u for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrq-0002FL-HO for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:16 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-_Au4mH3EOaS36PYCI26eUA-1; Mon, 06 Jul 2026 10:00:10 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 30A7E18009D8; Mon, 6 Jul 2026 14:00:09 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF2CD3000B4E; Mon, 6 Jul 2026 14:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RNSaQHktR+A/MgrymT5azxZ5ZUePYKqL0lOeXeit0N8=; b=eOwo8E5Qx+s5PaKG719XsSGEP8/oUVAKHOwx/6KmCVWzaevsU9UlDUEwsQPIhBRP5dLbeh mtaXGg+fzOrLb2fIjqE0X3hALa7Sb5d1M/IEzjJDBPBy+X2VJGzb2We0aNBanrdf99IaJg KHz8XWa7OhCoWiBfOGxg6d5VbPsz3mw= X-MC-Unique: _Au4mH3EOaS36PYCI26eUA-1 X-Mimecast-MFC-AGG-ID: _Au4mH3EOaS36PYCI26eUA_1783346409 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 25/35] monitor: reject attempts to delete the current monitor Date: Mon, 6 Jul 2026 14:58:13 +0100 Message-ID: <20260706135824.2623960-26-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346626114158500 From: Christian Brauner If an 'object_del' command for a QMP monitor arrives targetting the current monitor, reject this request. If the current monitor is deleted, it will be impossible to send any reply and the client won't be able to remove the corresponding chardev backend. Note, it is not possible to rely on checking monitor_cur() because if 'object_del' is called via human-monitor-command, monitor_cur() will reflect the temporary HMP, not the QMP target that needs to be checked. Signed-off-by: Christian Brauner (Amutable) [DB: extracted monitor tracking from larger commit; added logic to monitor_qmp_prepare_delete to reject request] Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/qmp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/monitor/qmp.c b/monitor/qmp.c index 67ee491f5a..1c67f40e4a 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -72,6 +72,9 @@ typedef struct QMPRequest QMPRequest; =20 QmpCommandList qmp_commands, qmp_cap_negotiation_commands; =20 +/* Monitor being serviced by the dispatcher. Protected by BQL. */ +static MonitorQMP *qmp_dispatcher_current_mon; + OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR); =20 static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon); @@ -369,6 +372,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data) */ =20 mon =3D req_obj->mon; + qmp_dispatcher_current_mon =3D mon; =20 /* * We need to resume the monitor if handle_qmp_command() @@ -429,6 +433,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data) } =20 qmp_request_free(req_obj); + qmp_dispatcher_current_mon =3D NULL; } qatomic_set(&qmp_dispatcher_co, NULL); } @@ -573,6 +578,11 @@ static void monitor_qmp_event(void *opaque, QEMUChrEve= nt event) } } =20 +static bool monitor_qmp_dispatcher_is_servicing(MonitorQMP *mon) +{ + return qmp_dispatcher_current_mon =3D=3D mon; +} + static void monitor_qmp_setup_handlers_bh(void *opaque) { MonitorQMP *mon =3D opaque; @@ -645,6 +655,13 @@ static void monitor_qmp_complete(UserCreatable *uc, Er= ror **errp) =20 static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp) { + MonitorQMP *qmp =3D MONITOR_QMP(uc); + + if (monitor_qmp_dispatcher_is_servicing(qmp)) { + error_setg(errp, "Cannot delete the current QMP monitor"); + return false; + } + error_setg(errp, "Deleting QMP monitors is not supported"); return false; } --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346457; cv=none; d=zohomail.com; s=zohoarc; b=OnDZXJxp02KRyiLNwY4Q+pt6a/lIPRFOPsNVpWr6L5fcNejwz4kCjirzEM9fa6NfS3CThEFing/123AO+O10iO5XyMMesgeNBImjL0l4Vs6x9tSmpBCg6W2ZS9fO72+F3Mju4PXdOCIKoP/6pbWx6yPcy22NDu7dghogXCsigLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346457; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Fl5EPhcFPPfv/Io+HSRS8V+d5PwlGFdl+hbJW94wq+w=; b=HqOg5MTw1dCPvDu6BO+Y9gkqjNwZmBGUqSKoWUOOpqmpfw/jpURmRfkzbN92I+1JV/234SeGX5Dmygslf1sg4CohwQT2m2TaUHYWY3h5zVFHy/rArv+42/lgN88EIxdFBWP4ayXWzNkeOSBmL6Slmf196zy0I4o1uAqMjt8d/es= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346457480263.92846746637065; Mon, 6 Jul 2026 07:00:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsA-0004rH-Jd; Mon, 06 Jul 2026 10:00:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjry-0004l5-7h for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrw-0002Fr-Fd for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:21 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-58-FHozwRZmNJO-wkvBa8WW6A-1; Mon, 06 Jul 2026 10:00:14 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6BE8D1800D85; Mon, 6 Jul 2026 14:00:13 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A369F3000B54; Mon, 6 Jul 2026 14:00:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fl5EPhcFPPfv/Io+HSRS8V+d5PwlGFdl+hbJW94wq+w=; b=NuyQ/XjuG2UlcUdPWGxNbtkTXlYP7qmN3ZZkbNsccWFfvhhWfCN2gRCj1qWQmJYq90MySu 3PYwzgSd2//zmUhLvuhm3Dcrs9cSG9+4WVe7IHSV2T7FWIkZtBCNMxZbTii8/5Iap8dNDX QsS09VhkM5HKfFRISYKNskBDL8V4Ydo= X-MC-Unique: FHozwRZmNJO-wkvBa8WW6A-1 X-Mimecast-MFC-AGG-ID: FHozwRZmNJO-wkvBa8WW6A_1783346413 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 26/35] monitor: protect qemu_chr_fe_accept_input with monitor lock Date: Mon, 6 Jul 2026 14:58:14 +0100 Message-ID: <20260706135824.2623960-27-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346457979158500 From: Christian Brauner The monitor_accept_input API is called from a bottom half, and will invoke qemu_chr_fe_accept_input(). When a following patch introduces the ability to delete monitors, it will be neccesary to delete the bottom half. Protecting the call to qemu_chr_fe_accept_input with the monitor lock will allow for synchronization with the deletion process. Signed-off-by: Christian Brauner (Amutable) [DB: extracted from a larger commit and refactored to apply to the new monitor class structure] Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/hmp.c | 2 ++ monitor/monitor.c | 6 +----- monitor/qmp.c | 9 +++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index 75b93f29a3..71a1888249 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -116,9 +116,11 @@ static void monitor_hmp_accept_input(Monitor *mon) MonitorHMP *hmp =3D MONITOR_HMP(mon); assert(hmp->rs); readline_restart(hmp->rs); + qemu_chr_fe_accept_input(&mon->chr); qemu_mutex_unlock(&mon->mon_lock); readline_show_prompt(hmp->rs); } else { + qemu_chr_fe_accept_input(&mon->chr); qemu_mutex_unlock(&mon->mon_lock); } } diff --git a/monitor/monitor.c b/monitor/monitor.c index de1f761041..4a45c15a36 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -562,11 +562,7 @@ static void monitor_accept_input(void *opaque) Monitor *mon =3D opaque; MonitorClass *cls =3D MONITOR_GET_CLASS(mon); =20 - if (cls->accept_input) { - cls->accept_input(mon); - } - - qemu_chr_fe_accept_input(&mon->chr); + cls->accept_input(mon); } =20 void monitor_resume(Monitor *mon) diff --git a/monitor/qmp.c b/monitor/qmp.c index 1c67f40e4a..dc15809145 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -107,6 +107,7 @@ static void monitor_qmp_emit_event(Monitor *mon, QAPIEv= ent event, QDict *qdict); static bool monitor_qmp_requires_iothread(const Monitor *mon); static void monitor_qmp_complete(UserCreatable *uc, Error **errp); static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp); +static void monitor_qmp_accept_input(Monitor *mon); =20 static void monitor_qmp_class_init(ObjectClass *cls, const void *data) { @@ -119,6 +120,7 @@ static void monitor_qmp_class_init(ObjectClass *cls, co= nst void *data) =20 moncls->emit_event =3D monitor_qmp_emit_event; moncls->requires_iothread =3D monitor_qmp_requires_iothread; + moncls->accept_input =3D monitor_qmp_accept_input; =20 ucc->complete =3D monitor_qmp_complete; ucc->prepare_delete =3D monitor_qmp_prepare_delete; @@ -665,3 +667,10 @@ static bool monitor_qmp_prepare_delete(UserCreatable *= uc, Error **errp) error_setg(errp, "Deleting QMP monitors is not supported"); return false; } + +static void monitor_qmp_accept_input(Monitor *mon) +{ + WITH_QEMU_LOCK_GUARD(&mon->mon_lock) { + qemu_chr_fe_accept_input(&mon->chr); + } +} --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346564; cv=none; d=zohomail.com; s=zohoarc; b=gukaWkwBexrZW8PNDytM98o/hIOlD2oa9xhvbq6nnOpmYHFwe2IOWBnHZN1j0qfcgNSE8VFzitMvMo0hAgcRmbZ2ocOTRnoxPvC9vAZAPbKqr63Yv1MeDDIWS8AdxLc1/wRWSsCnXI0jv16n6AMFAQYosf7AXef2uXdvPlMhWiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346564; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lQqYTdZqVINfz4rN5yt2noQf4zZl0P8fiYugTc4W+Ic=; b=Tg38Aa7iWQag2AxqYngzqBIANBiySN4h72KlIeRFGzOUy2C0g2BAjcYDn1qBlRtofX+yDEsMFhyKGwig6jRY3fuODw80UgtzJP9mOg7KhNMzQzM9KQnX5HWAoi8pg3onkQTz4Z2kvq6soR2pZOxdZVlO5nIQT1+hCVs3Nkd++kE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346564735445.06941756217736; Mon, 6 Jul 2026 07:02:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsK-0005E7-8p; Mon, 06 Jul 2026 10:00:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjs0-0004mp-3H for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjrw-0002Fw-JF for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:22 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-402-i2UObz6NMGeZtys4wnntKw-1; Mon, 06 Jul 2026 10:00:18 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4C8C51955EB9; Mon, 6 Jul 2026 14:00:17 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB91E3000B4E; Mon, 6 Jul 2026 14:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lQqYTdZqVINfz4rN5yt2noQf4zZl0P8fiYugTc4W+Ic=; b=PpJhYlLBZSIRLcH7ZmUffGq7Qw3hics4+x6NO1TG7KohWPOGM+DMZWD9D1Ucbgb8E5/KQv zlnOHP4PpH4Dp5Cy4lE001HoaGLq44LTu/hyZeHWT2BMQLdCfWLP1Cklo336Fho4sNqkt9 z9alhjxCi742sdwNSs55Za77AKPUt9I= X-MC-Unique: i2UObz6NMGeZtys4wnntKw-1 X-Mimecast-MFC-AGG-ID: i2UObz6NMGeZtys4wnntKw_1783346417 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 27/35] monitor: implement support for deleting QMP objects Date: Mon, 6 Jul 2026 14:58:15 +0100 Message-ID: <20260706135824.2623960-28-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346567464158500 From: Christian Brauner The removal sequence is: 1. Remove from mon_list under monitor_lock. This must happen before disconnecting chardev handlers to prevent event broadcast from calling monitor_flush_locked() after the gcontext reset, which would create an out_watch on the wrong GMainContext (see monitor_cancel_out_watch()). 2. Cancel any pending out_watch while gcontext still points to the correct context. 3. Disconnect chardev handlers, passing context=3DNULL and close the connection. 4. Drain pending requests from any in-flight monitor_qmp_read(). 5. Destroy the monitor object Signed-off-by: Christian Brauner (Amutable) [DB: extracted from a larger commit and refactored to apply to the new monitor class structure. Remove 'self delete' feature which requires complex special-case code] Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- monitor/monitor-internal.h | 2 ++ monitor/monitor.c | 22 ++++++++++++++++ monitor/qmp.c | 54 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index a82e1aacb6..5522e05464 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -178,6 +178,7 @@ struct MonitorQMP { Monitor parent_obj; JSONMessageParser parser; bool pretty; + bool setup_pending; /* iothread BH has not yet set up chardev handlers= */ /* * When a client connects, we're in capabilities negotiation mode. * @commands is &qmp_cap_negotiation_commands then. When command @@ -206,6 +207,7 @@ extern MonitorList mon_list; =20 bool monitor_requires_iothread(const Monitor *mon); int monitor_can_read(void *opaque); +void monitor_cancel_out_watch(Monitor *mon); void monitor_list_append(Monitor *mon); void monitor_fdsets_cleanup(void); int monitor_set_cpu(Monitor *mon, int cpu_index); diff --git a/monitor/monitor.c b/monitor/monitor.c index 4a45c15a36..ed195fd97b 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -179,6 +179,28 @@ static gboolean monitor_unblocked(void *do_not_use, GI= OCondition cond, return G_SOURCE_REMOVE; } =20 +/* Cancel a pending out_watch GSource. Caller must hold mon_lock. */ +void monitor_cancel_out_watch(Monitor *mon) +{ + if (mon->out_watch) { + GMainContext *ctx =3D NULL; + GSource *src; + + if (monitor_requires_iothread(mon)) { + ctx =3D iothread_get_g_main_context(mon_iothread); + } + src =3D g_main_context_find_source_by_id(ctx, mon->out_watch); + if (!src && ctx) { + /* Handler disconnect may have reset gcontext to NULL. */ + src =3D g_main_context_find_source_by_id(NULL, mon->out_watch); + } + if (src) { + g_source_destroy(src); + } + mon->out_watch =3D 0; + } +} + /* Caller must hold mon->mon_lock */ void monitor_flush_locked(Monitor *mon) { diff --git a/monitor/qmp.c b/monitor/qmp.c index dc15809145..2bec0f3c96 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -184,6 +184,12 @@ static void monitor_qmp_cleanup_req_queue_locked(Monit= orQMP *mon) } } =20 +static void monitor_qmp_drain_queue(MonitorQMP *mon) +{ + QEMU_LOCK_GUARD(&mon->qmp_queue_lock); + monitor_qmp_cleanup_req_queue_locked(mon); +} + static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon) { QEMU_LOCK_GUARD(&mon->qmp_queue_lock); @@ -597,6 +603,7 @@ static void monitor_qmp_setup_handlers_bh(void *opaque) monitor_qmp_read, monitor_qmp_event, NULL, &mon->parent_obj, context, true); monitor_list_append(&mon->parent_obj); + qatomic_set(&mon->setup_pending, false); } =20 void monitor_new_qmp(const char *id, const char *chardev_id, @@ -644,6 +651,7 @@ static void monitor_qmp_complete(UserCreatable *uc, Err= or **errp) * since chardev might be running in the monitor I/O * thread. Schedule a bottom half. */ + mon->setup_pending =3D true; 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 */ @@ -655,8 +663,14 @@ static void monitor_qmp_complete(UserCreatable *uc, Er= ror **errp) } } =20 +static void monitor_qmp_iothread_quiesce(void *opaque) +{ + /* No-op: synchronization point only */ +} + static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp) { + Monitor *mon =3D MONITOR(uc); MonitorQMP *qmp =3D MONITOR_QMP(uc); =20 if (monitor_qmp_dispatcher_is_servicing(qmp)) { @@ -664,8 +678,44 @@ static bool monitor_qmp_prepare_delete(UserCreatable *= uc, Error **errp) return false; } =20 - error_setg(errp, "Deleting QMP monitors is not supported"); - return false; + if (qatomic_read(&qmp->setup_pending)) { + error_setg(errp, "monitor is still initializing"); + return false; + } + + /* Remove from mon_list before chardev disconnect. */ + WITH_QEMU_LOCK_GUARD(&monitor_lock) { + QTAILQ_REMOVE(&mon_list, mon, entry); + } + + /* Cancel out_watch while gcontext still points to the right ctx. */ + WITH_QEMU_LOCK_GUARD(&mon->mon_lock) { + monitor_cancel_out_watch(mon); + } + + qemu_chr_fe_set_handlers(&mon->chr, NULL, NULL, NULL, NULL, + NULL, NULL, true); + + /* Drain requests from any in-flight monitor_qmp_read(). */ + monitor_qmp_drain_queue(qmp); + + WITH_QEMU_LOCK_GUARD(&mon->mon_lock) { + /* Disable flushes before cancel -- gcontext is already wrong. */ + qemu_chr_fe_set_open(&mon->chr, false); + monitor_cancel_out_watch(mon); + } + + /* Synchronize with in-flight iothread callbacks. */ + if (monitor_requires_iothread(mon)) { + aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread), + monitor_qmp_iothread_quiesce, NULL); + } + + /* Catch requests from a racing monitor_qmp_read(). */ + monitor_qmp_drain_queue(qmp); + monitor_fdsets_cleanup(); + + return true; } =20 static void monitor_qmp_accept_input(Monitor *mon) --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346454; cv=none; d=zohomail.com; s=zohoarc; b=b88IiBC7A/cdvhroH6IE0oohscCJsnADtsQdgseSmoT87yvdf6rxPfB8sbAmQUPRC7Ww/NmzkkSH6v1EsifrLL5B+FUssa7Rawa/FsozXr4X0JuZm+tkL0PSEQUuwFua2qfcdsfMgBx7gI6ycZgPS4BL5dNANkvI5Ho6J7QC2sY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346454; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kPsENzK9iISJvPWHQbgNDXzgaKpjXtLxpXR33/3zA3s=; b=Zdq6RSXA0rsQeKhIQBMiXn7hqsunwCdca+FgLnljHeiGC7A74P8pL70oD42XogbjhqaU+7J83OY0ZKkl66AUvduZ12I36/t87gegy+OpgkKTNUdxVeMtZe1OIRfsIQRC8yO1MYbZVSRkZAtsgjE0kF+fe57If6jizAme0S13YsQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346454820564.1940844028496; Mon, 6 Jul 2026 07:00:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsJ-0005Co-Va; Mon, 06 Jul 2026 10:00:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjs4-0004rJ-RG for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjs2-0002HC-Go for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:28 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-231-QwKOl_T4M9WyHHGLZi2W8A-1; Mon, 06 Jul 2026 10:00:22 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1074C1955D96; Mon, 6 Jul 2026 14:00:21 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BB0613000B4E; Mon, 6 Jul 2026 14:00:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kPsENzK9iISJvPWHQbgNDXzgaKpjXtLxpXR33/3zA3s=; b=KPAmawoS0Ija5q0xTEJevJCLDPio+pMm6neFkPwhh9oKxQ62VAV6FDhP+mZkA5Dmtbs3m+ xtBx2qBvlZt3Ghs5NZlCj4Yi/O4GWh5TAHjMiF2HZNaSaXRZq0BVOV2iLP4uStBsy42/0J Y/0pY6G67yKuidgiWSKPGBTcmB2rpvU= X-MC-Unique: QwKOl_T4M9WyHHGLZi2W8A-1 X-Mimecast-MFC-AGG-ID: QwKOl_T4M9WyHHGLZi2W8A_1783346421 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 28/35] tests/qtest: add tests for dynamic monitor add/remove Date: Mon, 6 Jul 2026 14:58:16 +0100 Message-ID: <20260706135824.2623960-29-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346455951158500 From: Christian Brauner Test the object-add/object-del QMP commands with the monitor-qmp object type. - Basic lifecycle: chardev-add -> object-add -> object-del -> chardev-remove - Error: object-add with nonexistent chardev - Error: second monitor on same chardev (chardev already in use) - Removal of CLI-created QMP monitor succeeds - Error: object-remove on HMP monitor - Re-add after remove: same id and chardev reusable after removal Signed-off-by: Christian Brauner (Amutable) [DB: modified to use object-add/object-del, removing redundant scenarios already handled by object-add/del code] Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- tests/qtest/qmp-test.c | 174 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c index edf0886787..3a325a04e0 100644 --- a/tests/qtest/qmp-test.c +++ b/tests/qtest/qmp-test.c @@ -337,6 +337,174 @@ static void test_qmp_missing_any_arg(void) qtest_quit(qts); } =20 +static void test_qmp_monitor_add_remove(void) +{ + QTestState *qts; + QDict *resp; + + qts =3D qtest_init(common_args); + + /* Create a null chardev for the dynamic monitor */ + resp =3D qtest_qmp(qts, + "{'execute': 'chardev-add'," + " 'arguments': {'id': 'monitor-chardev'," + " 'backend': {'type': 'null'," + " 'data': {}}}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + /* Add a dynamic monitor */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-add'," + " 'arguments': {'qom-type': 'monitor-qmp'," + " 'id': 'dyn-mon'," + " 'chardev': 'monitor-chardev'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + /* Remove the dynamic monitor */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-del'," + " 'arguments': {'id': 'dyn-mon'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + /* Add again after remove -- same id and chardev should work */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-add'," + " 'arguments': {'qom-type': 'monitor-qmp'," + " 'id': 'dyn-mon'," + " 'chardev': 'monitor-chardev'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + /* Clean up */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-del'," + " 'arguments': {'id': 'dyn-mon'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + resp =3D qtest_qmp(qts, + "{'execute': 'chardev-remove'," + " 'arguments': {'id': 'monitor-chardev'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + qtest_quit(qts); +} + +static void test_qmp_monitor_error_paths(void) +{ + QTestState *qts; + QDict *resp; + + qts =3D qtest_init(common_args); + + /* Error: chardev does not exist */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-add'," + " 'arguments': {'qom-type': 'monitor-qmp'," + " 'id': 'bad-mon'," + " 'chardev': 'nonexistent'}}"); + qmp_expect_error_and_unref(resp, "GenericError"); + + qtest_quit(qts); +} + +static void test_qmp_monitor_chardev_in_use(void) +{ + QTestState *qts; + QDict *resp; + + qts =3D qtest_init(common_args); + + /* Create a null chardev */ + resp =3D qtest_qmp(qts, + "{'execute': 'chardev-add'," + " 'arguments': {'id': 'shared-chr'," + " 'backend': {'type': 'null'," + " 'data': {}}}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + /* Attach first monitor */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-add'," + " 'arguments': {'qom-type': 'monitor-qmp'," + " 'id': 'mon-1'," + " 'chardev': 'shared-chr'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + /* Error: second monitor on the same chardev */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-add'," + " 'arguments': {'qom-type': 'monitor-qmp'," + " 'id': 'mon-2'," + " 'chardev': 'shared-chr'}}"); + qmp_expect_error_and_unref(resp, "GenericError"); + + /* Clean up */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-del'," + " 'arguments': {'id': 'mon-1'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + resp =3D qtest_qmp(qts, + "{'execute': 'chardev-remove'," + " 'arguments': {'id': 'shared-chr'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + qtest_quit(qts); +} + +static void test_qmp_monitor_remove_cli(void) +{ + QTestState *qts; + QDict *resp; + + /* Launch with a named CLI monitor on a null chardev */ + qts =3D qtest_initf("%s -chardev null,id=3Dcli-chr" + " -object monitor-qmp,id=3Dcli-mon,chardev=3Dcli-chr= ", + common_args); + + /* CLI-created QMP monitors can be removed */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-del'," + " 'arguments': {'id': 'cli-mon'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + resp =3D qtest_qmp(qts, + "{'execute': 'chardev-remove'," + " 'arguments': {'id': 'cli-chr'}}"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + qtest_quit(qts); +} + +static void test_qmp_monitor_remove_hmp(void) +{ + QTestState *qts; + QDict *resp; + + qts =3D qtest_initf("%s -chardev null,id=3Dhmp-chr" + " -object monitor-hmp,id=3Dhmp-mon,chardev=3Dhmp-chr= ", + common_args); + + /* Error: object_del must reject HMP monitors */ + resp =3D qtest_qmp(qts, + "{'execute': 'object-del'," + " 'arguments': {'id': 'hmp-mon'}}"); + qmp_expect_error_and_unref(resp, "GenericError"); + + qtest_quit(qts); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -348,6 +516,12 @@ int main(int argc, char *argv[]) #endif qtest_add_func("qmp/preconfig", test_qmp_preconfig); qtest_add_func("qmp/missing-any-arg", test_qmp_missing_any_arg); + qtest_add_func("qmp/monitor-add-remove", test_qmp_monitor_add_remove); + qtest_add_func("qmp/monitor-error-paths", test_qmp_monitor_error_paths= ); + qtest_add_func("qmp/monitor-chardev-in-use", + test_qmp_monitor_chardev_in_use); + qtest_add_func("qmp/monitor-remove-cli", test_qmp_monitor_remove_cli); + qtest_add_func("qmp/monitor-remove-hmp", test_qmp_monitor_remove_hmp); =20 return g_test_run(); } --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346624; cv=none; d=zohomail.com; s=zohoarc; b=MLoY985XxvfG8Tt1HKBE4KPzWmiHJ5ANPqTx1Bu7k05JmbNkJsLwHTv9bwajK9hIRA1yFoc9/iP2zb+5Q0khjU000hRFbOwJh5oO7PLA1wgEuz3STip/2NAyjKUJy9fMdD0xy7NHwHWHTDhJW+UzH7VC0KB7glqn/utwqXfZNxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346624; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Se/0ZK7eItCJ4OQQs6rXy9bI6QA70Ng5Q+Ft7l1hvT0=; b=UgkiNBArN329ttrJnKJsjLnR73JYqMc8MFfsw1KTrZzk2ukEiLzwd+yWKZAjZe79IBgaAgTi2WI6sTrb3jD9ekNcyTlDG9p2KaMPCqhcMk+0T+yumSlvCf4FtcZ92v0HuTB5WAH2ISeRvf64zMYbEq8zoyiJpVopmzQi8BQgxBs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346624106575.810052338629; Mon, 6 Jul 2026 07:03:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsL-0005P1-Fr; Mon, 06 Jul 2026 10:00:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjs8-0004vc-61 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjs6-0002Hi-12 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:31 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-f-hKBFTCNZ2o76mf8gZd_A-1; Mon, 06 Jul 2026 10:00:26 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCA911805A0B; Mon, 6 Jul 2026 14:00:24 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7FB523000B50; Mon, 6 Jul 2026 14:00:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Se/0ZK7eItCJ4OQQs6rXy9bI6QA70Ng5Q+Ft7l1hvT0=; b=Dhd221vukdRpKkvcIyBaeI7CmxyUEBydt8By9bkU/iNaosT96XjaUL6Ywttk+j9lCW412z OI0U7+L0ODlB9hMkvYX21U5rEN40cdpic6rQyoCzEaIC6ipVvHyP82dQNoF15ry9yFK28v jNYM3mJTP+PkDbCPkRFk4S8ip+/7pVg= X-MC-Unique: f-hKBFTCNZ2o76mf8gZd_A-1 X-Mimecast-MFC-AGG-ID: f-hKBFTCNZ2o76mf8gZd_A_1783346424 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 29/35] tests/functional: add e2e test for dynamic QMP monitor hotplug Date: Mon, 6 Jul 2026 14:58:17 +0100 Message-ID: <20260706135824.2623960-30-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346626163158500 From: Christian Brauner Add functional tests that exercise dynamic monitor hotplug with real socket connections: - Hotplug cycle: chardev-add a unix socket, object-add, connect to the socket, receive the QMP greeting, negotiate capabilities, send query-version, disconnect, remove the monitor and chardev, then repeat the entire cycle a second time to verify cleanup and reuse. - Self-removal: a dynamically-added monitor sends object-del targeting itself, verifying that the request is rejected - Large response: send query-qmp-schema on a dynamic monitor to exercise the output buffer flush path with a large response payload. - Events after negotiation: trigger STOP/RESUME events via the main monitor and verify they are delivered on the dynamic monitor. This complements the qtest unit tests by verifying that a real QMP client can connect to a dynamically-added monitor and exchange messages. Signed-off-by: Christian Brauner (Amutable) [DB: modified to use object-add/object-del; adjust self-removal test to validate rejection of request] Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- MAINTAINERS | 1 + tests/functional/generic/meson.build | 1 + .../generic/test_monitor_hotplug.py | 168 ++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100755 tests/functional/generic/test_monitor_hotplug.py diff --git a/MAINTAINERS b/MAINTAINERS index 97dcc78ded..eb0f9fc9ba 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3669,6 +3669,7 @@ F: docs/interop/*qmp-* F: scripts/qmp/ F: tests/qtest/qmp-test.c F: tests/qtest/qmp-cmd-test.c +F: tests/functional/generic/test_monitor_hotplug.py T: git https://repo.or.cz/qemu/armbru.git qapi-next =20 qtest diff --git a/tests/functional/generic/meson.build b/tests/functional/generi= c/meson.build index 09763c5d22..c94105c62e 100644 --- a/tests/functional/generic/meson.build +++ b/tests/functional/generic/meson.build @@ -4,6 +4,7 @@ tests_generic_system =3D [ 'empty_cpu_model', 'info_usernet', 'linters', + 'monitor_hotplug', 'version', 'vnc', ] diff --git a/tests/functional/generic/test_monitor_hotplug.py b/tests/funct= ional/generic/test_monitor_hotplug.py new file mode 100755 index 0000000000..5d8a159eb0 --- /dev/null +++ b/tests/functional/generic/test_monitor_hotplug.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Functional test for dynamic QMP monitor hotplug +# +# Copyright (c) 2026 Christian Brauner + +import os + +from qemu_test import QemuSystemTest + +from qemu.qmp.legacy import QEMUMonitorProtocol + + +class MonitorHotplug(QemuSystemTest): + + def setUp(self): + super().setUp() + sock_dir =3D self.socket_dir() + self._sock_path =3D os.path.join(sock_dir.name, 'hotplug.sock') + + def _add_monitor(self): + """Create a chardev + monitor and return the socket path.""" + sock =3D self._sock_path + self.vm.cmd('chardev-add', id=3D'hotplug-chr', backend=3D{ + 'type': 'socket', + 'data': { + 'addr': { + 'type': 'unix', + 'data': {'path': sock} + }, + 'server': True, + 'wait': False, + } + }) + self.vm.cmd('object-add', id=3D'hotplug-mon', + qom_type=3D'monitor-qmp', + chardev=3D'hotplug-chr') + return sock + + def _remove_monitor(self): + """Remove the monitor + chardev.""" + self.vm.cmd('object-del', id=3D'hotplug-mon') + self.vm.cmd('chardev-remove', id=3D'hotplug-chr') + + def _connect_and_handshake(self, sock_path): + """ + Connect to the dynamic monitor socket, perform the QMP + greeting and capability negotiation, send a command, then + disconnect. + """ + qmp =3D QEMUMonitorProtocol(sock_path) + + # connect(negotiate=3DTrue) receives the greeting, validates it, + # and sends qmp_capabilities automatically. + greeting =3D qmp.connect(negotiate=3DTrue) + self.assertIn('QMP', greeting) + self.assertIn('version', greeting['QMP']) + self.assertIn('capabilities', greeting['QMP']) + + # Send a real command to prove the session is fully functional + resp =3D qmp.cmd_obj({'execute': 'query-version'}) + self.assertIn('return', resp) + self.assertIn('qemu', resp['return']) + + qmp.close() + + def test_hotplug_cycle(self): + """ + Hotplug a monitor, do the full QMP handshake, unplug it, + then repeat the whole cycle a second time. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + # First cycle + sock =3D self._add_monitor() + self._connect_and_handshake(sock) + self._remove_monitor() + + # Second cycle -- same ids, same path, must work + sock =3D self._add_monitor() + self._connect_and_handshake(sock) + self._remove_monitor() + + def test_self_removal(self): + """ + A dynamically-added monitor sends object-del targeting + itself. Verify the request is rejected, but the monitor + can still be deleted from outside its own context. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + sock =3D self._add_monitor() + + qmp =3D QEMUMonitorProtocol(sock) + greeting =3D qmp.connect(negotiate=3DTrue) + self.assertIn('QMP', greeting) + + # Self-removal: the dynamic monitor raises error + resp =3D qmp.cmd_obj({'execute': 'object-del', + 'arguments': {'id': 'hotplug-mon'}}) + self.assertIn('error', resp) + + qmp.close() + + resp =3D self.vm.cmd('object-del', id=3D'hotplug-mon') + + # Clean up the chardev + self.vm.cmd('chardev-remove', id=3D'hotplug-chr') + + def test_large_response(self): + """ + Send a command with a large response (query-qmp-schema) on a + dynamically-added monitor to exercise the output buffer flush + path. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + sock =3D self._add_monitor() + + qmp =3D QEMUMonitorProtocol(sock) + qmp.connect(negotiate=3DTrue) + + resp =3D qmp.cmd_obj({'execute': 'query-qmp-schema'}) + self.assertIn('return', resp) + self.assertIsInstance(resp['return'], list) + self.assertGreater(len(resp['return']), 0) + + qmp.close() + self._remove_monitor() + + def test_events_after_negotiation(self): + """ + Verify that QMP events are delivered on a dynamically-added + monitor after capability negotiation completes. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + sock =3D self._add_monitor() + + qmp =3D QEMUMonitorProtocol(sock) + qmp.connect(negotiate=3DTrue) + + # Trigger a STOP event via the main monitor, then read it + # from the dynamic monitor. + self.vm.cmd('stop') + resp =3D qmp.pull_event(wait=3DTrue) + self.assertEqual(resp['event'], 'STOP') + + self.vm.cmd('cont') + resp =3D qmp.pull_event(wait=3DTrue) + self.assertEqual(resp['event'], 'RESUME') + + qmp.close() + self._remove_monitor() + + +if __name__ =3D=3D '__main__': + QemuSystemTest.main() --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346526; cv=none; d=zohomail.com; s=zohoarc; b=CHYaSaT16XgWAf1+b9QOA1i3UyY0/EBmupQ2Q09lJW/6M/YZG93CuhSHXjt+UJt/Z5u/CE77Ixri+SXOP6kGl9Y6zqqAC/kvE+jNHOYIxuRm5TXRxTqea7glFYV0hWYKNPkn1rodtycb0GSqJN8UhdYzYpqHZ8sgT3aVjlqwUAE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346526; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JkYoLrPE2YMfs8LSxSkzzotSoNvln2tacJDT2PKqUQk=; b=Kiv9jexKVRVSSRR5+iVJgeI76tiGe/6zrxYyZTlN86gKtXi7qZyANHo8CmzWMF68ge+IqlE7ZzFKlfk97BLjVnSDVkb6MkBhOPtVgtDaq0Y43Oo/QoYizFSHU1skihiXdBV/r6z0bZNLERjvMj1Y7EdeOVgCp5krmhY6fQLPKeU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346526950684.8031445828425; Mon, 6 Jul 2026 07:02:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsL-0005Jd-9q; Mon, 06 Jul 2026 10:00:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsD-00050n-CW for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsB-0002IB-EW for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:37 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-JNLLMoGfPGmm94EkaV-Vug-1; Mon, 06 Jul 2026 10:00:30 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A781C1955F73; Mon, 6 Jul 2026 14:00:28 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B64A3000B4E; Mon, 6 Jul 2026 14:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JkYoLrPE2YMfs8LSxSkzzotSoNvln2tacJDT2PKqUQk=; b=TImgC8OLKD4f+8wp76LmgeJ1DZjsQomnnJ9y+AzGpSe76TMHvIb4fGSsakz7qLgTBWTnpG 4B4+l3fZRJ2B2VVWK3TvabxUupAbYLrhACckhcTSgjATBdQxd6oBe7GyKw5kN+wJUsnUR0 TbcbO6lHnFaCPGuNrMUhXESLCLcBYTo= X-MC-Unique: JNLLMoGfPGmm94EkaV-Vug-1 X-Mimecast-MFC-AGG-ID: JNLLMoGfPGmm94EkaV-Vug_1783346428 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 30/35] tests/functional: add a stress test for monitor hot unplug Date: Mon, 6 Jul 2026 14:58:18 +0100 Message-ID: <20260706135824.2623960-31-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346528854158500 When unplugging a monitor there is a careful synchronization dance between the monitor handling the "object-del" command and the command processing for the monitor being deleted. The stress test runs a busy loop of 'query-qmp-schema' on a second monitor, while the primary monitor requests its deletion. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- .../generic/test_monitor_hotplug.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/functional/generic/test_monitor_hotplug.py b/tests/funct= ional/generic/test_monitor_hotplug.py index 5d8a159eb0..55af8a238f 100755 --- a/tests/functional/generic/test_monitor_hotplug.py +++ b/tests/functional/generic/test_monitor_hotplug.py @@ -6,11 +6,16 @@ # # Copyright (c) 2026 Christian Brauner =20 +import asyncio import os +import random +import threading +import time =20 from qemu_test import QemuSystemTest =20 from qemu.qmp.legacy import QEMUMonitorProtocol +from qemu.qmp import QMPClient =20 =20 class MonitorHotplug(QemuSystemTest): @@ -163,6 +168,63 @@ def test_events_after_negotiation(self): qmp.close() self._remove_monitor() =20 + def stress_mon(self, sock): + async def main(): + qmp =3D QMPClient('testvm') + await qmp.connect(sock) + # Run query-version in a tight loop so that the + # monitor thread/dispatcher is very busy at the + # time we try to delete the monitor + while True: + try: + # A command which returns a lot of data to make + # it more likely we're in the I/O reply path + # when deleting the monitor + res =3D await qmp.execute('query-qmp-schema') + # Some commands which generate async events + # as those can trigger different code paths + res =3D await qmp.execute('stop') + res =3D await qmp.execute('cont') + except: + # we'll get here if the monitor is terminated + # by QEMU in which case we must disconnect + # out side, but.... + try: + await qmp.disconnect() + except (ConnectionResetError, EOFError, BrokenPipeErro= r): + # ... disconnect() will probably see + # errors too, but we must try to call it + # regardless to cleanup asyncio state + # and prevent python warnings at GC time + pass + return + asyncio.run(main()) + + def test_hotplug_stress(self): + """ + Repeatedly hotplug and unplug a monitor, while another thread + concurrently issues commands on that monitor. This stresses + the synchronization with the monitor thread during cleanup + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + # Each loop sleeps at most 0.5 seconds, so this should + # give an upper bound of approx 5 seconds execution + # time which is reasonable to run by default + repeat =3D 10 + for i in range(repeat): + # First cycle + sock =3D self._add_monitor() + print ("# stress cycle %02d/%02d" % (i, repeat)) + stress =3D threading.Thread(target=3Dself.stress_mon, args=3D[= sock]) + stress.start() + # Sleep upto 1/2 second to vary the races + time.sleep(random.random() / 2) + self._remove_monitor() + stress.join() + =20 if __name__ =3D=3D '__main__': QemuSystemTest.main() --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346617; cv=none; d=zohomail.com; s=zohoarc; b=fly7gbEke6BXllMHg3BIDg3L0zh+Ibvcj6V2CskV3kMdP9n2KGbdiX6UUMuhW24evkMZcv3m1eLQBLg4D6FbEf11OSNF5ACnx4ppu3KW3IA7xh86hkJr+uilGuQQlZbDOb/FoVjxIVybIA4DDUV2oteHXbHIJ53MGwAmvml6IwQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346617; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uoHsXjgYznrDo6DK9WLu5UFtS0i8p4GK428gaDD1Ofs=; b=XdnuhAMu1zTmo6TyYk/yNJHrqDldAvzGcHM3VbmVMM0IVuMxdgFtwV2IhdGzZAFgSbNxB2ID0etqLWn33dqFrHm0I3jMr0+TJIVdD2LmYGtvuPtiAe50Zi4XqlM7w5Ael3/sHyt5BDYUCMfrmsc5f2z8WWsfVsV6nmilJX3VBUk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346617379779.1146496675796; Mon, 6 Jul 2026 07:03:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsL-0005Ra-Ln; Mon, 06 Jul 2026 10:00:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsG-000574-UY for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsF-0002KK-Bj for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:40 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-445-Mn5X5EgDM3m-nZzTV7HZLw-1; Mon, 06 Jul 2026 10:00:34 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9AE301955F26; Mon, 6 Jul 2026 14:00:32 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 208F53000B4E; Mon, 6 Jul 2026 14:00:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346438; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uoHsXjgYznrDo6DK9WLu5UFtS0i8p4GK428gaDD1Ofs=; b=jOsYiV4tuAmNIx3eadKAYf/euQHp4UMVxlr1XdT6KjZOLVDes5u2UlR8nqjDLdBBcv8gYQ TSuTgiUI7iv11G64cvWcTwCXZ7ObDZAZ8v/iYpJ+zRAaU13+RVOLtC0L0OetmBJYkbRbpz 0u0MmHvqRST1X9wYvq7bx11Q3rZ47Rw= X-MC-Unique: Mn5X5EgDM3m-nZzTV7HZLw-1 X-Mimecast-MFC-AGG-ID: Mn5X5EgDM3m-nZzTV7HZLw_1783346432 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 31/35] qom: add trace events for user creatable create/delete APIs Date: Mon, 6 Jul 2026 14:58:19 +0100 Message-ID: <20260706135824.2623960-32-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346617926158500 Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- qom/object_interfaces.c | 11 +++++++++-- qom/trace-events | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 3216a754ed..d83c12744b 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -20,12 +20,14 @@ #include "qapi/opts-visitor.h" #include "qemu/config-file.h" #include "qemu/keyval.h" +#include "trace.h" =20 bool user_creatable_complete(UserCreatable *uc, Error **errp) { UserCreatableClass *ucc =3D USER_CREATABLE_GET_CLASS(uc); ERRP_GUARD(); =20 + trace_user_creatable_complete(uc, object_get_typename(OBJECT(uc))); if (ucc->complete) { ucc->complete(uc, errp); } @@ -35,11 +37,16 @@ bool user_creatable_complete(UserCreatable *uc, Error *= *errp) bool user_creatable_prepare_delete(UserCreatable *uc, Error **errp) { UserCreatableClass *ucc =3D USER_CREATABLE_GET_CLASS(uc); + bool ret =3D true; =20 + trace_user_creatable_prepare_delete(uc, object_get_typename(OBJECT(uc)= )); if (ucc->prepare_delete) { - return ucc->prepare_delete(uc, errp); + ret =3D ucc->prepare_delete(uc, errp); } - return true; + trace_user_creatable_prepare_delete_result( + uc, object_get_typename(OBJECT(uc)), + *errp ? error_get_pretty(*errp) : NULL); + return ret; } =20 void user_creatable_add_qapi(ObjectOptions *options, Error **errp) diff --git a/qom/trace-events b/qom/trace-events index 44c63e72af..bac8472618 100644 --- a/qom/trace-events +++ b/qom/trace-events @@ -11,3 +11,8 @@ object_property_del_child(void *obj, const char *type, vo= id *child, const char * object_property_parse(void *obj, const char *type, const char *name, const= char *value) "obj=3D%p type=3D%s prop=3D%s value=3D%s" object_class_dynamic_cast_assert(const char *type, const char *target, con= st char *file, int line, const char *func) "type=3D%s->%s (%s:%d:%s)" object_class_property_add(const char *type, const char *name, void *value)= "type=3D%s name=3D%s value=3D%p" + +# object_interfaces.c +user_creatable_complete(void *obj, const char *type) "obj=3D%p type=3D%s" +user_creatable_prepare_delete(void *obj, const char *type) "obj=3D%p type= =3D%s" +user_creatable_prepare_delete_result(void *obj, const char *type, const ch= ar *msg) "obj=3D%p type=3D%s msg=3D%s" --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346597; cv=none; d=zohomail.com; s=zohoarc; b=RYTOhC4IP4gPVRuP1+UoaPer/fAInhjAHRvN5ikFIlDIIGza4PL7CCTjU8c4CjLixS3kgdMB6lqYiUCwG+B6zCEaILvsH6QpfLMMN8fkmeTD64M2cIFSHsiNRHf087PzspkD6WHrGIPUzk9zBVwgcNGunbGfrVYJoNEz5tns/n4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346597; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zyFPKHx+ctwep27OTevvSKhnSYAJcsDOrGvGj+MgEwg=; b=aNTm//L7S6lpdDzY+bcU1pI2h4IYw11mS4x9Lc8GbEZi0T10XsQIraSsRVyxtwuBsNxKoUFZhU1Jv/nG8lBnPhRxlaE2ZVgt5+mG+xXba9Cuz8NprjDG9zucn4bFRdXyI30hckLYdqJBDuZtIy0iFyU/4xCqS7iquAeR1uFebxw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346597979350.2259420006724; Mon, 6 Jul 2026 07:03:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsQ-00065Y-V9; Mon, 06 Jul 2026 10:00:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsN-0005lQ-VZ for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsL-0002Kv-7R for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:47 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-DVQdg0wzOCaKx9juHJ1-JQ-1; Mon, 06 Jul 2026 10:00:38 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6D8C41801238; Mon, 6 Jul 2026 14:00:36 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 31CCE3000B50; Mon, 6 Jul 2026 14:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346444; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zyFPKHx+ctwep27OTevvSKhnSYAJcsDOrGvGj+MgEwg=; b=WeUuFRhP/H2VrXw4xdMXPnGFRbfk1kKHV/ZZNQGfKZHe2q92r0lRJ36woEjbEyfJTTb2QC ncl0t89yUG1eJ6uY0PqDa6I0RD1bizYWyX3hT0FsPyl4DbJJ/f1aBNzEZRIlIuUSMcQVFj x4/dzRMt3QEorJoU14AguLBJ2r6vxRY= X-MC-Unique: DVQdg0wzOCaKx9juHJ1-JQ-1 X-Mimecast-MFC-AGG-ID: DVQdg0wzOCaKx9juHJ1-JQ_1783346436 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 32/35] monitor: add support for auto-deleting monitors upon close Date: Mon, 6 Jul 2026 14:58:20 +0100 Message-ID: <20260706135824.2623960-33-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346599835158500 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 involved a user wishing to spawn an adhoc 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=3Dnone|delete" property on the 'monitor-qmp' object. This concept could be extended with further actions in future, for example: * close-action=3Dshutdown - graceful guest shutdown * close-action=3Dterminate - immediate guest poweroff * close-action=3Dstop - 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 Reviewed-by: Marc-Andr=C3=A9 Lureau Acked-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- monitor/monitor-internal.h | 3 + monitor/qmp.c | 80 ++++++++++++++++++ qapi/qom.json | 22 ++++- .../generic/test_monitor_hotplug.py | 83 ++++++++++++++++++- 4 files changed, 183 insertions(+), 5 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 5522e05464..23829f32f9 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -28,6 +28,7 @@ #include "chardev/char-fe.h" #include "monitor/monitor.h" #include "qapi/qapi-types-control.h" +#include "qapi/qapi-types-qom.h" #include "qapi/qmp-registry.h" #include "qobject/json-parser.h" #include "qemu/readline.h" @@ -178,7 +179,9 @@ struct MonitorQMP { Monitor parent_obj; JSONMessageParser parser; bool pretty; + MonitorQMPCloseAction close_action; bool setup_pending; /* iothread BH has not yet set up chardev handlers= */ + bool delete_pending; /* close_action has started 'delete' process */ /* * When a client connects, we're in capabilities negotiation mode. * @commands is &qmp_cap_negotiation_commands then. When command diff --git a/monitor/qmp.c b/monitor/qmp.c index 2bec0f3c96..223e0643c2 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -28,6 +28,7 @@ #include "monitor-internal.h" #include "qapi/error.h" #include "qapi/qapi-commands-control.h" +#include "qapi/qapi-commands-char.h" #include "qobject/qdict.h" #include "qobject/qjson.h" #include "qobject/qlist.h" @@ -103,6 +104,20 @@ static void monitor_qmp_set_pretty(Object *obj, bool v= al, Error **errp) mon->pretty =3D val; } =20 +static int monitor_qmp_get_close_action(Object *obj, Error **errp) +{ + MonitorQMP *mon =3D MONITOR_QMP(obj); + + return mon->close_action; +} + +static void monitor_qmp_set_close_action(Object *obj, int val, Error **err= p) +{ + MonitorQMP *mon =3D MONITOR_QMP(obj); + + mon->close_action =3D val; +} + static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *q= dict); static bool monitor_qmp_requires_iothread(const Monitor *mon); static void monitor_qmp_complete(UserCreatable *uc, Error **errp); @@ -117,6 +132,11 @@ static void monitor_qmp_class_init(ObjectClass *cls, c= onst void *data) object_class_property_add_bool(cls, "pretty", monitor_qmp_get_pretty, monitor_qmp_set_pretty); + object_class_property_add_enum(cls, "close-action", + "MonitorQMPCloseAction", + &MonitorQMPCloseAction_lookup, + monitor_qmp_get_close_action, + monitor_qmp_set_close_action); =20 moncls->emit_event =3D monitor_qmp_emit_event; moncls->requires_iothread =3D monitor_qmp_requires_iothread; @@ -550,11 +570,49 @@ static QDict *qmp_greeting(MonitorQMP *mon) ver, cap_list); } =20 +static void monitor_qmp_self_delete_bh(void *opaque) +{ + MonitorQMP *mon =3D opaque; + const char *mon_id =3D object_get_canonical_path_component( + OBJECT(mon)); + g_autofree char *chardev_id =3D g_strdup(mon->parent_obj.chardev_id); + Error *local_error =3D NULL; + + if (!mon_id) { + /* + * Another monitor raced & ran 'object-del' on 'mon' + * before this BH got scheduled, so we have a ref on + * mon from monitor_qmp_event but it is already + * unparented. + */ + object_unref(mon); + return; + } + + user_creatable_del(mon_id, &local_error); + /* Pairs with ref from monitor_qmp_event */ + object_unref(mon); + if (local_error !=3D NULL) { + error_report_err(local_error); + } else { + qmp_chardev_remove(chardev_id, NULL); + } +} + static void monitor_qmp_event(void *opaque, QEMUChrEvent event) { QDict *data; MonitorQMP *mon =3D opaque; =20 + /* + * Protect against race if a client drops & quickly + * reconnects - we'll have the delete BH scheduled + * so must not honour a new open request + */ + if (mon->delete_pending) { + return; + } + switch (event) { case CHR_EVENT_OPENED: WITH_QEMU_LOCK_GUARD(&mon->parent_obj.mon_lock) { @@ -577,6 +635,28 @@ static void monitor_qmp_event(void *opaque, QEMUChrEve= nt event) json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); monitor_fdsets_cleanup(); + switch (mon->close_action) { + case MONITOR_QMP_CLOSE_ACTION_NONE: + break; + case MONITOR_QMP_CLOSE_ACTION_DELETE: + mon->delete_pending =3D true; + /* + * Do NOT run in the AIO context associated with the + * monitor. We need to run in the default AIO context + * which is the same context in which 'qmp_object_del' + * will execute + * + * Hold an extra ref in case a separate monitor races + * with the BH by processing an explicit 'object-del'. + * Will be released by monitor_qmp_self_delete_bh + */ + object_ref(mon); + aio_bh_schedule_oneshot(qemu_get_aio_context(), + monitor_qmp_self_delete_bh, mon); + break; + default: + g_assert_not_reached(); + } break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: 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' } } =20 + +## +# @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' } } =20 ## # @ObjectType: diff --git a/tests/functional/generic/test_monitor_hotplug.py b/tests/funct= ional/generic/test_monitor_hotplug.py index 55af8a238f..86092e781c 100755 --- a/tests/functional/generic/test_monitor_hotplug.py +++ b/tests/functional/generic/test_monitor_hotplug.py @@ -25,7 +25,7 @@ def setUp(self): sock_dir =3D self.socket_dir() self._sock_path =3D os.path.join(sock_dir.name, 'hotplug.sock') =20 - def _add_monitor(self): + def _add_monitor(self, autodelete=3DFalse): """Create a chardev + monitor and return the socket path.""" sock =3D self._sock_path self.vm.cmd('chardev-add', id=3D'hotplug-chr', backend=3D{ @@ -39,9 +39,15 @@ def _add_monitor(self): 'wait': False, } }) - self.vm.cmd('object-add', id=3D'hotplug-mon', - qom_type=3D'monitor-qmp', - chardev=3D'hotplug-chr') + if autodelete: + self.vm.cmd('object-add', id=3D'hotplug-mon', + qom_type=3D'monitor-qmp', + chardev=3D'hotplug-chr', + close_action=3D'delete') + else: + self.vm.cmd('object-add', id=3D'hotplug-mon', + qom_type=3D'monitor-qmp', + chardev=3D'hotplug-chr') return sock =20 def _remove_monitor(self): @@ -118,6 +124,75 @@ def test_self_removal(self): # Clean up the chardev self.vm.cmd('chardev-remove', id=3D'hotplug-chr') =20 + def test_auto_delete(self): + """ + A dynamically-added monitor configured with 'close-action=3Ddelete' + should see itself deleted when the client is closed. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + sock =3D self._add_monitor(autodelete=3DTrue) + + cdevs =3D [c["label"] for c in self.vm.cmd('query-chardev')] + objs =3D [o["name"] for o in self.vm.cmd('qom-list', path=3D'/obje= cts')] + assert ('hotplug-chr' in cdevs) + assert ('hotplug-mon' in objs) + + qmp =3D QEMUMonitorProtocol(sock) + greeting =3D qmp.connect(negotiate=3DTrue) + self.assertIn('QMP', greeting) + + cdevs =3D [c["label"] for c in self.vm.cmd('query-chardev')] + objs =3D [o["name"] for o in self.vm.cmd('qom-list', path=3D'/obje= cts')] + assert ('hotplug-chr' in cdevs) + assert ('hotplug-mon' in objs) + + qmp.close() + + # Wait upto 10 seconds max for chardev to auto-delete, which + # is hopefully enough for reliability under high load + for i in range(int(10 / 0.2)): + cdevs =3D [c["label"] for c in self.vm.cmd('query-chardev')] + if 'hotplug-chr' not in cdevs: + break + # Wait a little more then try again + time.sleep(0.2) + + cdevs =3D [c["label"] for c in self.vm.cmd('query-chardev')] + objs =3D [o["name"] for o in self.vm.cmd('qom-list', path=3D'/obje= cts')] + assert ('hotplug-chr' not in cdevs) + assert ('hotplug-mon' not in objs) + + def test_reconnect(self): + """ + A dynamically-added monitor configured without 'close-action' + should allow reconnects after the client is closed. + """ + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.launch() + + sock =3D self._add_monitor() + + qmp =3D QEMUMonitorProtocol(sock) + qmp.connect(negotiate=3DTrue) + + resp =3D qmp.cmd_obj({'execute': 'query-chardev'}) + self.assertIn('return', resp) + + qmp.close() + + qmp =3D QEMUMonitorProtocol(sock) + qmp.connect(negotiate=3DTrue) + + resp =3D qmp.cmd_obj({'execute': 'query-chardev'}) + self.assertIn('return', resp) + + qmp.close() + self._remove_monitor() + def test_large_response(self): """ Send a command with a large response (query-qmp-schema) on a --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346530; cv=none; d=zohomail.com; s=zohoarc; b=DM0PuTxWiW5VRt6qzw0H4mWO+N9BCaW6hsSvt5egIeZVOAfRsYlZoXRxLMN4ksu5nRarYecuj9wo8oReZ83ha/zmtqVlwiOZDKC4OwGTu6dFDQA1FD3YuAFXH8IBC5znIzrzM/GxCQxmCjN0fpTqj9z+OwEKffuEMmv44j1JKZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346530; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rxKTtegn6LNM5fVxrqivkl4REVae5ax0xTcSOpSDlfY=; b=jSJqpEK7vjWDVdUFPjJC5LpLr/BRcql63k85BmYXvzxF6E7nz6CFBkNbDZ1UlzGoPVbo8LcsU4zy+AR5VppnQW0B8NSdr40in/QaN63C4+oBRVRScLWJroADXoCVQI6Qhb2Bzy6a4ubJ5B+PSPxVAx4SPXPtQXW1139RwdbXkFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346530303991.1581917314547; Mon, 6 Jul 2026 07:02:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsR-0006An-Og; Mon, 06 Jul 2026 10:00:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsO-0005qQ-Jp for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsM-0002L4-SV for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:48 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-4ntjhnPgNFWQfGzd6o4xtA-1; Mon, 06 Jul 2026 10:00:41 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3A35B1955F71; Mon, 6 Jul 2026 14:00:40 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DD5123000B50; Mon, 6 Jul 2026 14:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rxKTtegn6LNM5fVxrqivkl4REVae5ax0xTcSOpSDlfY=; b=KfdRotmP9K2+nq4IRFXLkUkgfS+vwFkovnOY7AspY95GS7VB6tbKtJVse+h/RW1xUVDyLM jIa0x7I5oalD5vJ9RgexRMQM+B4Vs4/obR2UuhCh96nVwH3uRJHu2trhjIFl3rzfoQVOcv /cvmJdy4zdMF2aq6q13qeu8yGzMIrvQ= X-MC-Unique: 4ntjhnPgNFWQfGzd6o4xtA-1 X-Mimecast-MFC-AGG-ID: 4ntjhnPgNFWQfGzd6o4xtA_1783346440 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 33/35] tests: switch from -mon to -object monitor-qmp Date: Mon, 6 Jul 2026 14:58:21 +0100 Message-ID: <20260706135824.2623960-34-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346530884158500 Use the new preferred low level option for configuring the QMP service in libqtest and the python Machine class used by tests. This will avoid triggering deprecation warnings after the subsequent commit. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster --- python/qemu/machine/machine.py | 4 ++-- tests/qtest/libqtest.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index 3670c8cd39..bfb59d4c0b 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -304,8 +304,8 @@ def _harness_args(self) -> List[str]: ) else: moncdev =3D f"socket,id=3Dmon,path=3D{self._monitor_addres= s}" - args.extend(['-chardev', moncdev, '-mon', - 'chardev=3Dmon,mode=3Dcontrol']) + args.extend(['-chardev', moncdev, '-object', + 'monitor-qmp,id=3Dqmp,chardev=3Dmon']) return args =20 def _console_args(self, interactive: bool =3D False) -> List[str]: diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 4e22c66b75..c33c799c92 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -460,7 +460,7 @@ gchar *qtest_qemu_args(const char *extra_args) "-qtest unix:%s " "-qtest-log %s " "-chardev socket,path=3D%s,id=3Dchar0 " - "-mon chardev=3Dchar0,mode=3Dcontrol " + "-object monitor-qmp,id=3Dqmp0,chardev=3Dchar0 " "-display none " "-audio none " "%s " --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346579; cv=none; d=zohomail.com; s=zohoarc; b=eOl5CsAdXnmFo68t0XPrZOzzLpWZe2mzudpWzRtaTZgR5egXobyVS9Vr0UzqD2py3JThMfYkXDRobX8HqfayQcTHJgE/pndW1qM0uz1gS1VHm1061kzgGM4/Z6Nrd6JRvM0+GWC6uf0E+EEJOub/A58Y2rwaPWF+AmvP4iHxGns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346579; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fVWDFsDKYcR/h0WiYYSlXW8s55Ug8vhotJgDDaWSaVA=; b=TPsUbIF95aEp2nOtqedOL0C+RUceflKXO9SqKqqH1tT02t2SbvNKhmGEPCUVlKUJk9ac38/OEQqcTffUhQRexdqHFIPtXAhNhCL7T+kK3BTL1weMN/Uf3dYkMtAuPza4rXVW5tr46yaFytb1sH8AO/9g4NAhlXCluu5sr7He8qU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178334657942132.51061387405139; Mon, 6 Jul 2026 07:02:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsV-0006Vx-CL; Mon, 06 Jul 2026 10:00:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsS-0006Gw-1p for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsQ-0002Lj-5L for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:51 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-R7Eb-QfTMwSWEOWv2JCDtg-1; Mon, 06 Jul 2026 10:00:45 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E8C921955F3B; Mon, 6 Jul 2026 14:00:43 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B2D133000B4E; Mon, 6 Jul 2026 14:00:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fVWDFsDKYcR/h0WiYYSlXW8s55Ug8vhotJgDDaWSaVA=; b=OytacIp19KGaEDnFoY7RN9tPqjsV+lDDHKXMerdmI5unIqX6PSWxyKDoklifNeKHZUvqs8 f/9uYv58DfPKwq6oysNVjsyKvpFIfBja+6qd+sUjm5H+rkgWjgFlfsKdzC48eGDW5lCDTm Zbuz3JEL/kyq9/2xAbRY7s4wvexNJnE= X-MC-Unique: R7Eb-QfTMwSWEOWv2JCDtg-1 X-Mimecast-MFC-AGG-ID: R7Eb-QfTMwSWEOWv2JCDtg_1783346444 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 34/35] qemu-options: document new monitor-hmp and monitor-qmp objects Date: Mon, 6 Jul 2026 14:58:22 +0100 Message-ID: <20260706135824.2623960-35-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346581529158500 Add new docs for the `-object monitor-hmp` and `-object monitor-qmp` options, updating `-mon` to state that it is legacy syntax sugar for the new `-object` args. Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster Reviewed-by: Markus Armbruster --- qemu-options.hx | 61 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index e44b47de68..fe76c18c81 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4955,6 +4955,11 @@ SRST port). The default device is ``vc`` in graphical mode and ``stdio`` in non graphical mode. Use ``-monitor none`` to disable the default monitor. + + The use of ``-monitor dev`` is syntactic sugar for creating a character + device from ``dev`` and pairing it with ``-object monitor-hmp``. + Both the character device and monitor object will be given an ID + ``compat_monitorNNN`` where ``NNN`` is a counter starting from 0. ERST DEF("qmp", HAS_ARG, QEMU_OPTION_qmp, \ "-qmp dev like -monitor but opens in 'control' mode\n", @@ -4966,9 +4971,10 @@ SRST =20 -qmp tcp:localhost:4444,server=3Don,wait=3Doff =20 - Not all options are configurable via this syntax; for maximum - flexibility use the ``-mon`` option and an accompanying ``-chardev``. - + The use of ``-qmp dev`` is syntactic sugar for creating a character + device from ``dev`` and pairing it with ``-object monitor-qmp``. + Both the character device and monitor object will be given an ID + ``compat_monitorNNN`` where ``NNN`` is a counter starting from 0. ERST DEF("qmp-pretty", HAS_ARG, QEMU_OPTION_qmp_pretty, \ "-qmp-pretty dev like -qmp but uses pretty JSON formatting\n", @@ -4997,6 +5003,16 @@ SRST -mon chardev=3Dmon1,mode=3Dcontrol,pretty=3Don =20 enables the QMP monitor on localhost port 4444 with pretty-printing. + + The use of ``-mon mode=3Dreadline`` is syntactic sugar + for the new ``-object monitor-hmp`` option, each use of which + creates an object with the ID ``compat_monitorNNN`` where ``NNN`` is + a counter starting from 0. + + The use of ``-mon mode=3Dcontrol`` is syntactic sugar + for the new ``-object monitor-qmp`` option, each use of which + creates an object with the ID ``compat_monitorNNN`` where ``NNN`` is + a counter starting from 0. ERST =20 DEF("debugcon", HAS_ARG, QEMU_OPTION_debugcon, \ @@ -5747,6 +5763,45 @@ SRST they are specified. Note that the 'id' property must be set. These objects are placed in the '/objects' path. =20 + ``-object monitor-hmp,id=3Did,chardev=3Dchardev_id,readline=3Don|off`` + Set up a monitor running the Human Monitor Protocol, + connected to the chardev ``chardev_id``. + + The ``id`` parameter is a unique ID that can be used + to dynamically delete the monitor at runtime. Note + that monitors created using the historical syntax + will be allocated IDs following the pattern ``compat_monmitorNNN``. + Mixing ``-object`` with ``-monitor`` and ``-mon`` syntax is + discouraged. + + The ``readline`` parameter, which defaults to ``on``, + controls whether the monitor provides line editing. + + ``-object monitor-qmp,id=3Did,chardev=3Dchardev_id,pretty=3Don|off,clo= se-action=3Dnone|delete`` + Set up a monitor running the QEMU Monitor Protocol, + connected to the chardev ``chardev_id``. + + The ``id`` parameter is a unique ID that can be used + to dynamically delete the monitor at runtime. Note + that monitors created using the historical syntax + will be allocated IDs following the pattern ``compat_monitorNNN``. + Mixing ``-object`` with ``-qmp``, ``-qmp-pretty`` and + ``-mon`` syntax is discouraged. + + The ``pretty`` parameter, which defaults to ``off``, + controls whether the monitor responses are pretty + printed as multi-line indented JSON, as opposed to + constrained to a single line without extraneous + whitespace. + + The ``close-action`` parameter, which defaults to ``none``, + controls what happens when the connection to the monitor + is terminated by the user. If set to ``delete``, then the + ``monitor-qmp`` object and its associated character + device are both immediately deleted. This can be useful + if an extra monitor was hotplugged for a specific task + and should be unplugged when completed. + ``-object memory-backend-file,id=3Did,size=3Dsize,mem-path=3Ddir,share= =3Don|off,discard-data=3Don|off,merge=3Don|off,dump=3Don|off,prealloc=3Don|= off,host-nodes=3Dhost-nodes,policy=3Ddefault|preferred|bind|interleave,alig= n=3Dalign,offset=3Doffset,readonly=3Don|off,rom=3Don|off|auto`` Creates a memory file backend object, which can be used to back the guest RAM with huge pages. --=20 2.55.0 From nobody Tue Jul 14 21:18:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783346547; cv=none; d=zohomail.com; s=zohoarc; b=lGf+VacGfS7TTtRx2GOdFHJr9eoqQw/biM6Dihjed/0fBMa91LEPcB4lNcps7OIwZfykCgzyZMP0DAiO0ZZQw+au535XSUNBzHfgo80mpYxs6RPPmlnT0ZC0VYyFgwRzL2/U7Bu3s/tpX7YM5PT1CAwIWnNL+OxHrPi0mc/5FT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783346547; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vnvy6pEzikCVx6j0c1PWdDswTHlFm8rQhWGo5hLUrOg=; b=PnH0SSRVmyuzh2aQr5j2rOmhJ13zSkj/3TlA7pJ78Dj0vaMZ7AzAtu+xq2D3GwcVPM+dfOzkytOMRQnvvFd/vpNwDiGAb6oCkobyYtrm7ThJbmL3VekIuKADLaEp9Kk4ODU98pZXNfZ5shfg76awe+wiNNkAgGx8GzpORQeZOwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783346547690737.2695517866373; Mon, 6 Jul 2026 07:02:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgjsY-0006vh-QN; Mon, 06 Jul 2026 10:00:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsW-0006Zr-2F for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wgjsU-0002M9-43 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 10:00:55 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-NEwMpiPYP7eaqs81ksKsYQ-1; Mon, 06 Jul 2026 10:00:49 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C190218009CA; Mon, 6 Jul 2026 14:00:47 +0000 (UTC) Received: from berrange.com (unknown [10.44.48.165]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 76BBD3000B4E; Mon, 6 Jul 2026 14:00:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783346453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vnvy6pEzikCVx6j0c1PWdDswTHlFm8rQhWGo5hLUrOg=; b=dDuHFTE0VvyMonxo+WANJaUbc4lEmBmYgfgGB8b/60ILrxbtGXJFZsUKZjnkdCFcunXkig 1fbhANSTs/b7NWlPQjq1sBDtF/LrZadgvMdntZGtrSWW8mn2TUEWcUBEQMzrKDnP+q2smu /ZD88JydEm49Vb10YJbZ6EQXpYYe3fw= X-MC-Unique: NEwMpiPYP7eaqs81ksKsYQ-1 X-Mimecast-MFC-AGG-ID: NEwMpiPYP7eaqs81ksKsYQ_1783346447 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Christian Brauner , devel@lists.libvirt.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Krempa , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v7 35/35] docs: mark '-mon' as deprecated in favour of -object Date: Mon, 6 Jul 2026 14:58:23 +0100 Message-ID: <20260706135824.2623960-36-berrange@redhat.com> In-Reply-To: <20260706135824.2623960-1-berrange@redhat.com> References: <20260706135824.2623960-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783346549278158500 The high level `-qmp` and `-monitor` options can remain as convenience wrappers, but the low level `-mon` is completed obsoleted by the new `-object` support with 'monitor-qmp' and 'monitor-hmp' types. Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 Acked-by: Markus Armbruster Reviewed-by: Markus Armbruster --- docs/about/deprecated.rst | 10 ++++++++++ docs/devel/writing-monitor-commands.rst | 4 ++-- docs/system/arm/xenpvh.rst | 4 ++-- docs/system/i386/xen.rst | 3 ++- docs/system/i386/xenpvh.rst | 4 ++-- qemu-options.hx | 16 ++++++++-------- system/vl.c | 2 ++ 7 files changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 169c5dfe4f..023612748b 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -61,6 +61,16 @@ The ``debug-threads`` option of the ``-name`` argument i= s now ignored. Thread naming is unconditionally enabled for all platforms where it is supported. =20 +``-mon`` option (since 11.1) +'''''''''''''''''''''''''''' + +The ``-mon`` option was the generic mechanism for creating monitor +objects if the convenience ``-qmp`` or ``-monitor`` options were not +flexible enough. The monitor objects have been converted to QOM, so +``-mon mode=3Dreadline`` is replaced by ``-object monitor-hmp`` and +``-mon mode=3Dcontrol`` is replaced by ``-object monitor-qmp``. The +short convenience options are not deprecated, only ``-mon``. + QEMU Machine Protocol (QMP) commands ------------------------------------ =20 diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-m= onitor-commands.rst index 930da5cd06..7ae7efe327 100644 --- a/docs/devel/writing-monitor-commands.rst +++ b/docs/devel/writing-monitor-commands.rst @@ -52,8 +52,8 @@ shown here. First, QEMU should be started like this:: =20 # qemu-system-TARGET [...] \ - -chardev socket,id=3Dqmp,port=3D4444,host=3Dlocalhost,server=3Don \ - -mon chardev=3Dqmp,mode=3Dcontrol,pretty=3Don + -chardev socket,id=3Dchrqmp0,port=3D4444,host=3Dlocalhost,server=3Don= \ + -object monitor-qmp,chardev=3Dchrqmp0,pretty=3Don,id=3Dqmp0 =20 Then, in a different terminal:: =20 diff --git a/docs/system/arm/xenpvh.rst b/docs/system/arm/xenpvh.rst index 430ac2c02e..511af63e3d 100644 --- a/docs/system/arm/xenpvh.rst +++ b/docs/system/arm/xenpvh.rst @@ -27,9 +27,9 @@ Sample QEMU xenpvh commands for running and connecting wi= th Xen: =20 qemu-system-aarch64 -xen-domid 1 \ -chardev socket,id=3Dlibxl-cmd,path=3Dqmp-libxl-1,server=3Don,wait= =3Doff \ - -mon chardev=3Dlibxl-cmd,mode=3Dcontrol \ + -object monitor-qmp,id=3Dqmp0,chardev=3Dlibxl-cmd \ -chardev socket,id=3Dlibxenstat-cmd,path=3Dqmp-libxenstat-1,server= =3Don,wait=3Doff \ - -mon chardev=3Dlibxenstat-cmd,mode=3Dcontrol \ + -object monitor-qmp,id=3Dqmp1,chardev=3Dlibxenstat-cmd \ -xen-attach -name guest0 -vnc none -display none -nographic \ -machine xenpvh -m 1301 \ -chardev socket,id=3Dchrtpm,path=3Dtmp/vtpm2/swtpm-sock \ diff --git a/docs/system/i386/xen.rst b/docs/system/i386/xen.rst index 46db5f34c1..6ff5cdb1e4 100644 --- a/docs/system/i386/xen.rst +++ b/docs/system/i386/xen.rst @@ -79,7 +79,8 @@ of type ``xen-console`` to connect to it. For the Xen con= sole equivalent of the handy ``-serial mon:stdio`` option, for example: =20 .. parsed-literal:: - -chardev stdio,mux=3Don,id=3Dchar0,signal=3Doff -mon char0 \\ + -chardev stdio,mux=3Don,id=3Dchar0,signal=3Doff \\ + -object monitor-hmp,chardev=3Dchar0,id=3Dhmp0 \\ -device xen-console,chardev=3Dchar0 =20 The Xen network device is ``xen-net-device``, which becomes the default NIC diff --git a/docs/system/i386/xenpvh.rst b/docs/system/i386/xenpvh.rst index 354250f073..904778e3f5 100644 --- a/docs/system/i386/xenpvh.rst +++ b/docs/system/i386/xenpvh.rst @@ -33,9 +33,9 @@ case you need to construct one manually: =20 qemu-system-i386 -xen-domid 3 -no-shutdown \ -chardev socket,id=3Dlibxl-cmd,path=3D/var/run/xen/qmp-libxl-3,serve= r=3Don,wait=3Doff \ - -mon chardev=3Dlibxl-cmd,mode=3Dcontrol \ + -object monitor-qmp,id=3Dqmp0,chardev=3Dlibxl-cmd \ -chardev socket,id=3Dlibxenstat-cmd,path=3D/var/run/xen/qmp-libxenst= at-3,server=3Don,wait=3Doff \ - -mon chardev=3Dlibxenstat-cmd,mode=3Dcontrol \ + -object monitor-qmp,id=3Dqmp1,chardev=3Dlibxenstat-cmd \ -nodefaults \ -no-user-config \ -xen-attach -name g0 \ diff --git a/qemu-options.hx b/qemu-options.hx index fe76c18c81..acf68f8961 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4154,7 +4154,7 @@ The general form of a character device option is: :: =20 -chardev stdio,mux=3Don,id=3Dchar0 \ - -mon chardev=3Dchar0,mode=3Dreadline \ + -object monitor-hmp,id=3Dhmp0,chardev=3Dchar0 \ -serial chardev:char0 \ -serial chardev:char0 =20 @@ -4166,7 +4166,7 @@ The general form of a character device option is: :: =20 -chardev stdio,mux=3Don,id=3Dchar0 \ - -mon chardev=3Dchar0,mode=3Dreadline \ + -object monitor-hmp,id=3Dhmp0,chardev=3Dchar0 \ -parallel chardev:char0 \ -chardev tcp,...,mux=3Don,id=3Dchar1 \ -serial chardev:char1 \ @@ -5004,12 +5004,13 @@ SRST =20 enables the QMP monitor on localhost port 4444 with pretty-printing. =20 - The use of ``-mon mode=3Dreadline`` is syntactic sugar + The use of ``-mon mode=3Dreadline`` is deprecated syntactic sugar + The use of ``-mon mode=3Dreadline`` is deprecated syntax sugar for the new ``-object monitor-hmp`` option, each use of which creates an object with the ID ``compat_monitorNNN`` where ``NNN`` is a counter starting from 0. =20 - The use of ``-mon mode=3Dcontrol`` is syntactic sugar + The use of ``-mon mode=3Dcontrol`` is deprecated syntactic sugar for the new ``-object monitor-qmp`` option, each use of which creates an object with the ID ``compat_monitorNNN`` where ``NNN`` is a counter starting from 0. @@ -5771,8 +5772,7 @@ SRST to dynamically delete the monitor at runtime. Note that monitors created using the historical syntax will be allocated IDs following the pattern ``compat_monmitorNNN``. - Mixing ``-object`` with ``-monitor`` and ``-mon`` syntax is - discouraged. + Mixing ``-object`` with ``-monitor`` syntax is discouraged. =20 The ``readline`` parameter, which defaults to ``on``, controls whether the monitor provides line editing. @@ -5785,8 +5785,8 @@ SRST to dynamically delete the monitor at runtime. Note that monitors created using the historical syntax will be allocated IDs following the pattern ``compat_monitorNNN``. - Mixing ``-object`` with ``-qmp``, ``-qmp-pretty`` and - ``-mon`` syntax is discouraged. + Mixing ``-object`` with ``-qmp`` and ``-qmp-pretty`` + syntax is discouraged. =20 The ``pretty`` parameter, which defaults to ``off``, controls whether the monitor responses are pretty diff --git a/system/vl.c b/system/vl.c index 63bdd06dfa..061cbdf860 100644 --- a/system/vl.c +++ b/system/vl.c @@ -3239,6 +3239,8 @@ void qemu_init(int argc, char **argv) default_monitor =3D 0; break; case QEMU_OPTION_mon: + warn_report_once("'-mon' is deprecated, use '-object' with= " + "'monitor-hmp' or 'monitor-qmp' types ins= tead"); if (!qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg, true)) { exit(1); --=20 2.55.0