From nobody Sat May 30 17:44:10 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=1778508544; cv=none; d=zohomail.com; s=zohoarc; b=PlyaULBjOnBWUqpXhMg/zb68c+gDwljYQhdN6Lc3RKQyJgTmYM9pCqMHRq89yLKHGWNTVtUKSna09x8XW8hLQyNIjMtvbYhhE3mBdMKmOPJKLhKPqwwRdU058W+0RKYbicReprk6XGf7iMP6JvLZtF8uCeYAmDK0vJnP6sk7E9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508544; 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=iQp4e741RWeqANR+AnBnweSrNx7Xk2H8EAfqd4DwHpY=; b=kngUyrrTpEdcKgxsY7oWrfHupL0f/2jbQnPXocD6KJSaw0pTkWw6CxhF5udYw7OsgrR1oBmq1kf8VHNUXvZGbRjuWr88DFGUVosUPhjd0pjA1DYyBP1OxgtYMODYuV7kBSlt+xLijY19ZRqa/CIOX6TTCwxfTGfJzF4hJqPeTRI= 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 1778508544718232.25804560610572; Mon, 11 May 2026 07:09:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRFd-00087l-98; Mon, 11 May 2026 10:04:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wMRFZ-0007lE-K5 for qemu-devel@nongnu.org; Mon, 11 May 2026 10:04:49 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRFY-0006zV-1D for qemu-devel@nongnu.org; Mon, 11 May 2026 10:04:49 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-c70ea5e9e9dso1770677a12.1 for ; Mon, 11 May 2026 07:04:47 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.04.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508286; x=1779113086; 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; bh=iQp4e741RWeqANR+AnBnweSrNx7Xk2H8EAfqd4DwHpY=; b=lnFtAMeOgDTH+s6TX1fs8wZfB8Vml9lbnQEPPOJuhiRwMou9+Scu1bVPcJZEQLjCx0 VL0AcgTqpOjXIafX1cSd4s/+F/DwU3/FX1B/hK5iOVhCuCJbsWVFuDreeWPHVR1imqTz 02ZLNb9nxfyH6CTIx6spe+R9mIizdaBtwvaLYOWLpUocnxEidAakhl8Pa6htm1zmDOLi WBZxDqVW3N14rebFNHHr4qR5fb/BSoYZ+IJG1EV3rUj3sLoreDxkB/2uN9jNp1NfZvt0 CjxPcHSARdor8ZbGlQTAenqDt4gmyYmGDjg81s3Sb66Q4TgipTg1hyrxVkg7+j4CfEoc TViQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508286; x=1779113086; 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; bh=iQp4e741RWeqANR+AnBnweSrNx7Xk2H8EAfqd4DwHpY=; b=iPiUG+tyTVhNv9OTbwcYiTPeAuAb14n3NDS/8VV3OuuGkVxaDyN9zVQMtUgBCuaJFE mSRBntCq1tjM5iW3G2VkIb4OIJCalEq7w5Ch52QrYedh7An3oSSxEMS4xiWYcddFFTlQ ZKoV0+eKqB0UWYEWg/5LHYqQqvAt2I/3ys5aKG7WNXsFq96P3sAa0mHzPqG8L1CtA0yj nej6Ntl/7mDbCKn1AriU9TFzTB0gI9C5/EYXgINd52DSBPLjHrsHm4gATxsySEBeTa0C 2uCS28mt1W/CUNZOwLxbEcR1DcBihgbL1lYnAWeXdb/hfhdahFKz+W3edE58FnQqJ6JX aKnQ== X-Gm-Message-State: AOJu0YwDTTAQCZVYdqRaaYOXQujdIkd4Id45R8XefvgVwtl6WkxidwKO YZtxKVuMMcowA1H9I/weJP8KyBJOUogq8PFBm1Ne42tSnkiedYFemq1irJBIcW4e3qU= X-Gm-Gg: Acq92OH05UOOhEHn5SAHx50MVtWxxxU4eKHzZyOKAZnORD3gBdRR2RE8UGBxoUlfCHS yGROXvGq5x0YTemEs+7lTwj6H0Pel8cnYZcpMbgtnRfT1cYa4pSKZUrtFnD8D1MyncXJ87GCc2+ hxReVu/ztCs0gfcjg8jDHd4SJWsyEKsTbPNCzkxa9l9SsxzY/fs1a4coJIDeoJBdeNFi64e61as Kqm38hBecbelYg6ZscBtY40zYBiN4M4f2QJZlrYXKrm8NdSQoC44qjB7CcynjkQQ2uxSUz4dc14 +YInXN9jm9dxugcdbfvjVpRM/8D0ksjdn5oOirPZ/Tg7soOupk63guL9i1Euwad5umQ+TFOl/C2 2spr8Mvn0VW28RLPT1e/uleljy9qizkJeSJ15Ybc0A6V3HR960z1yy85rKv5pd6ZtYP0Eibzuaz qdMbxiBQfqRowgL98UFW/59DxYbVQujhxiSQfRmDh5i7x8uJNbxF35u1N1 X-Received: by 2002:a17:90b:2750:b0:364:a173:2d61 with SMTP id 98e67ed59e1d1-365abcf240fmr23421312a91.11.1778508285804; Mon, 11 May 2026 07:04:45 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen , qemu-stable@nongnu.org Subject: [PATCH V7 01/14] qapi/misc: Fix missed query-iothreads items Date: Mon, 11 May 2026 22:04:03 +0800 Message-ID: <20260511140416.28271-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52a.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=unavailable 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: 1778508546992154101 Content-Type: text/plain; charset="utf-8" The example is incomplete: it misses members @poll-max-ns, @poll-grow, @poll-shrink, @aio-max-batch. Messed up in commit 5fc00480ab1 (monitor: add poll-* properties into query-iothreads result) and commit 1793ad0247c (iothread: add aio-max-batch parameter). cc: qemu-stable@nongnu.org Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- qapi/misc.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index 22b7afed9f..c71a5fe657 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -123,11 +123,19 @@ # <- { "return": [ # { # "id":"iothread0", -# "thread-id":3134 +# "thread-id":3134, +# "poll-max-ns":32768, +# "poll-grow":0, +# "poll-shrink":0, +# "aio-max-batch":0 # }, # { # "id":"iothread1", -# "thread-id":3135 +# "thread-id":3135, +# "poll-max-ns":32768, +# "poll-grow":0, +# "poll-shrink":0, +# "aio-max-batch":0 # } # ] # } --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508426; cv=none; d=zohomail.com; s=zohoarc; b=OUGzbQ6fOYL3uaX5ZtzaBauXxjPld6KuDtTD6rwOa+6el2EJysuK83X/ytuLySk2Pz23a/aJrjhJpFD7zaQtQGbhwxaoqMwc+T5kzhLRzvu5pKvFFf7Mr3JwwGVYKcCoekogXqk+6BmXXmUXAvwVkKS+0abGXRNHBjaPq0siTqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508426; 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=nBCjD83HlngVBkTZV44gg9NW8YEfb7AZIJBhF0teGz8=; b=Gu3XelM0LWZV6ihZCyL3mbkox3jtcC7S38ObIxReya55l3lfGTeFa6EFskULmdH8bTDQKSActWoB5k5yvKHllnRzIh2EjPEYW8R8d/2IvUPIKNXsVY/4ljvHcz7CBqhhK5Fbjqh6utnW8bbn9gX0NMDNToRTea6uvJByaVmLhfU= 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 177850842661442.6374299572617; Mon, 11 May 2026 07:07:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRG8-0000Wo-1n; Mon, 11 May 2026 10:05: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 1wMRFs-0000Am-Ie for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:14 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRFd-000708-8W for qemu-devel@nongnu.org; Mon, 11 May 2026 10:04:54 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2bcd730e090so5699495ad.2 for ; Mon, 11 May 2026 07:04:52 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.04.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508291; x=1779113091; 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; bh=nBCjD83HlngVBkTZV44gg9NW8YEfb7AZIJBhF0teGz8=; b=JB6ptxV7UFcw/hvtlK8gUAYGvGLmY9wFbrA4d0lNasH0HkzoOUF4tXA/ZqKv0+E9Ra HkaHYtjLpZs2IxaMINJd/DQPgGzPK7k72KosysaVfdUCFmsbv43Ls3EjhQrXdIqQ0h7V ReY9WE5R7wq5Kc/GhOWKWuLcV+w87BF0GqIMVtkITozC7Xt8Kze4UO3GUtDsXfAmqTRO 2vGyEb9gPbl4eB0WrihVCaXOFap4F3j9+E+KVMkQT7xkwLU5RTMdIjRneNmjqzQUDPR3 Irx5mySf9ZsBdHMsB6/YHsGazsjvuPNeUXsyPD6zs6AkG6Z5F0MqgDzBsweQXsLV8kUO ++LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508291; x=1779113091; 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; bh=nBCjD83HlngVBkTZV44gg9NW8YEfb7AZIJBhF0teGz8=; b=HmO8fdPCvXxHcv06QEv+pzI9X06XzbrmIlGIbw/wwevfvjNMntRvzxiAuPtLLI1obQ T8AecNihIEMZgfVPnq4iq6zm1qwweH3VTUJxuRCKFivNCJ2pwApbKKGu/nPbS5a2OOSb b+TOWRHMuXplH1kzwQmxUiEK2V9J1nuyeTr/Op1mT0UMTUnnU5kIeR9UKHAOacC1+U3u wngOmYP/BfGqrFIBX6bw5jmCo7dDaf5NV/cySG2nwKo6aqTGAOiPa0afasoUdfT4TD4r dgCCH2h0iwsPrGdRVXVk356mupW67XxXt95l5FhgNaYTlWpgoVX/sGS39EZ0M0Znj581 8Hdg== X-Gm-Message-State: AOJu0YyTCszyUxVZlpQY9leHJbZikO4kbWSHb/Fy3RJ06xXFr1ito1cY Blmu7oDokbDI1cL8ARqqKyjWQg433oL40qhKktGSsfS3YVVHAtmaShIm9Srjl0vdQZ4= X-Gm-Gg: Acq92OFCamTZRhsxvY+TxDaNF5kHqwEaX+QLnxAg/zBjjbWUTwk/JH9S4Ace3jxwnGH vu6M4yohclLoK6D8eQ/qeJeRPf9bhVaZZ3btX15qkOQpbAemwmvrLfqGbdnFJkGEoivuDAQxSbO Mog4TXoHGKGXvWP2zTK8AN293s11ivYsD57dHymGgqYsM7yTuLnK5/14diib2RUKifI5cxhPQxC 8bp6iLu//NVc3Vk0i0Jn5aVBWywdV7MhtUNnoW598ZN/ukhJnQs3f3Y44hTr/R1kpmPf6MrELuV yYZKhc124qV/CBMg0BBWGGSymwIkzydDJLzhHDz9pOpxxrc0Imk0a44ZYJVED9ojN+wM55alKmI 21JT+sOt+VQJRaRTZEIybeU/sgQ/inPJKD2YI2hSzNgFKUAiG4BqZuiE1lzzYKO/fQNTRjyWvNQ CchdDZ/Tixc70ibPfFiAV7dZlF4aYzAs3L0jukC33cb4btT8gKNlG4eUb9 X-Received: by 2002:a17:903:b0d:b0:2b4:5ddf:24f with SMTP id d9443c01a7336-2ba793bf9fbmr275134495ad.10.1778508289716; Mon, 11 May 2026 07:04:49 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 02/14] iothread: introduce iothread_ref/unref to track attached devices Date: Mon, 11 May 2026 22:04:04 +0800 Message-ID: <20260511140416.28271-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1778508428246154100 Content-Type: text/plain; charset="utf-8" Currently, IOThreads do not maintain a record of which devices are associated with them. This makes it difficult to monitor the workload distribution of IOThreads, especially in complex hotplug scenarios involving multiple virtio-blk or virtio-scsi devices. This patch introduces a reference counting and tracking mechanism within the IOThread object: - iothread_ref(): Prepends the device's QOM path to a list. - iothread_unref(): Searches for the device path using a custom string comparison (g_strcmp0), releases the associated memory upon a successful match. - holders: A GList storing the QOM paths of attached devices for runtime introspection. A later commit will add QMP commands to let management applications query the attachment status of IOThreads. Signed-off-by: Zhang Chen --- include/system/iothread.h | 5 +++ iothread.c | 67 +++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 48 ++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) diff --git a/include/system/iothread.h b/include/system/iothread.h index a1ef7696cb..2871b06edc 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -50,6 +50,11 @@ struct IOThread { bool stopping; /* has iothread_stop() been called? */ bool running; /* should iothread_run() continue? */ int thread_id; + /* + * The list elements are of type IoThreadHolder, which can + * represent either a QOM path or a block node name. + */ + GList *holders; =20 /* AioContext poll parameters */ int64_t poll_max_ns; diff --git a/iothread.c b/iothread.c index 3558535b40..b805e4f97d 100644 --- a/iothread.c +++ b/iothread.c @@ -25,6 +25,66 @@ #include "qemu/rcu.h" #include "qemu/main-loop.h" =20 +/* + * Add the @holder path to the iothread's tracking list. + * The @holder is a QOM path if it starts with '/', else a block node name. + */ +static void iothread_ref(IOThread *iothread, const char *holder) +{ + IoThreadHolder *h =3D g_new0(IoThreadHolder, 1); + + assert(holder); + + if (holder[0] =3D=3D '/') { + h->type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT; + h->u.qom_object.data =3D g_strdup(holder); + } else { + h->type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE; + h->u.block_node.data =3D g_strdup(holder); + } + + iothread->holders =3D g_list_prepend(iothread->holders, h); +} + +static int iothread_holder_compare(gconstpointer a, gconstpointer b) +{ + const IoThreadHolder *holder_node =3D a; + const char *target_name =3D b; + const char *current_name; + + if (holder_node->type =3D=3D IO_THREAD_HOLDER_KIND_QOM_OBJECT) { + current_name =3D holder_node->u.qom_object.data; + } else if (holder_node->type =3D=3D IO_THREAD_HOLDER_KIND_BLOCK_NODE) { + current_name =3D holder_node->u.block_node.data; + } else { + /* + * This should not happen. If it does, current_name remains + * NULL and g_strcmp0 will handle it safely. + */ + current_name =3D NULL; + } + + return g_strcmp0(current_name, target_name); +} + +/* + * This function removes the @holder from the @iothread's tracking list. + * The @holder string must match the one used previously in iothread_ref(). + * It is a programming error to call this with a @holder that is not + * currently associated with the @iothread. + */ +static void iothread_unref(IOThread *iothread, const char *holder) +{ + GList *link =3D g_list_find_custom(iothread->holders, holder, + (GCompareFunc)iothread_holder_compare= ); + + assert(link); + + IoThreadHolder *h =3D (IoThreadHolder *)link->data; + qapi_free_IoThreadHolder(h); + iothread->holders =3D g_list_delete_link(iothread->holders, link); +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -108,6 +168,9 @@ static void iothread_instance_finalize(Object *obj) =20 iothread_stop(iothread); =20 + /* We don't support finalize without holders */ + assert(iothread->holders =3D=3D NULL); + /* * Before glib2 2.33.10, there is a glib2 bug that GSource context * pointer may not be cleared even if the context has already been @@ -356,6 +419,10 @@ char *iothread_get_id(IOThread *iothread) =20 AioContext *iothread_get_aio_context(IOThread *iothread) { + /* Remove in next patch for build */ + iothread_ref(iothread, "tmp"); + iothread_unref(iothread, "tmp"); + return iothread->ctx; } =20 diff --git a/qapi/misc.json b/qapi/misc.json index c71a5fe657..5fb7dcfcad 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -67,6 +67,54 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 + +## +# @IoThreadHolderBlockNode: +# +# @data: Block node name. +# +# Since: 11.1 +# +## +{ 'struct': 'IoThreadHolderBlockNode', + 'data': { 'data': 'str' } } + +## +# @IoThreadHolderQomObject: +# +# @data: Absolute @qom-path. +# +# Since: 11.1 +# +## +{ 'struct': 'IoThreadHolderQomObject', + 'data': { 'data': 'str' } } + +## +# @IoThreadHolderKind: +# +# @block-node: Block node name. +# @qom-object: Absolute @qom-path. +# +# Since: 11.1 +## +{ 'enum': 'IoThreadHolderKind', + 'data': [ 'block-node', 'qom-object' ] } + +## +# @IoThreadHolder: +# +# @type: the kind of I/O thread holder. +# +# Since: 11.1 +## +{ 'union': 'IoThreadHolder', + 'base': { 'type': 'IoThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-node': 'IoThreadHolderBlockNode', + 'qom-object': 'IoThreadHolderQomObject' } } + ## # @IOThreadInfo: # --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508413; cv=none; d=zohomail.com; s=zohoarc; b=FFDnr0A4ZW8g0gto7lDGp0RXq22AStgBIeoQvGisrmWb/fy8DC/jN8JouPnIYKGdcr4is2B3/HDSRpVSGyFwghic0pGKcM/yBudMHDhBH0AO2YUmasJwzauD7D2N4V00dftQGoqtiLpXh0FjzalFx3WAyPpHY7EKOn7Tgd1PjRU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508413; 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=w8HwQtZrBNwiBM3qiCF4oN8OZWtNeAVstfBNuSX9Enc=; b=Mq+sEH9UMuG2lilmgFENzYg3QEQ6KDu0zAoTu5D/Cr/e+jHVOxtPMftgr1bs0qFH/lLXl4xiqD/rS3ZmOiMVbg3QuoOAARst417arxjzB3Q8CInHgxW+Q1e/wx24Dv1KaxFYc9sYdlw805mbN+74vGKaC5FrwQmeXlKeZgVjA6I= 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 1778508413172958.0808306260433; Mon, 11 May 2026 07:06:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRG8-0000a5-Db; Mon, 11 May 2026 10:05:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wMRFz-0000Hp-Dt for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:17 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRFo-00070T-0Q for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:11 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-c80291e6237so2956529a12.0 for ; Mon, 11 May 2026 07:04:55 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.04.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508294; x=1779113094; 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; bh=w8HwQtZrBNwiBM3qiCF4oN8OZWtNeAVstfBNuSX9Enc=; b=rW81ejYVRyIM9BbqtA+eHTlxmNNQD7WKN66qg2KXNh0A3OyvX+/rYY+A3qkagySvQt eYQbCIUdFAuH57HQWu+2Z6oTcjqUDtcc9Senxl2LY3AMQkoMZQJaLOmQ51vbvUgRU+tG yxFBPvE94imwcor91vujiiTkqK58VMCncG2B5MXuBVZuPZIWla4zYIdUN05PDura8ymp V2uUHvZejjtJx5PkCRAX2Aa4JJ0LcMEuaSowDvRZV3pl1CTmHKkWpOf8OCt+jCGIlZx/ riy0rABAZtXC4FN7YauNq54Aoqb9oPoOG7X82m8ro7tA0uoCWUCKg/11h2QQ6F/DmcyN uN7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508294; x=1779113094; 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; bh=w8HwQtZrBNwiBM3qiCF4oN8OZWtNeAVstfBNuSX9Enc=; b=YRr8Df4Nnw1KlLX3Wnbn9q8c5BWy36nq8SKlTy5trY6k1M8zaN7/jiRMI3DqsprMc9 4Qo2pmM9pNMTNnyjty71c30txqbQwMQG0gFjdoLghOSkpqUIS7e1ffvlHrzs88iiUoWA Uk5Sjs8cLSfghyJWNNcSWqcyh9LOgVJkyOn3OoMDwgIQua3zoY9XjrxfN0MzsYzvzcWS 4DpxttIFJvceEMxmgx1PFZawyfC9iQ5qborhx7jE/rh/TpGcwJX48J9ZzZjO89JOF/5+ IQicyOeohMhfKDKbEa1Uq6edvMQvLRtBMUV1LuE2YXP7TUKJ5cW8vqSlOm1JI3qzuRUI LvoQ== X-Gm-Message-State: AOJu0YzjY8xGmbHjQsq3LTtw8opDwP9dk8Xs1XJqlAQyPd8aSjUmrGlT iVOUQ9RCAJWUhxLpsmtUvL2whZmXImRll3XA3gD8xdANACH3zZ8r2zgL0DgybLSg9D8= X-Gm-Gg: Acq92OFimxlWRGRwoZyewuCRLAtP2inNUAdaDmfostQY4DmeqlwPjiMMsDLUd2QoSAo cd0ExKGYZTry9Mr15aMnuA+V0l3sObtiy8O/MWTnNyQ2y6PXOB3yNbzWiWN/Sb1tK56xGpqZW9w P02jQ8ZzBR1RWNeU6Vrux97v40vlP8pwQp9EkuYbzhFcfdlvTBkZbW3QNB2RuUUChntsScPZqBH 8nBv80NkhL1CjFWjEuefTqR/4ea05nDCbTasKhPp/U4AtL2RLChJ54xODvhLHSqvBXEIUiecivD Ze/BB+ojGdmKokbsoCpF0t4thK5oGYZkPyKnfTQr4RxEhGBrjz0gtrvkoXpadu4NnOS5dYZCI98 2oca8VZZDm+ujJBDEnYcV3PYFfbwN8HMYdKz/y7XYZlewOl5n2L9yOyHntKBo/pmW+VWe8oiLHo i44T0hPqvqzxEuJyGAmFc6HHRwhNZMArk2iVMIeAzzYaVqIQ== X-Received: by 2002:a17:902:e74b:b0:2ba:5f24:caf8 with SMTP id d9443c01a7336-2ba7908c80cmr245771615ad.12.1778508293800; Mon, 11 May 2026 07:04:53 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 03/14] iothread: tracking iothread users with holder name Date: Mon, 11 May 2026 22:04:05 +0800 Message-ID: <20260511140416.28271-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1778508413555158500 Content-Type: text/plain; charset="utf-8" Introduce iothread_get_aio_context() with a 'holder' argument and its counterpart iothread_put_aio_context(). Previously, users of an IOThread's AioContext did not explicitly record their identity, making it difficult to debug which devices or subsystems were pinning an IOThread. This patch enhances the reference counting mechanism by: 1. Automatically incrementing the object reference count when a context is retrieved. 2. Tracking holders by name using iothread_ref() and iothread_unref(). In iothread_instance_finalize(), we now retrieve the source name from the GMainContext to correctly unref the initial internal holder. Signed-off-by: Zhang Chen --- include/system/iothread.h | 3 +++ iothread.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index 2871b06edc..313ef61124 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -70,6 +70,9 @@ 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); +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const char *holder); +void iothread_put_aio_context(IOThread *iothread, const char *holder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 /* diff --git a/iothread.c b/iothread.c index b805e4f97d..5d6f46d286 100644 --- a/iothread.c +++ b/iothread.c @@ -44,6 +44,12 @@ static void iothread_ref(IOThread *iothread, const char = *holder) } =20 iothread->holders =3D g_list_prepend(iothread->holders, h); + + /* + * 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(gconstpointer a, gconstpointer b) @@ -83,6 +89,8 @@ static void iothread_unref(IOThread *iothread, const char= *holder) IoThreadHolder *h =3D (IoThreadHolder *)link->data; qapi_free_IoThreadHolder(h); iothread->holders =3D g_list_delete_link(iothread->holders, link); + + object_unref(OBJECT(iothread)); } =20 static void *iothread_run(void *opaque) @@ -200,7 +208,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); @@ -419,13 +427,30 @@ char *iothread_get_id(IOThread *iothread) =20 AioContext *iothread_get_aio_context(IOThread *iothread) { - /* Remove in next patch for build */ - iothread_ref(iothread, "tmp"); - iothread_unref(iothread, "tmp"); + return iothread->ctx; +} + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const char *holder) +{ + /* + * In some cases, iothread user need the ctx to clearup other resource. + * When holder is empty, back to the legacy way. + */ + if (holder) { + /* Add holder device path to the list */ + iothread_ref(iothread, holder); + } =20 return iothread->ctx; } =20 +void iothread_put_aio_context(IOThread *iothread, const char *holder) +{ + /* Delete holder device path from the list */ + iothread_unref(iothread, holder); +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508423; cv=none; d=zohomail.com; s=zohoarc; b=SG44/QS2QNEw5MLxnnuO1JBFIQrqslMPBbIQjLUpF8uC7XkyhHIkILStCYCgKu/Cqe9fLRgFC9Mtj9pwsLYUnd7lNgUUg5rW7NPklROqWIJPmAOGjDtp2S6rvPe8/QAnK1wX+m9JqiCRDugJ3VcWq2dRFdXot2RACukwJ7VedfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508423; 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=4l9Xr1hbjH1tyACtoEoX12/kjkgfEPIxAbMNxctooNw=; b=MVMH1o13JcmYLg2wvVNnnPAswbG/dzuVFwmX7NNTm/wU58Bhnv//dnAkrpd5Tyo3vN8ZXLomvjXvO3Fyjz23SA2LlokVaWckXClcoXc4E/YNw68upTtcRQq2t1UR73PKPCGJR3W2LVgQnEJYTw7PeYKmmqG4icjnXbFgeNcpWrk= 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 1778508423037692.2766516182035; Mon, 11 May 2026 07:07:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHN-0002B4-5H; Mon, 11 May 2026 10:06:41 -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 1wMRG6-0000VS-7N for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:22 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRG2-00070v-3f for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:21 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-c80203b9d7bso1692776a12.0 for ; Mon, 11 May 2026 07:04:59 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.04.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508298; x=1779113098; 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; bh=4l9Xr1hbjH1tyACtoEoX12/kjkgfEPIxAbMNxctooNw=; b=nkjlZpmt9b6HKzhBTsnbCt0mEHsG8zoAOe+l55ou1etqqfGA3SnELxizO1IKa+Th8I T0gP4vyx+qUeiw89R6iC0AgsQCDAhRGxLDupNK6pBn524GpIw5BSttvcf+via1AAJTFz 1VnzngiYklMiVfB7AYxmvGzbsUTayGo/Un6adq40NWeIQM1Pubyauja8E32vb8M9gH4I 4P8JHpNpSUhPibSTptcGCYLkWt+rPpOQP9rPxQohjLePTM20N5nTJHZENYRgN5i06Gbg ZCq2BZQROcHf3a53S7nLAjftzXvu5Z+vWeKFdq3MksN8U3cMad8PO58IV026mfwnJ4aB Pdmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508298; x=1779113098; 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; bh=4l9Xr1hbjH1tyACtoEoX12/kjkgfEPIxAbMNxctooNw=; b=alP4KgWDQcyqpDGj1FRYU7RDUcjACLcV8DVqtCRhKHPC/qdancZtn0IuHlDJoRCFJz mHje0ClUestG9cADvA7zfXIrvpznb6nWWBoAJ1oh/SJStPW7DBf+WqkviESOzrfdBLG6 ZxuNuF1rTMujSVQTzZDgIIQZDEunnB+Iqxz1WT12ASOrOMrN8OIU0BrPrsnTbHmg/Uss q3vKWJp4Pkn+1i0a7X0GtuVDNMWdeIgRyjzMRtgnwBc4lN1KrCxXK8c8anBTt6+dZLq9 3IoIfJX96wiM731INU4+J0qXRr3EV2We6miV3s75Z9X6RDUlBK1FpSA86KAFQhS4wuB5 1gUg== X-Gm-Message-State: AOJu0YwRlAOqJRMGvL/IdCG5W3wtxGt/PbwuXfqJWhZgHKDibC8ZlWBI Voq4hIgBe95wjLOnpXGii8GJXEM6nwVfg11jY2ALCEytXyejrhHb67nhDW5EigWDJzc= X-Gm-Gg: Acq92OHTkseABjqhfZjE66X0XqfdRAoBXLYTGjHU/2FB+L1gdyoUb7ESGtP6ZLRizQz +R3zawbJ1aBjNV3Zdhevw2Z1XIBjJiyTZsuY9JAdjGIImW0vpSri3qFihJyMK81akFHKLIjrdYT 9UM0/wwePKtey0Ra69nGW4ma0Pp1g9dyxz9E/c13KpAuC6YXW4O3CPc12owC3aIeFR8JbeP5Qzi 8qZ5bBJ3HzkeWq/qQreQSrvtP4+7+uWsJEPCY4DZk8mk3H8VfqwUY70zU6/HwtETBX6mj6CFZ6J zlKMSyuBGQLzoyrE3sRMBZJXGIqYKJjsir+S5f4CwjOL6qqqPBTBV+XHkw23T2TI4wPBwa89iF7 deL8ddX5tDIVQvWLs/SAC845OAKnzopERoiXYfPnNI8BPq/quyS1nWqMdLjD/IRF++N0dUaCpJt lnxKfipi28FBBayLRTpL4nu/LMBLPtgQyGiyMKD72MB4S3wg== X-Received: by 2002:a17:903:3c45:b0:2bc:7eff:2d08 with SMTP id d9443c01a7336-2bc7eff2ec0mr101248835ad.41.1778508297875; Mon, 11 May 2026 07:04:57 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 04/14] blockdev: Update tracking iothread users with holder name Date: Mon, 11 May 2026 22:04:06 +0800 Message-ID: <20260511140416.28271-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x536.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: 1778508423677158500 Content-Type: text/plain; charset="utf-8" Currently, x-blockdev-set-iothread changes the AioContext but does not track the IOThread object itself within the block layer. This makes it difficult to manage IOThread reference counting (put/get) during dynamic context switching. Introduce an 'iothread' field to BlockDriverState to store the current assigned IOThread. Update qmp_x_blockdev_set_iothread to perform proper reference counting using iothread_ref/put when moving nodes between an IOThread and the main loop. This ensures 'info iothreads' (holders) accurately reflects the block device attachment state after dynamic migrations. Signed-off-by: Zhang Chen --- blockdev.c | 6 +++++- include/block/block_int-common.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 6e86c6262f..6e20579187 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,8 +3683,12 @@ void qmp_x_blockdev_set_iothread(const char *node_na= me, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_get_aio_context(obj); + new_context =3D iothread_ref_and_get_aio_context(obj, node_name); + bs->iothread =3D obj; } else { + if (bs->iothread) { + iothread_put_aio_context(bs->iothread, node_name); + } new_context =3D qemu_get_aio_context(); } =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 147c08155f..6edaf53377 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -1101,6 +1101,8 @@ typedef struct BdrvBlockStatusCache { int64_t data_end; } BdrvBlockStatusCache; =20 +typedef struct IOThread IOThread; + struct BlockDriverState { /* * Protected by big QEMU lock or read-only after opening. No special @@ -1289,6 +1291,9 @@ struct BlockDriverState { =20 /* array of write pointers' location of each zone in the zoned device.= */ BlockZoneWps *wps; + + /* Track the iothread for detach aio context*/ + IOThread *iothread; }; =20 struct BlockBackendRootState { --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508382; cv=none; d=zohomail.com; s=zohoarc; b=R49QBck7ONwdGpQWWfrbbOhkWPYtsVSvTu9gHoIXkno9wuXs0lLK0+AIK2+kiF9xzytkU+4o/BDUfOFBuOAHco1VpxSYIxO+IV0eDYPiBtjuj9Lgn4f/c/t5SIhQ3eEOWjyA0xDd1sC8uoi9RgbzfR93nZXhWBJbpmQNqTOcW5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508382; 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=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=V8JurXA2xLcZ5SRhuD9qIw5LG7ADIOZNQxbnXANYlo2u5b36UzQQ8Be3W4oka5nJNY3ZB91g0yoVus2puwxCGQULoOFBX8LcOLFpr1BP6JM8floZd+z1QVMu8bxKj9KlEWMIMYUt8K17Zkgh3CcoVv+B1y1JPgTm/L4Nzd4tk5I= 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 1778508382285426.85438832173975; Mon, 11 May 2026 07:06:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRGb-0000ve-Sn; Mon, 11 May 2026 10:05:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wMRG0-0000Ir-BB for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:18 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRFt-00075N-1S for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:14 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-c80167f56cdso1661887a12.3 for ; Mon, 11 May 2026 07:05:03 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.04.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508302; x=1779113102; 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; bh=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=fUZ+KhH/Ef9XSJ+HfUMeBWIV9XQdT4OD8ZVen6j/X3VfBI9ukADuOuufaW4/LOtbUs dqdKTfhISr6Otfrd6vwbkKXDgG25wEJLC9Cgd6lYby/JyU4ZukgL/1sZj4gsZVlqCZcM 1RCPc8jjmA4N3Yr9oogpt+VzWROKC3wOTRDq5xweefrWwLD482IEDKQgsrXyXheezFxC Oj9L9z65XoZ2NYJzD2oQKSP8SMxvtmpLnpg+avPj7tOG+Q9220WDzNM71417GSaaBOu3 Bc0cXWBUUGXOZfBfebIM7tgu6qLRa55MAqLa1UJJnKAtNvLUd6Zg4V8KP5b9gOHlUflc Kdpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508302; x=1779113102; 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; bh=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=llqQfYAR1OGz804ae7W+EwOeBjyG8hFMKHAgPJUArcXRn07aAXfTy1t23UoQSlOdDG 1yyNOL+R196deUzp1BuC704z2WDH3lLZWQIE9Q63bHEShNcdt+Jlm2A3cf1tg2rVJnYN IVXHpx1aS+90Rw1At6T5gyPZDNuvM1TGYoGC43lIr2rrGwXT9fehwd12uwiJ0Tk5INgZ rwKTSkKvua0XHuKXqujxKTrV2mS2i/nALblwsd2lj+Skt7WXyNDhRh2DnUgPuBu7QbUQ CjEH/NaDHgkdMWG1iJunrfrCt5q2LM/GbijUMstmBM8c1jw7Qh+0s4RBytwnEbW1+9EI SVgA== X-Gm-Message-State: AOJu0YyVVjs1ZC2QcUWmxzm5KyXPjPsXTaxHRIoNfdkreT/Wyc7SYhlm GrFuaeFjRjNeTze8N7PAAaUMI5BdF2FCww0w9Iiix2PXN6DSwv/qJszCEafO6VBoDxE= X-Gm-Gg: Acq92OGemJqkgcp6KhluX6ZwY5pEPu1FvDi9xpnHtKfrVIfPwIufmydBo8AWT28Lf+n 5ezCOMIXHx+EMapF7WOvPOJQ1KhyjgqYU1aP9u3JAi1thqbUHS8s64yC2eHtuAGanZje2e52tpS 6D1qKZCZMbWqoQJtpJwNRkEPrnYGbmTw/MxZMtVJ4OAkbdSAWMv1pAjR6N8ARHnsSOuWQ5ECf/j v61v73I3MyaivQTrmVrCLRCZP44JStM78ttTjsRZzCEsICZsA6IFW1FoKH2lsiAJS1LZraNy/D1 ca8JBIjXqJTSKXxgwlx0qilxUCb9L4k78zWfEqdwYHeNoDV+4H49fC0K6LzWO4vNNw58IbCq4tp yLHn6zOBPfyvSVgqSFfA9a2QOfIri+CApD/O3gk3MTFZLF34ZeXaO0h4Sroe9qP5wuGY3I8M0L1 mNEZrKLYrNPKzKFtYRUeirXMRM9OHVrsHhrkLy33PLQ542Pw== X-Received: by 2002:a17:903:11c7:b0:2bc:ac76:c1cf with SMTP id d9443c01a7336-2bcac76c3c9mr68827715ad.24.1778508301817; Mon, 11 May 2026 07:05:01 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 05/14] block/export: track IOThread reference in BlockExport Date: Mon, 11 May 2026 22:04:07 +0800 Message-ID: <20260511140416.28271-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x529.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: 1778508384882154100 Content-Type: text/plain; charset="utf-8" Users currently lack visibility into which block exports are utilizing specific IOThreads. This patch integrates IOThread referencing into the BlockExport lifecycle. - Add iothreads array and holder_name to BlockExport struct. - Use iothread_ref_and_get_aio_context during export creation. - Implement proper cleanup in blk_exp_add fail path and blk_exp_delete_bh. - Support both single and multi-iothread export configurations. This ensures IOThread 'holders' status correctly reflects active block exports for better debugging and resource tracking. Signed-off-by: Zhang Chen --- block/export/export.c | 44 +++++++++++++++++++++++++++++++++--------- include/block/export.h | 6 ++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..636633c324 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" @@ -85,6 +84,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Erro= r **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + const char *holder_name =3D NULL; uint64_t perm; int ret; =20 @@ -139,7 +140,11 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + holder_name =3D bdrv_get_node_name(bs); + new_ctx =3D iothread_ref_and_get_aio_context(iothread, holder_name= ); + multithread_count =3D 1; + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +168,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; + holder_name =3D bdrv_get_node_name(bs); for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,7 +179,9 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **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; + multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, + holder_n= ame); } assert(i =3D=3D multithread_count); } @@ -225,12 +234,15 @@ 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 multithread_count, + .iothread_holder_name =3D g_strdup(holder_name), }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -253,6 +265,13 @@ fail: g_free(exp->id); g_free(exp); } + if (local_iothreads) { + for (size_t j =3D 0; j < multithread_count; j++) { + if (local_iothreads[j]) { + iothread_put_aio_context(local_iothreads[j], holder_name); + } + } + } g_free(multithread_ctxs); return NULL; } @@ -269,6 +288,13 @@ static void blk_exp_delete_bh(void *opaque) BlockExport *exp =3D opaque; =20 assert(exp->refcount =3D=3D 0); + if (exp->iothreads) { + for (size_t i =3D 0; i < exp->iothread_count; i++) { + iothread_put_aio_context(exp->iothreads[i], + exp->iothread_holder_name); + } + g_free(exp->iothreads); + } QLIST_REMOVE(exp, next); exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..2bb98aae31 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,11 @@ struct BlockExport { =20 /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; + + /* The iothreads list for block_exports */ + IOThread **iothreads; + size_t iothread_count; + char *iothread_holder_name; }; =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508425; cv=none; d=zohomail.com; s=zohoarc; b=It542lYRNBjVXfHgpsQP4amj3uCMfJdq/oo062Qtqbf9ZDiaRH7xlrXe+YXklbwrlzpoTZCh5PQ2FmCXRH8hp+/FKn4rMUqyTfH6vnjglfI8WjXVyDG1PVoVlHNtq2f0MHSCcGp69SRHkLPOdvXjLUnw05ZuwKOy/Q4nT8+U4Eo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508425; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GgP4NvXflcioWVWaM/x7kgPS9jjy07btsZQtNOLI1OY=; b=cYm1yn/V5LaFI65E3cRrg9U4Lg1De6y80pDf78EOApZJ5jMYlqWS5AHA7hc+JV8D+BBSfD54jgYmZ7z8d13EfFjDayeuGG3z1uNjSqTcND6l6pfR6/GRKZ7JHRXDqPynfc8IfAwuKOyRxk06P1ecTXSxLuxOClxkkTJ63/55hR0= 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 1778508425877444.2363176268178; Mon, 11 May 2026 07:07:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHe-0003RL-9o; Mon, 11 May 2026 10:06: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 1wMRG4-0000Ps-KK for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:21 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRFz-0007Ce-V7 for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:19 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2ba3e3c4f87so39835625ad.3 for ; Mon, 11 May 2026 07:05:08 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508307; x=1779113107; 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; bh=GgP4NvXflcioWVWaM/x7kgPS9jjy07btsZQtNOLI1OY=; b=TtwxvkVv3raIBrpnYiMDdFEueNEH4IOUldM79hi6rZfndl4ELbuMOzewpeH1q4+Nco 05wRyIqxTriVXAnOH1DODvdHahSP5SzFG1wSfapNKPjHWnjnkXfSpizUoZd3PZQ3UNO9 X5mrBmWEFosfM4kz/z9xpShyeBQie1kfXvFC0q2a31sLdfkZT0tV6TYuR+OCxflDoOFo 53kJCeqR5LTV6sbPeIFpcLJrzwzz49PiTtbf2364QCdJynVQsrvG3AEFJyfKZFsE/nnw GVmn5Q5EcHQ4aut0cPs5oSfKn4SXL0hFmmdbs5HVokUmn611pWW0v2IUVzgY8e+JF6bS tpnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508307; x=1779113107; 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; bh=GgP4NvXflcioWVWaM/x7kgPS9jjy07btsZQtNOLI1OY=; b=me22qEMGEYCStoa+9DTrpH0JDesoXV2p6JdfLfyLlHTX9nB7H27X314PZ7S10iUHxi JZWCRMMaFLvxx4EcVbg6yo/xYGXfSMViiO5JpLY0k4BwtWtx87mNgDwubg+EDrgki+2B FURHeMdsIngZlzpVpeWyYoNPo9sTTIWT7Ae04b4Q327/Tjq/dJ6moE02Eik750FohpQ4 m3g+YCof39QbuZ9ndapVi/aOabAqecfJplXG2EPaT6gYFsvLbZMSyh0AAsXRsSbD61G3 IUDSFN4MQZ1VI50fy0QgoodI7hOEKqHfqpu/ipsgi/a2BLe+3peV2NjhWyG4MWfklxoz kZkg== X-Gm-Message-State: AOJu0YyH1hWAIvt1Ry/TCDoVQM/gk/+TJZ6diz4XPhR8Hk5A7/K/tH2+ +Eg3cHDnP8sHr43uMzIHo8iqHPLHAKjvNv/Gc0yGdIpGEfAom//qUxYAfpY5NEAyRRM= X-Gm-Gg: Acq92OEKe3WnTtZp0KoKvohUtQ6apxghe8FU+FGySZdvhgQyG5Ig72GtzFKNMvKfsJm oveqgQfkPDLYprAKRUk0mGZ3HlVeDz6cXDUTDIvwxqcHQ108D7q1MYn+sLXmtUsNZHIdUGhvvTq U0HOKu3dKMAs+NLZii57Sy3P4vu90vRfaQc0wy9WOYxcfeIrUriAdEjzm3flqx+9P6P3GdsyZBA gShHvOfOzHbVCAK+b/tjzR2XDINwjvmEvFmtv9Xo6cYu1k2G6yBHIGm82PgodGFesiSdCKfGMif yIEPvWkhr6QnyNcFlZzLdlRMPol/JnfZR9C4e7ADa/R7cTtLYTfwzrmeGP5cTKx8gwYdUnrD6Lc lQHdwej9IeIpqZ2TqHesqHW8sRuGu763sBaNwpOd2kT+IvHuNnmTBwPaMgx5bsqzzijK3+UqMje aBFoNMp4Y8Hb/s2iBYvQanpb6PNdQVJfZNUEHsvqlCq1Ug0WVwrHEHlvn7 X-Received: by 2002:a17:902:b585:b0:2b9:fb0b:b727 with SMTP id d9443c01a7336-2ba7a323e95mr186909865ad.39.1778508305836; Mon, 11 May 2026 07:05:05 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 06/14] monitor: Update tracking iothread users with holder name Date: Mon, 11 May 2026 22:04:08 +0800 Message-ID: <20260511140416.28271-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x630.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: 1778508428008154100 Since the Monitor struct is not a QOM Object, we cannot use object_get_canonical_path(). Instead, this patch uses the monitor's name (or a default type-based name) as the holder identifier like QOM Object. Because Daniel Berrang=C3=A9's "[PATCH RFC 00/17] monitor: turn QMP and HMP= into QOM objects" under review, when that series gets merged, the kind monitor can go away. Current patch assume the monitor already been a QOM Object in IOthread. Will keep looking at Daniel Berrang=C3=A9's patch about monitor QOM in case any future changes needed here. Cache the AioContext in the Monitor struct to avoid repeated calls to iothread_get_aio_context() and ensure symmetrical ref/unref during monitor lifecycle. Signed-off-by: Zhang Chen --- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 24 ++++++++++++++++++++++-- monitor/qmp.c | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index a5c4aba306..3e2c141c27 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -125,6 +125,9 @@ struct Monitor { guint out_watch; int mux_out; int reset_seen; + + /* iothread context */ + AioContext *ctx; }; =20 struct MonitorHMP { diff --git a/monitor/monitor.c b/monitor/monitor.c index 00b93ed612..b6efe776d6 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -529,7 +529,7 @@ int monitor_suspend(Monitor *mon) * 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); @@ -564,7 +564,7 @@ void monitor_resume(Monitor *mon) AioContext *ctx; =20 if (mon->use_io_thread) { - ctx =3D iothread_get_aio_context(mon_iothread); + ctx =3D mon->ctx; } else { ctx =3D qemu_get_aio_context(); } @@ -612,6 +612,18 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool= skip_flush, { if (use_io_thread && !mon_iothread) { monitor_iothread_init(); + /* + * Because of current Monitor is not a QOM Object, + * so using OBJECT(mon) is undefined behavior and may crash. + * Try using a hard-coded future implementation of the qom path in= stead. + * (Like the name of the "mon_iothread"). + * long-term solution would be making Monitor QOM, after that chan= ge + * here to: + * g_autofree path =3D object_get_canonical_path(OBJECT(mon)); + */ + g_autofree char *path =3D g_strdup(is_qmp ? "/monitor/qmp_mon0" : + "/monitor/hmp_mon0"); + mon->ctx =3D iothread_ref_and_get_aio_context(mon_iothread, path); } qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; @@ -631,6 +643,14 @@ void monitor_data_destroy(Monitor *mon) } g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); + + if (mon->ctx && mon_iothread) { + g_autofree char *path =3D g_strdup(monitor_is_qmp(mon) ? + "/monitor/qmp_mon0" : + "/monitor/hmp_mon0"); + iothread_put_aio_context(mon_iothread, path); + mon->ctx =3D NULL; + } } =20 void monitor_cleanup(void) diff --git a/monitor/qmp.c b/monitor/qmp.c index 687019811f..8e4a775fac 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -549,7 +549,8 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error = **errp) * since chardev might be running in the monitor I/O * thread. Schedule a bottom half. */ - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread), + Monitor *mon_p =3D &mon->common; + aio_bh_schedule_oneshot(mon_p->ctx, monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ } else { --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508393; cv=none; d=zohomail.com; s=zohoarc; b=ZkPdewf6CEdf4/JW5j8TmgrPyjIli5Ky+mmYHhGkoG4dz0PghAmHpV6sx5NwPvF7j6dK2xUBoLoL4EOpgVXmDQQQvK1Rkehp15iGamZXshFvhibH3963wmK29LKgcsWC2hgY831b/e1Kc9CtDdbvUay7PmZRkD1aa77bvX2qbUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508393; 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=bgUF3HiJphzj1Syby/WQ1ZPvl1qvI2+cLYn11/J12tg=; b=N1yp2U7fhXet/FI+skRaTSNrtwl27TF6rj0pLSfa0q35OVKwtpAwKtLHSkEJ7k/3As5BcKZCRRtw8ZHjvAgMicPUd5Io1qSfHBMBwN0MVMVAGFv7ZERWoh2XnmSTi3ONQHVKqesS5L/LGMVLarv7vGFBln/DBFkbUVc+LiKp5fU= 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 1778508393603670.6629231063728; Mon, 11 May 2026 07:06:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRH8-0001F3-VM; Mon, 11 May 2026 10:06:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wMRG2-0000O7-Jn for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:20 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRFz-0007Ed-1q for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:17 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2ba4efedbeaso31143205ad.1 for ; Mon, 11 May 2026 07:05:11 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508310; x=1779113110; 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; bh=bgUF3HiJphzj1Syby/WQ1ZPvl1qvI2+cLYn11/J12tg=; b=q4WswfOgNnra0tm9AEQYz1PBqer31KjzNf44jzmlB8C1T+tkTThw5lELptw1TG574J OD3OXgSeBtaTtd1oPbST5xdONNl0aeLY4ZM1vVCW9P1ZQyi9nxksyZPGYH90w1TQ07eU FYzIfoWx7a2H80vvEecT/UU2E3ob4vnCv3rjpEGLaQR0tLetfL8KGRhF3ANbeN4//eeo 46NGA4o/KDlWkQixbjcLEs4EbyOa+t7sWHYo+78MIFKT6ob6M+DOjxsXRri6krsZ/cON H3KeV9RdcsA8yjcCATDUuaDSKjT8Znp5i0gpeGsUt39rzsfHBk/b5IsYm4Ph0S7qx8vC F2qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508310; x=1779113110; 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; bh=bgUF3HiJphzj1Syby/WQ1ZPvl1qvI2+cLYn11/J12tg=; b=CySvGkcDYIM3K+P7D7eG2MzepvaKH5juGWr4Tw5skDSsuhID2BTa59RboUsi1lSmTc yC2nvzZS0aJmtpnbJ8RVUr4e0tMsxXz0NMTaZdAdfTzMnsLBuGaoI8ZbWhcbQU/qziXr HSGI9kUOPVLV+9GsWQzBZ040+Dc+YuFUki6ymqI9Ku78BfDIjM6rE9nH8h+PYy0M57rW bdjwt7vcaNYGyQXXA4Xon6tgkx6lY4mFL6eJsfn2kfI3CGDTfVU0JmWMc98vl6ey/bKf fx5YyBFZ0CM8tg+jDatDtuxGZkfhka9god8sRalOp8xX7zcRsslGwW3dCvX7I+a+qfcu Li5Q== X-Gm-Message-State: AOJu0YwseD7FjQeIWYZGc+WQuIgQFbkAHg5msn8UdnfXP6w33J5bILv4 E+GGECSU1W7bzZOoXLMAGKo5QafnUKoNIOUYApxinwwVbmZwi/T7z0vOM1ZfV6KY/7A= X-Gm-Gg: Acq92OE90NNRX4e+ojjJBf1t6JEFLbGW/9HqpLcGXW1DNGqYZP8eg5lCR5B0igxI8Xa ZGCOHZ1VQgSo3HsL37nQ7SsVclsTByJa3mur+g/r1iuJYPXCn+nPdTjfWWt8dL3DLWeCB+4C+HC IGPMfGOxiRoavu0D0NRoQyD3kaHyLjfUX24OuoMaSQBAm6AvVXUtkGg2PPoEqOF7EP1rvJ4WTVS H9jyPCfT82YiB5NZYjz5QupDR3baA9fj+qC+feXF9oAwcUdMAIJ6tfKPIkoSB2SYPfruXGkFC1o 8oYXLoCp1bkS6H0WBOiTEuTxJzqqrMIauMivkmz/alXzuHnoM9Vtz5erInEKJ3/ae3/SIcZLCCq +M/bhmsksuHGlzSXgyG4MnKTo1P5CeR2cRfeLv+D2AzWbtULF8mF5YYY+GC7KHu1wMAxTyzMwOQ sfvTAZOPtIzg7wZWv+GTKmn5Z/5xlKSt4eqe4tYRqdoeAy9FLXbhw+kapI X-Received: by 2002:a17:902:da85:b0:2b9:7051:2c18 with SMTP id d9443c01a7336-2ba78ac4fe0mr254898595ad.0.1778508309833; Mon, 11 May 2026 07:05:09 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 07/14] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Mon, 11 May 2026 22:04:09 +0800 Message-ID: <20260511140416.28271-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x631.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: 1778508396137154100 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context in iothread-vq-mapping. This allows tracking IOThread users via the device's canonical QOM path, improving lifecycle traceability for virtio-blk and virtio-scsi devices. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 11 +++++------ include/hw/virtio/iothread-vq-mapping.h | 6 +++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 9cb9f1fb2b..30e9fcf870 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1487,9 +1487,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; @@ -1521,7 +1524,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIO= Block *s) assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 95f13fb7c2..26ecefd547 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -65,9 +65,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], - vs->conf.num_queues, errp)) { + vs->conf.num_queues, path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); =20 if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 55ce62986c..c993281d7f 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,7 @@ 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); - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, hol= der); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +118,14 @@ 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)); + iothread_put_aio_context(iothread, 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.49.0 From nobody Sat May 30 17:44:10 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=1778508419; cv=none; d=zohomail.com; s=zohoarc; b=XQHF5CpgPiSX2tVUAGhQBqcNQsPKzH9mo0CLgm+DX9Y0/MzxbUYMTSZc5zofCiLQXj0zJpSlrzLAThq4DBQoem9yVL0LT5Ele0pG3CQHxU+ZgEOwrSSwhtCYiDUyq64AKs6QTwNvRq3TBAXkRfzZLftL6wX/joexwdF1nGkeMP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508419; 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=QKSigj797q5Eby1xdqeeW+3X9FWlNgDKbDV4584UafM=; b=MzLeWwT5xLunOzb9sXpnNVzJpYupUQzfZ4SpzhwGfVSta1BNvyPLbdV188tq3W4nwVmDgl/sZzmm/WXkvOokS8DPszNxP9re2sL/fry4kaHBhNsbGGLPv/PnGZvoniY4m/UofvGl5fNO+U97V9skS3MPbe8C8tePZNbYDNMkOrE= 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 177850841912746.34152201430288; Mon, 11 May 2026 07:06:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHM-00028p-2G; Mon, 11 May 2026 10:06:41 -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 1wMRG4-0000Pq-Jx for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:21 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRG0-0007F3-2D for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:20 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2b9e9a6802aso16803165ad.3 for ; Mon, 11 May 2026 07:05:15 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508314; x=1779113114; 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; bh=QKSigj797q5Eby1xdqeeW+3X9FWlNgDKbDV4584UafM=; b=gvpULlOABg+UvTDTbN62pdsaipH61IRuQEj7ZPOaEG9+YUDJfX4bjWtU+yyy55MrMV LlbbXC6OAsoWKt9fGG/w1O8VhOAx55G8dmS6WlUrr/HZkb3KJC9baIqI37NPWBwVerYU Y1ecPDGnBymVQsPq0W00hIXc0yFQFpNj06lhRu0iEphbKUo4VuTGujZ5gwykfTwlKnDT eXkTQTOYKKbaI5r3G90HJOWs5O5wuNoZB3w42sUdeiVXJp7gwFd9EpDDXNsvU/2mXp/L Srr1DGbxOzFTG587hekhDw+8MQOUCqZHU13jbNIEAU/MPGbU7w2C/+PasirtuG5GlsoG LG0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508314; x=1779113114; 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; bh=QKSigj797q5Eby1xdqeeW+3X9FWlNgDKbDV4584UafM=; b=B4SeMIaLy63YlUgvRwPaWyiEZxFmN1Dga1FGH72YbDKea2gs1WssBBg8YexYmI5J7z Uy9OsmtBqYzheuy+UgrLCfdi26SBmDZu5Ta/9X6vrHb2sZOV8AWkzrx+yDf1kjEgC78p +r43wSPJ/WxWtD1WqGAJN94TQUdOnQNLuOV3FvgSUuv1Vl6vlXX25I7VArytbgJ6IdK9 P13VSMJf2EH0012/TFuPql8bXnin6Ia6dfBlwZD9KI5e6owHpMbTAW/Ekgqog5lVXWCm vXvz5ZBiQXnzmJ99eVTb/pgOE9DMbnhB69S7T74CiFNNwgcVjbcXN/bEJLhOJ2+k17b0 LyRA== X-Gm-Message-State: AOJu0YxyCWbYkDcJHpZ35MIiwhsYFR28OVHiw9Jmtz5lOsTOsTrXSHvi 2l6JU0LB6CFdeCqdeV5/8KQBJzx04cqQ7fDV6R274PR9rygFGzn+tVW+KgaLFpmVpCs= X-Gm-Gg: Acq92OGpaywqAgBat4OBZAXh+itvvy6SsNszBq2x/xUzZyHWrhnZd1qgIlox82BNmjU wUeHo+BwG9GYLHN/+SmQmkYkUwHzCztA0HRjfKTEFrirLx3o483mvdhifCtt6AQiqZf1e4xi+f0 kGi8XdVXrnUM3ibFu0peTUE783D97HrXeg1hQEQe+BBw4HBjefVNukkFqoWXdL1Z5OWID3D9sVV BTtHvvLWaIJwbNtNEqiu+SRSFkthxXqKo4K6/vNagswTVHiUF1Yd4VH5fp7ekpOQ2nCcCVPqsI+ I7z150dn4aGRE4pwDAImjnV8ikFT21vmkov9064dglce/qC9kanIS3+XFv54U+xbMxwUcSklXoU Sqa5WP6oUKUFX3TpPJDHCxBtrSLcleA9CR2JlpSujbukX3ebyXnIpHY98C8hWwxCy60/N8sta3Y K3Veanw8cSYcRrkzw42poPPu51t6e3tKZwTq3gNYETFwLG2g== X-Received: by 2002:a17:902:e751:b0:2b2:ebed:7afc with SMTP id d9443c01a7336-2baf0e045damr162167775ad.27.1778508313607; Mon, 11 May 2026 07:05:13 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 08/14] virtio: use iothread_get/put_aio_context for thread pinning Date: Mon, 11 May 2026 22:04:10 +0800 Message-ID: <20260511140416.28271-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62b.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: 1778508432777154100 Content-Type: text/plain; charset="utf-8" Refactor virtio-blk and virtio-scsi to use the new iothread_get/put APIs for AioContext management. This ensures IOThread references are tracked via the device's canonical QOM path. Summary of changes: - Lift 'path' scope to cover both vq_mapping and single iothread cases. - Replace raw object_ref/unref with iothread_get/put_aio_context. - Ensure consistent memory cleanup of the QOM path string. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 16 +++++----------- hw/scsi/virtio-scsi-dataplane.c | 15 +++++---------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 30e9fcf870..e9f1dd5f8d 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1463,6 +1463,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, @@ -1487,8 +1488,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, @@ -1499,13 +1498,11 @@ 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); + AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, + path); 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++) { @@ -1520,21 +1517,18 @@ 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)); + iothread_put_aio_context(conf->iothread, path); } =20 - g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; } =20 diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 26ecefd547..cc318162f5 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,11 @@ 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); + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + path); 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 +91,14 @@ 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)); + iothread_put_aio_context(vs->conf.iothread, path); } =20 g_free(s->vq_aio_context); --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508450; cv=none; d=zohomail.com; s=zohoarc; b=ASIvgo8ZJ2vg/ZzgfKwvgdjqLe4LeSvKrU4PGBedFC0BUdO3O8KKf5XYeHZte4B//KVICXjFryy96hz21i5iOODxlBvEfoR3FovBA0TwQmOa6LyAMs4Sx86Oe4iA5IOlhWmHT0lfVHP/Q0/SHH75/pwq38iYAl4X59dJNjje28A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508450; 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=uuSnosvKOTz8eJA5oflodvBe0T0VjN/x4jx6Aoy2gcU=; b=RB1RyzO4GPoY0yLOES1jRLQ3SugxuDuCl2gC1Y/H6+fn9Jhqb954E91XzYlXeYL1ljRkvVLWHrTVmtnpMSPWGfK0wPPdd+JvAoUAk9ZOXxMdhSt1A4FunfzS6DghWpJbg5lh+rJopy/980eE/CLnH7jHzIg04Ujyjg1dhL+jRGw= 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 1778508450195108.08198086179061; Mon, 11 May 2026 07:07:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHW-0002hG-Bu; Mon, 11 May 2026 10:06:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wMRG6-0000Xg-H1 for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:22 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRG4-0007Gq-Ad for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:22 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2b9705613ddso26658095ad.1 for ; Mon, 11 May 2026 07:05:19 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508317; x=1779113117; 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; bh=uuSnosvKOTz8eJA5oflodvBe0T0VjN/x4jx6Aoy2gcU=; b=Ja0ZSqQSTEs8F1f9UUiWhp9EXOm4mOv8yydf3KibyUWTVDm/sJiBH4BtxIH+eBZaU/ E3raFYTQFdEFsEH4d20L1Dgv8aGuKnQX7CSeH+dbZ+X3Mxa2vZ/AlqWPifRIBhD3Ra+k JUcn2iEZxvs3ZsVXDDaFw1HuIurDMiFRDWaN5NM5VJcrGHFsMgSDqGAMDWV78sbf1GdJ 9pT0/xn/GJedXCuxzsSyuSNSk6fkf+FhIVE3XvMN4Udqt4RSIxodqTYH6gaan30NMYmn Acd+IwZcvjrTGzYEfjDMkpRcAHRncK0bNfgLabWNyn4NRDFHiuKI/MDcM5augoPXBfvR DknQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508317; x=1779113117; 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; bh=uuSnosvKOTz8eJA5oflodvBe0T0VjN/x4jx6Aoy2gcU=; b=BFrx2KTHPGagMB3EnGLU7F2nz07tzEmw7nfg7m1FsgB0VjvU5zl0slYLxKJowntuG7 W5vYV4Pe5jAqFeIuqMhJpM1+iRpnQmfP9OvQ/d7vqqy2ZY8Aonpc0+Qsanb5hp+We2Yy 5N8njSLAVVBA/l6L/uSSPl/n2dhSaoreOXVeEg2n1qyR94cBCC1mI2jf171TOKk5czsX zZ1cRKdMevPBg2UsLhhrINxvqpgQIEpDqdyGnt/K+ICZbMxyvWDwU9stV+szTKSdRTBT 6ahgzoqipIcSoxqQQycefGQWeMXJaLY9QMYsNyCpIwSmzSwliRxbpZ+UJ6QMlxq9bsIb gW9w== X-Gm-Message-State: AOJu0Yyave6bA5/PvNOk15p9fDIZU04cOT2QgiMe+lZfrlt4CUrBvOnO aZ6UY7Z/wNb65fSXU4d1srcwmO9SFNm1CPbLmJ8RnF8UBAsDJn5rmP8OjxzXUr6Cqxo= X-Gm-Gg: Acq92OExCcsKDKfx8o47zf2Qkh2Tt13Xd2DZ+B916Nr4pYHyWKkwqgl+MOW9oRngIAc AgBKPpGaFkgOUmcxXhKq/9p6BKYRzxqdst1JRhBsTjwPysHKPgcDy5ua2gQkk/aHofpZ4Nfi/lz P+QIE0peFYzpE4fsRT9DVz5uwluFgJZkhMxrEGoxJyUTXMPEacA5UxALt/KsU/U/jb/a+GhhNLm 5Cm7OCjrZLoRQHqXXAtJZ1wtJ5xsVmJ9wKXgr8Cn9pVP0F/yMSP6waNA3AEhYpVXSjHNuX/QVSE DyJjIk6w0zibPYlEutzFSSHJL9DYGNB59Ex6VZrpoHkFWl6zeQrUGMW0HFTcIWlHWs98okr3saj w1dI6Hl1d1NjXI1cjr5nDe8EgqTfDH54qUBeIKC8oe8XgR3fTa6RAozwPVnKZ2QS6rXtMmgzmOq PGIiOOnlyM6yotd/xs3DVim2/fNrzo0rqHu/hCVwS/H1YkZQ== X-Received: by 2002:a17:903:380d:b0:2bc:e2ed:fd03 with SMTP id d9443c01a7336-2bce2edfee0mr27144555ad.39.1778508317518; Mon, 11 May 2026 07:05:17 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 09/14] net/colo: track IOThread references using path-based holder Date: Mon, 11 May 2026 22:04:11 +0800 Message-ID: <20260511140416.28271-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62f.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: 1778508452594154100 Content-Type: text/plain; charset="utf-8" Convert colo-compare to use the iothread_ref_and_get_aio_context() and iothread_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 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index abc1326b70..8c83da95e8 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 @@ -926,9 +927,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) + @@ -968,8 +967,10 @@ 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)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, path= ); + + 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, @@ -1408,6 +1409,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) { @@ -1434,11 +1436,11 @@ static void colo_compare_finalize(Object *obj) =20 qemu_bh_delete(s->event_bh); =20 - 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); } + iothread_put_aio_context(s->iothread, path); =20 /* Release all unhandled packets after compare thead exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508542; cv=none; d=zohomail.com; s=zohoarc; b=nhclVdooRw7lxFznxvPJ4ItB2QGfspQMUXZZQSjUrNUZ35n8O62Oo6Gf8J4OX+CiMQ8kOASUbakMVkX9ti3/1Z5dL5mx8nIF1kDOpUFAALBV7tJIFQLrrGIqugrC4AuYImjGjRbIqRlEY4OI2DOu0qBkb1AmmEa7QKbvtQYkG40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508542; 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=23F2qkNukByaUJQk9pbl2bbnzE/ZXLLhOxWd32Zs67g=; b=Pz5F02C5C0OO9l1hLdOVoNT7MfCcv5xuBq+vs4IHt/T0iLPZvdjYy4isOacEHJoTnLPR9RR9SoVr79Wq9rojZSRAz51UCXwkFDraRu40vXe2RQIDUtclfhF8TcwbxBE1Vyet5T7eFhbJXmtEIOg04hE59hDQfPlK9yr03IhvjGM= 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 177850854253855.307400672231324; Mon, 11 May 2026 07:09:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHW-0002kT-K4; Mon, 11 May 2026 10:06:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wMRGG-0000qM-Bt for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:34 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRG8-0007Ih-3o for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:25 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2bcd730e090so5704255ad.2 for ; Mon, 11 May 2026 07:05:23 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508322; x=1779113122; 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; bh=23F2qkNukByaUJQk9pbl2bbnzE/ZXLLhOxWd32Zs67g=; b=DhfEXw3R7kjiveTG+QBsn6IqpHPzvHPYcdPHS721FGgA18WQ3vv2F5gOIEDFRXz7ne IEios4SJ/RwGLc4hBCO90tdcqRRsLWK7+Msu9cCD/hn1ZettEKEbWCkWndlM78R6xhhU a7gNrigq5ST47dl1b/9gxwkCRzA2CThWe7TcLjW05hWbSlHFdwRA5leFQwOmA0+XMMVt O+g/RtjxqbjzQ05JPsyrBOyU58IWHrAsZnzF1SwwgZk3TU5qsSxSwxvNUZ3+GyPGOKAS LbXi4FDQJ/5iaBPJNzW/0Ut3wEWreq7e9+g4gFev6wxMN3tR0uRR+yShvAngduW0lPxr Pkdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508322; x=1779113122; 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; bh=23F2qkNukByaUJQk9pbl2bbnzE/ZXLLhOxWd32Zs67g=; b=eg1+EadCqH6XOa+iEnOCXYOojWc4xZGI2cKW291BddvVij/5dZU/w9iL914n22cehV PmDnVJsykngsHEy9STuTfALBOABv+eVLl0dc2a36UJFhiMrIS6VlLn/N56WLUF9exFON 2aPAgtOc1XcUWcacvUG18QkiMFG4D7GEtDvziUIoZ5igIxcVICwrwZdaFdh0ehB2Nz4a V5OqNM7VK2YDznCJv3g+RZxhDG/kb4PC6Xu75i2Jt/KbpKs7eDzYBLlfDwXm0mR6QZWd zY8y5tiIYPEALEfpQtJWqqXANbrXIbPx+FCBFVOM3WS2jwR+BEQakTFP5BkJdyElshPP SGTg== X-Gm-Message-State: AOJu0YzwAlPi+45LIUtiJq+qUAQmy0bMofHkZ7wE0TMLVird0mKDAWOm P+XyejIGKZG/vHwRDnfEYKfFa9kmK/gAkRS3JwmkMtJvPykg9LPixc/t4r5t/x4v5Hc= X-Gm-Gg: Acq92OFTJ6ui2ppaZ/UIr0Yg1mGS+BNcQdwvVRR4XTNtZOXdAx+QTCOuM6GhZTnLehf Idd56Uukb8mO2v0jGoPVljZq+hPB6FhskwkJD9KGHeG/fDYw0j6vRGbAxvp7oc5SxTo+wO7KEPt Pkuxmk8iGfFeFG2bFkUc5GL0ongaJiiWhoNa0nmAUhpciHi7g291rYJq9U6gSUtPMsnjpc89kj1 Hln5AI+wUBxrnefaq85U/mxoegItZn+sN0KJAHoTPS+dC5sYfNamw87ay1ZvzVddRq+FvlYJrsb 0zevwh1jOYHeAENVnpRJnCxcQ7yGVdN858QztVMK+TqIqGWNkWQiD9UaeN6dIbJuUZ+c5upDTB7 yCnhrzBR7E5pIpfB7JTj0gTvgYJmojl9m8Re2xfRi/trvCmrNZcExQsmSn36q3lnqbfCGmiO1Lt 6fOaBOkKYIfEmYjOV5gUdqpDJ0zK/etwriBOx/lC3tYyPMJSxXtCTRZacL X-Received: by 2002:a17:903:350d:b0:2b0:6f21:8289 with SMTP id d9443c01a7336-2ba79c2232amr235690825ad.25.1778508321394; Mon, 11 May 2026 07:05:21 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 10/14] virtio-balloon: Update tracking iothread users with holder name Date: Mon, 11 May 2026 22:04:12 +0800 Message-ID: <20260511140416.28271-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1778508544857154100 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/virtio/virtio-balloon.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 4c5f486ba2..8a4494905a 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -892,14 +892,16 @@ 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)); + s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page= _vq); precopy_add_notifier(&s->free_page_hint_notify); =20 - object_ref(OBJECT(s->iothread)); - s->free_page_bh =3D aio_bh_new_guarded(iothread_get_aio_context(s-= >iothread), - virtio_ballloon_get_free_page= _hints, s, - &dev->mem_reentrancy_guard); + s->free_page_bh =3D aio_bh_new_guarded( + iothread_ref_and_get_aio_context(s->iothread, = path), + virtio_ballloon_get_free_page_hints, s, + &dev->mem_reentrancy_guard); } =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { @@ -919,9 +921,11 @@ static void virtio_balloon_device_unrealize(DeviceStat= e *dev) =20 qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_bh_delete(s->free_page_bh); - object_unref(OBJECT(s->iothread)); virtio_balloon_free_page_stop(s); + iothread_put_aio_context(s->iothread, path); precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508419; cv=none; d=zohomail.com; s=zohoarc; b=ZI6N2uE2apAgXtLgbjHS1iNht992OrIOM/eBnlRBB0Kud3lNUArC5hKI/yDYYazT1FybI/H72whnSn1gZCHVa7wxWEfEchKub33Q/2mOIyRAEHQtWHN6omtjFXFHJpIJoST96Kmoq9+YBKkyAliZK7p7QdNRYNv0YSsy9iCVVk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508419; 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=NsI6Qqs4AUchAJ89hl2uKc8SPPduRq1NaW8uY3dlWFc=; b=ch5xM6u06o52MEk3emfEkPZB5ZLkIMZMwOwpaziTNMqyApPVYLDESwC+DUA3Nnae5dKwnAF/m+ombM00bEKrxlYOIINobQcoJTSjEbs9w9hC28va/XdsWBtZYDyjrBgIGH1TjBzxbDQgCnd13J5PvYh5OcXACXfpEKQCwj2B4RU= 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 1778508419894416.869478039521; Mon, 11 May 2026 07:06:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHL-00028M-Rc; Mon, 11 May 2026 10:06: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 1wMRGJ-0000u3-P8 for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:45 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRGG-0007JC-1e for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:33 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-c8016d642b2so2456292a12.0 for ; Mon, 11 May 2026 07:05:26 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508325; x=1779113125; 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; bh=NsI6Qqs4AUchAJ89hl2uKc8SPPduRq1NaW8uY3dlWFc=; b=I+tIaful+U8PFhjg+bFUo78zYvyNsuOF2PMCOiEHPyD55qRCIHP+Smht65YZ1Fo1ko Dm+bq/brmzUEtUXVRvtHkfz7Urxl63CJihk1KSqTXcqhsj8h/iRg87SIXJZPG4A3d1ra +89JUc9tzHFYD3bzCHVcjYf8IahxSKeumvWIx3PENbFKtD7olPBnM1ymzv6xhkL1x9Gt MmP11WdsydVZjsxs8j0B6M/InaLJ/3f75qtFZIR1uNaEvQfCTwhRW/20g4HL2+pdT6Bm s71tFGesQl0waD2Jfd3zUdP6RsbN0u+Z2tuEJ7yvUJFsaa6IuJVewl+ehQ2nh5h+c82Q 3lSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508325; x=1779113125; 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; bh=NsI6Qqs4AUchAJ89hl2uKc8SPPduRq1NaW8uY3dlWFc=; b=W3TBcjetGZA2iWxsmftxRTRGn2ezrsdF9+JmuSzg9STbhDJGH/jTCOxB5yrzI4FFCB g+OowwdOywcKSINZXM8CEPb+omOM20vMK/VPCsCexHe2bpkU25oRAOyyocqC3XWzPFqC cgqT9kCjfQ9rPPz6ji/SSa63v85MOk/NHOerWZdUavBZZftPqXy08ie68xuT8VLQH2sL DZ8kKn+cfrGgXJ28UOV2t+r5n0fQPxgghy/KjLaTweSQ9FRMETiArZhr2smj2kkspzVP TqB3Ol/ijBJ0UOVIe8V6JaujQw64f9y2aCJ9kO8/Pj0mZXSzjvcBmxu2PUFI1yH1gmj1 F94g== X-Gm-Message-State: AOJu0YzbRZZYn/3O22USPiq1zbGid1TNj9EUdJ51nvwAOaJXXMbI9bc8 lDeNkJ36YufTWIG84HpMDzZYqwe7qbBgMC6X4YBcGwIqQ6gh8Fq6YrWLd/iFX0f8eGE= X-Gm-Gg: Acq92OEcjMK4Q11xr3zZabU5lhGbDfeyxmt3Q98VJtqzGnpIx+9Mnt/IWRtWHgo46XP it6myYJiVPm+tkMCx6luGdte4KVCfUHQ8n/5X+TDj4L3tlG6YFg2UM8rwFDPar4wgEez//n4Y6L 0jLaQfaoADqIuDvqYO+Lg4aEV0GodK9ch5pDWhqNHuMGMKdGMSO380beuwvH6M0ugVtCzLc03gs P3bmWaQIH3xq9gDa8KG79pLo9FA4rfE2dxLy8/4qyEoJMiHe7BIbTDvr3vTZgsDSMdvdteYwH0I AsGLkfxKoYHUfKhcEYrNd+AOv9tZ4BUCRPjFKcNZzX3ru0f7qEvCEDiSD0L4b7kMM7CYWkTGZhl f5a1abG2BIiKydtlFJwA86XsPid7oLzd6tchMGo/G0neX3/GAgwnobzf8h2ST7LR1+dUzAjMTPO +ID2iCqpCut2pPyJpqv8g7LsdS70HpE7xiP5BuC/D5DPndmA== X-Received: by 2002:a17:903:1a23:b0:2b2:6fbf:ea2d with SMTP id d9443c01a7336-2babc864863mr163916755ad.7.1778508325346; Mon, 11 May 2026 07:05:25 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 11/14] vfio-user/proxy: Update tracking iothread users with holder name Date: Mon, 11 May 2026 22:04:13 +0800 Message-ID: <20260511140416.28271-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x531.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: 1778508421694158500 Content-Type: text/plain; charset="utf-8" Add object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/vfio-user/proxy.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 314dfd23d8..eebe202c4a 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; =20 if (addr->type !=3D SOCKET_ADDRESS_TYPE_UNIX) { error_setg(errp, "vfio_user_connect - bad address family"); @@ -917,6 +918,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, 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)); =20 /* init defaults */ proxy->max_xfer_size =3D VFIO_USER_DEF_MAX_XFER; @@ -936,7 +938,7 @@ 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, pa= th); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); @@ -967,6 +969,7 @@ 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)= ); =20 qemu_mutex_lock(&proxy->lock); =20 @@ -1021,6 +1024,8 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) qemu_cond_destroy(&proxy->close_cv); qemu_mutex_destroy(&proxy->lock); =20 + iothread_put_aio_context(vfio_user_iothread, path); + QLIST_REMOVE(proxy, next); if (QLIST_EMPTY(&vfio_user_sockets)) { iothread_destroy(vfio_user_iothread); --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508401; cv=none; d=zohomail.com; s=zohoarc; b=M0yJQyTDgKPVkn5tChulCxfx9WIlXeEGMEH55P+eGj9lYcqjIQmAHCF1YwDPkQCC8M5MiHybcVDa8MeZLoTyIKmF5QuyXQXeV7fGN9V4mxuXC93v4SsuPdpbUiLERd0ZOepPvwl1l4wAWELqa8xus0DFyfjyHsQcCvoLEPLmP7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508401; 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=2bylwVIvheE4A13Mb11/ZHCJxDZDhKuXhRjY1sr2Fkk=; b=hlgLPwgmBS4WZKIebL3jQoWVrZO/nP0i3/Jpyl8nbw2VXXIXUbGcmZJoYXkXZ25of5u2LtgQesJmxVnGw2l5y7Q/0J1lhCsdi8sBVQgg+w/RuRp9Na8pgsOVQ0uW/yKAupURMutzIRbnWbloCMHMX1tvRUAiXp3ox5BWifZkbHE= 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 17785084014821007.6898257270823; Mon, 11 May 2026 07:06:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHH-0001pd-WB; Mon, 11 May 2026 10:06:36 -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 1wMRGJ-0000u2-Nk for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:45 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRGG-0007JY-2v for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:33 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2b45cb89f7eso27637395ad.0 for ; Mon, 11 May 2026 07:05:30 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508329; x=1779113129; 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; bh=2bylwVIvheE4A13Mb11/ZHCJxDZDhKuXhRjY1sr2Fkk=; b=BdxOT7aqDbbuRH4v+Ckp/1qfIYExY/BqTAWoniPtEK5pBgPa1Wbbyo4G9q+bxMpqd8 gaoDpTjRqCGNyKsdYqCrVPqkVp4Ch8ozSkLmgDIBSvEMlfc30fyvHNZBJvnMTtXKieXW DrpGK+brhNHOfk8gvyFDgglLCH9FhHJCR1du8xr4WIg6JSUXTBAIlItDV86S9gteY8te GTdl/lXUDO+nhrSeix5OLVsUMgEtxK8LSV0QYkZBRjUI3FpFFfRGv/UUC4a0LNRXV9yI +kzX8siwPRZzYskCp24MEVhMyqLYnG3XuQF1E2MhWLHRAtW/DMgoqijtOEk9y0lxSfGr t0lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508329; x=1779113129; 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; bh=2bylwVIvheE4A13Mb11/ZHCJxDZDhKuXhRjY1sr2Fkk=; b=ZK10O5O1Kos390mp2o6VXERVUvJq1j2BIImZl0LaXd7XqwlAUpAYePJwkDryZGkOkF hWD1qpa2o7jKZswKDdwFto5UUeAcOdndTxD5wAzfhtaytswY84kaUnQg8BlISmphmhKY 4adPNbDi41OLHS/tvyE25+mDUJt4Ez9uqzMNCFwlBcr8149Ob8sGLAZJMETIzMcQi0Ln lcz+3dFWm9+KSkj1B4xJBUmPGd5StaBVog9G0yEfLbPo6sG12FTevyEZJ05My60L7okp iywdlWdWpKcOj7gKk4Ibw2R73t/qoV5JRwEfwkq8wbJIM9KZP+QWeMoe8xhzbi6aOmmS 8/zQ== X-Gm-Message-State: AOJu0YzSpMXovPuxBOYqwzpt2ngJkhTfHtJRX/Xs0HnCxi/pg8vI9TGi bExhEPPWGU2Xay/fuiB57rnT/zapaztqLOcohEH9WT+sSvgJ0P6xxumuJh1rAMAelkA= X-Gm-Gg: Acq92OFP0bDUrTAPUCbpX/y5RGLdQhbUTv/KiPM8WVT/2x2EVsefWinaJk8tOy2zlXg ctGJID4F9wL//WaO6mDn35p9OPgXxqcsWFB4oyQK/yewFq1+ighqNjSNbxg5wC/y6XPOHH0djvl FQSRusbW7oTBNmGZCEFUZmFtWKwztg6z4zZJg6rpD/UIKaPMW4VXOb7oykdp83OLWtEjcyv7X/W hinqPVTnUxBQAdc+4JnsKu6ltxKcPZOVFOFVx4rEnpg+70R6WZkyZ8KXWdbCLwQIPQbxgVd8sb/ ZxS+EUp/NWZKldMt8xWgAJbmT8ii0C2RVVlhb9GCAcDXggKHoC2JpOD4yNsMMkK8zR5TgItQUlf cseknIz+j2Q4jnpKoAVYs336tT0TvezFzOwGfXGswnlgG/ms06Fi434FKUorKXHXGBmhWm+Poo2 wGrh4nrDj6H6JGkxPgjibfoo9jDrWWyQYViDqAWF4urgVuOw== X-Received: by 2002:a17:903:3c45:b0:2bc:7eff:2d08 with SMTP id d9443c01a7336-2bc7eff2ec0mr101276615ad.41.1778508329304; Mon, 11 May 2026 07:05:29 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 12/14] xen-block: Update tracking iothread users with holder name Date: Mon, 11 May 2026 22:04:14 +0800 Message-ID: <20260511140416.28271-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1778508403261158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/block/dataplane/xen-block.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 48c2e315f3..552bd8b039 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -621,9 +621,11 @@ 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)= ); + 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, + path); } else { dataplane->ctx =3D qemu_get_aio_context(); } @@ -652,7 +654,10 @@ 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)); + + iothread_put_aio_context(dataplane->iothread, path); } =20 g_free(dataplane); --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508528; cv=none; d=zohomail.com; s=zohoarc; b=Pz+mX7BXMSGNoMD7+4ONMt/xo8zH/71BipS2yKkUgZ1iINQqDrT1CZZ5caiS2ieJn+aoNPq0mP06kO4aDvloasTYMAtzr6m8eX55GWSPg2wbqOHYxbhuJwrLYd3aVy2ecp8gm/2NgZegkwR746lp14IHrmzrf6brjJucx5/vvN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508528; 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=R3N5Xo9vISZc6fDn2rpqzE+2yy09KDkC5TvyoHeOVaQ=; b=mS0qRSdiQ+oBeCzDMWCuysYBVTmtjH6birAnsSWx9Vk9O4PeM8WBpAdXHFJjjcCOl+T4tkpIUqGpjJ/S5CeO6gz4hvZOPEPH3q9Y0hrIbhhD9pJtDR7wyB0QBSeuOI1+cVv5VJ56rtOt9kTYC6cy1Jcu7oQkJn3KK2JB1PIBCUE= 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 1778508528765107.38558230764409; Mon, 11 May 2026 07:08:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHW-0002eb-11; Mon, 11 May 2026 10:06:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wMRGO-0000xA-EQ for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:47 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRGJ-0007KR-Ds for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:37 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2ba3e3c4f87so39840825ad.3 for ; Mon, 11 May 2026 07:05:34 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508333; x=1779113133; 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; bh=R3N5Xo9vISZc6fDn2rpqzE+2yy09KDkC5TvyoHeOVaQ=; b=ZWLKWEurYyc2gtlsbpjL4o9qKah++ft9ifqQTJFHNtmp2YRPIgnu+eGDXoAQFX1ChR XLQUiK5jkmWTe5kluTegptjRvA8nO5lUk7aXKaRj5oYkKx427Ifeb9oFeVnr3/7yvQfZ A/uKrQMnKJtryxUxTAtcYoKMVbaNWx9KuB/lVMOiqyCgJTlPBn13UlYLRGzlp+cHUa6q idI1KVu+dCec9a4e6xg3BhBF+apbzcn8Z0tLwsWuxrgQAchRIPQQs9H3B6DSGplUY+QT X8cWOrWrLAIHLn2rmh3k+X7UD+w+sUHghVtqgrPv4oZVAYVkErQK14EFfOgEQIO3n8b0 KrGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508333; x=1779113133; 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; bh=R3N5Xo9vISZc6fDn2rpqzE+2yy09KDkC5TvyoHeOVaQ=; b=ZhQ0he8VQetFC87YX5k2UVDhCe5aAkHViQmHKOOh2ZSo8zKwUL3qQXTUBvheE86OPr aeFBHNZBxW5rSFFk6SE9KxoEPNkZdTNq/Vfx60NgAaBYRVcZZogGh57Gx6mhgCpWSjZC TG5wvGswMzCpapKIOUSQxdd7nAZkVOuwYuyc+EYZ3FrPjkQW4cbP9UvrZabqK273q4Ii 7dGc+f0rttsUiQKvGaLhJsQInvjPYV2TkadiRKHuNkLKUWEiesPnvSpBdkUuB836BHuO OVLXyKkM6JaSqat8ZD6sT8Jy7l4x6eOl0oReIz0dLyYxto0LGP15IARZ+J17+Y97cpVm azgA== X-Gm-Message-State: AOJu0YzE8ffNg/4AUcQqkoP5SrzoCn7RFSc9j2vex9MctvRa6L+3/Jdy 4Rh1B107Lrk43jHR9mtKTfDV87J+LarHb9KEpAv8hJyoznI3+nzKKlVFqF2OM61Udno= X-Gm-Gg: Acq92OF8ArV+Qxd2L6qqVOVqFvUI9KVPcvovdPN+r71p+bt/dBemWfr0R11dY926+zP URrSsp5yjzjUfBx4AoN4GaaZC2G+6pC3Q4JRaLOLgb3K4jRGsQ9vmK/QcykobNbsfPc85x9c6zP HrzlH2PxOv6IyPpak7JF+ysZbSwAeSzkaa/sAOe0jfaoFZ/PvFCgjO4bHPnyU2C6NT52f7U9xR7 ab2ioPe9Otwof39ZJ7mL8od9c7uaM6uv8miClNS4dumhY+GcAnkMyOS3s6SIP94h7CKKzNCb1C/ eR61fBJ6SIbkRPko25Z7UshyTrSqh203UxZa1mn5ez1dgKGJaskQuHBdH2iHo9vwNBERCUU11Eh oK6GRCJTXOj8DX+EROv9w9tbfJMBOEyfBSO2xC1GlkWl5771gx4jC3ozgV2g6m0V5CG5aUxAi+E cFSG26nTEf+LX5Ie79dax/hTp5VRM0/TYNkoGR2EIL6Whm0Q== X-Received: by 2002:a17:902:c406:b0:2bc:f2ae:e122 with SMTP id d9443c01a7336-2bcf2aee2d3mr7705795ad.2.1778508333187; Mon, 11 May 2026 07:05:33 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 13/14] qapi: examine IOThread attachment status via query-iothreads Date: Mon, 11 May 2026 22:04:15 +0800 Message-ID: <20260511140416.28271-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x632.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: 1778508531219154100 Content-Type: text/plain; charset="utf-8" Extend the 'IOThreadInfo' structure to include attachment metrics. This allows users to monitor the associated devices by identify them by their QOM paths. New fields added to IOThreadInfo: @holders: IoThreadHolder (QOM path or block node name) of the devices currently associated with this iothread. Users can pre-allocate multiple iothread objects to serve as a persistent thread pool. When a device is hot-unplugged, it is detached from its iothread, but the iothread remains available, allowing future hot-plugged devices to attach to it. (Since 11.1) These fields are also exposed via the Human Monitor Interface (HMP) command 'info iothreads' to assist with manual debugging and performance tuning. Signed-off-by: Zhang Chen --- iothread.c | 22 ++++++++++++++++++++++ monitor/hmp-cmds.c | 22 ++++++++++++++++++++++ qapi/misc.json | 11 +++++++++++ 3 files changed, 55 insertions(+) diff --git a/iothread.c b/iothread.c index 5d6f46d286..a78744284b 100644 --- a/iothread.c +++ b/iothread.c @@ -24,6 +24,8 @@ #include "qemu/error-report.h" #include "qemu/rcu.h" #include "qemu/main-loop.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-misc.h" =20 /* * Add the @holder path to the iothread's tracking list. @@ -93,6 +95,25 @@ static void iothread_unref(IOThread *iothread, const cha= r *holder) object_unref(OBJECT(iothread)); } =20 +static IoThreadHolderList *iothread_get_holders_list(IOThread *iothread) +{ + IoThreadHolderList *head =3D NULL; + IoThreadHolderList **prev =3D &head; + GList *l; + + for (l =3D iothread->holders; l; l =3D l->next) { + IoThreadHolder *src =3D l->data; + IoThreadHolderList *entry =3D g_new0(IoThreadHolderList, 1); + + entry->value =3D QAPI_CLONE(IoThreadHolder, src); + + *prev =3D entry; + prev =3D &entry->next; + } + + return head; +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -465,6 +486,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 iothread_get_holders_list(iothread); 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/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index db92d6cb86..be799766d6 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -237,11 +237,33 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qd= ict) 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_printf(mon, "%s:\n", value->id); monitor_printf(mon, " thread_id=3D%" PRId64 "\n", value->thread_i= d); + monitor_printf(mon, " holders=3D"); + if (value->holders) { + for (h =3D value->holders; h; h =3D h->next) { + IoThreadHolder *holder =3D h->value; + + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_BLOCK_NODE: + monitor_printf(mon, "[block-node: %s]", + holder->u.block_node.data); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_printf(mon, "[qom: %s]", + holder->u.qom_object.data); + break; + default: + monitor_printf(mon, "[unknown]"); + break; + } + } + monitor_printf(mon, "\n"); + } monitor_printf(mon, " poll-max-ns=3D%" PRId64 "\n", value->poll_m= ax_ns); monitor_printf(mon, " poll-grow=3D%" PRId64 "\n", value->poll_gro= w); monitor_printf(mon, " poll-shrink=3D%" PRId64 "\n", value->poll_s= hrink); diff --git a/qapi/misc.json b/qapi/misc.json index 5fb7dcfcad..39ec19362c 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -124,6 +124,13 @@ # # @thread-id: ID of the underlying host thread # +# @holders: IoThreadHolder (QOM path or block node name) of the +# devices currently associated with this iothread. Users can +# pre-allocate multiple iothread objects to serve as a persistent +# thread pool. When a device is hot-unplugged, it is detached +# from its iothread, but the iothread remains available, allowing +# future hot-plugged devices to attach to it. (Since 11.1) +# # @poll-max-ns: maximum polling time in ns, 0 means polling is # disabled (since 2.9) # @@ -146,6 +153,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IoThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -172,6 +180,8 @@ # { # "id":"iothread0", # "thread-id":3134, +# "holders":["/machine/peripheral/blk1/virtio-backend", +# "/machine/peripheral/blk0/virtio-backend"], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, @@ -180,6 +190,7 @@ # { # "id":"iothread1", # "thread-id":3135, +# "holders":["/machine/peripheral/blk2/virtio-backend"], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, --=20 2.49.0 From nobody Sat May 30 17:44:10 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=1778508453; cv=none; d=zohomail.com; s=zohoarc; b=OCHt6uh2PwdgQFI4eao7Z3o6W4k7CSx2n3EP1nbny0OxOD8qdfuEc6Z3Ynr0mO9uxSWP9su15ZvnSycNGpk4UfmDiHx2iGpuUWaK40L1cllIYRH/2OrcZtAdtZkvyH1yrBLqnMolXr7tSEou96Nq4L0YTVNN5A/Bt5sy5DSk/a8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778508453; 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=FZb1GGPCvoF4z/BARiR0nVXitII8lcm428TmgYXryN0=; b=hcz9tg6S1VnYXoXfjUbAqYPIIJ873AX3xDT92q1LZlwzRXc1SItq1Eg8QgByWRt6/709gohoMzbjXIrELyFCFyHydROwjqWKBrNaEDO6Y4utIzn45TgPvv0J4zo0HfxQhLWQjkW8hTfFmz43rSTr9DlLDO2EwntJgLiid1x4DKg= 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 1778508453726929.948389351353; Mon, 11 May 2026 07:07:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wMRHh-0003h7-6S; Mon, 11 May 2026 10:07:01 -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 1wMRGS-0000z3-JB for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:48 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wMRGO-0007Li-3V for qemu-devel@nongnu.org; Mon, 11 May 2026 10:05:42 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2b9ea536877so25257935ad.1 for ; Mon, 11 May 2026 07:05:38 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([115.108.63.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm105113435ad.66.2026.05.11.07.05.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 May 2026 07:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778508337; x=1779113137; 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; bh=FZb1GGPCvoF4z/BARiR0nVXitII8lcm428TmgYXryN0=; b=SLqaycl8Gb9fBQhpWmJh5CXS+msUfdhrdhjB/XrRb28QOcYMCoUd22N35ridhzg4CI m3Qit9Orc6dDZYYVFSJcXMqdepyOdjVgxsecr8JAdDyxANUalRFQQqhuLf5vISTCFwXp grc+TgmCeXkcqsVys+RuIGcZycnYOM5U7gWFTRz2MJndwQkwbx13wLRMHmLzojQ4360Q IqhKX6IqjJvRseK0yq9CcfAynUittlzPxNYvYxqIzMlVMnSEwqGHcbjAkKRkRvRqZ9fF 5P2fpZgAfl+1nVjDiyRHUc7CaDgFbN1FauZCWoZIPJkHpUGuHhddNr3iPcmb+BHiHBoo 59kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778508337; x=1779113137; 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; bh=FZb1GGPCvoF4z/BARiR0nVXitII8lcm428TmgYXryN0=; b=LkN1hjNNgYvGlYWcDX/oTKhea4G2/NXrlgvdZeNzcad2e4oOWiaV23/yy05Vt6CjW7 w79K26EQRt/e1v6A8c0GSTJ8BCOR0QMeM4b4RRpbfplV4miPFQl4jh99sJXzNaQvM/S3 3Q0Gm7JM0BUY8Cf/0pRNB5xcvZuhwV53yU1IJ6obyV/sKc8FCi/9LCmiTuom1jw1E4vH 5U6t8Uh/5yJFxuoVK9c0BCjACtzAg7PTcZDZnqMEkAQSvHODUrme1zxch7s4hAKe55wv zARF/Ksos0yUuSY5S9qHzjRs8epPcokNzUOc0rD6IyKZGp80Y8ExuF6v06aaRGLBzv33 7BYw== X-Gm-Message-State: AOJu0YwELxR6yEH7qCktD8VH+tM/hAhVksP1Nv5WuyzZAJM2YBfFGsKa BT98NACXTZNOexFL5LE0wqfu9x3fCRUSYl3pjDSQ/1ob2/ILmHRplDf6oVWhgu+cga8= X-Gm-Gg: Acq92OFyl/5fIZeDE3gZOGTyGGc3X2KlxN43u9jaAFeUoN8BCjMN4BcAIwAqSagv48X vCzkPYYi17NoFDfGggWRbFRfvU99urxymb9zaSTDxJWCUW+hWjrFaXAsm3/WgzJHzChAEWcJnMl CSuWazS15k6KkUq2C7zRxCC0GEQ94qdRLmWn7l9n7O1clSCiTsJ4HEA/ruTz38NBm4KCmIMFPs0 8M8F7vwkT5Nl5R+91wGfwVcdeYE3c+gPcAGhxWJ4yuZjt66rSiZUdv6gbJQ/sM0OpOXFcpJZ9B/ m+dILVBDx9DthnCEKPNrJJKSgv29/jm//Dr5/Ab6XYJHLlP3t6kw2TZ4n9HBKyLpkOBK9RopHi2 QobSOraLL2XQ6OxOxbJJsMFLwZLQdWSbB8fb1W26ozDnsiC+UjO0PeE/86W2Tf0U55dSLP8qu9M wFgVYyq760xa1axNRCqjdJJijGNgqVy4ADfrZIxqmm5AUvPA== X-Received: by 2002:a17:902:db01:b0:2ba:76ff:57a6 with SMTP id d9443c01a7336-2babc858f46mr177992785ad.4.1778508337351; Mon, 11 May 2026 07:05:37 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V7 14/14] iothread: simplify API by merging iothread_get_aio_context variants Date: Mon, 11 May 2026 22:04:16 +0800 Message-ID: <20260511140416.28271-15-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260511140416.28271-1-zhangckid@gmail.com> References: <20260511140416.28271-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x634.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: 1778508456743154100 Content-Type: text/plain; charset="utf-8" Simplify the interface by merging iothread_ref_and_get_aio_context() into iothread_get_aio_context(). The updated function now requires a 'holder' parameter, ensuring that every retrieval of an AioContext for long-term use is automatically registered in the IOThread's holder list. Update all callers across block, virtio, scsi, net, and monitor subsystems to match the new signature. This cleanup reduces code redundancy and improves the reliability of IOThread introspection. Signed-off-by: Zhang Chen --- block/export/export.c | 6 +++--- blockdev.c | 2 +- hw/block/dataplane/xen-block.c | 3 +-- hw/block/virtio-blk.c | 3 +-- hw/scsi/virtio-scsi-dataplane.c | 3 +-- hw/vfio-user/proxy.c | 2 +- hw/virtio/iothread-vq-mapping.c | 2 +- hw/virtio/virtio-balloon.c | 2 +- include/system/iothread.h | 5 ++--- iothread.c | 9 ++------- monitor/monitor.c | 2 +- net/colo-compare.c | 2 +- 12 files changed, 16 insertions(+), 25 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index 636633c324..37bcb4f4d6 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -141,7 +141,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) } =20 holder_name =3D bdrv_get_node_name(bs); - new_ctx =3D iothread_ref_and_get_aio_context(iothread, holder_name= ); + new_ctx =3D iothread_get_aio_context(iothread, holder_name); multithread_count =3D 1; local_iothreads =3D g_new0(IOThread *, 1); local_iothreads[0] =3D iothread; @@ -180,8 +180,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) goto fail; } local_iothreads[i] =3D iothread; - multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, - holder_n= ame); + multithread_ctxs[i++] =3D iothread_get_aio_context(iothread, + holder_name); } assert(i =3D=3D multithread_count); } diff --git a/blockdev.c b/blockdev.c index 6e20579187..7eb206a02a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,7 +3683,7 @@ void qmp_x_blockdev_set_iothread(const char *node_nam= e, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_ref_and_get_aio_context(obj, node_name); + new_context =3D iothread_get_aio_context(obj, node_name); bs->iothread =3D obj; } else { if (bs->iothread) { diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 552bd8b039..f5984c86e9 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -624,8 +624,7 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice= *xendev, g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); =20 dataplane->iothread =3D iothread; - dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, - path); + dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread, p= ath); } else { dataplane->ctx =3D qemu_get_aio_context(); } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index e9f1dd5f8d..eaefd7d245 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1498,8 +1498,7 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, - path); + AioContext *ctx =3D iothread_get_aio_context(conf->iothread, path); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index cc318162f5..7b37e3d223 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -74,8 +74,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, - path); + AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread, pa= th); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index eebe202c4a..9a9059290f 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -938,7 +938,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("VFIO user", errp); } =20 - proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, pa= th); + proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread, path); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index c993281d7f..7dadc43c44 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -94,7 +94,7 @@ 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_ref_and_get_aio_context(iothread, hol= der); + AioContext *ctx =3D iothread_get_aio_context(iothread, holder); =20 if (node->value->vqs) { uint16List *vq; diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 8a4494905a..bd47ba8256 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -899,7 +899,7 @@ static void virtio_balloon_device_realize(DeviceState *= dev, Error **errp) precopy_add_notifier(&s->free_page_hint_notify); =20 s->free_page_bh =3D aio_bh_new_guarded( - iothread_ref_and_get_aio_context(s->iothread, = path), + iothread_get_aio_context(s->iothread, path), virtio_ballloon_get_free_page_hints, s, &dev->mem_reentrancy_guard); } diff --git a/include/system/iothread.h b/include/system/iothread.h index 313ef61124..cdeab63f0a 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -69,9 +69,8 @@ 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); -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const char *holder); +AioContext *iothread_get_aio_context(IOThread *iothread, + const char *holder); void iothread_put_aio_context(IOThread *iothread, const char *holder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 diff --git a/iothread.c b/iothread.c index a78744284b..d73de821c2 100644 --- a/iothread.c +++ b/iothread.c @@ -446,13 +446,8 @@ char *iothread_get_id(IOThread *iothread) return g_strdup(object_get_canonical_path_component(OBJECT(iothread))); } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} - -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const char *holder) +AioContext *iothread_get_aio_context(IOThread *iothread, + const char *holder) { /* * In some cases, iothread user need the ctx to clearup other resource. diff --git a/monitor/monitor.c b/monitor/monitor.c index b6efe776d6..0f9642f11a 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -623,7 +623,7 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool = skip_flush, */ g_autofree char *path =3D g_strdup(is_qmp ? "/monitor/qmp_mon0" : "/monitor/hmp_mon0"); - mon->ctx =3D iothread_ref_and_get_aio_context(mon_iothread, path); + mon->ctx =3D iothread_get_aio_context(mon_iothread, path); } qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; diff --git a/net/colo-compare.c b/net/colo-compare.c index 8c83da95e8..57d81f8bb0 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -968,7 +968,7 @@ static void colo_compare_handle_event(void *opaque) static void colo_compare_iothread(CompareState *s) { g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); - AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, path= ); + AioContext *ctx =3D iothread_get_aio_context(s->iothread, path); =20 s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); --=20 2.49.0