From nobody Sat Sep 26 20:00:46 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=1789467523; cv=none; d=zohomail.com; s=zohoarc; b=EtImR7AfHMG8Ww5cHcuSMAXorjL4iY/mjwJOANyxMmADUJvR+K0qys7rqy/EmeANJeJ7LKtWKpnQOQV+0VBDAaG9bXZd1k029HPfhm38C9UpShmHP7rq7XyIl4G+EIUnUbgd6rlJxq7WcMQyg2V0O3VPsyQbOUteemnWqsoy4R4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467523; 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=Er4P8E9bwo23WMOqnc3KMSVAUjE4O4btiiMlCHE7dwc=; b=azueTvaK3bFe00j1ydCLBbL2ViUXLKJdLW4V9x5Vpob6Wl17VHB87HEzAI5rgR5aLPWPOfD2NcAfWDklw9WmAmDxF4STKceAC0cYoydO74nZPIuljKA4RSQzV7EuK+xOQ7y1I1f7JJh11TL8FMxsLfXrBnwZpkEYT2t9gnSHSCo= 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 1789467523658686.4306748241136; Tue, 15 Sep 2026 03:18:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEO-0003JB-E8; Tue, 15 Sep 2026 06:17:40 -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 1x6QEA-0003I9-Hm for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:26 -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 1x6QDv-0002ih-VA for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:22 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-39b350c6920so2836192a91.1 for ; Tue, 15 Sep 2026 03:17:10 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467429; x=1790072229; 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=Er4P8E9bwo23WMOqnc3KMSVAUjE4O4btiiMlCHE7dwc=; b=L9ULX1a94ALnvw9ETC4T62ygfqmDAKKZYCF264GfDFe8NcOfgOgkHi0vTL+nhsvE7d rm6FMp2gbT4oxsjzbFsaHnCEDOQHpyfynhltaskmXRNpwiwrloff9OoHdvI6JMCkzmOE vZhK5Gkt+AakgRCy8JGNUMl0tN3cK2kNuXQ0Eo0xR8cLDuKdzZYQhAVqdRcmQZ/7tL+9 lGGOQ7DU2AI5Qs4aM17XUpKFuO5cy3FH2W2jhbhabwalCkcgQFiTCtembfJPJGT5V/2i Wah6WQ2KjNEYFYXWlZUNLvrdLV3MEiDIvBjXH0fosBPKx5IeTq60VsPHSajP5EvP/fHx hVYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467429; x=1790072229; 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=Er4P8E9bwo23WMOqnc3KMSVAUjE4O4btiiMlCHE7dwc=; b=08POYbu0/Rf+1fOlaIjQ1jrwvM1Hhz10MIRNbz7WN0zEAJ7Jk3HVHf1N/vV9xTP/hX VtUho1viMh8agD94AZcbMu+b0fRQY2A8MqLJn2R62XyJIQZZ4V1AwucHfoWCl+Y9faBI a+5qAeEFMhZqaupQBCEWRpsSb1e9qxU1VL2/AU9e7d+QiZyOpI+kgPcieLydeAnC4PIl 5Pz6hJc/HNhhk8HEauRtEfeANfcebK738wLgy961/ry4bNza6y6DabzojM2xHvBU7PbZ UFiL4o5Vrr6/TkwIn3YTMYioKRRsCX3IQLwO/b8K1DZJa2nJYO54W1bIIUlZzURlE1Eg GAXQ== X-Gm-Message-State: AFuF++lDxjH7NrNdxqJfYLJX/IArolIIxC55aTFG7vOoVwd6YJseFF4k s/mIey5Nr9v7ZrqDmWT2eO1Ux2kc9QJY5lTNHS++ML8i5Ml1c/uZCe4DJGDOJFIxffg= X-Gm-Gg: AYBFou24Pq107Fq6LG+Z+cvxfTGoB7It03W54kRLEmwuPDXGX0Ufolr2+1gIzsK3rhm UDaWBFlbKLapjfb/ANFRfeyZ15UN2RQC7H9B9IolDmL7uZ29GyJgmb+FXtgxyGEXSCRTl1/FMPR k51uHu74p133UsNts8NFE/ARX8X5AYY5TPGtSItFZtzsOC4Vn4YYKFAzcaO2NCefW5AhrjPoUOb IxqEjZPeWkWm3w450R4z2lZDFi+7/2gZOQ224RiHQ048rUeC6UuFMnnP+JrxHSukAX9gG3en3Kx 5IV+bSyfrOZEJvngsihWiqm+knrlEQwxSqDI175WU8L7rwjF7aCYPsMS6G/YXwfNe8uEqXJkHln pq4i1VfTvL03iVvgCMgc9BryWDDpEsO3xIFFSRX5tvwxDrt2VjzgP1y4Ma1iPoRXzSTctO4FKVz eI8vqzY9WS6o8V3kD1kg6SaLpqk7HBHvCxjq0xbqGAHZavUb+YLB6Wt5GPq5mDFQNSgoXJ2MrW/ DWgpY8qk8EFfwN+0EK22ZfOurgFPLs4Dcv19w== X-Received: by 2002:a17:90b:1642:b0:398:dc16:3c29 with SMTP id 98e67ed59e1d1-39debf7a8e2mr13348196a91.7.1789467428926; Tue, 15 Sep 2026 03:17:08 -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 V17 01/13] iothread: introduce holder tracking Date: Tue, 15 Sep 2026 18:16:43 +0800 Message-ID: <20260915101655.3216101-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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: 1789467525659158500 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 76eea6df38..6b0a7c557a 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:00:46 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=1789467607; cv=none; d=zohomail.com; s=zohoarc; b=ODqeHaUtD3Ksr3MinCwnKEsA2vNKRCur8xBIQmT+N8YX4akS3A4UipgScSC1eh7EL6Ns2szq+4twPstC8YLEFtjvNbizFnwyaKezl1Lt1M4WYa/znFPlAot6YlZkFz8FXk4gbco3LmfFDGC/9N8iqxiRUSr5feKhN3cJdumLmVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467607; 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=ffn71e+pIgrmkpZMSuNM3s3wiDknQ8z6eWqR0ElZS0U=; b=ZMT9G1Y8D9iw8sZ6jYp6sZLtk6s/S9daKHR1ukF/vOTA3NK5uW8U9fVJ0pLfNMnRRgp8oewb5l9bzLwcUu0F7Y8VTQb3UolADU3+AdaersNwgClLPfabJaDtTzx4tqwHTqEj3t1yRws6TY8DlTqUxc5q+gAcRNXgoOKEw2aCYR4= 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 1789467607134845.9501152291176; Tue, 15 Sep 2026 03:20:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEf-0003Lk-0o; Tue, 15 Sep 2026 06:17:57 -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 1x6QER-0003Jo-3s for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:43 -0400 Received: from mail-pj2-x11.google.com ([2607:f8b0:4864:39::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6QE7-0002n0-RT for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:42 -0400 Received: by mail-pj2-x11.google.com with SMTP id 98e67ed59e1d1-396ccc02279so2817716a91.1 for ; Tue, 15 Sep 2026 03:17:13 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467433; x=1790072233; 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=ffn71e+pIgrmkpZMSuNM3s3wiDknQ8z6eWqR0ElZS0U=; b=q9R2PQ5Zla41P22ehTVqkUKer2kZGhpWjfKgozWcUmsOoh6nCUxvEOYXc/c7cLjYWM VWNzVlNVr4EbUVpBSShYgntpNLyGLfro9cfBKdSuCAWhAHsSByPOTIl+YjEZx3wIfS9w KXOfRp6tSScV5toK457eBMMTJ/cwFl6sd2nEY91bcVIncfsttnC4rnwm2IXHY8JDfvC9 vuz4KfgysUm4QIsLvRxtvHW0XWo3gWWtTgfnWRIyhOJojdVzekDFKkr8npZMecx/sRGd TmTi5WwVJ0cKeom5puRj4zMdP6TDK7oj7gMhASTlDztoWYHfJs6ExoTii5RKwTlpI5VO 3WxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467433; x=1790072233; 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=ffn71e+pIgrmkpZMSuNM3s3wiDknQ8z6eWqR0ElZS0U=; b=QM9kjAcCK+tJ2xAGwY0qpUBHXdl8KtL5peO0p1sK+TuBqRo0ZLzNmepUQeLy4LC9g6 7bK/nwyogovJwaOnza1M3f9i1a58mVgxvPWBq6WIfKglQpP+Os7ItQ2sVaJxZG1R0t5k Cu6qlMZvCOIC68xm6Wyk0gBEIzMZrWQ/RbPrTzCHCT8Iko7zHXnGmk/NrtikMuDQ5tOQ b+KRtpWKp17lsSz/Rf6XFJghfY812BfiogWKZQvmKYvyctx1Dsd+GyBLt5Ic0Jwye6rX /A2wZGLvOM1YgDwymGhGhDX0pvpPWmnvvHUDP9wOJ4wQtvbpZPyyZS9LknGwHIuXsz+K zeYg== X-Gm-Message-State: AFuF++kvHL97o9REA/ajIy3ZnbMbYwjwHt1pu22C5I1dtsEmIWxKzhUn 3oaXu18PiW2hESYyJA3baeXQBORY72OyjZbDojiK0SqkOIZHFCB7ardoc06mYu68GTg= X-Gm-Gg: AYBFou3zAUHe2xVKgmZsK9oe4dHUMxc4kNa/6O1cpbMCjnSohmBpOqBPfd+o3U0i6XH 6G1IYZaAsfneNTckEYEthKqp5XZAiiC//QVACXXJm6+OcS+Hh2m33jvMz/OA3bXE4+J2n2WQRM5 swg4WYjIQIT6SkCECkcXAmi2S7E6agN0adqvX7PC8Itm6s1rdhVaVGWmZnZQQ1zJZSX31PTfeiD 31WPBewV9bGJI+4DljpwnEXj9R17Tn/sDMOEpzADEs1GcYFAk5pjlyBNygqkaov8MrrbuhQ5k+3 SxLgkRO0UBBlCapr6p/rk5Z8G6TA1YaBFNaA9W0xIHGG8bQF0IxiaWOVZTB2SPXyKGsjj2SI/1v SzOFgKEgxV7EhV8uWJS86SFXQl9lm8uv8joJzHr0MaleOYjFDjdnN+fOMtzrHcwVESP1M/eRLEx 9RUtXYTn8IpZXJjXIU/gL/17WVxAZJi+NNawM2pQ0D2aDt5C89aPzp8McyqCUCwdFPm+GdvvPyz CAGR67zq0dWun2xuoEH8wj0h9y+ZrcrFBw9wQ== X-Received: by 2002:a17:90b:1dc6:b0:39d:84af:a0b3 with SMTP id 98e67ed59e1d1-39dec09cf6dmr13687164a91.18.1789467432842; Tue, 15 Sep 2026 03:17:12 -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 V17 02/13] iothread: add holder-aware AioContext accessors Date: Tue, 15 Sep 2026 18:16:44 +0800 Message-ID: <20260915101655.3216101-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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::11; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x11.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, 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: 1789467608159158500 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 6b0a7c557a..5a4291a2f0 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:00:46 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=1789467515; cv=none; d=zohomail.com; s=zohoarc; b=k30lEfJZDUOnSwTsnMVW1yIqwXOi4tA9dgkFOGURvhXe6c/z3Ac127kI1OmWGkwSeOearMv3VBNvwjylsJLlQekxYWzCaY/mLdH6zyP3RgI0QBmWHg3xYxmi2TL+8B8WBCRxbJ5T1TpUUNELZNRi8FBEcyVH7vcS/qgnqug/6tQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467515; 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=RvDQaYiIXt2D5x1RS9N9VvUgUl+TPWBKcbpxUFMuWMb7tIuIkdEYmZKRrja71/LAi7AXhM/nlCPfiJUFUxsdQzjJcLjOysnxTki2xCjhGJL+ylOkDzwHwxqnTOkzBAdEB6sh4rgPMUqgXy+rY7eFerrLmabyGcroPhbZlvbnBMg= 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 1789467515526222.4783656738016; Tue, 15 Sep 2026 03:18:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEc-0003LQ-1z; Tue, 15 Sep 2026 06:17:54 -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 1x6QEH-0003Im-HC for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:35 -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 1x6QE4-0002ta-Ci for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:31 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-396ccd5cf03so90654a91.1 for ; Tue, 15 Sep 2026 03:17:19 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467438; x=1790072238; 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=WakNdi6ItIzUUWdER9Nc++QLR1q+Mqg6F8ket8YOxb9mHYiwgn5mNsslo34hOcHrl/ d+YyKZd9htNhP8+rbuhZpoyFNVCRfzulzLL86hz1LZ6sv4r1I+LFx7WUqTfWJOykDfiQ Bey4StrJxP70noOMAToKK+eQH93ftLoNY1cDC5aVmXRJj7i+Asg26/mJ5Y3l3E/d89Ny AMRzaBuK+VRA4WIJ16uFRTZt3+2c1gyEQVYrWJftKQPgpk7jreIQK7q6trhX0e0IfiCd tsiSRiEBEQwjhlt+x25rND/r9PyN2gCmEjmW2immDfeGxIcIP/okHRg9LTIFiGSgDEDq 6l7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467438; x=1790072238; 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=msrdAXURIq5qfS4tkuAzwZFarWUqyuM2X2a325LkO87mQL6/Al0hXDPb7yPeDkENg0 jsWyNjXEhNpjjM4bXd8ip18fhCR22oOj1QvpyovNj1FkRIJK+LVSBXArZ0yGZvqIKDs7 TuYb88T+4DLY7voOv0a7ec8kpsaQtfqLUZTdNKrpYrD3E5ObLSBBGHQ9FhCjxBvoXW80 iEC6j3VDOVTHn0yUJ+wHz9y8kC9b1C9s4olk81nc8proCmReVEHaAjjfcG/flkC+6ExG 51Z4L5G6onQpELhb9kyTrOT3JmInoqlBN0J6+Y9bXWkC+vniaPLWpMPVhk5LWglVOKMW U3Rg== X-Gm-Message-State: AFuF++ni7FROSedahFBchXhK+4/Lk6fGlAqhVJLzklPZ1hqa73nLY/mL EmwMucNjZrspG5TtIGX4BKmCOeD+JabTWJcIVJvLg8MY50oTxYd4TUSgtgBrMN/VQMw= X-Gm-Gg: AYBFou3JWRCGN8Vrk4MQFd5BTORKWld6DV/Gre+9/51V4S35R9+TPMjWP7xByUJks+9 /5uDMSdlBhJFSxgo8dnDbTbh23moKzPn9MAKsI4dDXBWYyXyvpBoEwlZjQ8xZfir/8LgPYvLSu6 wHmGsYboBi/vq6uHe82Vg+iHyzUxysV9l4ysrl2uIvFtNqFVCPVGE3vtgq+x4zKgMind8uPaae2 V7HXDdzzPIAZdRgd7OIjMaZNtVrHGmuSnB6fsCywjEqTIQavNg/dEiJkTQPSR/RGRH95H5m04IM M9tDAIybY/Zzy0prEGCnp4X8cIW8DFU+9jVio3rFxfRKZfthtaeWALCTMyoNIALur5X57XilU4c F+eMOIgvDmfs5RZWW2cRb2o1QpeSVFFHdtBxxHGbPd9r1trSSilmD+y3joQRUKXGw34xixiTOY3 fAy6ZHdDdagMu6AVd7dJEQnqvpxehmrNFz67EOmcVLuMYEnHzJFirLEgpJQa4qSoBO9NX7D7hFu RDXT97T0WslsRMMWKclNM41WUg= X-Received: by 2002:a17:90b:3e85:b0:398:c794:ca26 with SMTP id 98e67ed59e1d1-39e1104d9admr386660a91.25.1789467436671; Tue, 15 Sep 2026 03:17:16 -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 V17 03/13] block/export: track IOThread references Date: Tue, 15 Sep 2026 18:16:45 +0800 Message-ID: <20260915101655.3216101-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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: 1789467517565158500 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:00:46 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=1789467568; cv=none; d=zohomail.com; s=zohoarc; b=DujXW4RqRo+QaZvCDBx0T9IJhUEEw3N1kVoMuAV1ScTwp0O0xIAnHOL00t/rKSUST3NDz6MiyCAJTo3DsPaCZU+vrfPmqlbp8iKEuI4HUAFNtu5MBpTZguHa7xVv90lZDTe9O/o3lPG1IIWvd4yV0ICPzOBcYG0rKvAa9eh5Cb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467568; 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=GKWCgK70nUpOWFkQR+h3sL5lRDcML4I45/LVfyTVJbUarDtZF1L64ybljR6uWHhulKhq5lEmo3WpluH/FOAJNh+zCohxKyXUnq8RLesRgBiE2PeqgfHIA7w0RAWjn2AtoF8CU10g2lTsf1vFIoi+MC07rKo9KcHrj1SEll2Lmrg= 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 1789467568792555.0711026386657; Tue, 15 Sep 2026 03:19:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEf-0003Lq-0h; Tue, 15 Sep 2026 06:17:57 -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 1x6QET-0003K3-Iz for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:46 -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 1x6QEC-0002wo-4S for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:45 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-398beb616f5so1185829a91.1 for ; Tue, 15 Sep 2026 03:17:22 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467441; x=1790072241; 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=n8pyuYvxvSIhyaz/BBykDQlarifpjIIKdnbizMt0+8P1bF3irLnfSHI5Dnwgm6dYV+ 0AEgW5Y8LJ0Hcfi8ZJyz4BMIqov/LzgB/uK/OxgW/s1IA/2afnvWMtXG/UxGDWc3AVNg yZ90n7ON3arHartn0431q6UNg5Q73wIbzmbLN6P4ONiNANoItReVPvrmmhNmTpYKiNXY /OCXx3GPRnGwvya1Eg96ymDNVi2Ypa7kv5J9N0HyWnuNwfIgw6Jm68dw41xaua8GwW3g RcUNqRWB3IZ1WJQhJUrLy9ea6usZaPi/IIjm3sjo08azuC6NX/0DFZw8yzCWVNt0lXll byWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467441; x=1790072241; 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=PIhF3rBkOt31ojW3xogtMTeOOPSpfRBrcXjZvpgO11/Gm5d5FYvzdFvmXlgBUx4GBz AsMuqk2PWhOR9DO9iar0VUW0F1n6TjTdpcxChq06O17yeCc7KkmSMB+iEMfNJfWRR3zx O+uvirMz/oKO7hebQEGdlpd6tm607Mu0QynQ/wEBAJbqfXODgmHujA9p5pOQ048L9e2w pNMzjyStfKyG8XTyQ+mhi/sHEcfWU4nA9O+/xL+jTqUAr0MUbj45nE8LeyaZ4w3vJJiL BqmtrhXT9obPVMX31jVm6Bkj9sXVJ+Xn+BVG01N+Mt7Q4/6JysQwqGMW3MXFQkmbNx2x Pe5w== X-Gm-Message-State: AFuF++niUnzQirU6r+5rwndR6NvuJqys41ICWDg5MLbF/RaFhepu3f0O CNCdidqV0BNpFjz3oCoTZIMWLtTYqIWYrnd3lAQhWWYo6+SBYgKo5+y/OCbKSA== X-Gm-Gg: AYBFou2IqkGTOuxCrxQAi7rulTXMd+gViZK8oedEcUoI4pS0T9RogUOKR3A0+QrcfYm Zd2sSDxHjKFl6DAbCSbLz7heuNQIXb3npgO/Ew2H4SoH9F2QAXV7uqx3ZY1jb0ml5lf5lXP9pIy PN91T/2zvUnwTxnjORMor7B2D5myrrck70kEl+yI5Qnz4oTbJ8J3vhIUYz1UhQvNbaPcuW67r8Y S2tZMt3v6lvwc7Fp/8ZqWTdQj54jdphiiguiRgJ4uIQ8oP+/VkGORkegBwwfenrAt7vuoL5q9Bz K4xIvY4iMBbxgJ93YSOHR3D03mfZfrmt0upeYYpyrgqDXLpVnvBa5LfVdOifZmsWQgpQ6gRC/W0 TlPUmRn1KIKYcvMd3PuTBkrZRICo6lj1+fRTbATX+NB7Z+2zkeD6Ayek5+YwRNDg+8FDHxxT+vz hIPLkxMadQp2VPLfHM3ehqBX1Ok23csS1Y7qri4fwtZuDskMP27E30PsQPoEpxIyKzuPLKWFf1F TRprCj3HSIgjZayh7rC5RmfnaZ8 X-Received: by 2002:a17:90b:2e49:b0:38e:7297:a92e with SMTP id 98e67ed59e1d1-39dfe0e21efmr3481012a91.9.1789467441242; Tue, 15 Sep 2026 03:17:21 -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 V17 04/13] monitor: track IOThread users with QOM paths Date: Tue, 15 Sep 2026 18:16:46 +0800 Message-ID: <20260915101655.3216101-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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: 1789467570035158500 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 Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- 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:00:46 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=1789467556; cv=none; d=zohomail.com; s=zohoarc; b=e0xt8H+DD08oSlABjtLlt5LcOenP4wcTfvArmWACDH1LYaFtId+XgXs9zT8OLWQ2gIcVrw7DtNEJqfIR+A4f0+TSrWTJyZc/6ehEhcc8gKbEcT1yh4xnC7KkWjiYfllgv9Mj/+JW5omgTEqV8oja4O+36/TAO97I63U6PIA29ZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467556; 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=km5JaLJu9f0eHAXPSG3iGDGeBfqUUoEPjqGyA/4VHdc=; b=WWRdbTqwFma+TuOyCUg0Uqxk56vILnUyiXO+0LFWJ0QL9sCQ/As6c/GwnJs6mW0+h5wnLsoJ+LrUArxrNpgAGyGM1Sd523mt82OHi8WVaNd7ZnjHCERKVbu0SH3lXSpce/c0TWjSzk2eOM004TRhEzP2kxuItTQD3bkbMrOjSug= 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 1789467556427494.6638173219703; Tue, 15 Sep 2026 03:19:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEf-0003M4-Sr; Tue, 15 Sep 2026 06:17:57 -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 1x6QES-0003K2-Ol for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:46 -0400 Received: from mail-pj2-x11.google.com ([2607:f8b0:4864:39::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6QEC-0002yU-4r for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:44 -0400 Received: by mail-pj2-x11.google.com with SMTP id 98e67ed59e1d1-396ccafb752so3047708a91.0 for ; Tue, 15 Sep 2026 03:17:26 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467446; x=1790072246; 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=km5JaLJu9f0eHAXPSG3iGDGeBfqUUoEPjqGyA/4VHdc=; b=al9DuloIVlWStmBASf/BNbf6X3t5Ffd5yTwDrVM2/M2Coozr77ULAJCfBAscasg5xM MxaYCvDOlv5EixG1nxpQJkmnFRFvTNYQa8I48/LuuqqyNtfnh8PEATvgLBn3Py6YTRKI nK752csRgiWoEhN5Bp9PMH07RcrNdzsAAcDAO7hw4mo68bqb8NRoAGq8lhEGPi5ymTIH YARuxqWWTDCPs9fOwuh76OCsH00p4HCe8sHauTWYeywRLGr62AHcC/pgwjs3QiZT4GUk WnoM2pvLBvK0h5BTZUADlQ7rlCvwPm07y6xFp9IRmelR4w4y13I0KeyCtdC5XhPwx/R8 TLEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467446; x=1790072246; 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=km5JaLJu9f0eHAXPSG3iGDGeBfqUUoEPjqGyA/4VHdc=; b=tULmRbXk0IZDr2J/cgK6XJXkeaoR0x5kiybGOoHl6+kBMR4TQR4WdS1eI4XFEXwlm7 eDja24PyGerlTRfiq0bCryUgUnk1a3tv6LPxPsT8ktZV0R1Dw9SKW6YdsHxm+vOMIk6w q5n76/8F99HLqd9aR5qANhuv1t5bWHbVi8PL0oBw9bERjLRFLJD2Fa7SFxu1k8ln3mny ZPODuSLD9t7RBh2k33fosoKvh6ex2LV14KuHJz1fV0hKkdQUjsRTZpWKYF1Z0/XA64Kr B7uRS3Jz8pwnOvEG7JTdYfvngutZoKMcPEiCgAOAep5xstdYryk+1TC0R/YpFM1Yv8xt 7pgA== X-Gm-Message-State: AFuF++ncmz4bmzdS5Q7f8IUxYSEkp0FIADuNwf6w5AGk8U6+xl3UtmRP wlea3SIF782RbdZ/b1hlWf0wbPFSqvBqxV3g2DEL8OQ2hOqwRyunJWzNO+L2/8ho3N0= X-Gm-Gg: AYBFou2gLDrwsWx8P793si2U0szz4lnG2XX23uU6r+EbrhBD0SG6IG3Bs1EkauGQiLb kdzTyJaaarg9iv2ReJHNnG5DKCsniCiLdg/CyQ8bbVi+5N7rOwD7t25O3EviCaQFGwllUVgYnIK u9llbt0AHWefFa6/o8iJJ12/513aPtnYFo9Vs6el7Gbdz/G6HG+mC503StUU14ijLGv+Ihvcw5W tkUdrBI+ZILgnnbzNZV0KkUGiARI5XvnxTKbnarD3uwCvxmG4m8T73IQbtEDbVsyp4jqpuD4+Rj DAULGDV98QmJBiM3VRp44YljXukftUUdFEFMs+YM3rLPEv197O5mQwPmzjDPOAjSUoBv9ayJ69O S1T4iTdMHNrFnTzzZMfwUB3SGmW+c4aNG38wGT9dVN2bDZ32b0vd0ML+ushwWHqanOkExo0/vWI 0NplwG0t7RsAxcxDeZM5Mv5t0VLhBgITy8mLqJWcDGdTynx0KjPQ61MB8lWacz+jginCxRvjqUc /bSkO14rSh1tgni/k7JmmnIp2M= X-Received: by 2002:a17:90b:5887:b0:39e:8d5:fcee with SMTP id 98e67ed59e1d1-39e08d5fe14mr3095574a91.17.1789467445714; Tue, 15 Sep 2026 03:17:25 -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 V17 05/13] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Tue, 15 Sep 2026 18:16:47 +0800 Message-ID: <20260915101655.3216101-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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::11; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x11.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, 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: 1789467557786158500 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 Reviewed-by: Stefan Hajnoczi --- 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 61c341ce2c..b2887d74f9 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1499,9 +1499,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; @@ -1533,7 +1536,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 bcb6e44133..ac13f4a1ca 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:00:46 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=1789467514; cv=none; d=zohomail.com; s=zohoarc; b=dZsQRxWuoOKhaxOx1WZxv6muMJxz9lvQ2ssrDVHZOtY1hILyw5J0VrEIy5ViHAvIB2dURCHuPvcEyxQuASi5lwPwvGkUuozAW1iTsXZEAMfMFwHRgg2s2agc9vx3eZfBH6JFersosVdg87RNaZOTJGHRhvntDOSVGifvp8ZF/gg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467514; 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=6tg37X+WJ5K6NgI6xa4zk6E5LxsaBQnLXWji4A3r66A=; b=Bq4l4T9D+Ru+gdgeo5o9yF64pJk2rKAZzfevmoPafC1ctSPF5GpUw2w8jfNCZPW9IgyT4klyIomYf4HtxibGfMkcHKaFkUfP4c0KbvEduPb8GuS6GHx0tcg1ATDDIX+e4Hv8Mbrno7yn2zSwM4gmzx7wFuFi6Uc4GTl5zJ7z1kE= 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 17894675148271.9344086182337605; Tue, 15 Sep 2026 03:18:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEg-0003MB-4P; Tue, 15 Sep 2026 06:17:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6QEc-0003Ld-FU for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:55 -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 1x6QEH-000312-0R for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:52 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-396ccb1a990so2661668a91.3 for ; Tue, 15 Sep 2026 03:17:30 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467449; x=1790072249; 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=6tg37X+WJ5K6NgI6xa4zk6E5LxsaBQnLXWji4A3r66A=; b=QxVy1WsYgvaXQ1o28P3/zy3i0T1MRf1Hehuv+AQT+MK0TGJmKEKgySZaagihvPG9x/ ut5ZlgkUsTyL0VPMYg3hJBZKdiFJNk+XrKpEkk/goU6DfG5Hj0QFyNjwuS1zsl50ipuP QR9ct55Ap5g6EddPiQyObe2zFjxfDNEPlXMbWfb+RlkMOosfzDorLd/ogQsoqf2fTbxM Uc0iGo58AQ5flImAhfnas8MRDYLleHahJdkl3PQ3CclYRRR4f7f/CxeN6jqVv85gH8Y5 c07Tymt/hNI02LCsrUyXHqoIkhNTwSMysrH3tTSKGC42T/Axi6ZG2r2yrqhtliPpLupF 22cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467449; x=1790072249; 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=6tg37X+WJ5K6NgI6xa4zk6E5LxsaBQnLXWji4A3r66A=; b=wqXzYkgmEupjw9YBbLUJ18aHZ7yT9/RjsOAqByz2nRL6KK4r3PsYCixnHuwCYy6uU9 mvd8lmkol9vyqBgeM1WIdRSbb5dYuzzhSFLZooiAuiZz/OnEMNxps92lfO1X1329wutT q7qkNPCglV3VGAA7GimCy89iUlewbekGrOTnLTo8vYQhfVAC1YGz6mwVvJn2U4yBOfUc aOyoutBSWWXzdtbwSFdZyYizbstVG9+STi21Y/iPcWSn3yAM2f6ACK0tM8uMD728NV7v 7ar6ecfJReQ9DFWT6zVSnUvG+V9mxWSt1caJMsJQRrBZmHt96mKgTK3maxt+ioVso/UM 6PsQ== X-Gm-Message-State: AFuF++kOVBp1gVn+IcYisM2AVAq4QlJ2lPBui17AqHYo6B+0/2opey14 aMHXpquzcQQbyPTpKNnuBO1nSr2TMq1HY5/hDH0o5d6UpLZYjK7XArFHscyAex56lY8= X-Gm-Gg: AYBFou2R/JiwFpqJLGA9q/f5jfGj8OK46WuBZtvMl4jGAV8lEZyd2qXty1hNPd5++yp 2Utaft8vR8ScLNAFTYcaz6Sdmm7lq7UXPK+28rtcHtIPPHCfb5Y7JqXhBeFNAMepGVbKW+oCuSx n7zkYyCzQIiVxhLk9Xr2f41VvkybNYLVBREeyVq1DDxUIEq3Ukji0aIp+JGjAZ7InsJZCSeluK+ 35gVXlrjumXZVKuNLV4moOqclNGQqyz0dQHuO4WTIttN2IxWcjKul+3W6xuuUaXv07VlKKmvOYr X75D/gm+jkNVhtt+PDe0MJ7rkS0qc6u90dxLGuSEiSd/P17n9E4elkLeCSx5x3JiJLD9B0VG7zM jD3TNZt/Z/aZpYzS9O0gO/pXSOy56Ktc/9Goiv8CQy1jQ9qKUkBJZ/Cbycb4ID5KYNctudNYZEF qtXbevuIrhBLWJw61t/DT3Zkq5MgSw8ohvZPTJNRCsGHEr12qxfY3YT1wmwJRSBdjIehyswNnBd WhuglLyE11HQCkZkTvyudq/+AY= X-Received: by 2002:a17:90b:17c8:b0:396:65dd:4093 with SMTP id 98e67ed59e1d1-39dec04f9d9mr12367570a91.14.1789467449452; Tue, 15 Sep 2026 03:17:29 -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 V17 06/13] virtio: track IOThread references for thread pinning Date: Tue, 15 Sep 2026 18:16:48 +0800 Message-ID: <20260915101655.3216101-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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: 1789467516048158500 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 Reviewed-by: Stefan Hajnoczi --- 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 b2887d74f9..9f567f4c65 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1475,6 +1475,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, @@ -1499,8 +1500,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, @@ -1511,13 +1510,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++) { @@ -1532,18 +1533,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 ac13f4a1ca..d66946f279 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:00:46 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=1789467556; cv=none; d=zohomail.com; s=zohoarc; b=AyfEZsPXCLeME09Xe+GUTUbMMDsv/7tMZLMAdg1JzYg17890IUVmTj2KTfWXUjs9gIpshgA7c4wu5VmZm1JwZBSBauUOegyf8afLQ4zK2x0UueWCqiVwozXYJyg1V3MYIKWtKunUjxnyUR3h5qBAQWnfStLX+qUy2F6cj/4RGzA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467556; 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=mfmIe9qtImQJjokT4YGF4HMvihKuRDpEAw29fA55fkxWizoWiy4w1nsYem6qw59lgGzLcheQRyqeL+Rowldp8/liO/vWl/golmV17L3PnBomviq2rLW9qEPTFQbb6XUdr+35i/3B2R65kYpSl7qj/YtmGQSc5F8/Uapb0SUcZSs= 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 1789467555997368.6085387368739; Tue, 15 Sep 2026 03:19:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEn-0003Nb-OO; Tue, 15 Sep 2026 06:18:05 -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 1x6QEk-0003N3-7l for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:02 -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 1x6QEO-00033k-Ob for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:00 -0400 Received: by mail-pz2-x10.google.com with SMTP id 41be03b00d2f7-cc1ceb47d53so432393a12.0 for ; Tue, 15 Sep 2026 03:17:34 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467454; x=1790072254; 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=LtcSUylcFuK8zBL5h/42SU1UIJzfk337zjL8xgHq0+xKA/C8wlakwrf6bW0d1/gKkc ck0dsi3K0wUBajdFJ2Uh4xyS0r2F6PL8+lEzQELmpnb+MGVfIJnaBQn3DjQkQaBUDbHR IjRUnT60wWOzKjDfFv5IUTm7hEVerkBxfn9qy0Xtea92RxESuui+jOTaPROkR5iWolpV YKOkKLv2uFQknlIxXaGh256q5CQmyA13nPH9raEM1uO79v+XxxvFMpHyqDoc3C5DbrA9 3PkNDbxhBZ0YyTryKhQs9RSg+pYM6ipZzSxF+dx23UwS2eHWhk5aYf8APq4vnbkr9cm3 ik0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467454; x=1790072254; 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=rb0zCOTzT9UPnwaksTauQohfkYP5id/rBp4wrcFRxflT85wgbIxqDZJQpI/HWQNIwf tXX2h7w4uGBKa6fnLYoNGBwcI1sg4hmVsWUGiQcSvBqzUEXDCyxsXieFLC8ZYpX48gza 5I3d7AWIQjLI85i7E+IcOrLcGLORqf93zTc3MdjVwytacdzrrbikn4Ds7bJs24x8FlFn XSNNd+VFZvTgRh5owJd4OeIoSqnBrpuxqtsNdwYEUuS6PxHsk9V5DUD5nxWMBWWZw6Yy QTJRiRcEaKjoumQUz+1+QmedJUJob5BiLCCHf+GXJrbAd8xtFB/2SbQ0zEBaUZzGNsiN wHvw== X-Gm-Message-State: AFuF++nRYeq2eUIozy9LQHlmVKfhk/8DP8eMKWKyYroeAXpkpjOhMrmX 6IFGEozOitfKM5SgH1cVVpZGVCQ4UghWcmjUaL0nB/ECYGoBAKITSVSv+CNnrw== X-Gm-Gg: AYBFou2ulxu6Ip54r4BLqkiR/7GKRavG1gTHgCeF7OrSuonIY5R2i6XiVUoOIdB7nnB T/fsQ1I18j4Bl7UKe+u/bEFaVyt/qXdg9T189O94Jl9ra4horp0wnvYMdkw6UqmACLPLq/TnpoO 2MuU4iNqRJaeEpToiBVJ29EUOsaoElg8bB1yWM0/TUvAz7ajj5xWfywgcCfCmyA9yOF0P/gRkFP meR3SMkBbY5YaNFAaklSDJs71Xuh7ACBrP27kxFe3PcfwANzzyki0PZf+r4yUduyKoopLLkPYQ2 9yK12zZqhG+mlyzUfaABjsTyySnYs62usuQUWfnfWfT6B3qGQj/uYUknsoftsEghd59YNGl+TqX tXnvvDRDJcKVJzpAffc2EtMG97Xl+q0PZCQ9Lhb15j8v2Nf/nULpbzUHJRlYRqv8+od7KkWYVv5 CRCJzfHpyqZnTXm672pyzaA0Ir9cdnGP2fTBkBsb3OmITnLNXSzYrv7+LgAdd1TBCly8fTVdtS9 dgN9mJ5BdCxjjaENl+7bm27xTM= X-Received: by 2002:a17:90b:5646:b0:390:84db:888e with SMTP id 98e67ed59e1d1-39dfe097622mr3817911a91.7.1789467453747; Tue, 15 Sep 2026 03:17:33 -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 V17 07/13] net/colo: track IOThread references using path-based holder Date: Tue, 15 Sep 2026 18:16:49 +0800 Message-ID: <20260915101655.3216101-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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: 1789467557771158500 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:00:46 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=1789467610; cv=none; d=zohomail.com; s=zohoarc; b=YEvEOqIkhvv68YUzFMQ5D4QPAYIev+EWfTFzVKSyH7fwTvoW0XdtyHm5kY8CXOf3JW7ggeXhn1SlNojG6EmnsoYoCPVUGTK2CUZ4bVnpztEr4OENlMvOGaRoFnZsiMRiNvt2K0zkBjgseCEd3Mudhmd9I3cu42SdEPHmo6Loscg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467610; 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=aMpJO296pImnzMQ4cy37vlFU1XekjtBMhU2RmUAJ+r0=; b=LhmlJfl3yvxS/KcHXUXEqbSobcFre77WA7OObYF8DFAdOh/0SoM+t6IxMYkSQYhpAQdgjAhk1pro79xEwrs1VzYTvp3cAYkiSdaVOWTitOXPJrt7bI+vFYq+/JIB0WJXdG0C1S+yZTQCAQMJvo2B9Eg30HnxawyNMcrx02e0CLo= 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 1789467610074398.0404186825348; Tue, 15 Sep 2026 03:20:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEo-0003Nq-Fc; Tue, 15 Sep 2026 06:18: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 1x6QEk-0003N2-4u for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:02 -0400 Received: from mail-pj2-x11.google.com ([2607:f8b0:4864:39::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6QEO-00035V-KU for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:17:58 -0400 Received: by mail-pj2-x11.google.com with SMTP id 98e67ed59e1d1-396ccafb74fso3045202a91.3 for ; Tue, 15 Sep 2026 03:17:39 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467458; x=1790072258; 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=aMpJO296pImnzMQ4cy37vlFU1XekjtBMhU2RmUAJ+r0=; b=neLwXr5IMOHGwvokoOXbHkNHyqc4AQQwqN24es79O0RJi32zFewFSpn1iuyd7bgSy+ 7KR/4+IJCZVLjAgVzCU48BN+frVQpNALnhfMHqhAOfTujsOCYhMHptFLgyKaxPGorFMt HiTn4yfWFV+bsKOjQEnrsWopmJScVfmu3eOJN3ndxoJBGO0hINmZg1SMbsu70NyM3Gsf 6pApJq09iRFJU2IZNnEca12swqsubkz/txwRfFcDQP+7PbogDYt0vOnqazm4RlckIvhC bcFW17geBr01FCxTDATme6GihntH5ah9ZluxeIy4jj0ucCjtFdAFRkJyJoWubAxoEcJR grOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467458; x=1790072258; 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=aMpJO296pImnzMQ4cy37vlFU1XekjtBMhU2RmUAJ+r0=; b=Semx9sM5jDb4+OqSc8S52I496XHd0zVSIyxwaRB2w7Wm7Ohplqfkqmo+9+qmDMN5/Y +7Sm1JVrfPS825pje2in6WUyRH+6mppgO3Zhb7YW/KbmHBTGVsrmrmxfbOz7WBdzWWqQ EOo9vCJvf29iMeUCGisolcN4N+we14nd6dl+e1XZyBOsKRgUXl7Zw4yvMG2GABApmTP3 mdN+LtgTajIzi/WAhVcEyysXgPz9HlCky5Cp1JsTbPEQtmd/pEyiu0yBVVrNzgKaLfn4 6ZPOSe3+6xxoWEsqcIQwbTt+RqojLU1fQOq52Ccsbsn/y+EsLZtHoO5leZwB4jPwjU2U W/KQ== X-Gm-Message-State: AFuF++nB2kBJopjI+WcCReKBWW69SUTFOljTcn9PKgfI9A7n4WjtOzsy ymYhkPwR/4HmY1QrI+/TbZImg+DeDFSwjA62b2UG8YHejl+bO3zedMwZcjUZAhuglqE= X-Gm-Gg: AYBFou0hiH9vm59JjgbgG/nlRHzCXOp6c6pNX8JzE6geQPF3Q16c1zXGz4hlwv66pqY TugBumqRRiPHTMLXZ9ZBT2ingWhNTZY8zpODI0q0KxoTPPfdGdc+xhcmltOMJ8hEZnFTzkKNgaI SZIvjN09evMl1jH6geZpLL8IfB0CJwZDyKwaUPODTSGoCA1/o6KoTDwETlCadzJVvH70ZntM5VA YXq8jN0pPnqSq9DfQ5oBAECKsI9h4rU8iexM2U0E2VifLcMtzx1LC6QSUqofILeyNL5wjZ83jYU Q41x0nWHZZ56UiJwlGaWLuYoPhPVc5ycOE/EBxcLiFX/aJteYGOI68fXraPNGs7LvfWYGAh4KeH x13cC3tXZj+H4rQ1g/XiO3Mai+vHnC5MLmBTVa1OmAte9XpnBsoQluq9fq5eouv3mAxwEbXDDTs N9eQ5tHhbf31yV6UXMm3jQnOjqPQ7kitAHVdDgZkiFWEZ/4NJ5f5g3esYkv13WWe19bRkvxBBdZ 4uIeDQXeNMDZt8O/gO66Mj3uuM= X-Received: by 2002:a17:90b:1c83:b0:39e:27e:21b3 with SMTP id 98e67ed59e1d1-39e027e229fmr5043656a91.9.1789467458389; Tue, 15 Sep 2026 03:17:38 -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 V17 08/13] virtio-balloon: Update tracking iothread users with holder Date: Tue, 15 Sep 2026 18:16:50 +0800 Message-ID: <20260915101655.3216101-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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::11; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x11.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, 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: 1789467612047158500 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 Reviewed-by: Stefan Hajnoczi --- hw/virtio/virtio-balloon.c | 21 ++++++++++++++++----- include/hw/virtio/virtio-balloon.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 07d519cf6d..cfc581940e 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -896,12 +896,19 @@ 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), + s->free_page_ctx =3D iothread_ref_and_get_aio_context(s->iothread, + &io_holder); + s->free_page_bh =3D aio_bh_new_guarded(s->free_page_ctx, virtio_ballloon_get_free_page= _hints, s, &dev->mem_reentrancy_guard); } @@ -928,7 +935,11 @@ static void virtio_balloon_device_unrealize(DeviceStat= e *dev) =20 qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { - AioContext *ctx =3D iothread_get_aio_context(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, + }; =20 qemu_bh_delete(s->free_page_bh); =20 @@ -936,9 +947,9 @@ static void virtio_balloon_device_unrealize(DeviceState= *dev) s->free_page_hint_status =3D FREE_PAGE_HINT_S_UNREALIZE; qemu_cond_signal(&s->free_page_cond); qemu_mutex_unlock(&s->free_page_lock); - aio_wait_bh_oneshot(ctx, dummy_bh, NULL); + aio_wait_bh_oneshot(s->free_page_ctx, dummy_bh, NULL); =20 - object_unref(OBJECT(s->iothread)); + iothread_unref_and_put_aio_context(s->iothread, &io_holder); precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-= balloon.h index 53bbaa4c9a..5c3731b3e9 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -54,6 +54,7 @@ struct VirtIOBalloon { size_t stats_vq_offset; QEMUTimer *stats_timer; IOThread *iothread; + AioContext *free_page_ctx; QEMUBH *free_page_bh; /* * Lock to synchronize threads to access the free page reporting relat= ed --=20 2.43.0 From nobody Sat Sep 26 20:00:46 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=1789467580; cv=none; d=zohomail.com; s=zohoarc; b=XszjMV8jXepeDrCkQDHIFgMieOg+Fyq65RR4HWo7G11rSrgsK0J99lInYU/gdaS73kWiFRkiL8OF0JLTg3Op2GRLLSLOsLKe8LT8Kf6MjKy4c+lp235LWD+MFprkKxHA/c++C2bw3SQ7y1PuqYd6WRwgbIEVMwrOkIbRafUd3iY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467580; 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=ex0FX0osK1WtlBhTxAQ5jIZl7f6iencP84/uSGCs18Lrh5TSb4vcj8waHq6jn7dI6zN6FUb1VaRCh4QWL+Kx0J3uWYnSxEdhuL/xg5a10i4YI5r91QuMvk6SAjYhpWkZIHnIZWIfwXxA78E3JIGbN8aqFHn/bMfRpiM/3mnFfWA= 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 1789467580207416.22086850549147; Tue, 15 Sep 2026 03:19:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEx-0003PV-4U; Tue, 15 Sep 2026 06:18:15 -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 1x6QEv-0003P1-T2 for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:13 -0400 Received: from mail-pj2-x11.google.com ([2607:f8b0:4864:39::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6QES-00037b-13 for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:13 -0400 Received: by mail-pj2-x11.google.com with SMTP id 98e67ed59e1d1-396ccd78e6eso888568a91.0 for ; Tue, 15 Sep 2026 03:17:43 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467463; x=1790072263; 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=XccbiOIcbMROOBm46u710VgwIkTqPHnOoEJ2sabfd3Wo4EZMy909fFxgV5Kc52nhX9 t45cyGj322LBx20/yJ/PSPtqgIQpIduZ8G5G8u1cNVfG0NgeHyjc+PlxTmnewGSGFJaa ol2V5k5+VrNL5f0NvnzLa4wxbnO1ssgP4tHclO9Ow6WPASPdq3IrYwwoCFqiwJ4MoyKj 5vVRCDL+qEk52x7PdF6ML2hqt5GnT+mCtY6hS5ppXOxxzNFYvRK+yK5PJyapvLRpVy1e uXVF+QZBjL2Xi9v2BpCu2FM3PoXxYS+U7KpgjPjJInFkJCmjeu3WO6iX5SOsiXq8QlGU fAgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467463; x=1790072263; 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=22g1KvzLoXL/0gDWRVfR1mKNDqzoH31EdF4YRJruWCuwk87dGnZC7jOOipCgvfZ+xh oBjCfdvX8Ngk2960gIUQtrU5wEw68DktJii2dk4rh36KZh7UjftRKDqP6PndXDXMzIXQ iQPMCf9mE40bR/EnSwZkd4dcieaHHDrkSSZs87siJPXkI3ZALlOK8U6PEe05IpyPkDUq Zy6ySWJvQjR+FfvIP+Q+dN+fxFEkd3dn2NoSftkGJ2e0TErwHst7lgmlm6TgOgiZMHTo Z/N74miES+bOFow1YDrzEDLE75APNzq+KwwssMJyN4WnD4AEnCTaHAcqRpmSKH4gGSxA C00Q== X-Gm-Message-State: AFuF++k7Kx5yigamurWYo+SJJ6lH/FfgNFZ8O8A1OIY4Th9azYllZxlt UvgtdYMhrOTdjRzecdyK/wogD3y255mRfXeiTwltYOBvnLf7oO+dPu5MsoGe1Q== X-Gm-Gg: AYBFou2/QE+rCwqOdKK44UDD6GKxn60LdhUJf9L1rQrgQJMPcr8dW2ok0fJYIb0EbcA iuyE50ySaz+iL9STXJi/KPCV4skyw/sgYoszfL8/6lZkDTeGMbHcZKAlm4XEXOL7aBc+u5nNO3e HXTr6xqPvD9jgZYNqtq7TMcxX20Q4YWG/sBijrfaVvjz1YixgyHYKNpQ+iLpUYzg+QNeHsiBsrf jyyVpVKs3D71HQpA3IEq+HRkh5uwXs04SVicRfCGuGV/4BCiVr9PpaDMX/CCR0vdJ47OEIiGLic AK4AMi1WFbNXql+m5e1vjJFTgFz4RdxzGD9H8Qlu87ve4iGIZTQXLoywOTWgVayhks88pxIifKY vZ0gQSArFeOByPEkvjnnBXgJHHXu/ky2cP9fe1LekSKnXl0bivJErwouwhfwcv5jPBj4WSBJKpV qsyE+EaM7lLVu4+JuudiNzrV6klnWYZZBE2uXuX9QP8M2Ng5dLLAzXCcMLy/sSoSZmw3Z/kdDpZ JDJM+MOMCsjfExCWOxecvvbjxA= X-Received: by 2002:a17:90b:1c84:b0:39d:f247:bb2 with SMTP id 98e67ed59e1d1-39dfe128816mr3441605a91.12.1789467462648; Tue, 15 Sep 2026 03:17:42 -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 V17 09/13] vfio-user/proxy: Update tracking iothread users with holder name Date: Tue, 15 Sep 2026 18:16:51 +0800 Message-ID: <20260915101655.3216101-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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::11; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x11.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, 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: 1789467581897158500 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:00:46 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=1789467605; cv=none; d=zohomail.com; s=zohoarc; b=R0ztgcVi4Q7Wo2b34enBoT35luYm2Iezir+e86tmZmn5ZqBtm7HaziChq9qBea4jjFQcIkNT5Xl/OrYZyoZ9MpiD6MGr1+ROVRxRCx+4XPqPyd6DerhWHvOOAqBbeFHtUUZPtrYkrSVQXCRwGaMso67ScdhXHaECclL4L4iDh04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467605; 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=H2A8WLqU13d9t82o688ipLMh18YCnuWi+S3a7+/OeOfOYmILiT8/dN87RLnHrwTQwWfJj1ELX3wefkuP8NU7PIUymPvXiWN/8TUD/rYH2MbIYxEEyMVY4jF/dZpAthoeQxXoBjWOkLn5eW1UN+9QBOZU6K3ovYj0/i3V08H/RO8= 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 1789467605203363.7250528981292; Tue, 15 Sep 2026 03:20:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QEy-0003Pr-Gj; Tue, 15 Sep 2026 06:18:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6QEw-0003PG-Us for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:14 -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 1x6QEX-00039b-VC for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:14 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-398beb616f5so1186004a91.1 for ; Tue, 15 Sep 2026 03:17:47 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467466; x=1790072266; 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=sXVuJnvJg8xQBD0MstKCp2Ovqi7Vdws5oRb5qM7+poQGPlqEExuy7TdpbP58I6b1CY 4neb6VF00+Yd/IUq1qCZo1P3tFo8yke3N57mYF/TrR6qvDslnczzoPLQCJnkTjksKaOj yDRz49SEjZG14esI1DYP3yjYbyhL8zo6sN0CQOFlUhbarZxOzQcyDUcSMoPdmRcUTr/v R7itZaf2asEVMsvwdRduZ+LdK4Qs24FJAhkOlWNOqC1vkFO/QY+9w1Rs3UurcPAaAeWh bdz/8RGr20ixLwLgYDggcB9sQPcOoydWCd0zUARuUSwf3aZDN8DscdMvoSCmfiEERY6k 9ofg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467466; x=1790072266; 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=OcQQ4zjYR4enWNgLhdKGL542lwJxo9k3e0zBDs6JhRnNFq5eCsLcbGhhzqPqFnU4UY UhTuOj6c+ylW+Bii936cLX53/oTsXMETQb90WJuxVtfW5XEIwlbpyC9O2sZww9kmW7f3 7sSrMeBcYlZYFBCna7ZjVRarTgdyUqWNJbIWRph5AwMBJezJg7Ba/dcLce4nPLy72T2u mSxqskiVLzVe9DrtXzk1zc6EhidZ7rXT2ScDKaw5Z/K1jVdmaX75b0zAmq7UFMKWYVNV TVX9MiRoRBm//scnyW7xutAYkIdZuh44FMtp2YuYfCoqicV5R930FPpm+yA6nKHKnVqq NY+g== X-Gm-Message-State: AFuF++ms4tPvsyyg8e7XAXsmSOk9I8wAL7r9w5lJf9ysoqhFuXs+ewWD foo6/AR02Vuu3agIcnNZlXfhjocC/sF4+gK15C3JQSwTVURnymumURUWsP22Kg== X-Gm-Gg: AYBFou2geJkJJ/gP0jiS8PjNG12D0VTVLopdp4g/0Dd4es6q7UcHpVn6hXVO26It6aa OrzzKJb6lSjqkK81Q5o0o/QfwZQaZgdmf3m2J4w+KFr16pFycY7FppiAIcud0VnBNU89cgEjBMc zzWrV0XDuqQlzB+1SObgZcUfGiwkH5T+8/3GWne40El+6ZK8c05xRafshrYfcBdhMiKHxJHGxde MSs6+HLcylNFWYMfIDEKwM0G8Rp/lRFJLQsPyHMyWKcHfe//oq7ZJKDeeSLQMR2uLgXXdXDz9ob mSEsW02Ao02UWvcB0Uq05bDqC5y4gJz3niJNsDzYhGXN/Sw74slZ1694rjKEwcJtPV5WHKS80Jx xYM9h52cN/MbPneYQj93yqphILUvfcMqmUfJ1Q5AfViYxIGLVnEyNLw9GpqplLXIQjjcdzABS/r +2JKdNUVHmH/yD54cDm4bZFMeF64Ne3xUH6SYt+mDqJ0rjUWKoHwvKUfaK1z/zZa4s3isf8Krff VH8TawHD5QPUsX3cGtcndAG5LE= X-Received: by 2002:a17:90b:2e85:b0:39b:5622:d645 with SMTP id 98e67ed59e1d1-39dfdcf350amr3107038a91.0.1789467466406; Tue, 15 Sep 2026 03:17:46 -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 V17 10/13] xen-block: Update tracking iothread users with holder name Date: Tue, 15 Sep 2026 18:16:52 +0800 Message-ID: <20260915101655.3216101-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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: 1789467606158158500 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 Reviewed-by: Stefan Hajnoczi --- 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:00:46 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=1789467517; cv=none; d=zohomail.com; s=zohoarc; b=ej4wjT2NWHdtgXciGIJunc425Ow4q4x9QFGOjxVHmyKERAU5gFmHkYelTfTTX8ZrF/JHLV7HjxtOQWQ4Uh0s9rr4gLWdJSjN+j4M5mPqbAtIlp1iDh9YXK1b+6rfsOjuqTh6CfC6Hrl+GNMQtFppaR6kuq3euDYQL1uy+VnXKfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467517; 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=XgUai7INIGBNZdNAcVkSX1izqszRp7KvPTKZYTdxG4GAV9c9H7f9BD574BUpy/YU1jbuF3uqGoGCB56j7Z5HtFTlgaeTAmkzvJ9EhCtL+NB8L6V46SYLYdVAZp84DXmBs+SKou47yS9950DHrNoMzx4F9COwLdwMA3zTw1TGPdw= 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 178946751745345.72789994512823; Tue, 15 Sep 2026 03:18:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QF3-0003QO-BZ; Tue, 15 Sep 2026 06:18: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 1x6QF1-0003QA-Hj for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:19 -0400 Received: from mail-pj2-x11.google.com ([2607:f8b0:4864:39::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6QEb-0003Bq-SH for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:18 -0400 Received: by mail-pj2-x11.google.com with SMTP id 98e67ed59e1d1-396ccd4f99dso78473a91.2 for ; Tue, 15 Sep 2026 03:17:51 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467470; x=1790072270; 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=VRWXaJ2Jp3af4lm0bt2mB1n9CBJ4rnKS5WUlWToTQMhPRDNnFBwxvLCWp2yxFhFDEk iiJWCpe3sEJhtyBzpCjj+6vePVZfn10L15ABClplEzTpeaE1TLAdOn+grGDNfOdvKNWT r8rpVM1vXgIkbLL58bK/FxC+jTbgDfN+8nF3/gZP3dlyk+LwD/JgV+J9EILNbiaqlhcg XqF8Y/qnT2duUKvFKruPgBDqD1s2+c7zhs7MEIb4rsxPmdqC9HLuut4/dq+nh67TjF6V Qxh8XXqDEnkoDhbf8Et6VKjCdXO7zstZluqaM661IaqOiciG2+N4EYaNx+9GC1dOFmf+ P5Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467470; x=1790072270; 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=i3vPRhAoQPswoR6/Izcaik3thsd23dcO9zLTz0v/0jTE0lM4SZ3ap+RV/RXPVtXKhd y/8QVvvw6j9k3yGfLc1R2dY1X1qZK1VOlC6ZXviKD3l+E0pMuNFmRo5nm+Mii8hkD0nW GKN86RNPACB8oZ1riyaCqN3tN6JbmwyAryuRTbNOs94nx58yy1BLLhXd+iz4GO2wmm/I ZVj2p05iC5oe5gTO0cU4kPdTeiXOMwrqb84UEXFBHMjQTpV0Oo7eKPUWADJXyeHYjCSI sKH6cpuv40uhdusRvkFaZ5GyKV7YDEqG60pqOiUCCIL9ngY8QIwBclEmm9x6OSkzhlZC 0oeg== X-Gm-Message-State: AFuF++m/QgJIxiZ2s2DNatx/l+o9FHJcQPgG1mTzHRsmtOThY824PshF 6e9OcEMNeQTmvTrUIIs2Cos4jOCxp80HP80hrOdgsInrJ0Zll+fG7ZAneR4/Wg== X-Gm-Gg: AYBFou2zvwrSkbnyNJZ2hUtjsE3L9aY8CjwmbN6I9xTISeNY9e7YJgSDt7rM6IIFcRb asyRVTDD9XfkNnN226Ix1eNxCPL3KgdNYI/26ziAUeP9ImqXsSdDl2Mzls2pnqzxz+OK/kurLWN eza+H1wSJ6Fw7mDO7TGCMZhqFh9i5BAq7ESXHeSGvxydpdx7RIDcqRAoGL++Ez01G5UJJpddyP1 eVwwEqSrepqlM985KsJHhmrjbFE5TuXIEyEHG5QYFzUZF3hEGc44q9iEzDdxicFPQX+VW/jZJNr dpKG/QJhirKAI7CklonsqLdbMxgnOhZfns10aYN1XxLtZnU6lQnQeHsPyobe41uO9aEZr4hGaWr sc9IJhFHd7j8NujKLKrArSPenfKfF0lNw4TmdYh8yeod8dRmWADgBJWP9O/J/vKhOG4soA7nbhh Np91Pu8P0asunjjikIx8cFs9v3gu5DqDFytQeenf9WwK4HIPAE+fi9De3CxSpGaf35WeZfWAisX t5+LzIGrFlKYdsFLQvRZbnyNck= X-Received: by 2002:a17:90b:1d49:b0:398:deed:6e1d with SMTP id 98e67ed59e1d1-39e10ce0123mr487016a91.5.1789467470275; Tue, 15 Sep 2026 03:17: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 V17 11/13] monitor/hmp: display IOThread holders Date: Tue, 15 Sep 2026 18:16:53 +0800 Message-ID: <20260915101655.3216101-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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::11; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x11.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, 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: 1789467519560158500 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:00:46 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=1789467527; cv=none; d=zohomail.com; s=zohoarc; b=ArKYg9pFUJv8iSEqMQH0e2ganmQHuIuBQgwOTH1m0A3BfO4SfYZzC7dP+AtdmU2J6Yf3nW0Pm5mE802wGxWc200w06DWDsWqUuRm4NwF+TbOD2uIUkZT5Uhf5vjGtpT/6CDPxys0EfP9dToGBS3GDrwE4YOk0va1lL6ifgD4S3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467527; 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=RrbAuQeObwoe3B44WXO+dXDkeSkoTkk1yzxeYZ2Gj5k=; b=XdFgZinsS135nOEQj7P02LkhEdHa2x5HrrAtyk6cRqtmY5PdRlotY08wpSImXfLd37ZT/OYE/wwTFFwam2kc5ZCJA0OEsEk7RN3HJH0qN0rO4GO5XabIguOZkmSg32GNl+8p0zwctx9V1POzpZv8w2tACzkbJvW9fOsLJyofqqY= 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 1789467527419996.0906795787549; Tue, 15 Sep 2026 03:18:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QF6-0003R2-Qe; Tue, 15 Sep 2026 06:18:24 -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 1x6QF5-0003Qq-7d for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:23 -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 1x6QEd-0003Dr-Vn for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:22 -0400 Received: by mail-pz2-x10.google.com with SMTP id 41be03b00d2f7-cc4bdf8acd6so2228852a12.1 for ; Tue, 15 Sep 2026 03:17:55 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467474; x=1790072274; 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=RrbAuQeObwoe3B44WXO+dXDkeSkoTkk1yzxeYZ2Gj5k=; b=DxTrobxiXxyzvGz3E2W59sMes0SrmV7J3H1p7ABclT1QGQhVX4RPnlsgaAXN8JY/Qf 2aheK6RaD2bL9aVxfwANpN2tQAGfLoXgSmhC8cw5/Ftc0ciN1cv6oq1qUOR9cXvONHLD Hz7rrMYYoT5w6756u0chEX5MVKzOqxeabmqH4TIE89vhwMA5tv1PO3vM67PDdG/b/XDL UYrwKOpWUu4+y0Rm4SxLZYENMOyPuZMtt4Wn5+nsqCFQ0SkdHW7DvgWnRawnwySQk+XA /7Op4l+8oaHPOCxp0OOdjUK7X9eTK79hLgLg8dvMNB5M0kX2J8rrsSsgbzpohXCL8Guk 90EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467474; x=1790072274; 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=RrbAuQeObwoe3B44WXO+dXDkeSkoTkk1yzxeYZ2Gj5k=; b=V+5uhDb+Tav6qUqeFRLkb6Y4zCEzAJihryE4agZZXPf4OZWAU4lT3IGJlqPHCOO2C0 TmXfA2px7u1bIKPQRFjmC7yNJD+8gILdL4JfjwQOYBfdlhW7kfIK/ha8efr/NHco7bRr mSFW6kV4zD2637npZDlYapckppnIbEOZnE1OKxq0hSB6XnZ5mB02E3Qym81S+UjKWLdB uCYtSlb1KqTcnXFsddgejBcJ5k4Gbu03J8qbEKhVOyp3nKK0LwiJtTTTT3M7DZMm8eLm N6QdhzKCGU0OsqrDe2yovLlIQbqutWB/C9PteW4HSh6eT2iFUS8fBTyimZvihsQAwDwf SKlA== X-Gm-Message-State: AFuF++n4CIeplHQj2qM7S7CFSITCdF+i2wY+fhMu2weq475CKcFaWhWr 8jUfanzSvaoJIVSyQ99CkNSa1iJDaijOgOc7nuwSy5xxAkfFqcq+yBGohsoy2w== X-Gm-Gg: AYBFou2pdMjVNDxkWxPgxXxLOys7/Bd9eEWA+Alhu2sKPXsWQQ1pEBZNRaFB39kz2rX 0QzaDFef19hEUYB4fkfkHW7fCkVPUMfQH+Nd93vaLQdXjVY/0NEW17tZcjVnYFr5FtH8FBNuiIU Y0VZit3h+ldNRHH4B2u2MSNKJwg1tFLfA+JAkrjmlwIdMftaueL3NxLNbXbCigHsACtegOYkiJN dzfaSgsFd6Z+NprGsnuBAQpbux2wq4rokwNmOcE7WBbWKibbNuNdooX84vzGmueau6NivU2thgO k0mJNY6196fc62gD7Zu0UBmTICe3lJApMsyNp+jDjrwcAv8xgWVZcBRmz0ab2EcTklXOwAUVaWf X4nsXSXCTQNZO7apFm+18YI9cRSa2M50t3r4xoSiCOUvuVVi6dqlpmEKc4AX19mZzYTO87JjhXd iVKBvO94Ipkd2SKoMIkFfNX80JDxeRquGU07TP4O42G+xoJSMCgljrkKGXkIfJzAymiRG92y5eD 0d26CyeTGD4HFadAboIV1d9BIE= X-Received: by 2002:a17:90b:1c81:b0:39d:f66e:1720 with SMTP id 98e67ed59e1d1-39df66e17d0mr10792199a91.13.1789467474536; Tue, 15 Sep 2026 03:17:54 -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 V17 12/13] iothread: make legacy AioContext getter explicitly unsafe Date: Tue, 15 Sep 2026 18:16:54 +0800 Message-ID: <20260915101655.3216101-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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: 1789467529689158501 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 Reviewed-by: Markus Armbruster --- 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 5a4291a2f0..28460afb3f 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:00:46 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=1789467558; cv=none; d=zohomail.com; s=zohoarc; b=CoP8ofO2V6blUxG3V7EAdbLbVFjlClx+HC2Uj3nYJ36yIx0474K552gatxwEWME4SQ+WtYAC3amMtJUPf5rmmAedjRKVxlJg+ajcJ2IgqO9ZOWAK3xakVkIYvYqPMeXnhmnjEWBBSWOcCAv9HJZzhEaWN+7Pzmbrbg/9JirWafA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789467558; 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=mjtpDU120J7utvnEK+70JJat4q5LovyVH9QekOY6ecYnrsz5qKy8Ahe15viYkdaPSctvO7a5CCghdQGL+s32+45Q/lPQ2ySxWWOZ9tnGn5uV9T+Z8KBwRzhbOBlgAZmg4BavEtP5hmIBCXfrItC0Jasm58LrEIO9c5qVougpZzI= 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 1789467558796920.0369454538286; Tue, 15 Sep 2026 03:19:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6QFL-0003gw-U1; Tue, 15 Sep 2026 06:18:40 -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 1x6QFD-0003Rs-LE for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:31 -0400 Received: from mail-pj2-x11.google.com ([2607:f8b0:4864:39::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6QEj-0003F0-Mr for qemu-devel@nongnu.org; Tue, 15 Sep 2026 06:18:30 -0400 Received: by mail-pj2-x11.google.com with SMTP id 98e67ed59e1d1-396ccafb752so3048099a91.0 for ; Tue, 15 Sep 2026 03:17:59 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39dfdacba6bsm4416868a91.14.2026.09.15.03.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 03:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789467478; x=1790072278; 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=NWqbNFG/yGHyeDpHYwaUOvo8FvYQUgKKKdwA3x7dTg81RKRLyo1mp2pkWRZ9zhPg1v QwbMhldYX0Cf5rJ6kaoDb8fEWc/Y9medETuNTzb4Z7FHJ5tsbSJ1Za1p2wFyrtUK/+UA 79wii02dtiyq/mfRbeKFCRz6it3O55ZdqYm7ve1TfNo0ieDtFwxJNjy7V0gYb0sC1R5e Fwr8xak848Hk2yjthWrbqn3IXZdH7M/iSnM1RRvAAXTpqxlS1UBjeglIRr6mKco6qde3 1JiipyJQ6RCaV2r6XOfQAih95h0LJl/21YZKvnezbH0ZeEudUTq6VTb29116CPTSzTNe zEug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789467478; x=1790072278; 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=rgaKdwRSTHwOpENPZwbLgho4ak9gsVQVEjM3HnL6Va3wQgLDLBfF8GRiNesMJlQDBj XCzmqSS7cBXr0sCV8zRWrm9Q39ljeRLpEj8VmwTkXKjE2IudhwM7Rpfu43B3dyHZUjTf Ym/oc1lHrpO6v7b7xYqFgJV2MMzGo7Msfw7nWZXz7uCOycyEbx0TNUTGYDs9X+T+oEjy 3dXOjaD7t/NOWLLSSSucjytx9QQP39qeB2mTaPQTNZsS9OTbw2Tl3q0HhIHhEIeSgk7H PNMA85FiPNA0ZAupKclWeCzlTZokICeKjdFQ0amUGvioYsAQcXIupcCIMs5wTLOR2vgw x2Tg== X-Gm-Message-State: AFuF++lTEr+/4pcL5DWUpR0eN3Zt8DYxvDR6Y1bDtasHifuWKjv3q0hJ Rq1DDgolWmMXvyxZ0cID4kv480GQEoMgXYkXpqwcCokSWRP3XIfO7FSsdQ+KLy5Y4rQ= X-Gm-Gg: AYBFou0qxU47XitS3AySUq9aAbcjiVCFmcCE+mwueDvbykJ9AoZqilw1p0MeGOCRweM cY72g6CPF0W7tH4GLZ+fI1L4YdQYBzvpoSTxDwDz8nwIeccwCGtjoHlc8DE2OFbOqjrir4s3UUI xyPQL1TzNHj+qliYN4fMSwp2fcnwlAqI0LP3PQe0reUf3t7f7XuurUWgJLssP+XWbZn0yHC3AeS cBCbjqjFA5tf6V9BIXTGylfNDpauvuWX4LMvVqbBp+CJPu1jl/jInS16qYn6pPDjXisiKnerohF Sy6lpksPHfoOxZ3Ifd4Tc2SEoS1ZCMlyzfqX6bQf6YYw3AaMnHQ3LrcPmxTWx0rViRJMNmFNCuS fYcWdOEiI2P8SWtsbdTOUGGAZwCvFuBeFjRiQY0WUFPt1Kx8trcx7TA/5VMxB0CoXDBtFWAraTT vYGihMTj+wt7lEiTC1cTMbS4/m8WoE4nihv6dDcyATfwzFdQtuoWcTT2VyclY6/DqSc8t43LSIO 5gL5Mf1ghJ9xkGXXpSiVUfWrdM= X-Received: by 2002:a17:90b:1c83:b0:39e:27e:21b3 with SMTP id 98e67ed59e1d1-39e027e229fmr5045563a91.9.1789467478557; Tue, 15 Sep 2026 03:17: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 V17 13/13] tests/unit/iothread: update AioContext ref/put helpers Date: Tue, 15 Sep 2026 18:16:55 +0800 Message-ID: <20260915101655.3216101-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915101655.3216101-1-zhangckid@gmail.com> References: <20260915101655.3216101-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::11; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x11.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, 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: 1789467559932158500 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