From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121321; cv=none; d=zohomail.com; s=zohoarc; b=Qef/imuq4lJcUlRc8xGsab/jBPcTAttRCudr38XcxVLR2cLbJY+ecWWkhwDO3qfvdy/g/UYtq0gYj4pigdCY5KvKQ8p31eYvb0fCxbTLQ8PxiFEnEt9O/1dUQMli8xJK7HSr+KJRMr1lRbTGTFA1F3kHf96h8kTIm33W9NFdHXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121321; h=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=oseK8j5bYgRDO/3pjj5kj8+f5w/39DM9IAFzzThU830=; b=CQKpm9+AQzEph1jFlVn7n7WnCtZpLb4JJiT5DNMy6Y4kDnkDNRE33T58w0wZ6ub7kxRTxp/swtYdWuFi5OpVYHit5o7aCCZ+2+tZhoCACUg3dUYYpHRQU0h42ptpn8g9U/2C9g+9tMdm9+KpqQPMHkQv/eXuUgt5NazjwHOlpZ8= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121321074155.3592459709996; Fri, 11 Sep 2026 03:08:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yAN-0006I2-P0; Fri, 11 Sep 2026 06:07: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 1x4yAK-0006Hl-SI for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:28 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAI-0007Dw-Df for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:28 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2dcff8f44f2so10372955ad.1 for ; Fri, 11 Sep 2026 03:07:26 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121245; x=1789726045; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=oseK8j5bYgRDO/3pjj5kj8+f5w/39DM9IAFzzThU830=; b=Izp4FjFA5tAv+IQb6fyHHhonAAXwofW9+CWyt92rHotxHs2b5UmtHMhdeImso08MRO gaFSGgyF/Zyd8jF3NAu1Xmk0U4sKtOgxOb41CtH5k/Y83RlIHx9njlPoJ5mRaBHXUt3b DXBkQiJSP3UD3TB4Zqay4prwcmpgqdBto+J+JcNC+JrJgWvPbkTPEdOnWFTrWWGqkEzn 2QTWLEH5ARtxS1DfXISidsabw8aO+EfekxoVNYzCiYeXK6sA0J4eJcQ8ypQdxV1WtRzG 4H8NYtDETSetpEHLl+vC/OO1EkHZT8bPSg9QXfXBI4XJ3NRGN3ouR8bUWwPOTqzTzMzo RRDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121245; x=1789726045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=oseK8j5bYgRDO/3pjj5kj8+f5w/39DM9IAFzzThU830=; b=SJVYWlEcIMHJ5+wkFKX9N/Y2yRnc211Wr+i0nlTgsfEZZsgkofcKzIvi9orsI+pBvK H7U9aMlSjToP1LYRLzn6AT2TFekj1y5dx5JBAl3LwOzP581PrdzxuWzyk64qutCQJpM8 +MpifGuYuor9F/ownWz+TczRKQ5qj79vUFt96Jw6uO9+matceiWUCtI9U+haRMmWS37W +6sZzeSue/GZf+wtrP8SCfalxFrxefU2U5/APSnNHayOngGOqKmCksXk8ABzaC75k4SE o8XoWPLwtgPxtFQW93ZX/gPQPFiOGRVl6pa2DjJYb2yntO9HapuBTzfU2q2RMRzDlY3x 1GzQ== X-Gm-Message-State: AFuF++mdDynabK+NCamevE6TShY+p/U6IOztlfH1tz9gUfKXyBCxyGtF 49HrJUDlw2lByjMN+GeE7J4hZ6h9kjXY/8ifnjv7xmi+JeVrXY9hxm2SFwOLqAl6p1Q= X-Gm-Gg: AYBFou2ljQevEiOR/Gaqb3HDl6xqwmbNmhr5yODMV3IgSCplaff0gYdUad9oGHs2YFe Z0xuCM/TkD21snP01uHrzB6WMa4a2s+IyfDZJIg6ViQSwnRxsI7JASTIKuxbr9ncNxe6uXdeUJ/ xKaWi6rWct6UjgGiw6cwdyAhYs3CuvIAl4jd5g5VvWfQ6mE2gk1oFG6UbD181RFol0KsS8Shf36 LmYAu9qa8QBJZeWTZgpQh7QeQROkTTNbLF88IrXDRKibmnbTYjY+EseR0du4YPXr2SDGm48G6a5 o7JZxot2huwGJNFBlz/Bk7Yae29oMwVGjX1ff5yIkfEAh9To96jAdSEPpmNrnfRCYNn6ha1rxOv yKNC7gqHxn7wseY0Tp9uwXAuy2+MUcU7AyHsbJKd94SyoQxu+K0Yhc1SqpXlwnjBhPmmFI6W3N8 Xz/GmBL0vFR7Ie2FZ0msd7o+kPcHpxFD11Dj3N5hGsNZwA0d1nZ+HMrP3dFQraae7PRzN6VzrJe OJOV3w3bjc5YZVrWkBAd+My9VE= X-Received: by 2002:a17:90b:35d2:b0:39d:8d38:8b04 with SMTP id 98e67ed59e1d1-39d9bbea1d3mr6188397a91.1.1789121244812; Fri, 11 Sep 2026 03:07:24 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 01/13] iothread: introduce holder tracking Date: Fri, 11 Sep 2026 18:06:57 +0800 Message-ID: <20260911100709.726366-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121322531158500 Content-Type: text/plain; charset="utf-8" IOThreads do not record the QOM objects and block exports that use them, making runtime introspection and hotplug debugging difficult. Add: - holders: a list describing what is holding an iothread - iothread_ref(): add a holder to the list - iothread_unref(): remove a holder from the list A holder can identify either a QOM object or a block export. A later patch will expose this information through query-iothreads. Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- include/system/iothread.h | 5 +++ iothread.c | 63 ++++++++++++++++++++++++++ qapi/misc.json | 94 ++++++++++++++++++++++++++++++++++----- 3 files changed, 150 insertions(+), 12 deletions(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index a1ef7696cb..b8aeb32b0e 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -18,6 +18,7 @@ #include "qemu/thread.h" #include "qom/object.h" #include "system/event-loop-base.h" +#include "qapi/qapi-types-misc.h" =20 #define TYPE_IOTHREAD "iothread" =20 @@ -50,6 +51,7 @@ struct IOThread { bool stopping; /* has iothread_stop() been called? */ bool running; /* should iothread_run() continue? */ int thread_id; + IOThreadHolderList *holders; =20 /* AioContext poll parameters */ int64_t poll_max_ns; @@ -82,4 +84,7 @@ void iothread_destroy(IOThread *iothread); */ bool qemu_in_iothread(void); =20 +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder); +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder); + #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 3558535b40..66dfde626e 100644 --- a/iothread.c +++ b/iothread.c @@ -21,10 +21,71 @@ #include "system/iothread.h" #include "qapi/error.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-misc.h" #include "qemu/error-report.h" #include "qemu/rcu.h" #include "qemu/main-loop.h" =20 +/* Add a deep copy of @holder to @iothread's list of holders. */ +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder) +{ + assert(holder); + + QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder= )); +} + +static int iothread_holder_compare(const IOThreadHolder *holder_a, + const IOThreadHolder *holder_b) +{ + const char *name_a, *name_b; + + if (holder_a->type !=3D holder_b->type) { + return holder_a->type - holder_b->type; + } + + switch (holder_a->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + name_a =3D holder_a->u.qom_object.qom_path; + name_b =3D holder_b->u.qom_object.qom_path; + break; + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + name_a =3D holder_a->u.block_export.export_id; + name_b =3D holder_b->u.block_export.export_id; + break; + default: + g_assert_not_reached(); + } + + return strcmp(name_a, name_b); +} + +/* + * Remove @holder from @iothread's list of holders. + * + * It is a programming error if @holder is not present. + */ +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder) +{ + IOThreadHolderList **prev =3D &iothread->holders; + IOThreadHolderList *curr; + + assert(holder); + + while (*prev) { + curr =3D *prev; + if (iothread_holder_compare(curr->value, holder) =3D=3D 0) { + *prev =3D curr->next; + curr->next =3D NULL; + qapi_free_IOThreadHolderList(curr); + return; + } + prev =3D &curr->next; + } + + g_assert_not_reached(); +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -129,6 +190,7 @@ static void iothread_instance_finalize(Object *obj) iothread->main_loop =3D NULL; } qemu_sem_destroy(&iothread->init_done_sem); + qapi_free_IOThreadHolderList(iothread->holders); } =20 static void iothread_init_gcontext(IOThread *iothread, const char *thread_= name) @@ -373,6 +435,7 @@ static int query_one_iothread(Object *object, void *opa= que) info =3D g_new0(IOThreadInfo, 1); info->id =3D iothread_get_id(iothread); info->thread_id =3D iothread->thread_id; + info->holders =3D QAPI_CLONE(IOThreadHolderList, iothread->holders); info->poll_max_ns =3D iothread->poll_max_ns; info->poll_grow =3D iothread->poll_grow; info->poll_shrink =3D iothread->poll_shrink; diff --git a/qapi/misc.json b/qapi/misc.json index baa50cc844..bb49969b4b 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -67,6 +67,55 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 +## +# @IOThreadHolderBlockExport: +# +# @export-id: The unique block export identifier. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderBlockExport', + 'data': { 'export-id': 'str' } } + +## +# @IOThreadHolderQomObject: +# +# @qom-path: Path to the object in the QOM tree. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderQomObject', + 'data': { 'qom-path': 'str' } } + +## +# @IOThreadHolderKind: +# +# @block-export: A block export. +# @qom-object: A QOM object. +# +# Since: 11.2 +## +{ 'enum': 'IOThreadHolderKind', + 'data': [ 'block-export', 'qom-object' ] } + +## +# @IOThreadHolder: +# +# The block export or QOM object holding the iothread. +# +# @type: the kind of iothread holder. +# +# Since: 11.2 +## +{ 'union': 'IOThreadHolder', + 'base': { 'type': 'IOThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-export': 'IOThreadHolderBlockExport', + 'qom-object': 'IOThreadHolderQomObject' } } + ## # @IOThreadInfo: # @@ -76,6 +125,10 @@ # # @thread-id: ID of the underlying host thread # +# @holders: the QOM objects or block exports currently holding this +# iothread. When a holder is detached or destroyed, it is removed +# from this list. (Since 11.2) +# # @poll-max-ns: maximum polling time in ns, 0 means polling is # disabled (since 2.9) # @@ -98,6 +151,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -122,20 +176,36 @@ # -> { "execute": "query-iothreads" } # <- { "return": [ # { -# "id":"iothread0", -# "thread-id":3134, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread0", +# "thread-id": 3134, +# "holders": [ +# { +# "qom-path": "/machine/peripheral/blk1/virtio-bac= kend", +# "type": "qom-object" +# }, +# { +# "qom-path": "/machine/peripheral/blk2/virtio-bac= kend", +# "type": "qom-object" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # }, # { -# "id":"iothread1", -# "thread-id":3135, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread1", +# "thread-id": 3135, +# "holders": [ +# { +# "export-id": "export0", +# "type": "block-export" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # } # ] # } --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121262; cv=none; d=zohomail.com; s=zohoarc; b=d66vSJ2Cs3jWaPNsRf9D00acR8lB0BWdEF5PUK2jlGrFUwa95hnNm7qE2m8iY1zPYv6oPmKQ+AuXJ0K3K9rMA1wa7I3rlk47S+dCWRG6cYcgXmwIkw5dnNYl1Uy5b9OJZvDYKYJPNdPm2l2QmiomlhlAApVZ8/Y1a4JWtvHKd+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121262; h=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=Pz3DcON57YEbbfHibWzK/oVMwkZxaS7iLzoMd5bKkPw=; b=XWWvqjhxYk+9TBvCpvJJaMPTvkqUIgz0N5Kpysey9HYdK5ulWS5tF5uiyYQtMex4SOcyObjxwt6fB6Y7ZivBUbPZK18+a8ss322c7Vxj9buv+JF51jAyRAVpCyNfikudbvqxY8hMOx/Kq7ySin7hCMBvPiORLJT2KAUd9xyAPSo= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178912126241595.97242045174585; Fri, 11 Sep 2026 03:07:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yAP-0006IQ-OV; Fri, 11 Sep 2026 06:07:33 -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 1x4yAN-0006I3-P4 for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:31 -0400 Received: from mail-pj2-x10.google.com ([2607:f8b0:4864:39::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAM-0007Ev-3Q for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:31 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-396ccc09d65so558819a91.3 for ; Fri, 11 Sep 2026 03:07:29 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121248; x=1789726048; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Pz3DcON57YEbbfHibWzK/oVMwkZxaS7iLzoMd5bKkPw=; b=rh+Rpyd6NaB20CJvcW5lH+pz3ppMqamo8zO5T4Wv6/mBuUbIkCh/4WCUPkHMgDpiql /R+pKWCcgLQoIH7PIVNPPnKVSoI6bfNUxUl8AiIZSBVMgVVfOh/FbtZT0cjJodbfZOlN EGnntUpxzYNXQ8i+Q4qyxMZ9yFpZP48a7n+XEOShm3kuXwquXfNzdEq/S0/sklpHN/de t/VcVHaxu8NLMVcED5Hsf1pfJPLhLimO9FMpDBLYDO+hHxri82mhyKBzBJGuIhDUFGYp 4fE6gl1NdnlkEN96Z3Vkz6/BKko3Ulam97R7fb5SZFpARU2IMcoaZtwOOnXNRRSWWAoa L4hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121248; x=1789726048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Pz3DcON57YEbbfHibWzK/oVMwkZxaS7iLzoMd5bKkPw=; b=Ar73TA6ZrkmSIsp9cmIe3kzKjyP4cC5BuD529mU6amidBJRazflD2g3R/+TzTx9bbr 8ynsb31ozfApXS6HXMxZwzqI5ADVX3MYiTv+O+agR0u4rQL+MAHaDwBu3QtBLTMRfP1N S4JCJt3QeLPj8fRYjFJb4zVJ7xEqvjGhP8tJN9sxHd0Zo7339nH28oyzFBHrvSM/J/xs Fdf/lf2l/+c6jJjODU8gfwH/WXryygCcDKkz8ZQO7pP+bQg2ifyGwH83X/ekNfB7PTzS Yv9V3D7ZdWzoT8f8qU/Zgl0s8t9WixyfhvpULgBZARbhcWhyqc13VZlDFFioX4+Ukm84 koMQ== X-Gm-Message-State: AFuF++lbUgTqtrCR+TXdpTsnqbfQOXlshISD8a6zuh/gVTJZO/0mW1WP mGg+rqH4ekm3FGFg2A06xwYTtcyczA1lUrl5OqbW6LM1iC+qFJlpR9zny4VQBg== X-Gm-Gg: AYBFou2rd6ZKIVgrpFRae2+cMz4lI5BRAPYGZdOUOSY+U/7hpgTW7Tc3K89e2NGa3PI Ots7wyUGVUKKLGN8p10/bHrCOP5Kg4y3gUCFqxCeUArbrzggBcjP9c8fq5DmnR8l1NJANZcJZ8o GIO/ZpNHFZiplzY25fU1Y2tcJhR+XBLtXisuivIjE76LowV77mgEIVlVIKta/UR2LD+EOquJaSn /hc4EDBlSvYSI/KB7tgJeeJRz7xGBrc5nU3/JZJfBg0SurRCw35O6AdTiB0oqocXr/ITIIAFQgU Gcwyes2d0GVDpfqneNm2YSLeBT1CsH2pu8usan+xTI+ysu/TsMejS+ESV/AmARQaHFUubgH97gR snHBW09acExlSUXJy1ae8PlHaWNxPrjZ/IsBrlICpohoLYiHakJsVyVmBSNVpdoa8GqY/b/tjKi oOycG2wQvIq56CR6imR6gfW+noj8hBdi+u9kNAAK+xO+fpJ/nKm+qDN51dL1aE84hRGVwbv63Rh j38nqW15VwZgC7daKrIVo5po/8= X-Received: by 2002:a17:90b:5111:b0:39a:e002:f192 with SMTP id 98e67ed59e1d1-39d9c3f0dbamr5943540a91.22.1789121248398; Fri, 11 Sep 2026 03:07:28 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 02/13] iothread: add holder-aware AioContext accessors Date: Fri, 11 Sep 2026 18:06:58 +0800 Message-ID: <20260911100709.726366-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:39::10; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121264833158500 Content-Type: text/plain; charset="utf-8" Introduce iothread_ref_and_get_aio_context() with a holder argument and its counterpart iothread_unref_and_put_aio_context(). Previously, users of an IOThread AioContext did not explicitly record their identity, making it difficult to debug which devices or subsystems were pinning an IOThread. These new helpers provide the infrastructure for callers to register their identity. Subsequent patches convert existing users to the new helpers. Registering a holder takes an IOThread object reference so that the IOThread and its AioContext stay alive until the matching put operation. Document the ownership and BQL requirements. Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- include/system/iothread.h | 22 ++++++++++++++++++++++ iothread.c | 24 +++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index b8aeb32b0e..f6c5f95dd9 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -67,6 +67,28 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); AioContext *iothread_get_aio_context(IOThread *iothread); + +/* + * Register @holder and return @iothread's AioContext. The holder is copi= ed, + * and a reference is taken on @iothread so that both the IOThread and its + * AioContext remain alive. + * + * The caller must eventually call iothread_unref_and_put_aio_context() wi= th an + * equivalent holder. This function is not thread-safe and must be called + * under the Big QEMU Lock (BQL). + */ +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder); + +/* + * Unregister @holder and release the corresponding reference on @iothread. + * Calling this function without a matching + * iothread_ref_and_get_aio_context() call is a programming error. + * + * This function is not thread-safe and must be called under the BQL. + */ +void iothread_unref_and_put_aio_context(IOThread *iothread, + const IOThreadHolder *holder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 /* diff --git a/iothread.c b/iothread.c index 66dfde626e..58dace351c 100644 --- a/iothread.c +++ b/iothread.c @@ -33,6 +33,11 @@ void iothread_ref(IOThread *iothread, const IOThreadHold= er *holder) assert(holder); =20 QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder= )); + /* + * This guarantees that the IOThread and its AioContext remain alive + * as long as there is a holder. + */ + object_ref(OBJECT(iothread)); } =20 static int iothread_holder_compare(const IOThreadHolder *holder_a, @@ -78,6 +83,7 @@ void iothread_unref(IOThread *iothread, const IOThreadHol= der *holder) *prev =3D curr->next; curr->next =3D NULL; qapi_free_IOThreadHolderList(curr); + object_unref(OBJECT(iothread)); return; } prev =3D &curr->next; @@ -199,7 +205,7 @@ static void iothread_init_gcontext(IOThread *iothread, = const char *thread_name) g_autofree char *name =3D g_strdup_printf("%s aio-context", thread_nam= e); =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_set_name(source, name); g_source_attach(source, iothread->worker_context); g_source_unref(source); @@ -421,6 +427,22 @@ AioContext *iothread_get_aio_context(IOThread *iothrea= d) return iothread->ctx; } =20 +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Add IOThreadHolder to the list */ + iothread_ref(iothread, holder); + + return iothread->ctx; +} + +void iothread_unref_and_put_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Delete IOThreadHolder from the list */ + iothread_unref(iothread, holder); +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121290; cv=none; d=zohomail.com; s=zohoarc; b=PnHZ3nklCNyipJtwKyoI0cWwLqOnpQjEwmKdGQXXiCcpgLx8UT6fANJmEuhFyOEZzhX84QZbpmkH1Iw/8JKMPJUiUTKS5ov0+XXjlPG99Bb9q2JMvYd9C+5fRYE3WuhyXWotJGrN5oybW9nUcdBlPAoSkdG6qozWB51ZuiIcEDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121290; h=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=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=mBRD+6TOSB9hXCrkN9RTHbI+9c5RtW7D3iIRpPw5PLSkoen2gFovpZb4P2wLHKDwEBEBO9G682UWxqsL6K6pZ4T6vjiuJb1bAdgb7KWeSG4IIb+JM0pqJtKWyY/3r0eKjvqgp8pXHmqXIz7KUvkakC3KiodJ7mLd9CORVVEKpNw= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121290328675.3038607478362; Fri, 11 Sep 2026 03:08:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yAU-0006J1-F7; Fri, 11 Sep 2026 06:07:38 -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 1x4yAS-0006Io-9Y for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:36 -0400 Received: from mail-pj2-x10.google.com ([2607:f8b0:4864:39::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAQ-0007FV-DG for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:36 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-396ccc02279so712751a91.1 for ; Fri, 11 Sep 2026 03:07:33 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121253; x=1789726053; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=JSHJbAD2Yep9Z94o9jvxYdKpZQ7k1aZ7qkMmxBquu/tJG6xyrCuqzeC2BcLPokFJZh A0KNhSwpPLhsyogkbTCRu1GinzAgjmg8AzTKngJbBFcT/7MgR7W/50v1NmcU5qRvLzNd vBCjAMpcDBjS9EbnDsUXQwOZR3r6RwPEoYZjPo+SOFzPDAmIy6ky1duG5F7TkjviUuOF avpj9c0YJ8Ag8OKtGfVDtDjlM4evXY6fOnjgYnIdmXnjM57j34iDHa/LXFLpv/5ibssy K6jnDwJGBZpxkYljX9wl08+O8C1N9xwR/zg5k/MG7wsKfFexNFGlCFsHNyeETvKa+A/V T6FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121253; x=1789726053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=hugq0YeEuw2MctDU3SyUU8eDsB9ROYlLxpMpD/GQX9R2Vuh3gOW6k4GfcWxsOC4pkj 4RdLkVNVf0cYayqDAOmRPXD55iP6r1og1vxuubbkt2dnLDj8dwhn9oSiGXXnRyeuwWrO cwMoIC4uGPVh9yiCrhrN5CwQIq6bnfbYz8J+C3LkiQ9u7xNz8wuOQzM1ArdXdKljNbMv V+O1sYEI//s08XZTAev3mCImfHjfxStWPQjyy/Cfy/NslS0+kxJGM56Cfo+xwdyZzSZ2 nP/tIzBCh62Nh3+IloWkPFwTxay1Dqt8RiwqfkO5pUw8/+jZLnmxtW07NZoIUr2jmdBH f+nQ== X-Gm-Message-State: AFuF++mO3bJZv82vfxbSluoodBKUvxyfK6y8xDBbV6VzNl2TV8ZxFPfF MkKCJHNegn3tZWrC3dB8hE+c05cg1cvwfFfVx0onCiQZtc/42Bk8WzsUrD58yDi6GZM= X-Gm-Gg: AYBFou3owU+5IsPdMzWphI8dccaf6hOvZhhPSQITRhP3lObQ8NlNRPcKaTyxPZgzWb7 0MO/ST3cR9QtviQeqdiJS7jSzHv3UREOGOlIFOHPYZ5NJGeKbzkIMGfx8S7C0UKHIjV/dJy8rK4 /MGUUzgVe6nMM9HHBH+80/yD3PfG3Yg4n/89yHztSD9RbIRAyRLDCmiFPZxdcKjd3bSZErz9tIR QeF43SCIpXqwUg+Wsdcd4N4T0K8/wJ/HI59Va7HlND3xLJmniIrT8lVbMfPr8CVORkXg7dLw/sC WgSK55Hoty79Sxh5QhruN44EV15mJiTrgW51Cf7uINWSGuT4KIBmptKQG/3lc3s7m07TSLfYluf 9zIDRRMfLFdPdsp0vG48rXpwUE6IMFCcQSU7cI0zc+TQABt7hyPvuprLAvA/ZcQtAq9ynwi7+J+ yE/slFt2WyeXr+mf8dVNq4bnPZEvrwIgcL0Oo+WQODsIFap/d/mc46yxW31RhWv04IMSq2/SSyQ 6GhyCblOlFzdJxKbWolJAQyInU= X-Received: by 2002:a17:90b:1c88:b0:39d:83d0:41b2 with SMTP id 98e67ed59e1d1-39d9c230cccmr5294822a91.15.1789121252752; Fri, 11 Sep 2026 03:07:32 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 03/13] block/export: track IOThread references Date: Fri, 11 Sep 2026 18:06:59 +0800 Message-ID: <20260911100709.726366-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:39::10; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121292343158500 Content-Type: text/plain; charset="utf-8" Track the IOThreads used by a block export and identify the holder with the unique BlockExportOptions id. Acquire holder-aware references during export creation and release them on error or export deletion. Support both single- and multi-iothread exports. Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- block/export/export.c | 62 ++++++++++++++++++++++++++++++++++++------ include/block/export.h | 5 ++++ 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..0e019545ef 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,7 +15,6 @@ =20 #include "block/block.h" #include "system/block-backend.h" -#include "system/iothread.h" #include "block/export.h" #include "block/fuse.h" #include "block/nbd.h" @@ -72,6 +71,32 @@ static const BlockExportDriver *blk_exp_find_driver(Bloc= kExportType type) return NULL; } =20 +static void init_iothreads(const char *holder_id, IOThread **iothreads, + size_t num_iothreads, AioContext **aio_ctxs) +{ + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_id =3D (char *)holder_id, + }; + + for (size_t i =3D 0; i < num_iothreads; i++) { + aio_ctxs[i] =3D iothread_ref_and_get_aio_context(iothreads[i], &ho= lder); + } +} + +static void cleanup_iothreads(const char *holder_id, IOThread **iothreads, + size_t num_iothreads) +{ + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_id =3D (char *)holder_id, + }; + + for (size_t i =3D 0; i < num_iothreads; i++) { + iothread_unref_and_put_aio_context(iothreads[i], &holder); + } +} + BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { bool fixed_iothread =3D export->has_fixed_iothread && export->fixed_io= thread; @@ -85,6 +110,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Err= or **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + size_t iothread_count =3D 0; uint64_t perm; int ret; =20 @@ -139,7 +166,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; + init_iothreads(export->id, local_iothreads, 1, &new_ctx); + iothread_count =3D 1; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +193,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return NULL; } =20 + local_iothreads =3D g_new0(IOThread *, multithread_count); multithread_ctxs =3D g_new(AioContext *, multithread_count); i =3D 0; + for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,9 +204,12 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) error_setg(errp, "iothread \"%s\" not found", e->value); goto fail; } - multithread_ctxs[i++] =3D iothread_get_aio_context(iothread); + local_iothreads[i++] =3D iothread; } assert(i =3D=3D multithread_count); + init_iothreads(export->id, local_iothreads, multithread_count, + multithread_ctxs); + iothread_count =3D multithread_count; } =20 bdrv_graph_rdlock_main_loop(); @@ -225,12 +260,14 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D drv, - .refcount =3D 1, - .user_owned =3D true, - .id =3D g_strdup(export->id), - .ctx =3D ctx, - .blk =3D blk, + .drv =3D drv, + .refcount =3D 1, + .user_owned =3D true, + .id =3D g_strdup(export->id), + .ctx =3D ctx, + .blk =3D blk, + .iothreads =3D g_steal_pointer(&local_iothreads), + .iothread_count =3D iothread_count, }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -250,8 +287,12 @@ fail: blk_unref(blk); } if (exp) { + cleanup_iothreads(exp->id, exp->iothreads, exp->iothread_count); + g_free(exp->iothreads); g_free(exp->id); g_free(exp); + } else { + cleanup_iothreads(export->id, local_iothreads, iothread_count); } g_free(multithread_ctxs); return NULL; @@ -273,6 +314,9 @@ static void blk_exp_delete_bh(void *opaque) exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); blk_unref(exp->blk); + + cleanup_iothreads(exp->id, exp->iothreads, exp->iothread_count); + g_free(exp->iothreads); qapi_event_send_block_export_deleted(exp->id); g_free(exp->id); g_free(exp); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..ce8e4eb604 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -16,6 +16,7 @@ =20 #include "qapi/qapi-types-block-export.h" #include "qemu/queue.h" +#include "system/iothread.h" =20 typedef struct BlockExport BlockExport; =20 @@ -89,6 +90,10 @@ struct BlockExport { =20 /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; + + /* The IOThreads utilized by this specific block export */ + IOThread **iothreads; + size_t iothread_count; }; =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121349; cv=none; d=zohomail.com; s=zohoarc; b=H9uQc625ZyDzrFVjWHunzTQuPvX6dtny9G16LT+v19vHb4X9J/05SmkTqpI+w1NDsXTOvbYVaiNINz/cFTCWZR/aqqv0WP2eKipDnFvo/BKowFPknSpV+DFogQxi0f5G2z0hm0v9ZoP8dRNs7m//vkSkWEVy+8ZFDfLLebwNElk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121349; h=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=JoV/L3vaZSj9f3RbohvwlCdSIoQZKn965jasW56Se3c=; b=CZWfAaHgDTuo4FMR3EgV8+ks6K9YMrYnzE0rq0hoTp8EnzUo0NRVKnTVQAw+7FvWFpcSFqybMGhFYvzQu7xW5pEXFNTXHIBKvP4OT0xfngY4vUfDnuxsINKad6sm8RiOET8Ji2F15+zhjfVsg54itFvF1S4EFJRVRY0EfzxfzPw= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121349690202.42538730253852; Fri, 11 Sep 2026 03:09:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yAZ-0006MT-By; Fri, 11 Sep 2026 06:07: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 1x4yAX-0006L1-Qq for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:41 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAV-0007G5-Rd for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:41 -0400 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-39675172593so742676a91.2 for ; Fri, 11 Sep 2026 03:07:39 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121258; x=1789726058; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JoV/L3vaZSj9f3RbohvwlCdSIoQZKn965jasW56Se3c=; b=glJcR6fS/2LB5UOaJOXm2oSmY1DR2onKbu79QT5lcydm5DHl4e0m/6KUnfz+WC5CG/ 53ZGzx0QEx530Pmx1Li/EdVoVu39qIOXu5AAQcj8XV1OWfcUf6pWjgDEzyrWjErB2ly/ 0n/rzwXQP2DmVsCw20QNjNuUiLQQ4n8KD0lyoW4O+CsLnFyb7tyXMQkz88q8JUUTl2Tc p6MmVDIqbnf5bBTcFFI3xVfjbVA9bQcPhVcWMhq/REmLPPrw/xZbj1tlKpZOboapknTk CGtnFHLoLeTdBZGl6Bw1Ee5w8EDC56CcFVZsMLg10xmpgGRQ0hyhlXsskIbyh56OTaTm qYLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121258; x=1789726058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=JoV/L3vaZSj9f3RbohvwlCdSIoQZKn965jasW56Se3c=; b=qpDWDjIMTcvxjFzRYqzzaT2AFSmn9xnNeOyvTOpKMF3sSBALuMfn8cBCKjtZ7qaFvS vg9eE1KxxjmL+bTLBPDlUUHj4QmEGZqKjC/SGEBiKwOfgVIs30HZYayDByi5bC4FVDZb hxyx5GU2H3+Blg7qiEWuWEWMjEZU1/3FTgjRccqaAZtJ2k6uUbLht9LRTLvw3U+XAF21 SnGezoG4w5xpJ7Hl/lVwpoWt4Dj7eisf6l/0c8fOXY4Vq7EemdPayx3qmux9RHsmXj5e u5xBfGgst570MblLAB4zRyxF1cIr2win2Hzlx9Fp8CVE0Sm/SPv3V2VqjjqwI8k4K63C v8vA== X-Gm-Message-State: AFuF++kd0fuU5KfPEHVTwWyW9kyRvnQsl4MnnLYUD8n3XbxAlEGDB+6O b7AKF2n1gsP6ddeMLJsl//HKPcnFQB93xK9nh8GVI0535/3a7n05TqQijnAhbj1T0TE= X-Gm-Gg: AYBFou26SMyA250I/MWd6PwiZ3TkIrqSysJ9OGwwRQP7mU8ARXMAH2+MpQ6zL9A6GQU yoneQJZbyn+tlFE6gAdFf3pSzse/IN8ZbqdovG+J4/xWvIsyHdBnmWGR7X5WGJmlQyd3rnPDbOG vA/Y3M8kAZh7a30yzLJv44Bi2GRLtXTm3HkKdbh5HSUn0zWZXKt05RdfXi2q4Y7NXe65ZWKSxNi MVOvwYR14gTWGf61woq67N708ZUvhSpoZnIuE1KmMLX8DvIJ+r19e98jUD9l+CHNRdbeTI7jqKK 04MG7C5qWQ9HFZGqjVvkPPi4p+voXcvFeprR1oTF6mDI8pSafpLqB3YD+JbYM9/sznJenpOUUB8 02ggbJhmuFXFtdxNZyqq+Y5NSaLOwPFP6y/jKKJVgGid2Uzc/fBXBtrbRQuE6dYo4SOlT5K+1zQ BAfoCNNPuO+UARb0Hns1krK5yToMsJSIREsDTWOiJzKjbKBp8s7Qf4B/7r7PY3jL64SHr0/Thki 3o4dW4cNkz+WNCVA8i0LetPahI= X-Received: by 2002:a17:90b:1648:b0:36b:bec8:94c5 with SMTP id 98e67ed59e1d1-39d9bec50b9mr5560376a91.10.1789121257478; Fri, 11 Sep 2026 03:07:37 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 04/13] monitor: track IOThread users with QOM paths Date: Fri, 11 Sep 2026 18:07:00 +0800 Message-ID: <20260911100709.726366-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1031; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121350703158500 Content-Type: text/plain; charset="utf-8" Monitors that require an IOThread share the internal mon_iothread. Account for each monitor explicitly in IOThread holder tracking, using the monitor's canonical QOM path to distinguish holders. Acquire the shared monitor IOThread AioContext once and store the IOThread and canonical QOM path so the holder can be released after the monitor has been removed from the QOM tree. Use the stored IOThread for per-monitor checks and accesses after initialization, and reuse the stored context for later operations. Release the holder from monitor_finalize(), after resources associated with the AioContext have been destroyed. This pairs the reference taken in complete() with instance finalization and keeps the IOThread alive throughout monitor teardown. The internal mon_iothread remains hidden from query-iothreads, as before. Management applications therefore cannot use it to determine which monitors are using the IOThread. Nevertheless, track the monitor holders so that they follow the same explicit holder and IOThread reference lifecycle as other AioContext users. Signed-off-by: Zhang Chen --- monitor/monitor-internal.h | 7 +++++-- monitor/monitor.c | 36 ++++++++++++++++++++++++++---------- monitor/qmp.c | 14 +++++++------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 822a66d06d..020afdaebf 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -77,6 +77,11 @@ struct Monitor { GString *outbuf; guint out_watch; int mux_out; + + /* iothread context and holder identity */ + IOThread *iothread; + char *iothread_qom_path; + AioContext *ctx; }; =20 struct MonitorQMPClass { @@ -109,14 +114,12 @@ struct MonitorQMP { }; =20 typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList; -extern IOThread *mon_iothread; extern Coroutine *qmp_dispatcher_co; extern bool qmp_dispatcher_co_shutdown; extern QmpCommandList qmp_commands, qmp_cap_negotiation_commands; extern QemuMutex monitor_lock; 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); diff --git a/monitor/monitor.c b/monitor/monitor.c index 2654b81890..a80d8dbf45 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -55,7 +55,7 @@ typedef struct { } MonitorQAPIEventConf; =20 /* Shared monitor I/O thread */ -IOThread *mon_iothread; +static IOThread *mon_iothread; =20 /* Coroutine to dispatch the requests received from I/O thread */ Coroutine *qmp_dispatcher_co; @@ -93,6 +93,16 @@ static void monitor_finalize(Object *obj) qemu_chr_fe_deinit(&mon->chr, false); g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); + + if (mon->iothread) { + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D mon->iothread_qom_path, + }; + + iothread_unref_and_put_aio_context(mon->iothread, &io_holder); + } + g_free(mon->iothread_qom_path); } =20 static char *monitor_get_chardev_id(Object *obj, Error **errp) @@ -164,7 +174,7 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) return old_monitor; } =20 -bool monitor_requires_iothread(const Monitor *mon) +static bool monitor_requires_iothread(const Monitor *mon) { MonitorClass *cls =3D MONITOR_GET_CLASS(mon); return cls->requires_iothread && cls->requires_iothread(mon); @@ -188,8 +198,8 @@ void monitor_cancel_out_watch(Monitor *mon) GMainContext *ctx =3D NULL; GSource *src; =20 - if (monitor_requires_iothread(mon)) { - ctx =3D iothread_get_g_main_context(mon_iothread); + if (mon->iothread) { + 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) { @@ -516,12 +526,12 @@ void monitor_suspend(Monitor *mon) { qatomic_inc(&mon->suspend_cnt); =20 - if (monitor_requires_iothread(mon)) { + if (mon->iothread) { /* * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. */ - aio_notify(iothread_get_aio_context(mon_iothread)); + aio_notify(mon->ctx); } =20 trace_monitor_suspend(mon, 1); @@ -661,7 +671,6 @@ 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); @@ -680,11 +689,18 @@ static void monitor_complete(UserCreatable *uc, Error= **errp) mon_iothread =3D iothread_create("mon_iothread", &error_abort); } =20 - ctx =3D iothread_get_aio_context(mon_iothread); + mon->iothread =3D mon_iothread; + mon->iothread_qom_path =3D object_get_canonical_path(OBJECT(mon)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D mon->iothread_qom_path, + }; + + mon->ctx =3D iothread_ref_and_get_aio_context(mon->iothread, &io_h= older); } else { - ctx =3D qemu_get_aio_context(); + mon->ctx =3D qemu_get_aio_context(); } - mon->accept_input_bh =3D aio_bh_new(ctx, monitor_accept_input, mon); + mon->accept_input_bh =3D aio_bh_new(mon->ctx, monitor_accept_input, mo= n); } =20 int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) diff --git a/monitor/qmp.c b/monitor/qmp.c index aec0315775..e235302fb3 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -187,7 +187,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 - monitor_requires_iothread(MONITOR(mon)); + MONITOR(mon)->iothread !=3D NULL; } =20 static void qmp_request_free(QMPRequest *req) @@ -678,8 +678,8 @@ static void monitor_qmp_setup_handlers_bh(void *opaque) MonitorQMP *mon =3D opaque; GMainContext *context; =20 - assert(monitor_requires_iothread(MONITOR(mon))); - context =3D iothread_get_g_main_context(mon_iothread); + assert(MONITOR(mon)->iothread); + context =3D iothread_get_g_main_context(MONITOR(mon)->iothread); assert(context); qemu_chr_fe_set_handlers(&mon->parent_obj.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, @@ -717,7 +717,7 @@ static void monitor_qmp_complete(UserCreatable *uc, Err= or **errp) =20 qemu_chr_fe_set_echo(&mon->parent_obj.chr, true); =20 - if (monitor_requires_iothread(MONITOR(mon))) { + if (MONITOR(mon)->iothread) { /* * Make sure the old iowatch is gone. It's possible when * e.g. the chardev is in client mode, with wait=3Don. @@ -734,7 +734,7 @@ static void monitor_qmp_complete(UserCreatable *uc, Err= or **errp) * thread. Schedule a bottom half. */ mon->setup_pending =3D true; - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread), + aio_bh_schedule_oneshot(MONITOR(mon)->ctx, monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ } else { @@ -788,8 +788,8 @@ static bool monitor_qmp_prepare_delete(UserCreatable *u= c, Error **errp) } =20 /* Synchronize with in-flight iothread callbacks. */ - if (monitor_requires_iothread(mon)) { - aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread), + if (mon->iothread) { + aio_wait_bh_oneshot(mon->ctx, monitor_qmp_iothread_quiesce, NULL); } =20 --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121323; cv=none; d=zohomail.com; s=zohoarc; b=O8ImC++bY/Pw8NIdyGEUowTg0lSWUMmvFQtDMVR8eKToNHWHTCSeiApIHY87cU5FZAVVcB5e1HZosQ5JX4x//Z3dKEL82bjbzke4YHkNSC5hLRAErHbjWOohRvZP04wQJB4A++1pwY9NEs3kLvbtY8u6FexrN8n24iyNeSMTUkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121323; h=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=y4Ly304K5RRD8FDCK8Kyv4PpWyXS/MRy2p4mFYN+SIU=; b=gK8sutun54YQSTIzFaD2e0BBN6blzIbkdDIIFx3V+uuy2GZTx4s/W82CVfZ7JSneIp3U03GYo93xsTPtUQU3Pm5SAtmH8heFTG3gVn3VA0jpUfgtYugNtsekQGUgYsfEBuec7bvTyIRmqL/DUZWUBzLQ/VTHCDrHaufHflVQo5g= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121323797313.52239259986834; Fri, 11 Sep 2026 03:08:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yAc-0006Pd-JN; Fri, 11 Sep 2026 06:07: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 1x4yAb-0006Oc-1d for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:45 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAZ-0007Gd-6a for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:44 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2d8f265cbe6so6879295ad.0 for ; Fri, 11 Sep 2026 03:07:42 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121262; x=1789726062; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=y4Ly304K5RRD8FDCK8Kyv4PpWyXS/MRy2p4mFYN+SIU=; b=lsiYi3syO409vq+Q+fIZMniWgESttYYLBCgogyuRqfE36+v1OEvNZoQA99ItrP89y7 Me60eKhZ1jzvZwaD+cVlQTU9WE9bXM7kLlgbgeLUAuzRwyZoD8TRKePsHRiGc6CRbL7j wHfrL6Qd1NBUjfQMMLfAd6cix2jVqMZo9wG0zqaIuue9G6vyGVccw4qbFPJclY4wagSx xpRPdQErM/VIDKZBw/r9gU+2FwSbrGu5NKMNn9/lrlXlRanpDHIC5Yx4LimVPQwHEjH7 /9Q5TRkeSZVlea375RFIESGcuMjRzM7uAvr8LSXTWz/K7xZu6hGKvuqireG5t1AIxKvX ItVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121262; x=1789726062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=y4Ly304K5RRD8FDCK8Kyv4PpWyXS/MRy2p4mFYN+SIU=; b=LuxEuDEsNAq7c1nZeEbIkR5fAROchLTbfneCZihN/2WjuPcriqYM9PlBU4zxh5EE8W /rsCDAZj/HBHRf+Q8luXEPA1yhsx7u3qkeq8cy6m5ocptQl+FZjYTe1CmZpdC2uhYbnz N8TZermmvK72Hjs5GIN0XxCfSwXARFmK7TTV8vGM1rIhVkEPwH/o2nkNJ1WzrBRCTmtq NOxBsKJDMk8RaLQRBD45LH826/q+iS+ReafQe549RSmJC4dQ/2pF+w8UpdRD502kh+Sp Mra3RikWxwBdjqqUbtHr4SI2L2rD2/6PXMvwsJHfZ3grJlrS/V2ApNaG41U8NfVMVxKN mf4g== X-Gm-Message-State: AFuF++k2IpCBvOzMzmeXfLVSbL1upUVKAC1UacBJHuhqOxONYT/tNdJ3 OzsgEBhTLMXpoFNxzdGZxwIg1MoXAdRVU+Ou9uGJB0ihcl1h2K7Q215itSuXTsgAUbA= X-Gm-Gg: AYBFou2TChbQFTtRkKhuCZhCRLDcQUWMmapPFfXGkDRIXR796NK8YN6ADgUEqUZWHgx 7r3+vFvg6SgZkUtCToP4N0A4WkGfZlD9J617iFRkvp4SGxam21IxuJsr/ipDSB8VPDbv9ZUfeR9 /4WCW7lS0m1h1QihoUI8X/OG4QgT6FZWuY++b/vwzJvicW4v+G606Go3PXUORYnEtWwgNXTUnnc Ar8phbMMpk5pBZsfqgrtmy7me26CAhoprgkHrUOM6FHxex7RK7iCPQFPRVUwfnbS8LAt/X8EeRT 3A0yoH8fSGpphHMD+aCtKtTgR+GhbB8fijnzmdViBdxTsg4tPtNcplxKtL1LtDP+Hpw3zU26zMp 1R75THG/opqhcInWz43w+Jp735WZ2UlJGSiRofk0iOHZ1M+uxz8nYkAG7LsmcBw0vRbber3C4bV A4vsO7VbRiq4xiutTtVBxXbY7vKOgQveu8sAUrNiZDu2zPrCeBj72rv2IiyMwziiTiH5XHKZOhK Rbn1gF1eyCsQ3EQl3HT1wpt/Ws= X-Received: by 2002:a17:90b:3c89:b0:398:ba9e:75ff with SMTP id 98e67ed59e1d1-39d9c35047emr5852556a91.21.1789121261625; Fri, 11 Sep 2026 03:07:41 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 05/13] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Fri, 11 Sep 2026 18:07:01 +0800 Message-ID: <20260911100709.726366-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::629; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121324558158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/ unref_and_put_aio_context in iothread-vq-mapping. This allows tracking IOThread users via the device's canonical QOM path, improving lifecycle traceability for virtio-blk and virtio-scsi devices. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 20 +++++++++++++++----- include/hw/virtio/iothread-vq-mapping.h | 6 +++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6b92066aff..4b2cf3d52f 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1493,9 +1493,12 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlo= ck *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, + path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; @@ -1527,7 +1530,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIO= Block *s) assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 95f13fb7c2..26ecefd547 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -65,9 +65,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], - vs->conf.num_queues, errp)) { + vs->conf.num_queues, path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); =20 if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 55ce62986c..60e1d55005 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -77,6 +77,7 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp) { IOThreadVirtQueueMappingList *node; @@ -93,10 +94,13 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_get_aio_context(iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; =20 - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, + &io_holder); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +124,19 @@ bool iothread_vq_mapping_apply( return true; } =20 -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; + + iothread_unref_and_put_aio_context(iothread, &io_holder); } } =20 diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/io= thread-vq-mapping.h index 57335c3703..0d39caddf3 100644 --- a/include/hw/virtio/iothread-vq-mapping.h +++ b/include/hw/virtio/iothread-vq-mapping.h @@ -17,6 +17,7 @@ * @list: The mapping of virtqueues to IOThreads. * @vq_aio_context: The array of AioContext pointers to fill in. * @num_queues: The length of @vq_aio_context. + * @holder: The QOM paths for attached device. * @errp: If an error occurs, a pointer to the area to store the error. * * Fill in the AioContext for each virtqueue in the @vq_aio_context array = given @@ -31,15 +32,18 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp); =20 /** * iothread_vq_mapping_cleanup: * @list: The mapping of virtqueues to IOThreads. + * @holder: The QOM paths for attached device. * * Release IOThread object references that were acquired by * iothread_vq_mapping_apply(). */ -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder); =20 #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121309; cv=none; d=zohomail.com; s=zohoarc; b=Ff+nh/UygQY9i9CNUS0moWt3z4XRBMI0u9gkCDFyxflhPhrp8UcSyUb7Wf6VfGMGvrv9Zos+IIABs1YPe7XBAibYP9B+rmUrjSMVSZX/tZmRnHvMsj9eISz4GzzU/uWQgBsEgBEH+w1U8VI2ZL4nmMdi7FI5qlX7bfOoqd+1zJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121309; h=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=GCwys0A7wABlzdjCSJp+U9W8UOKwT+jGbbtakz7i/jE=; b=bn+GzxedbuZkMsG5KB+NROhyp+/xHVfcy4JG1YjVU6CyTWEYFlmSU2hwjYyhLQDREV6WwGaCBt8aTHqZU65wzsEbf1r43Z5RZ2vNMKtYpQFPBk1i0B+cdPj4N/g63A6qeUN1MJ9dHDa/IV10GEGaAEZPP9/jNbyOvoGjDDiWqZE= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121309867971.2788611217065; Fri, 11 Sep 2026 03:08:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yAw-0006Xu-CH; Fri, 11 Sep 2026 06:08:06 -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 1x4yAf-0006QW-AA for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:49 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAd-0007HA-9B for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:48 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2cc891373e0so7151215ad.2 for ; Fri, 11 Sep 2026 03:07:46 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121266; x=1789726066; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GCwys0A7wABlzdjCSJp+U9W8UOKwT+jGbbtakz7i/jE=; b=U5NcfII/2VP63IVM8XtduNsK85ZgLukfO1jToSCfZ/b2CQ1SZ+2smg41/Q/kCIvs/4 lVa02/T4lEgaogJt5S/qpDOFkTw5xOrmugSpwqbpJiJpeMsIzPulF1DQy1mUyDhPuODZ HlJ1kRxFSZA6EcYcOTJgpOqVNnOkbP6PYMdWTpNvdUn9vNjViIrI1tBCi4vYLp2i4sXR ObclyBc1FicIhc4dDjs/rvIuIQdxZ6y7S1J2dbNLxCbYNYjZwQ3gtKpVS0n871zT66ds DU01dEWCzv178sk+/dJWa1NMkUu1o9N6pEKy81iPYyMTowLPToOmYMgZJ9h6Ehqi3VKQ 1cJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121266; x=1789726066; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=GCwys0A7wABlzdjCSJp+U9W8UOKwT+jGbbtakz7i/jE=; b=BlBIn//ME7OU9yVIuTMBwhQRFdSmo3rNwLe3YCxvDmAp3rL6GG2t4yLaVXrtkQZYdB ujOJ7MkaVdCYZm0hUc6jylOup3CubMCj0RrM1aV+K37aNFoXv3FyvrnloJsJ16FHZb0k hhp+gCqTa2NYbT0WCWsIqKGmcj16qayJVEZ/Zru/Qu0Qe3NnxO0qnPkFTo36sLnruINS IeOPq7Klw4nhDGBu3ka8WrWepTxkebFcoXSIXsLOVXecC5opi+QOEvj0BfPvLRIKYEoQ ZbBR5ibGAHhptbNhDKrwBGZ9hLLuXFmVM0UvvQb0ckD2VKhjGlpZwrUpcQ5crXsEHHZM RQMg== X-Gm-Message-State: AFuF++kBN7+xnMZ8tWE+zONMoReLVO1XdI3uCJLQf1Fn8Mpcv9Y9NI17 /biCOHhfd3SJJjSMUFrDCOu0c/qsMZSxXwAh1bXkF4wO3BdBR8lTJBP0k7uh0A== X-Gm-Gg: AYBFou3ZMOfzBW0kHe4/+ULE9gNPAc0e1ofHW0XZ8mg9NPoctZkthp840o5sf+H/Q0d Anz8vw8uKYUg8QHCncwVueuvrVV4JkoxvQ2r6xiwcoUnQhQEJ7OLWyLZ6YmDdTpeL/NBgLJhtxs fcXzTL6MPpjx2rWiYR+aDglg9amZq8jiZHDVvwH+YhmAyFGGl4cMT5lrjE38c/EVovtLZv3EgOe EDSS1N66i2Fe32IJdNRXO3nWTqQWZohYB/71TdDZ27efUfb6tSRNZ6AH30TDd0X0APnqkKLA4s5 BIU+GTuLW+gc6rnBAOtPTkB3yuCaYOanyQx9ydLbQhq2U3YSHkN5HQCjcXcg6g3cn+KYRl6JSrO wg8waNZFVHPtcrIMopoPyCX/a9qsDIlCEBFc8Zs8gc2mMQ+emaH8g1MBuTOCFg7azNO/T0cs/g5 4ttVRfgNtkOrt0RX0JAE8J1l0pgKRlIRYdijMn8bFemiDvj8KktQKsQ8+e0azwKzrGRzQ5g+8Ff dyl93kmBH2idQeEG21EG7oGdxc= X-Received: by 2002:a17:90b:518f:b0:38e:97f0:aa4b with SMTP id 98e67ed59e1d1-39d9c1bef27mr6038784a91.13.1789121265714; Fri, 11 Sep 2026 03:07:45 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 06/13] virtio: track IOThread references for thread pinning Date: Fri, 11 Sep 2026 18:07:02 +0800 Message-ID: <20260911100709.726366-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62a; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121310391158500 Content-Type: text/plain; charset="utf-8" Use the virtio device canonical QOM path as the holder when virtio-blk and virtio-scsi acquire an IOThread AioContext. Replace the raw object references with the holder-aware acquire/release helpers so the users are visible through IOThread introspection. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 23 +++++++++++++---------- hw/scsi/virtio-scsi-dataplane.c | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 4b2cf3d52f..db7f513da5 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1469,6 +1469,7 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) VirtIOBlkConf *conf =3D &s->conf; BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (conf->iothread && conf->iothread_vq_mapping_list) { error_setg(errp, @@ -1493,8 +1494,6 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, @@ -1505,13 +1504,15 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_get_aio_context(conf->iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, + &io_holder); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(conf->iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < conf->num_queues; i++) { @@ -1526,18 +1527,20 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) { VirtIOBlkConf *conf =3D &s->conf; + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { - object_unref(OBJECT(conf->iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(conf->iothread, &io_holder); } =20 g_free(s->vq_aio_context); diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 26ecefd547..55bbf045ce 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -28,6 +28,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) VirtIODevice *vdev =3D VIRTIO_DEVICE(s); BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { error_setg(errp, @@ -65,8 +66,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], vs->conf.num_queues, path, errp)) { @@ -75,13 +74,15 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < vs->conf.num_queues; i++) { @@ -94,16 +95,18 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { - object_unref(OBJECT(vs->conf.iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(vs->conf.iothread, &io_holder); } =20 g_free(s->vq_aio_context); --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121370; cv=none; d=zohomail.com; s=zohoarc; b=L0Mh04BdR55p5+99x9PTivHpKFxHRt+wuElW5UEzNk6FwsBHvePoLUHUqYoSF7XG3vR9dSRjfUIljktYYFk8Ln82B1qBVhihjIETE6ae1uk+b0qoLY8S/NwlLtVCHW4RqisojrhMeZVtklEwcsxS7n9U70E4FbODp4foFxmDn1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121370; h=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=yEaJNJW0M3RfOG4LVNk4cR5m8NBuIru80hqnsp5wPiU=; b=XFG1Al1yxGVINQh1CfzzBUrdHvuIesrLfHedcCSYjtLhmeXNCOYYtbZa2Lgwg+/qqaqb9BusD/9l9x5Ap7NQb52LL1n/OffaLcy0EF+4OUT3JXPbEbUBTUSMeUslsqKsPihsajJrgKa431lTFfOz18VGdW+VA/lvlhCAXZ6BmJo= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121370961607.0625240561275; Fri, 11 Sep 2026 03:09:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yAy-0006fq-T8; Fri, 11 Sep 2026 06:08:08 -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 1x4yAk-0006X2-IM for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:59 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAi-0007I2-Qe for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:54 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-39b9a99469fso674483a91.3 for ; Fri, 11 Sep 2026 03:07:51 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121270; x=1789726070; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yEaJNJW0M3RfOG4LVNk4cR5m8NBuIru80hqnsp5wPiU=; b=ikICaOg1F4GzRDUKCnM65Zt77kPA//VA163ijJ94vBQ7OF9ab+yVU66xJ7e6twkK+U ffvOHigOBj0dsAAwmAesBSJFaafwJV0cdGRTpQHK8WrI/mA/reMTeuaa0vEKP7v7MqD6 M1CDVKHepzwnwtKUMxOpAZpQBehGrsSDRnzUSLW7puGUhqQ4C3CksfosT6EXu+nrYZCl Zsl2nua+zwrD3rUwKjYHbnmdKLxOCGZ8ZT2f/zP4/8UirjGQhERjHbnjaKefl6FtaDR/ fJCKpcnk+n6n/8wOtjdQT0dD30vOZEp0SDvOqdsMvINSKV6m+nc4qeFTjfmFnBbP6t/v 3sXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121270; x=1789726070; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=yEaJNJW0M3RfOG4LVNk4cR5m8NBuIru80hqnsp5wPiU=; b=IQQimTBsRbMKrY7o2P0vLk+Q0KS7nDE9qFyk6epkbUEw5F5PT1IS8xIvJiVc1a8l4i TiZ2RvJ5YwZ4G2EXCmN2CXtcfIfxeX+GAdmHKiaB9J1SRzpcUxd9BLWIlmLPL7BIeILh lIsVYrn+zNOJni+c55Hsf0C2/7t80JtHkBvp/Zpm5HVnOJVl3dK3U9eboEv8B084++af ZeAVYG5T/px5AeAW7p0K7efNMzvuXHhrUcSr3NQ2wHROtS6HgAaozapr+sh0ie9q+b8W TupMKFS4wOSqEzVpjzDMtKTpHpxVxHjQWstKFn1/jwzhnHNUIAlX9Izl+mfofZZHjLVR A2wg== X-Gm-Message-State: AFuF++kpDwTe9lnROckVJ7xUJP/WmCvs9AEffz6hYg08Tcq1G3+cVzgJ gdBWvdl/ttMraaidofErazU2jS2mTrYlszbNx6RfFgLq+uPbVF0qkNZE7OQdPQ== X-Gm-Gg: AYBFou1JfVieFAse1rwa6Hm47h4YBa9kRVamUjK5gY6LXp8d0ZCGXI1iVnBjf18pSsv 1JHNgC5y13QPBwNvt7e/QdVdRZgym3/DlOhYo66SRXbUNtswcnR+dxhbmUtnSqqZx6CfgArGmfb geBWExHEZ9MpVB8Ezz8qfUmCfXnKJ5P2IVy5fCwaEbl6/TtaoBvfja0C7W9i02aEUguuw3z/XDe zfgBk/rFKRsM5WpwsTbK/7RwP9+HW4b1Bfy1r0+cftIkxOrg3VSk2VI/xZkrpD7ZoK+3ytCKPlK KUaips8VD8KFyWXPCTVFLsPqX/MynMqD+GlAhjBD456sHP4agGkTPSGzIdXL3DZqlyDJaHc7vJI fUyQwq0SXRfBfsAfgUAAjJd0suU0bBkiQzzWahTrJ7ZiSF3d4ZD8rMUmSKTF+o8g0uwZd75I6Xj +xgCe3cdHWppPDWElBp1MODfWWjSJV7WsyC5n3yyKtEFSrt+KumssO22nUx2dmscMEATBMjcwoB wNcivkHXN07KjmNSIuUwE50JRU= X-Received: by 2002:a17:90b:4a8c:b0:398:9c0c:7c72 with SMTP id 98e67ed59e1d1-39d9c3891d8mr5771997a91.25.1789121270103; Fri, 11 Sep 2026 03:07:50 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 07/13] net/colo: track IOThread references using path-based holder Date: Fri, 11 Sep 2026 18:07:03 +0800 Message-ID: <20260911100709.726366-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1033; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121372783158500 Content-Type: text/plain; charset="utf-8" Convert colo-compare to use the iothread_ref_and_get_aio_context() and iothread_unref_and_put_aio_context() APIs. This ensures that IOThread references are tracked using the COLO object's canonical QOM path as the holder ID. This refactoring improves IOThread lifecycle traceability and aligns the code with modern QEMU iothread reference management patterns. Signed-off-by: Zhang Chen --- net/colo-compare.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 5986fb1e88..361ee32729 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -130,6 +130,7 @@ struct CompareState { GHashTable *connection_track_table; =20 IOThread *iothread; + AioContext *iothread_ctx; GMainContext *worker_context; QEMUTimer *packet_check_timer; =20 @@ -922,9 +923,7 @@ void colo_notify_compares_event(void *opaque, int event= , Error **errp) =20 static void colo_compare_timer_init(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - s->packet_check_timer =3D aio_timer_new(ctx, QEMU_CLOCK_HOST, + s->packet_check_timer =3D aio_timer_new(s->iothread_ctx, QEMU_CLOCK_HO= ST, SCALE_MS, check_old_packet_regular, s); timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) + @@ -964,8 +963,15 @@ static void colo_compare_handle_event(void *opaque) =20 static void colo_compare_iothread(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - object_ref(OBJECT(s->iothread)); + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + + AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, &io_= holder); + + s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, @@ -1404,6 +1410,7 @@ static void colo_compare_finalize(Object *obj) { CompareState *s =3D COLO_COMPARE(obj); CompareState *tmp; + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); =20 qemu_mutex_lock(&colo_compare_mutex); QTAILQ_FOREACH(tmp, &net_compares, next) { @@ -1430,18 +1437,20 @@ static void colo_compare_finalize(Object *obj) g_clear_pointer(&s->event_bh, qemu_bh_delete); =20 if (s->iothread) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - AIO_WAIT_WHILE(ctx, !s->out_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->out_sendco.done); if (s->notify_dev) { - AIO_WAIT_WHILE(ctx, !s->notify_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->notify_sendco.done); } =20 /* Release all unhandled packets after compare thread exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); AIO_WAIT_WHILE(NULL, !s->out_sendco.done); =20 - object_unref(OBJECT(s->iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(s->iothread, &io_holder); } =20 g_queue_clear(&s->conn_list); --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121321; cv=none; d=zohomail.com; s=zohoarc; b=VGnqIK9eAj442m4aN/takXvm+APoFQDdQPnb8hd6kq88nNl+OauaTp3Ej4ftpKgq6u1fCAjU3PgVysI4JDFqNbNT/2a2lTvko3H28HhICXcK0xbBgeV8vCPjuaOHESZjK1rnaDg5eluwXfBOWJ85E0K18DL7inqDvFsBsEfRTTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121321; h=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=mf9E5O+vpQ3XA+Jie+/p9nC3sGIPSjge6K4hjAZVK9U=; b=iPWjeMUpuQvVWBNLMLXId/OhiAl2n8oktWZauQt7dkSW+AiN8V5RJRUKHlY+Yqv1frBeFOOpe1LLWBIthoKwhO8RGnGF+zejcwqqrOL1RVJEO4TcRzbF33p8g6JZj4H6Xe98qTHn47MiNf9w/YR6k0aLuMfMDZPxWHcE2jzwyAM= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121321069707.8472172884057; Fri, 11 Sep 2026 03:08:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yB0-0006jQ-Pq; Fri, 11 Sep 2026 06:08: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 1x4yAo-0006XD-5V for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:00 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAm-0007If-Fp for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:57 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-398a5aad413so722262a91.3 for ; Fri, 11 Sep 2026 03:07:56 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121275; x=1789726075; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mf9E5O+vpQ3XA+Jie+/p9nC3sGIPSjge6K4hjAZVK9U=; b=Bp+Yd8uU0kf3mJ/rIrfSv+2lqpAHPx+U1xgvDliCTS3mostrNBGor7AsfVqLgRipwJ WfoNxMYMz7VEbuDNX24Pu2+MwphDMF8IacPBU73DNDDcX4NCeICDbNlfGRz3CBI9G4hy XczpzbPnF8J4BdgPkfWLi7Z4/B8pehJlOYRF0DwkwWjxuI99Qg7eFnpUy96Lc8z7BJSK hZ1JgWsmOkDUqLMB0kf/N1c79i+bi2KAJHYZgfz1KZ3xzL9vPItiZ8JY+82yIfCbe3lt kMmy5sQqY633vDjT+Sje1On77HX4Kg6eP48PqoBm7rcQkbjXN2C3Os595OShshvH3BHj 495A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121275; x=1789726075; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=mf9E5O+vpQ3XA+Jie+/p9nC3sGIPSjge6K4hjAZVK9U=; b=W5C5I1zetYQv2ZHJAutTybkzxxRU/KpBcv7QhcILIXdRKVun646ztj9l7fapWX+0v4 wl7Yk1Mk4UCiF4Ny7hc96edjupzLAbb1LF3ZBY4T5bf5h0AslqEalhu0I+Sw8uoSiNcB kiacSoJU53KqBuEy7nB6pdSAOwexZh3ItF7uqaZmdzTu/Q06HFnZ5Nbc6IzNGFPAcyfE 4FPBm3Jxg+mLxmAhcUzmFiWHFTtvLN4141ggfHrgdOypQuAXDOmfcXhAUFdACUIR4MXP eucyYTOopIeIYhtZitm2RQAJ2uo4UKubLo+mPMUkuR6v/dm+2YiAArqFFJ8ZfhBrEZIp Y4NA== X-Gm-Message-State: AFuF++m9ee22DL9myvjAaLzteFrMTzgtNe7yXUdhzBAJiS/etilzYKh7 2gWlygkcST2SmbAaLj/E/F9JL5I6JFjH8ls9IZD9ufQDNiOPj84LpBIbcBAEabj6f0g= X-Gm-Gg: AYBFou1T24PcJiuV2KdGzW3v8WL3eSfFOHnO0MGHTY9QOdD/KU+cFdQP4EyBXsu8JLK F3rzHyE9++RT6/NL3+NbEmiaaO5CJTa3f02M/e7jrF9GFjJSxmQJEUAKE+CJheipY810q6we5Bx 449JdbFa6W2BceHg8LEQL5ImDQou9Q9GVb2H8RMpc7Bl4JtiSLN1cAG0uS8Nlvon/MPQL/n6P/r vM2pw4Jg0o2H6KV7hgPmwL8Qp2qTmzCYJBpn0HeQFC5BpJPEIpPILhFKLtV7kRV0WS2yK25O4pN z5ut39ec3IBQV7zHHQy1b0hnMK6ld8s95Gl7DXz7UvlWAcYSK1EC/PeJnAqg0RPiZ5WBaaiIb4o qUNkAeSMfp1t7Ym/3wui9gUd6tjgfUG+F+1WJDBAodoeERrsPZGQx1jVKmmTw35QbUwnDkvlanh qsP0T3rKUmpOp2pgCIkuazSB7HB/yx0/TOTHkOB1RmpqCPK/2mtzrDHFVtAWcpeYNdbFWc4o/FH CQwxmfeyyAdKVTCn9f+pK9wRWw= X-Received: by 2002:a17:90b:2b50:b0:380:21b7:e727 with SMTP id 98e67ed59e1d1-39d9c1c199dmr5907522a91.14.1789121275020; Fri, 11 Sep 2026 03:07:55 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 08/13] virtio-balloon: Update tracking iothread users with holder Date: Fri, 11 Sep 2026 18:07:04 +0800 Message-ID: <20260911100709.726366-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1030; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121322457158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/unref_and_put_aio_context. Signed-off-by: Zhang Chen --- hw/virtio/virtio-balloon.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 4c5f486ba2..7c9c8d2a41 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -892,14 +892,20 @@ static void virtio_balloon_device_realize(DeviceState= *dev, Error **errp) s->svq =3D virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HI= NT)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page= _vq); precopy_add_notifier(&s->free_page_hint_notify); =20 - object_ref(OBJECT(s->iothread)); - s->free_page_bh =3D aio_bh_new_guarded(iothread_get_aio_context(s-= >iothread), - virtio_ballloon_get_free_page= _hints, s, - &dev->mem_reentrancy_guard); + s->free_page_bh =3D aio_bh_new_guarded( + iothread_ref_and_get_aio_context(s->iothread, &io_ho= lder), + virtio_ballloon_get_free_page_hints, s, + &dev->mem_reentrancy_guard); } =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { @@ -919,9 +925,15 @@ static void virtio_balloon_device_unrealize(DeviceStat= e *dev) =20 qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + qemu_bh_delete(s->free_page_bh); - object_unref(OBJECT(s->iothread)); virtio_balloon_free_page_stop(s); + iothread_unref_and_put_aio_context(s->iothread, &io_holder); precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121371; cv=none; d=zohomail.com; s=zohoarc; b=C72PiTkoTkuHBNJIRYkCuEeeBfbnzkSrfSByPd5ACnPcSloQafdIeVmGT78iI26/+j5J/lPOyq+btnTbq9FbwXbPqKzIUrl/Yo1sAHwuniGY6pwrcM46NZz5f9POxWyIMEoSKc/SQIQCflFi4KD+1aW78sntD8RG+kXzF8nlCdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121371; h=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=zNkftpkxFVpDoZUxzARQ6dpOC1MsUJSxg+vsslS00BI=; b=EWgpFfxUBr5ibSFZkERIwTrNlLwXR0AWv1TgLSDSJvhTfvUltH1+MWBtHxCaO5QON9Zyv7PH5WveIMJGyQTTJGTGHDJmvEggxfC11v+uzm+RcB6Ibw6lPTUDOFvbABvGNVm79Bp7ESz2fPqDOB5q84SNu/tQ6qUIaKUAG0LTLtk= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178912137171171.39743507104083; Fri, 11 Sep 2026 03:09:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yB1-0006lT-Ai; Fri, 11 Sep 2026 06:08: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 1x4yAt-0006bz-7s for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:05 -0400 Received: from mail-pz2-x10.google.com ([2607:f8b0:4864:3b::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAq-0007JK-VM for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:02 -0400 Received: by mail-pz2-x10.google.com with SMTP id 41be03b00d2f7-cc1cebad4adso678485a12.1 for ; Fri, 11 Sep 2026 03:07:59 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121279; x=1789726079; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zNkftpkxFVpDoZUxzARQ6dpOC1MsUJSxg+vsslS00BI=; b=Wg4xiCygpzAy/voxCjd77iXdoXd+bVrzcrE1YYcOaLtTfrp+Ey/ou3w1s0n9M140jJ LO4htqF7hBq7ATQhHgq8+GJk0WzKebSoh2ptDSKwM9LzNDmfni2WlkA4xo+u1MOmKPDZ fNdc5eCzpMH+MwkeEQ+vK0T4PIvx4yIAPZsnbq6EnJIJasRl3X6yrsWNy1fFEHJe5mdA AzsUvNOWoyaa8rD4Pl2350L73tKDQukZgAt/r8UWd71TEIbKTvHHKIIgWkujLQrvPryz rRHSdnWCarKphstLk+deICgEk2dvpBjeTUtzehGtjLYvwH26y4OIKPW2dOZgzajhOjay tZKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121279; x=1789726079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zNkftpkxFVpDoZUxzARQ6dpOC1MsUJSxg+vsslS00BI=; b=gWH4TSDCiIlB0VRFXsnZjqWsE0vvz/luAJ35KEztVwxWGI254cn+C6RrfVOnunuhMI XEEkwMdZ3QNiMbVop6EkvOMMC7WWNBCGRjJpIU8lhTSfFi7r17RVJRp5YhIlUYttm7Wz 5fSH8zRnOGQ2ZhF5n53vwkfb7/e8PYYolezkjMuHCFGReWW2vm1PvUPrIUB5pXTH8ZEr esnWKqmxjqFrMTGd68u08h3OcJCm3herTlEib4oRG/yp6iquATKY6w9ApS9RpKfotqX0 Hy0kGRkyqpztMssmI+1IUtT19wwA6N4Ou6BFTJ89bJCeaZOVxoBDXHUCKvlywRagQmuO 1agA== X-Gm-Message-State: AFuF++lhifAjh4/1Camlw3K2uzxroBEVUacvQ+pt8Gnjg0KB3KXbJ8wI rkTHxhTB955kHM5dn78NgVcnHorZ8MrnF7iQmrYC9ePTvdtN72M5CAGRJnrUnw== X-Gm-Gg: AYBFou2/gHaQaQCaHxU8EQQY199Hvfg50T6bWbCe+IdqZgwgjYcZlYEOyv1BwF9ahoT rHBVcvl3srhvrhzcw5Z1sf0Wr5I0r1oJzfX1qb8QXH58RaX2nihmbA4twUY6k1vWj3Ra+AKp8SL 84Xm6QLXwJZTlAV1YORw5AkZqSr7rz0hdHo6gESmnC2PJSe0Woi6VFI5kWcT7bOnPovVcGPzYHH elwQV2UGxgerSbwg7sXJQSpwAlWhehsPB22rhBfaxOmcSGLbeCT82pgfbwxmZXWyiuRSOYWXriT DLS7OyxXbwKzWJWV61TNdiqUD1ywF/OACJv9zAbACBMMMbz+aYUdRSyuFwZC4U9+cL1YIsUk245 uiEe/C/Edh1fzuX86zHjNKpvuzotyoDYCFLJFE2uq6IgxoqQS/YAz5+TneuQm8PD25y9MnJvmmO hXatXcrFvoDz5l3s4N72oKHU2vIkF2p6drDqXHALxrjUomquj0n730j5VXhzddGMMsP4dAem/0o i2oMru2tgFpV8S3Q9mVQQKJ1YE= X-Received: by 2002:a17:90b:2588:b0:38d:fda6:4873 with SMTP id 98e67ed59e1d1-39d9bd99cc7mr6315063a91.10.1789121278837; Fri, 11 Sep 2026 03:07:58 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 09/13] vfio-user/proxy: Update tracking iothread users with holder name Date: Fri, 11 Sep 2026 18:07:05 +0800 Message-ID: <20260911100709.726366-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:3b::10; envelope-from=zhangckid@gmail.com; helo=mail-pz2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121372770158500 Content-Type: text/plain; charset="utf-8" Add object_ref/unref calls with iothread_ref_and_get/unref_and_put_aio_context. Signed-off-by: Zhang Chen --- hw/vfio-user/proxy.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 197aee07bf..e642fb0ad3 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -898,6 +898,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) QIOChannelSocket *sioc; QIOChannel *ioc; char *sockname; + g_autofree char *path =3D NULL; =20 if (addr->type !=3D SOCKET_ADDRESS_TYPE_UNIX) { error_setg(errp, "vfio_user_connect - bad address family"); @@ -917,6 +918,11 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *ad= dr, Error **errp) proxy =3D g_malloc0(sizeof(VFIOUserProxy)); proxy->sockname =3D g_strdup_printf("unix:%s", sockname); proxy->ioc =3D ioc; + path =3D object_get_canonical_path(OBJECT(proxy->ioc)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; =20 /* init defaults */ proxy->max_xfer_size =3D VFIO_USER_DEF_MAX_XFER; @@ -936,7 +942,8 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("vfio-user", errp); } =20 - proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread); + proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, + &io_holder); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); @@ -967,6 +974,11 @@ void vfio_user_set_handler(VFIODevice *vbasedev, void vfio_user_disconnect(VFIOUserProxy *proxy) { VFIOUserMsg *r1, *r2; + g_autofree char *path =3D object_get_canonical_path(OBJECT(proxy->ioc)= ); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; =20 qemu_mutex_lock(&proxy->lock); =20 @@ -1021,6 +1033,8 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) qemu_cond_destroy(&proxy->close_cv); qemu_mutex_destroy(&proxy->lock); =20 + iothread_unref_and_put_aio_context(vfio_user_iothread, &io_holder); + QLIST_REMOVE(proxy, next); if (QLIST_EMPTY(&vfio_user_sockets)) { iothread_destroy(vfio_user_iothread); --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121302; cv=none; d=zohomail.com; s=zohoarc; b=cn1Zt0dTUrx/pBMIBIowvGK8vLMKP+RUm5z2nficASm8BGKaFYiIHURTXwyJTuP0JiQjkzeaKCX5WU01O8vQvTLo5biZHN5zMpuGoQU9XicBSBWSRhwVOxZnK5WOIqmOu+NZOVu6/YdXCCBtR4KEaSa4RCgqBcNKF5xPt8fZ18A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121302; h=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=F8RfjQjVOX1tJDdARKFAxVYWhrl5wDLHiadJICm/sXU=; b=G7VkdOKIkMylENDogc4lmUvuOpnI9+dFBnPJitceOXxa5YCI1RnJP1p6sIYG7lCCM+6MBiS7S4M+k4ycn6YChpNvcJzFEILyGn8VP39/8rk3wmPc+5+ZKZQxmOX5ZYpTLUdytlGIv+5+jJws+CkTy95vaYvK0Cdl0ZS2tHBFx7c= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121302554428.54051405186476; Fri, 11 Sep 2026 03:08:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yB9-0007AO-Dy; Fri, 11 Sep 2026 06:08:19 -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 1x4yAv-0006cN-S5 for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:06 -0400 Received: from mail-pj2-x10.google.com ([2607:f8b0:4864:39::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAu-0007K1-8C for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:05 -0400 Received: by mail-pj2-x10.google.com with SMTP id d9443c01a7336-2d747eefadfso1420395ad.1 for ; Fri, 11 Sep 2026 03:08:03 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121282; x=1789726082; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=F8RfjQjVOX1tJDdARKFAxVYWhrl5wDLHiadJICm/sXU=; b=tAtf+C92GSnfQL3Litdjw5/Rj4XVGyqMSYVaHv1yffSg3Y9GMVozBugzk8Erw1FRtI 9r+r7p4xTakQyG5F13hx50DbtTuv9kcBbzotVnUk5WgCkD3FcIqaeejwGCfDq0fccUX4 zM56b0ZUO3P3djJgUAYsWaleGJMpOG1CkWypqrnBZyOsML/HyE1W/MFbZBl4BFGwhqO1 p2OhG+ck0+r06AIy8D6OHDpnG1h77vkka6jO2wl+TLf8CTuF8E0HIUV8IgE3CqMPWcu9 RN3g95AEk9R0IgZkNTOITGG2CHxtRT39axLAXnGnhVJkEfSk98Hu5QjQl6AHVek7CbZV hTHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121282; x=1789726082; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=F8RfjQjVOX1tJDdARKFAxVYWhrl5wDLHiadJICm/sXU=; b=Hv9pZC2bBmQbIdKdBmf4v4T6KvGDwqovSWBTyhJLmnjKH9BvyZM5wgWcRLNqudKJXz RCCvtDDjIqhoAplza3MoFgRXf6m7a2PfPGbaLEX//QR3kAvt/yv2gBnVC9w4LoQkbKVM xpYYzFdVJJkuwUsyrPhF7c6FRbJJwjhUVO035NvbDqPo6zAyfCuKSS+aDGTpNIDN+iVl mehbQ59/TbUd/v22eeV3PA7T401KHT1sGJQ2aFdK+UioE/LgfASg9myUzFpdWgzmRnsw vSrcKK6kynhK8tTWMP6Coq07TvsrflWPVYdViR+ssgWDsRqKSAIpOhTLnmrOvl3/0ljp CM8g== X-Gm-Message-State: AFuF++nrFSec0L8KTfUXIh31vNL5pE7XN9+D8weQJkcF7i+wDvnGnRyE 87eEmySldtDcZ23YqOZLNVEVHnaPcmU8Sa9bW7BR2vJHPU/TH/9q4tovSh91tTmGzNo= X-Gm-Gg: AYBFou0InffUWPgneTKEZoCqxk5DrpZNMUuXeUCQYWgCqzlilOvEr+tDxowFEi55X+/ Wg703TKWdZ5ioafchzOMmVyboSTO9G1nVechlfngPzTtc3VPPjevcmeUJJt3l/AjzBAfllbiXjX x2kL0EukDPeJ0pbWx7ZuA2F4bWKnYdaRlAyRemuJJ2G49ohVhw44nAd7jgair6TDtdjfs0PiKQ1 ArqT+lbMqElmAQT6MIYcOkhY+hfmNgcPz1H9WsO11GxuRrcSi6HxHai9GVLrxKLX/HzPFITSN7g KIW8SM5BP3bKqJdwhcio2XY7lxW32nJC9XFOKD95drKteKQnY9jmWD0LbiPhe+KCcefh5t612R9 uisnv/DY6KFfMxksJOzp01bnNzesAvH3fWg2pUPPyqYVG3pFZExy8UN4kg4xpILSaJhvVujfsKg DaSHHnYDf0X5xrJQM4UxnvAo0LVQCwTQeVKp2Uuu0ScYbf2H+0KjuzNUkcz1/PbBXJigDOH3ofg Zn1CUOjoumz4lkZI0P4tA6KIgs= X-Received: by 2002:a17:90b:35c7:b0:395:8124:ac53 with SMTP id 98e67ed59e1d1-39d97eeba04mr3573329a91.6.1789121282513; Fri, 11 Sep 2026 03:08:02 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 10/13] xen-block: Update tracking iothread users with holder name Date: Fri, 11 Sep 2026 18:07:06 +0800 Message-ID: <20260911100709.726366-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:39::10; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121304376158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/unref_and_put_aio_context. Signed-off-by: Zhang Chen --- hw/block/dataplane/xen-block.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 48c2e315f3..9dfe06e1be 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -621,9 +621,15 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevic= e *xendev, QLIST_INIT(&dataplane->freelist); =20 if (iothread) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + dataplane->iothread =3D iothread; - object_ref(OBJECT(dataplane->iothread)); - dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread); + dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } @@ -652,7 +658,14 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *da= taplane) =20 qemu_bh_delete(dataplane->bh); if (dataplane->iothread) { - object_unref(OBJECT(dataplane->iothread)); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(dataplane->xendev)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + + iothread_unref_and_put_aio_context(dataplane->iothread, &io_holder= ); } =20 g_free(dataplane); --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121319; cv=none; d=zohomail.com; s=zohoarc; b=DpUsXWTdSuqB0nLrULScj/VKqraW09zCeetapsTMwrzgWmB+VhCH4rUyY6bTfbBjLgBytymdQCMHIhGGRmxCkbOO/NUPr7JcrrA1ty7Po67hDin/HtZLrTjWEXCUiwb+10eyu9iydJdlavs2VIPxsZAl6I+coXprU1jdJcl/Dkk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121319; h=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=l5YVe05pjG97AGrI1ym/t5dZv++HeTZWtnHCxE2pueI=; b=BrX6ZK/a09uVmvjJ45bb0nrvuIQr2KTO41x//oU6bi0Y8ZPB/2044uyUgeCyJOKqy+DZdNsrz9NBcmKYSmx/8l1bIglSk/hwwb+I3E8dujDwTV1wqK1M5ORUUOV/HX36YJ3oNhuMY6U5aJ91oE1Vleb7eODxLUYIk+0BrGPXgqI= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17891213197641003.7547980085469; Fri, 11 Sep 2026 03:08:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yB3-0006sm-L2; Fri, 11 Sep 2026 06:08:13 -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 1x4yB0-0006jR-3L for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:10 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAy-0007Km-Fj for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:09 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-cc1c9879395so503182a12.1 for ; Fri, 11 Sep 2026 03:08:08 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121287; x=1789726087; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=l5YVe05pjG97AGrI1ym/t5dZv++HeTZWtnHCxE2pueI=; b=FyTSSfKuLPli1mDCawowJgDIq2dAe6+ZCeCu4W+jd0HD+v36tEtk6nH6e9n9EgPOQB wU3/rqXvDp64Fypd84pRO8GqqIzE+EUnqRoeD3d88vfWkoxDa4jFbO7t5u0Cihc0nVNv 5jHLqacfVSITHB7gzCgyjlWJNhiukkvW4/5L22WzOOw1IoqXoML6UguIKZdYtDL+U/dK zhiilsPE0MqLiUfJwEmShg6l+F4BkNfpe4cLlgFWIV9q6qStHbhehoW4HyGG8Hyf1lDR YDz4B6pUzfVKyxugnay6SPoVmH1CMyqK6oN7+3AHlzZ2WPbINtsfoG+MR33X9CHPhJHD y88g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121287; x=1789726087; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=l5YVe05pjG97AGrI1ym/t5dZv++HeTZWtnHCxE2pueI=; b=pmBmB0G2ez/VlWl+RY8e/cVe8Eg+WUVNhBCwiRCMW5w9GJJgYrUrCNtaPR0qd9jb5P O8H0cIIjmWk9MNtisSGFFBppWnLPw3zTmYDJSgoDyL6aAC+FYrWdCk2hB0lZrC2C0ABs MjWdO39l8p/j4mtGlim1Fg7rrI5Ju+UYU6F/Sx5GBr2X70G6BfuG+UdZDlw6AbgpkcTT vspj3WjfGlP0AzLo2SkxGqoD/2Fz6TuLcgkGPTyi6X09F85krz8juA351YnOYdS0iDEl q93cAHaJa3DEGjw92pZFe/X1d234wJ+tUKwNG9mp5FbzW33FodsxXJYDKy/b/k1OFKFn sDzA== X-Gm-Message-State: AFuF++le6m9PeZTjLEdBgQvqAWvvgf2zA2LqsocrntLPlaoK9H1Tf0De gFxejJFV8McPuXqtWYYvmjgWElzdncAr56m4GQHj9xHe3pft3GC+tzJcXU3/goxCYJs= X-Gm-Gg: AYBFou1jR4H1JVW4ygE19c2pdWhoLsGlgxHF+bagwvxv0hLkBE3FAPyL9GywuUROS1I Z7Eu2X29lI53nwRKYwnC7MBamV15XnrwOc/Mt5Yi+/dUmxDmF7JGapgQ3FpniE2pIErmnG26amW aJljKF3ZhCLk2UOxQAjH6yhFNkxYRKkRMHnMXEVUmWiQCVjksTfudUO34vLmw5vM7PzoObRGA0C 6idZwxu9ScaUPLUI0aCtos/1s+LCUd7lD3iabrQ9R+clK3QQ6tfP17tXaaOeAgEQE4xgK30CeH6 Z9NfoK5p08eL5VYAsKy5DNKPj0neXWWSWc0pdUSZ8YAk+Yi5eGc+lGkaISGqP2Nh8rX+T53c0si m6ppUSH/I5ik1sF2ziwDJjz1IK0fe5NNHkVKXBLe/5G6I0NtXsw+paBex+52PHiKKuHIX0Up5gJ 0N4Sl/iAcYNhldx0yF82mG+r0WQIM9e+Zql8Cqnfe8sr9r/KZzieflIjFcAExY/2n5sQU02Jw5t aUKPP175AcYBl8m9lU234eFRGM= X-Received: by 2002:a17:90b:6cc:b0:37d:f983:7b5 with SMTP id 98e67ed59e1d1-39d9bd8fb3bmr5683632a91.9.1789121286838; Fri, 11 Sep 2026 03:08:06 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 11/13] monitor/hmp: display IOThread holders Date: Fri, 11 Sep 2026 18:07:07 +0800 Message-ID: <20260911100709.726366-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::52d; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121320515158500 Content-Type: text/plain; charset="utf-8" Display holder information in info iothreads to aid manual debugging. Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- monitor/hmp-cmds.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 91701ddf33..d7dd24d951 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -246,11 +246,31 @@ void hmp_info_iothreads(MonitorHMP *hmp, const QDict = *qdict) IOThreadInfoList *info_list =3D qmp_query_iothreads(NULL); IOThreadInfoList *info; IOThreadInfo *value; + IOThreadHolderList *h; =20 for (info =3D info_list; info; info =3D info->next) { value =3D info->value; monitor_hmp_printf(hmp, "%s:\n", value->id); monitor_hmp_printf(hmp, " thread_id=3D%" PRId64 "\n", value->thre= ad_id); + monitor_hmp_printf(hmp, " holders=3D"); + for (h =3D value->holders; h; h =3D h->next) { + IOThreadHolder *holder =3D h->value; + + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + monitor_hmp_printf(hmp, "[block-export: %s]", + holder->u.block_export.export_id); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_hmp_printf(hmp, "[qom-path: %s]", + holder->u.qom_object.qom_path); + break; + default: + g_assert_not_reached(); + } + } + monitor_hmp_printf(hmp, "\n"); + monitor_hmp_printf(hmp, " poll-max-ns=3D%" PRId64 "\n", value->po= ll_max_ns); monitor_hmp_printf(hmp, " poll-grow=3D%" PRId64 "\n", value->poll= _grow); monitor_hmp_printf(hmp, " poll-shrink=3D%" PRId64 "\n", value->po= ll_shrink); --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121368; cv=none; d=zohomail.com; s=zohoarc; b=e+ZmwV/PnJP/rUg9DhKw/gy32G0nKNdfVafw0CblbAyXV4CC1+6AlUpBx/eNPZyvw4e4/zk9JvvIN+XbisWuokjJVSr98HA1zCZn+iNAUX9lg7UTtqPBBUOEBLTNiVrZeyqUxWjAMaxEii1gt/D917Z2N5uqkj+vMfeA0u4n160= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121368; h=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=eT2z61ETCwbPUrXaErCLWHNfA53NPyn2CS022Z4AC04=; b=P6sAReYBPvYF26BAqtA4RLVZo4ooXKAR3GBh4UbuLU4GMl40JZtECWom4v9RMmRyoo4fyyLf1CKR+KsBPJMuoewUs9CmTbF9mjIck8LFZcPXcMdxboUd2rBPWxNqsZ3eFANh9troWnSOZncGGWgptJYZvvNRI8n38ieoaqHalo8= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121368537451.02620624397; Fri, 11 Sep 2026 03:09:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yB7-00075y-Ly; Fri, 11 Sep 2026 06:08:17 -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 1x4yB4-0006wc-RO for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:14 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yB3-0007Le-5B for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:14 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2d8f265cbe6so6883745ad.0 for ; Fri, 11 Sep 2026 03:08:12 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121292; x=1789726092; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eT2z61ETCwbPUrXaErCLWHNfA53NPyn2CS022Z4AC04=; b=A88HGkXRv6Kq3ef8vqbm/cqVYAQy/RKoOrRXFLy1NJP0RhIPTgRHn5ZK7R+/ijq2+7 dTVEtX1BGqLVPO+/X4owGEvUMbnLvX80n+npo+aF1jJ49ybvEjMRqNkqHy6m/Tfs/frU w9XQVaTxxfWVPrIURK3hkmOSg7gp7A+2Rw5nhoSgoCn41qjMLCexvoHXNaPPOfbOhdg/ ixwvVe0mxe77iG2HUi7CFcM9kL8azpOYsou4pZKPBE403uoNaHVX2vh8Ftydom18GSeK gIQSoUc/G403mPiazk3ALXfhfCbToC3oLXCDmwkg/wS6JqucgFGJruZxbTVmg5lb2BQo 5GgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121292; x=1789726092; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=eT2z61ETCwbPUrXaErCLWHNfA53NPyn2CS022Z4AC04=; b=f/3Te+2F9MrKI/ExR6FMq8rR6lfYqs+ehKbnd+0r760hpyUxgOx/un1RIY05GeEkGT oGD2/OmFJwNDzPwqlDkEpI9QUuMn4tP+LYqkS0cA7w+/3xpKe9GvXeg+DbSw5w0HpArh +LqVQ24TtdtjuvbvS4LCiIPA70lMglCkDoESiegt4ZK0xV8r+vsLJPegx5VMfx+d6GvJ reqX5HaLMX2lF08h6fDXKiduo2656kKF7etTsgoEuEo2CEOzwGPA4B7ZQ5bRMPB1OXIP EAbU8norubvP66pxi87qd5R0eYK84H6MqdcRizYOrcIfvFe7NcPF0pQgzNV3oeI3EdTd 7l0g== X-Gm-Message-State: AFuF++kw3yT2ZNOaPhHTaOr9r5iOu0OGK6YAsNo4TIth//4ojC3uVzns 2nym4Jx1tn5DX/1IxfU/Y+kCw/CfqT28Z3803M64hDpvVwcUmBKzBagEiK/RhlVI8qE= X-Gm-Gg: AYBFou3otYYcMi9CY4h78Ai/beq9CmcxPu97GyAJmPZKR1ZpjmGtJxJSS3vO4Ok3IHm WW+LtLHW7NeziMU8UXUFGGIWH23pNHYKAMwBCwe1dlzczxMjA2mK5C9EHfAA2u04JIpabquM0DR ThqgF647TZWpDlWiXaurN5AuMy0jxO+p29fF2bh6CENX2av0OZDn/++izwTj4sL/HF8yTwfN8Oj tDZSufvO9CPJisE0K9+c5GfX7gYB9BXLYPZi6ozxOm64Y9P6vu96nydPN571ldad8T8VAFiUSkf BJncuPA5pYYzoudd5fmFU0KTeOfT23yIfsq+ADrTvquseZJ0QU5pfXqIUWyu/Eg+SPAIJfDNttW W/IjSB8TavHKoYnd1LPAuUZbOLWhFVzTHQhwMWQHjt2O6pDBO8651Q2+NUi+jgLoFMka9gfeREd oCHLo0/ChL136wSAVe8WGcAIcNnWLwl3xFm0eZlMqp7uZJP/k9/VCDdG70Kao1HLMhnAJdD5XD1 rV6+gZDKiPitFmwsUlz0ZdRpJM= X-Received: by 2002:a17:90a:da8f:b0:381:25ce:bcc2 with SMTP id 98e67ed59e1d1-39d9bc10072mr5177160a91.6.1789121291620; Fri, 11 Sep 2026 03:08:11 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 12/13] iothread: make legacy AioContext getter explicitly unsafe Date: Fri, 11 Sep 2026 18:07:08 +0800 Message-ID: <20260911100709.726366-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62e; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121370744158500 Content-Type: text/plain; charset="utf-8" Now that holder-aware callers have been converted, rename iothread_get_aio_context() to iothread_unsafe_get_aio_context() and update qmp_x_blockdev_set_iothread(). The block graph retains only the AioContext, while detachment happens outside qmp_x_blockdev_set_iothread(), so this call site cannot provide a matching holder lifecycle. The new name makes its existing lifetime assumption explicit. New code should use iothread_ref_and_get_aio_context(). Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- blockdev.c | 9 ++++++++- include/system/iothread.h | 11 ++++++++++- iothread.c | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6e86c6262f..3bd32feb39 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,7 +3683,14 @@ void qmp_x_blockdev_set_iothread(const char *node_na= me, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_get_aio_context(obj); + /* + * We cannot use iothread_ref_and_get_aio_context() / + * iothread_unref_and_put_aio_context() here. The block graph stor= es + * the AioContext but not the IOThread, and continues using the + * context after this command returns. A matching put would need + * to be tied to the block graph's context lifecycle. + */ + new_context =3D iothread_unsafe_get_aio_context(obj); } else { new_context =3D qemu_get_aio_context(); } diff --git a/include/system/iothread.h b/include/system/iothread.h index f6c5f95dd9..9850cdb3dc 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -66,7 +66,16 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, =20 char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); -AioContext *iothread_get_aio_context(IOThread *iothread); + +/* + * Return @iothread's AioContext without registering a holder or taking a + * reference on @iothread. The caller must ensure that the IOThread remai= ns + * alive for as long as the returned AioContext is used. + * + * This API exists for legacy callers without a clear ref/unref lifecycle.= Do + * not use it in new code; use iothread_ref_and_get_aio_context() instead. + */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); =20 /* * Register @holder and return @iothread's AioContext. The holder is copi= ed, diff --git a/iothread.c b/iothread.c index 58dace351c..ae9290c733 100644 --- a/iothread.c +++ b/iothread.c @@ -422,7 +422,7 @@ char *iothread_get_id(IOThread *iothread) return g_strdup(object_get_canonical_path_component(OBJECT(iothread))); } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread) { return iothread->ctx; } --=20 2.43.0 From nobody Sat Sep 26 20:50:49 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1789121365; cv=none; d=zohomail.com; s=zohoarc; b=L88KMVf8gYi/5g4Ag2zVE0qeUofcGzsDsyVu1+ZNigj1W4hwmrleMEjipsv3e0UJAhJLoHRsdRhRaL+fq2ZPra84FVHyuWyST3Qa1xXL3fIx57gttC9FbA7p2r7WmAGC3ixPC7crL/aP2UkEJCaTHLr6jyqJ92XJBxQZjENzXy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789121365; h=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=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=exlXLu2fwhdxmHZWsYMhA4e5Bl2X/IzLJJSMcfcCO1OI3HoYYvUME36A6Ss0r7CeU5CUeKsSP7UnbNMiFmeNifmSuA3sh6G/WU5HG8frZ9aqEMpkwL8nG3Jp5PcwzQKmQ+6jP163Y+rGZ3xKrGg7TUSAKTtwPIxzGMW8Cdp5Ckk= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789121365070991.0201651482618; Fri, 11 Sep 2026 03:09:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yBA-0007Ct-VX; Fri, 11 Sep 2026 06:08:21 -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 1x4yB8-00079P-Ss for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:19 -0400 Received: from mail-pj2-x10.google.com ([2607:f8b0:4864:39::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yB6-0007MP-KY for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:08:18 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-396ccc09d65so559302a91.3 for ; Fri, 11 Sep 2026 03:08:16 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121295; x=1789726095; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=hqjWpngRBGve57jf+ZeRY64Rp+iabw1dUTSFyhz3uCREFOyZtEzeI3RLkDGFm1j4tq OO3V0HYr8j4C610j5GN1YmKYCkwIVkAj1lzwdeFOrsU1fxLG/1JunH4zKCGYweIesy89 jJhw5CUaWeSO+svxXWsI96OX+GTTHOr1RG53CehchZFUtS2bxRrX30ffmlwA7coLhoZE wH7U6R+sWapoaCfYrMFUos5NmB0OGa43m7ZdptqlvputpWEWhfKh7WLWV0+36Mt82nNj WXO9ojMp1olDSyy/es8xTq9MZZFalu2kXlxR549W9PAGU3xNaxr+KNBSVW2coWSgExOc 3YPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121295; x=1789726095; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=cF+wtKtX+IYHtNa4I/EE07UQrJrAKGLSSIeHi/BKnYGd/OBIm1jx+XIKtJIXLRCiTz eCHAU+RRJ6BwNghCOPawsIWhpHhmJ9srcjJTqfg57jHpGzejFJIiEeSO8GrfCeSyg0q3 pmWRbudaPZR+cFEZn1joDl4zZLyW1PSx566PWJVau1T+sQaNHN7oxpkwkMEepM65Dk42 mvjBjv8oCrtKZRcaKJwdWxNKbd5cGCr+63RliPwTj8kpgjXDW5Xgu5iE28J7sRMfI7IQ dudQGY5IPYesdprYegN3078xdLXxlKiz205GTQaUiBXlP181b27DobLjmzH3jI8wkKrt yEew== X-Gm-Message-State: AFuF++lhrCDGj/Q6AhnXBkeVnP4U/1GbR1mLkVvLWdQxhxX6UybGuK7K /nAA2efTnqU9lTYe89zP/HhhPFbwHcUUVsk7RAGkh3DI7JgOCLdieKquqFhPZQ== X-Gm-Gg: AYBFou3QHJRTNTI6IZFd7igq9OgzZnvVNUrAiPSwsDoU20RXKS8orXOwbTLl4Fo7kIK qYiDKZsTLUaB6tawx7ZzAo99kSWamrwXG23TdlecDLLIRpwkioxzahGReh3+x/YSsheYiZlLUiA VrSafjfxS3u1o6GxwuA1VfBSTn1H53Aaa0wH/gOtEVx7/BCPxstrH5YGdj+5i4829g1RRSTG789 xb0+PY09KfakLP1bIKcNVDkSMeOeF1oN9aGwB8OVxUMz/HC2jZAfXmsaftLm0+JgcVf56Xw7jnl NG0qXgtuTmGRt3BfrxDsMyrzkpo9ANdqDGlNqTFDKPBeb/UMf7ZDk1HCJxsqZc7EYl5K+pSt6bv ag2fG5Oa8vLgJKz1doFJuz/Clblij8biWyykoHzuzYyuFCKIwXo9Sn4Wr+ArPaHr+pTVFP1E015 BHLTJPsVsWIrjICDRgWM6NRR+w9sF22NRr6nNnAL7s7cHefbDNEM1cjxcuoiZ2FuPXqW4NE4r01 bo5xfQ1koDaltzBN6MMGqwflk4VmcK2i3AD1w== X-Received: by 2002:a17:90b:5246:b0:398:d2a0:87ff with SMTP id 98e67ed59e1d1-39d9bc67660mr6313009a91.1.1789121295212; Fri, 11 Sep 2026 03:08:15 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V16 13/13] tests/unit/iothread: update AioContext ref/put helpers Date: Fri, 11 Sep 2026 18:07:09 +0800 Message-ID: <20260911100709.726366-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:39::10; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1789121366745158500 Content-Type: text/plain; charset="utf-8" Update the unit-test IOThread stubs and callers to use iothread_ref_and_get_aio_context() together with the matching iothread_unref_and_put_aio_context(). Signed-off-by: Zhang Chen --- tests/unit/iothread.c | 18 ++++++++++++------ tests/unit/iothread.h | 7 ++++++- tests/unit/test-aio-multithread.c | 5 ++++- tests/unit/test-bdrv-drain.c | 18 +++++++++++++----- tests/unit/test-block-iothread.c | 21 ++++++++++++++------- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/tests/unit/iothread.c b/tests/unit/iothread.c index a363bf8f70..790cd2dce7 100644 --- a/tests/unit/iothread.c +++ b/tests/unit/iothread.c @@ -30,12 +30,23 @@ struct IOThread { bool stopping; }; =20 +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ + return iothread->ctx; +} + +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ +} + static void iothread_init_gcontext(IOThread *iothread) { GSource *source; =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_attach(source, iothread->worker_context); g_source_unref(source); iothread->main_loop =3D g_main_loop_new(iothread->worker_context, TRUE= ); @@ -113,8 +124,3 @@ IOThread *iothread_new(void) qemu_mutex_unlock(&iothread->init_done_lock); return iothread; } - -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} diff --git a/tests/unit/iothread.h b/tests/unit/iothread.h index eb4d0c77f8..9bdac074c0 100644 --- a/tests/unit/iothread.h +++ b/tests/unit/iothread.h @@ -17,9 +17,14 @@ #include "qemu/thread.h" =20 typedef struct IOThread IOThread; +typedef struct IOThreadHolder IOThreadHolder; + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder); +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder); =20 IOThread *iothread_new(void); void iothread_join(IOThread *iothread); -AioContext *iothread_get_aio_context(IOThread *iothread); =20 #endif diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multit= hread.c index 9179cdc6a3..66ba5a466b 100644 --- a/tests/unit/test-aio-multithread.c +++ b/tests/unit/test-aio-multithread.c @@ -69,7 +69,7 @@ static void create_aio_contexts(void) =20 for (i =3D 0; i < NUM_CONTEXTS; i++) { threads[i] =3D iothread_new(); - ctx[i] =3D iothread_get_aio_context(threads[i]); + ctx[i] =3D iothread_ref_and_get_aio_context(threads[i], NULL); } =20 qemu_event_init(&done_event, false); @@ -87,6 +87,9 @@ static void join_aio_contexts(void) for (i =3D 0; i < NUM_CONTEXTS; i++) { aio_context_ref(ctx[i]); } + for (i =3D 0; i < NUM_CONTEXTS; i++) { + iothread_unref_and_put_aio_context(threads[i], NULL); + } for (i =3D 0; i < NUM_CONTEXTS; i++) { iothread_join(threads[i]); } diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 43b0ba8648..05c31ffca8 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -537,8 +537,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_ref_and_get_aio_context(b, NULL); =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 @@ -612,6 +612,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); =20 out: iothread_join(a); @@ -762,7 +764,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, AioContext *ctx; =20 iothread =3D iothread_new(); - ctx =3D iothread_get_aio_context(iothread); + ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); blk_set_aio_context(blk_src, ctx, &error_abort); } =20 @@ -892,6 +894,10 @@ static void test_blockjob_common_drain_node(enum drain= _type drain_type, bdrv_unref(src_overlay); bdrv_unref(target); =20 + if (use_iothread) { + iothread_unref_and_put_aio_context(iothread, NULL); + } + if (iothread) { iothread_join(iothread); } @@ -1398,8 +1404,8 @@ static void test_set_aio_context(void) BlockDriverState *bs; IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_ref_and_get_aio_context(b, NULL); =20 bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, &error_abort); @@ -1410,6 +1416,8 @@ static void test_set_aio_context(void) bdrv_try_change_aio_context(bs, qemu_get_aio_context(), NULL, &error_a= bort); =20 bdrv_unref(bs); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); iothread_join(a); iothread_join(b); } diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 5273ff235a..fc9735d056 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -466,7 +466,7 @@ static void test_sync_op(const void *opaque) { const SyncOpTest *t =3D opaque; IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; BdrvChild *c; @@ -493,6 +493,7 @@ static void test_sync_op(const void *opaque) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 typedef struct TestBlockJob { @@ -549,7 +550,7 @@ BlockJobDriver test_job_driver =3D { static void test_attach_blockjob(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; TestBlockJob *tjob; @@ -595,6 +596,7 @@ static void test_attach_blockjob(void) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 /* @@ -612,7 +614,7 @@ static void test_attach_blockjob(void) static void test_propagate_basic(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_verify; @@ -658,6 +660,7 @@ static void test_propagate_basic(void) bdrv_unref(bs_b); bdrv_unref(bs_a); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 /* @@ -676,7 +679,7 @@ static void test_propagate_basic(void) static void test_propagate_diamond(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify; @@ -736,12 +739,13 @@ static void test_propagate_diamond(void) bdrv_unref(bs_c); bdrv_unref(bs_b); bdrv_unref(bs_a); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_propagate_mirror(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockDriverState *src, *target, *filter; BlockBackend *blk; @@ -807,12 +811,13 @@ static void test_propagate_mirror(void) blk_unref(blk); bdrv_unref(src); bdrv_unref(target); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_attach_second_node(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockBackend *blk; BlockDriverState *bs, *filter; @@ -840,12 +845,13 @@ static void test_attach_second_node(void) bdrv_unref(filter); bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_attach_preserve_blk_ctx(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; =20 @@ -871,6 +877,7 @@ static void test_attach_preserve_blk_ctx(void) blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort); bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 int main(int argc, char **argv) --=20 2.43.0