From nobody Sat May 30 17:44:06 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=1780090517; cv=none; d=zohomail.com; s=zohoarc; b=TffliekHhHDqaU4udTbwd0Tv3oAuoc6J0Kaqf5r7WJldyLSVAVd5X2z4kOrFloef3V08wpASzT2S+vGAR0ZiKZBHhB9FT6DKuBxroNB9WniT2b0OZY17wHWcdcjgTxUcGf1cOvg3q5SajIYOCO5CzH2LC4HdsoaPOvdge43F4OM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090517; 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=jFvmn5UuZdXFbB6coSJrTMP6Uu/gDUWn+Deo+FIXEjMxVgX694Nqutddb6a2YnsHEaejnx9JZBf6IfttCGWcbxt0ltqoCbNg6GTSzNHZfF6ANkBqROVZB5/NJUPmI2X9y0vUIxz34UrXXYTwendQJhU5P3pGV+JGMJOIx2JArz0= 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 1780090517374636.5768371748227; Fri, 29 May 2026 14:35:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4q6-0003HO-5X; Fri, 29 May 2026 17:33: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 1wT4q4-0003H8-K3 for qemu-devel@nongnu.org; Fri, 29 May 2026 17:33:56 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4q3-0002n4-1G for qemu-devel@nongnu.org; Fri, 29 May 2026 17:33:56 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-82f8893bff3so6707714b3a.2 for ; Fri, 29 May 2026 14:33:53 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.33.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090432; x=1780695232; 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=CpshXBPZyOA5xjJpKTVoq5E7A1o+fKvXRmCl/5ghqAjNY3FbBbCqremTsCoaf156E0 i/QwmOSTyhkiJohcHwiDQ6kwkx/wwAqYRcI9d6xnnG66Abe2X7ZRKZiwG4XWNqebZCcN cd15yikpP+wQU7Gsi06SkRs6HYz9+Xdu4lcbzmhrZGkqJVVP/u4dsHVa21m3D1/M6/6X oGawVs4+I7DS7oykjsYNPHYRP4YWeQwQs29/Te2VPXz+p3/wfwG40/+DToPai7of9V0U quqGYtvbwRMGYrrsDXHXa2GjcZ1k1Cc1J7KFs8wI2aWOc7YttbUjUoYFcL1IEcofVA5O eVoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090432; x=1780695232; 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=KxSiXeCTtWshTQ9ogNEGXoXDUX6BkAQB2mtUl0QND3H2WmV21wIXuvvAKpSJFVDutO HIG9i87cT78xC74M2aPqWlqFpHqJ99zsvLMDE0QWJru9PN7sEPVZOcHdoU/2FVqdOqBx 1f2dV/ZZtlzbNwCgmgUmTxBGl0TwgbcOrpyofgU5TTdojkCzEBGTwbiiA563BPjipdud FYjEw0DXrrFmcswv5irvW8hHA6PF2FxP2hzdqsKjNXOJSM1MAzlxI8PHswtUWgwrH3uw uuyKtidxkB7jGY7qXZ+9KiJH5dSJXSuyXD46G72APQ8eKRpjQ5JEZx5gFui//hLFWnZS Qo3w== X-Gm-Message-State: AOJu0Yzu2PziA2uxJZs3UHTPbHJ+52qFy2kaqUQHDALMBPVv6OxmycvT zRcgeWwmA+Kar1lirM+22d9h2cGeTI2R9kDyDQajW0tBSYO8C9pVip6DbSnuvvUESpM= X-Gm-Gg: Acq92OHgnhrFEgNQiyz58j1J5ExrmfjWqcRlB3vSq+CBflYF+g9frtCfgNOie+F4cHm 38hrsp5RLsNQBCe/9ikdVvyJe4B2my73a3p8JdAfUHhOXmgP0RAhCouA2paRLRwNj+wKtiJE+fM d4aXM3Po+qiN93U2k4BB0CtKBcaBgB7jl5n8APwMA+S/eu+YrT9C8LwEIDrUSdF9QtMD5+Zh0sj ImNom7+v7vi+hcbO95Driyo2CneimyxMFpFOTzfzcv/6aPTh0LJHmolk70Ns7l2myJvD92Il8Ey Gl6n/JiSulUAFXHLtxeQSg9XAI14gM8O/+STTTCFLf96RvlNuHGZTd5TesKgR/Vca7ts8q3BmyA qjTlBYd6WrAt/L2vvE4BxwRbbaI9SZG17OICNiLTeTMXYMERZ9x7QLjsfJGlZ2lzIvZ1EnBMm3w HXmno6SDuJ6L7L8kCWoor/go1lQt7l2dwXkYnMmOszz54W9+W4zXALzFWuya0gu84= X-Received: by 2002:a05:6a00:288b:b0:83e:ccd6:2dc8 with SMTP id d2e1a72fcca58-842255cf64fmr1164964b3a.27.1780090432514; Fri, 29 May 2026 14:33:52 -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 V8 01/15] qapi/misc: Fix missed query-iothreads items Date: Sat, 30 May 2026 05:33:07 +0800 Message-ID: <20260529213321.96271-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::42d; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x42d.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: 1780090518871154100 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:06 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=1780090458; cv=none; d=zohomail.com; s=zohoarc; b=fzls+f/FAWdRHe/wjN4PuSOpZ4gOQ4DCHudb1NgqP1GwfmbTRoD0cci2dIPpSHgyQU2Bc8ggpG0sxA+ii0yh7FQYi2KEzVo++z0m2nMd/dYLfr+2dgTZY87B6O4Oa0J5xOt5Ja1OhFJW+eZGCnrWaG4J6rQhNgFJlL4NgubJmU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090458; 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=H9zFq1iyzk05zoEMX2h9nWXYnORUY596qmXYMUCTaFo=; b=aijxXvxiYnr0j7sCJq9+j5NXu47KIrIiSmdKfay+GxK6ct8hOymIoF25k62jp/k6YWTWJIgw8wGjPyuK6gsL+Ynug5HXSiG8Wl06xZfLC7biNrKKJuQB6ee4OsE8O3abDvWTUUaCKqWd6YRoTANXyitKL7lCTczH+RItqaj2PwI= 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 1780090458631558.923472170743; Fri, 29 May 2026 14:34:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4q9-0003If-2J; Fri, 29 May 2026 17:34: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 1wT4q7-0003I1-7U for qemu-devel@nongnu.org; Fri, 29 May 2026 17:33:59 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4q5-0002nU-8c for qemu-devel@nongnu.org; Fri, 29 May 2026 17:33:58 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-82f8893bff3so6707726b3a.2 for ; Fri, 29 May 2026 14:33:56 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.33.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090436; x=1780695236; 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=H9zFq1iyzk05zoEMX2h9nWXYnORUY596qmXYMUCTaFo=; b=dqbeGDnm8aK6dWoVJYx63hKVfl6Oyf+VrKOX+JERDgvSNRe7ILxYrFQiLr8HRVootB F7N2oY3msd+7cANZbmsJ1q+kJSCBZs83xoDZ8+gqiHsTN2V7/wQtF5vomAG0FPNAZNlq K/ej1rPciat1ULC7fCVRtDpbRCq9kW90GVPVBCeEsrosP45Q6J6CLZmr24z/W/DriV0L ngn9atEYYwn4VM42Me3cE1IbO47hfBhKNVpc2ctsnSSOLpeVR6gPPmltWV2r3iDdUbVP gjbTUyd6HSU08IQ3vtq52PiuCHbjOmLzkxsweVYGT4pahewpU3o2s4m7wI92fIISCmxZ EeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090436; x=1780695236; 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=H9zFq1iyzk05zoEMX2h9nWXYnORUY596qmXYMUCTaFo=; b=o5XSXPy8VjX7hVi7rFww/6qVenLYlZly3orZjZLK1+a2gb8VAzW0inf0/SEwo9wd3k Jl5c29/Qu1VGftyln9PlvIVVH73NRtWoh6h10XZzi6qtrejJuzuXTyCAAfzyApNH7h3F o8SsvhgTVDMBmHY9s7tCdWzSY0ixHiV5DH6KGc4Q1dPGQkrLx1Jy/bxkgqROaPuFnnfg p1YlturOlsHdWkDy9gm2E4a78nHSvak0uzvlI1AZ2Ao0Z+pVYXiiz9uXy+fh+hLs7yot /iobgmAJPP8jZyAlsXDZKTcBdr8HAJwTRTbzxZQrg1IWInY6O6VU/n4wnhDzAVZGIpZY uUSg== X-Gm-Message-State: AOJu0YwvqohgrNSUtmJlBcgjyyIOc5QSGZMSrn73ZOUG4W1yn33FVFA6 B+sVEf2dc/XiSwCOZWWWVjlW9WBBK9RFWNoaHOzHPHziU2mF0JTzcMRRVx6IRJWOp4g= X-Gm-Gg: Acq92OFaJm4yQKSQ1Oj9Z/u8dA+s3msT2q37xj4/BvVYZiBQa2GG28MXitcefxL1Qga T+d5k6Ry2IkbMsoNq/ImA62ER5semb4aqY3mmSviJzfOF2eMbvsjQJvVZH02VPwF/4W/C09jxuz hN1kgaQEb+hhNsr+xv70w+mj0oR9C+rq2DR8RKn97raHKKjjdt8UKIQOkqGA5FFcYTWRa3i/mTJ yH9i9BlZqKzuvO0gTLjSjMx4a3BSeumhSICx/9iscm2s987Aaor2K6fcRdyw/ITCMEi5fabpHJc cX3hYltWBx1tbYSVR0hy/IeoayoNZf2vDSzOAp1jamWprBWEsh+Opk0xC/tlIatwMW7FPV6PRTg 4Aic0CXOCGMkw+2igtd01zUEF97vUS0xCE9qOLBciJoC51AnBPsr/n57Cq1esVBmtAB/eviPo5N zz42CVgEPPDsJDNOTNjnEv0/2Kp/Wbhs5XkLnw+hITZFp6/Ko9/Y7qFkr8PftfmTPifL9Bs1dub Q== X-Received: by 2002:a05:6a00:b8f:b0:838:a932:de26 with SMTP id d2e1a72fcca58-8422538611fmr1121728b3a.1.1780090435682; Fri, 29 May 2026 14:33:55 -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 V8 02/15] iothread: introduce iothread_ref/unref to track attached devices Date: Sat, 30 May 2026 05:33:08 +0800 Message-ID: <20260529213321.96271-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::434; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x434.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: 1780090460602158500 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 IOThreadHolder to a list. - iothread_unref(): Searches for the IOThreadHolder using a custom string comparison (g_strcmp0), releases the associated memory upon a successful match. - holders: A GList storing the IOThreadHolder 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 | 94 +++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 61 +++++++++++++++++++++++++ 3 files changed, 160 insertions(+) diff --git a/include/system/iothread.h b/include/system/iothread.h index a1ef7696cb..b9207ad829 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..3301b8d495 100644 --- a/iothread.c +++ b/iothread.c @@ -25,6 +25,92 @@ #include "qemu/rcu.h" #include "qemu/main-loop.h" =20 +/* + * iothread_ref: + * @iothread: the iothread to track + * @holder: the IOThreadHolder object initialized by the caller + * + * Add the @holder to the iothread's tracking list. + */ +static void iothread_ref(IOThread *iothread, const IOThreadHolder *holder) +{ + assert(holder); + IOThreadHolder *h =3D g_new0(IOThreadHolder, 1); + + h->type =3D holder->type; + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + h->u.qom_object.qom_path =3D g_strdup(holder->u.qom_object.qom_pat= h); + break; + case IO_THREAD_HOLDER_KIND_BLOCK_NODE: + h->u.block_node.node_name =3D + g_strdup(holder->u.block_node.node_name); + break; + case IO_THREAD_HOLDER_KIND_MONITOR_NAME: + h->u.monitor_name.monitor_name =3D + g_strdup(holder->u.monitor_name.monitor_name); + break; + default: + g_assert_not_reached(); + } + + iothread->holders =3D g_list_prepend(iothread->holders, h); +} + +static int iothread_holder_compare(gconstpointer a, gconstpointer b) +{ + const IOThreadHolder *holder_a =3D a; + const IOThreadHolder *holder_b =3D b; + const char *name_a, *name_b; + + if (holder_a->type !=3D holder_b->type) { + return -1; + } + + switch (holder_a->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + name_a =3D holder_a->u.qom_object.qom_path; + name_b =3D holder_b->u.qom_object.qom_path; + break; + case IO_THREAD_HOLDER_KIND_BLOCK_NODE: + name_a =3D holder_a->u.block_node.node_name; + name_b =3D holder_b->u.block_node.node_name; + break; + case IO_THREAD_HOLDER_KIND_MONITOR_NAME: + name_a =3D holder_a->u.monitor_name.monitor_name; + name_b =3D holder_b->u.monitor_name.monitor_name; + break; + default: + /* + * This should not happen. If it does, name_a/b remains + * NULL and g_strcmp0 will handle it safely. + */ + name_a =3D NULL; + name_b =3D NULL; + } + + return g_strcmp0(name_a, name_b); +} + +/* + * This function removes the @holder from the @iothread's tracking list. + * The @holder 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 IOThreadHolder *holde= r) +{ + assert(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; @@ -356,6 +442,14 @@ char *iothread_get_id(IOThread *iothread) =20 AioContext *iothread_get_aio_context(IOThread *iothread) { + /* Remove in next patch for build */ + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)"tmp_path", + }; + iothread_ref(iothread, &holder); + iothread_unref(iothread, &holder); + return iothread->ctx; } =20 diff --git a/qapi/misc.json b/qapi/misc.json index c71a5fe657..d9f82f0922 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -67,6 +67,67 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 + +## +# @IOThreadHolderBlockNode: +# +# @node-name: A block node. +# +# Since: 11.1 +# +## +{ 'struct': 'IOThreadHolderBlockNode', + 'data': { 'node-name': 'str' } } + +## +# @IOThreadHolderQomObject: +# +# @qom-path: A QOM Object. +# +# Since: 11.1 +# +## +{ 'struct': 'IOThreadHolderQomObject', + 'data': { 'qom-path': 'str' } } + +## +# @IOThreadHolderMonitor: +# +# @monitor-name: A HMP/QMP monitor. +# +# Since: 11.1 +# +## +{ 'struct': 'IOThreadHolderMonitor', + 'data': { 'monitor-name': 'str' } } + +## +# @IOThreadHolderKind: +# +# @block-node: A block node. +# @qom-object: A QOM Object. +# @monitor-name: A HMP/QMP monitor. +# +# Since: 11.1 +## +{ 'enum': 'IOThreadHolderKind', + 'data': [ 'block-node', 'qom-object', 'monitor-name' ] } + +## +# @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', + 'monitor-name': 'IOThreadHolderMonitor' } } + ## # @IOThreadInfo: # --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090469; cv=none; d=zohomail.com; s=zohoarc; b=d6l/GFX6eEPdy73vDFo+MOdClvygs2WpYGw54FYx5roW/Fu1VQ9klSxkMae4CyctfF95DGLbqLuHnlI/+WRC3zBOhDfwN+doAvL1lqn++qo9DmV9xC/JPCCHAXmkSWdU3eyfBwQliXY3FMxgJz6n/BWQL1dCgAuwS8STC/7MDCg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090469; 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=lSVN7N0tEjZKy75a4H0lIBwRWq1dCfq0ezm3QlZHeNQ=; b=cEJpAVQA51aI7goZhE5BEJDmHGCXL4rfZgv2kGibwcztL4zgDDBX20fTU54jtRiQfAzl7HFpHtmACN3OfUcvKd735Ole/1GTP8dIoO6j9SPp8QcumaSzu0O60x2nKqPfKtRGFgqsQnMMLRhZBTu8TGJ+e9UMpo9zNIOk39Ao82A= 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 1780090469095638.0727991383955; Fri, 29 May 2026 14:34:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4qC-0003J9-A3; Fri, 29 May 2026 17:34:04 -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 1wT4qA-0003Im-Ae for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:02 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4q8-0002oT-GT for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:02 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-84229481d44so60010b3a.0 for ; Fri, 29 May 2026 14:34:00 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.33.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090439; x=1780695239; 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=lSVN7N0tEjZKy75a4H0lIBwRWq1dCfq0ezm3QlZHeNQ=; b=GT5SsdAAb/CvoZEm63yE4FRHWI0XHDZNxzvz452eHoHAjvprAAqXWtJ3nQoLLrZlNf hoizac+DZg/VfGva6nkdCC1+Otbh0Lja86yeJsNgNFPeOlPZziEgxpQKrGqpg0MgXId6 AL+P61a+kkOgVDEeebd/8MVadhF/eR+b+5bo4eFugcjQhrYbwhsfjTQGEAjW6mQ0Oixd Sg7ZTAWZRfguIJYp2KQK5BPgDtLiuYwVQrPj2C7Mj8xOvcQZkToJpF8uILC2B8hK/Cur rl3Bs+khvd2P0i72yQEaOmKF9rmWD4Yc6avlwayLAPrDe70DZGFr947UNj1FKPqnptN4 PJYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090439; x=1780695239; 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=lSVN7N0tEjZKy75a4H0lIBwRWq1dCfq0ezm3QlZHeNQ=; b=iI+A6RrWjnA8yUa5+9eEs9qT0E/rpEM5Hb+I5erIgLUvBe9IBmqYjVrPXzCwftjAMS qnTwLjopmTW4+GmsHv6e9iNAieIT0sFF3m5lQQ0wsTEjFBwwphNGZDdpSTPdbuM+pG7v Fd2Pbf+sVFpRHiwQSJQt4ONRoqW4IqL8sMd0ulgIq+7TfPb0ZcFpPMvAC3WI72qH3Q41 NunLfvcNNpzcgePaUJ6YCHQrC7Ajmzby67C9293gm4sNzTlBf4G5+a1Uf/HreKI1239u wfAhRzvk0b7ovw5vCMF4Os59UkN25ow538M5I2PyZ9HPOMuTtJlZ7RdSb/RVY/RTqSIK 0ewA== X-Gm-Message-State: AOJu0YxOa8WsRFd3epSTRTSt8K5gAiQeRKo+Y0rV/x9QWQGy4fSGtM5l 5jnp85jdyaMYCGBvGdlIzo2WLgXKP9Rf6wZ+fwjYhOI+9+PR0KKlA+8PN+EwIaIagiw= X-Gm-Gg: Acq92OFgLyRYikzO1hNk9lSPuCkXWrelzE0k6SqVAhzmI316CEnGB9H2dFoL5teeFED wv4fjZyd3xoXO/PJkAf89gFUfMgBMgqrWj5Z6rhckbDOd2dEZWVVbvThHRBUrVFkGoHxgCwlkZY 0DpAB/G/TWHfQiUJJScdn8iIMyCvPzU20WpU1F7lnLBHO1dl65hmei4zVHDmG8xkkju9Lssh9tk L1ppjdap2vj2eQ6CG7WuE9MHbIBCxK9RstL77wKqezlvbxXVbcke6ZA+xYCGVxiJ343wWFYxUIC cQwFvGxBowbDrrIrhRfyEqnXL+rabJ66uOtdbTsdqYq3hDA8buOKiZKIGj6yOZK/LEvkOf7J41M wmc8XKGi40mqlnbP3tOdHMczq5OSNLsjXPHjcrHj6VItL9qoDZrfQ8Kvv1VQmvIOGIO4AGCQER3 az17GvG9e80eCRIrYd+yxW1bN16Bjq9KSYrdsZiclDDU2X1Faf8J11+4nCk0n+RAA= X-Received: by 2002:a05:6a00:3904:b0:82f:de7:d29 with SMTP id d2e1a72fcca58-842256d563fmr1234542b3a.31.1780090438981; Fri, 29 May 2026 14:33:58 -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 V8 03/15] iothread: tracking iothread users with holder name Date: Sat, 30 May 2026 05:33:09 +0800 Message-ID: <20260529213321.96271-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::432; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x432.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: 1780090470726158500 Content-Type: text/plain; charset="utf-8" Introduce iothread_get_aio_context() (In this patch named "iothread_ref_and_get_aio_context" for build, will change the name in the last patch) 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 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 | 4 ++++ iothread.c | 31 +++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index b9207ad829..b483bbfab3 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -18,6 +18,7 @@ #include "qemu/thread.h" #include "qom/object.h" #include "system/event-loop-base.h" +#include "qapi/qapi-types-misc.h" =20 #define TYPE_IOTHREAD "iothread" =20 @@ -70,6 +71,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 IOThreadHolder *holder); +void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 /* diff --git a/iothread.c b/iothread.c index 3301b8d495..528002c34a 100644 --- a/iothread.c +++ b/iothread.c @@ -55,6 +55,12 @@ static void iothread_ref(IOThread *iothread, const IOThr= eadHolder *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) @@ -109,6 +115,8 @@ static void iothread_unref(IOThread *iothread, const IO= ThreadHolder *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) @@ -223,7 +231,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); @@ -442,17 +450,24 @@ char *iothread_get_id(IOThread *iothread) =20 AioContext *iothread_get_aio_context(IOThread *iothread) { - /* Remove in next patch for build */ - IOThreadHolder holder =3D { - .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, - .u.qom_object.qom_path =3D (char *)"tmp_path", - }; - iothread_ref(iothread, &holder); - iothread_unref(iothread, &holder); + return iothread->ctx; +} + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Add IOThreadHolder to the list */ + iothread_ref(iothread, holder); =20 return iothread->ctx; } =20 +void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder) +{ + /* Delete IOThreadHolder 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:06 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=1780090489; cv=none; d=zohomail.com; s=zohoarc; b=hBg+U78iITEQBByyn2QMkAhb07TVOteKPHV7TjbTAxy4X+x6UxxUyAnIZBuxOVFuj2iX88rKs9it6D5wH64Cb6btmEGGq8aIN+sAzSpiodvBS630og8dvlJiussimNMxxNuHRc0AaGHEfP3E0MUScfVzZ6Hu45+QRWxq7AKKyr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090489; 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=tDeHKlljfDpSkFWWN2SnpQW0cIV42Ft5R4hhaWwRewI=; b=cBhviGFBMpnCEd5XeZHO1gPOER03HtR1Yf2Se7RgW1CuUls65xdQA9S+AndhXhUkN4Kv+r1L6yBSc6oIjYeDxMoO3FiaYBx1u4Rcl9SX0st3W561rDGA9IdMV72rlQs2LL4gOBz/SijZxtvMR7hGnvjB5/ly+L8FBnWdwvOVvx4= 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 1780090489461558.7242260505745; Fri, 29 May 2026 14:34:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4qE-0003JY-Td; Fri, 29 May 2026 17:34:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT4qD-0003JK-Uj for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:05 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qC-0002p2-6Q for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:05 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-8422c327755so5506b3a.2 for ; Fri, 29 May 2026 14:34:03 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.33.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090443; x=1780695243; 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=tDeHKlljfDpSkFWWN2SnpQW0cIV42Ft5R4hhaWwRewI=; b=QvsLB6he1OB/yWjdkb2DfYhkKeGGsM/eqYxphU/GKFag3VtGFn4P3sSk6OpFdlOXrQ 3hxT+S1Rx/5Y0lmfcuOYDA1u3mpt/1ePmIwGO3ZUDI+VQG8G9NAoAX4uFh9sG/6VwUrZ Rs1LmQ/daL/+nTJlIwzTvC5K8dSjKYZErEMf6pS3u16O9y9kPX3/hGRFlX1EJSH9Wn0I GaBa6xWWZxKepEhcVvxPLnEksXLi1/PdfAig4zrr640kJZ3NfUbWvFdFYHdCVopsbeFT qteMFJwtpSOCJPgpCxy0b+TWjZwmeSSt9RrFabz0c9EFvw2enD4d1HhWe/uRThULXXe5 HZhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090443; x=1780695243; 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=tDeHKlljfDpSkFWWN2SnpQW0cIV42Ft5R4hhaWwRewI=; b=SyZmUHwTBrQaR0/9DxT2h4qxzzBLVntfREhkl8raCKwkiq5gAALQYu30vt3wmeZSJ0 OaDBxpHVvJh9dX9KeHRFIlybR0cfc3Tiq4YeISaVp2D9MACT+iZ+0wpHzSa+H4JPEfBM ObpuwECweK2AmBYmHp7eRtCwV9KAlGy/LjoFEyLqWZdrwzASVFqLct8tBM0xe7ukHk0Y fhYSBcKpmfRhaOjHEdvDtgnsmwUsZAy4XdXwXsd4xxYceHJnWlfguS8zwCY5XTVfwRHo brgHO9AlV9E7ElyBgWEbclymcXBN0fqhkR3ssaOcZV5xSPCKtTrimp0XBs/snsIrSgGa CJvA== X-Gm-Message-State: AOJu0Yw/xgAzh/BiIMA2uaZiThMjlNOnPaj0o4NlOGtHndcraFEzXEz1 dN0hqBkzMjkr+2P1Jw4bCdIMSwb5EPlLv3OszuG5CVCTcZ7RIriqECI/AIeuMPxvJUs= X-Gm-Gg: Acq92OGhMmyzUzPjd/MIbtTr8cBXgUe7X9mKI9TA/F6NOVKUt14z0Gj3BDaOlq0ymgy allLCgDDwLp3+OGBn3ALDImpwlWuLVSl7wxdcKK+m/vKqgWhrR7+vcKWa2AW9RChktjs8PP19LA kQK4cxC2xho8DBRBCqNwzfm2tcPIqMem8hBbQJgDaOlU9HQWekV6v23AugV9EEPNwpzvo4EDTiG ZgNW7rUvtASMbDuBM/zk7mll0F95d7wFaGwogBGjPSj5pAOva+lLgAoA9w+wT/PHKe+TUXzvqbC OuGgo3b9VeQM/K9bHjHQrnf0LhpUOeEoEynpRjggnxbI0dCYE4Hz4xP8bSUSuKy3E6JXAeqddqX qC0DLMYAOsAZ0CytoD5EaaEUS9Edg7BALIXdHXQ+pkeNPMtq+tnhpsx++FDoGXJuxFxysov3yWJ 7cjrW7lI8eyLXB4wJ1YDVPQSQbYz5W4dnLffZwRKkZwIYG1pMpdreEmKt8DvtaIcZzLFbezpHqo w== X-Received: by 2002:a05:6a00:8c5:b0:83e:eeab:aff8 with SMTP id d2e1a72fcca58-8422543c27cmr1143929b3a.25.1780090442962; Fri, 29 May 2026 14:34:02 -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 V8 04/15] iothread: introduce iothread_unsafe_get_aio_context() Date: Sat, 30 May 2026 05:33:10 +0800 Message-ID: <20260529213321.96271-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::432; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x432.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: 1780090490600154100 Content-Type: text/plain; charset="utf-8" The iothread_unsafe_get_aio_context() is a low-level unsafe way of getting the AioContext, recommend migrating to the new API with IOThreadHolder as much as possible. The blockdev is the first user: Every BlockDriverState would need to get/put the IOThread AioContext in bdrv_change_aio_context() or related functions. However, the QEMU block layer has been moving away from having a per-BlockDriverState AioContext. It is possible to use a BlockDriverState from any AioContext (including multiple AioContexts at the same time). I'm in favor of not associating BlockDriverStates with IOThreads and instead relying on their device owners (e.g. emulated storage controllers) to be the IOThread holders. Signed-off-by: Zhang Chen --- blockdev.c | 2 +- include/system/iothread.h | 6 ++++++ iothread.c | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 6e86c6262f..baeab3a3e1 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_get_aio_context(obj); + new_context =3D iothread_unsafe_get_aio_context(obj); } else { new_context =3D qemu_get_aio_context(); } diff --git a/include/system/iothread.h b/include/system/iothread.h index b483bbfab3..064c05e78d 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -71,6 +71,12 @@ 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); +/* + * The iothread_unsafe_get_aio_context() is a low-level unsafe way of gett= ing + * the AioContext, recommend migrating to the new API with IOThreadHolder + * as much as possible. + */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, const IOThreadHolder *holder); void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); diff --git a/iothread.c b/iothread.c index 528002c34a..a85e960e45 100644 --- a/iothread.c +++ b/iothread.c @@ -468,6 +468,12 @@ void iothread_put_aio_context(IOThread *iothread, cons= t IOThreadHolder *holder) iothread_unref(iothread, holder); } =20 +/* Recommend migrating to the new API with IOThreadHolder as much as possi= ble */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread) +{ + return iothread->ctx; +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090566; cv=none; d=zohomail.com; s=zohoarc; b=IM3QZ2P3DIz00rCjrZ/0c75RMFbksONmaIJ9VCaFuZhE4IBxMfSr7ttuVMubHv9en3IQxE2RuBtZWChltW5VY1mTVOs1AmKS6qOfVWINJuY5KpTj2P2ZSiVE1DEMbiMQLsB7rkiMOZWVSPvQcrFNXTlnnVPtwjmgJxuPEAsAjew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090566; 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=L2I8RSgxtS6zilF0lFLp60gipvFmJj5Si+EneANHl4s=; b=P+KyovIRhNcUozlizJsJmDLDF6AzzMnu1vAIclxhQFA/7cy5aH93HAEQGIdZphjCid2gfUZg7leqvKHzqZZrtppO46XN4U6W9RclFdH8tXY1egTlBxIV669B7wlUFnfmM8YaZyZO1k+iWAdtjlyJR45abQwFJNnBDMeP5/OSPE4= 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 1780090566354113.78714676608456; Fri, 29 May 2026 14:36:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4qI-0003Jy-66; Fri, 29 May 2026 17:34:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT4qH-0003Jq-1T for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:09 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qF-0002rN-6j for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:08 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-842264dde84so108301b3a.0 for ; Fri, 29 May 2026 14:34:06 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090446; x=1780695246; 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=L2I8RSgxtS6zilF0lFLp60gipvFmJj5Si+EneANHl4s=; b=YUaCAqVk5ioJVxtKX+FjcdkhzPnD2wjoUvcjQzrSL3HeDxkBCy9OmZLTPwZ2FpA8YG xCuzdYz8fVZaaBRFrVpO4TGsfd4rFuhkJ2O6x8kQi1XKu60ojirneGrJAREIesFUThiB K4AJqxRQ/SzURUZEdhJ7iKIWNj36I2OSh9PHVr2Oh9Y0zbNdpLEwLCtY6xL+YlscZLcX G4E0UXWhjGG5wz/8iyVYxAr5cQ7IKg4fLJ495Uj27sr+8j3sfN/Bv/MyurbN6rk9WeR2 1SCCY3DNS+JJ0lZdVKIm5c29Lbwv602eX7k4/kk85PewSXArdMwkYU/J4B8QLkA7R+Ry tSZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090446; x=1780695246; 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=L2I8RSgxtS6zilF0lFLp60gipvFmJj5Si+EneANHl4s=; b=Xwc3/QKvfkCt6LECCRvj2AqgNsyI5Lg9ypGrxSISpKCdn0PBXwcqRLa2kJqTG05BqF bpz8TozknX9SJ8HcWAKtTj8Smml2cxe+IYRNF77wZ5K1x53NkNCWqb0/YCjuB5IeNE0c tthagIXo5cBNS3h2VficMLEmTc7zoDaDDM34Sn4AymyGJXdWR1HO9abo4/GmoAsDFB9x PNDU8MKthMcOzC1D5dQoEXzAdlmxz5sup7QCyOyC7lCfjzpy2H5YqIGgWqNUE+9kdlx8 WgnuhBAjXnBeWgyEkhPGxDtwZ0eWG9UMogzvAffru8EF28jaQxfxkQ31svPJtDHdJI0G eVNQ== X-Gm-Message-State: AOJu0Yw2veHRkOdPCc14q1YGw23/hfP0I98YMCXGflLU5P3+qQkR7M+h o919yAS81ZFZsqCSgi9frssjt89FffulFD4U0eCv4ab9CCp4lOA/LAsa8Bk2omHrjus= X-Gm-Gg: Acq92OGGr9asCo4vmRHP7Cpi9PVd1C57basGK8p32opH0XjjCpSwXRHZire59SbpyeB tcOjHzSb6+gqAh+sWfeXJp5pgrFMyuX22fP77D+F8cz3Mmoep3cwnpbjIwSoWGuGNeSxMgUG3S5 PkEUJjrKtw61ySyfZKmb5lJIhlOe2FdqbW9/+NpMzzrPq8fNV2bC2u+Gvmn68tNP6DUKlo/kn/a rj6WDstHPYkG1kmUUNsAE2qvgfGA24n0229yg2DGtF3SG+UqrWcRVmCFHtOtI63N+EAiPpQ+PC2 jJ0gEX+DiWOzDec5hKwU4hzsxzfN2Pxhf8xqPFKEvIwtaSi4saAS39Oi1Jt+Y1ckYpE/VmG/pLC c2O1INfbEv+JJUEngXTUH4suPgOcrhZuWThKbVo+pJ7i4IoW7qw8UA8lCZRYG0lvzB6q4CXE233 J531q5UvlQNMWEWPgBS3X3ywfdwN7S4R5SQem7CFTFU/xwKLQZtdOuqmrb7/8FNkc= X-Received: by 2002:a05:6a00:2d8f:b0:835:3f9c:c681 with SMTP id d2e1a72fcca58-84210d462c3mr4150507b3a.34.1780090445786; Fri, 29 May 2026 14:34: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 V8 05/15] block/export: track IOThread reference in BlockExport Date: Sat, 30 May 2026 05:33:11 +0800 Message-ID: <20260529213321.96271-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::434; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x434.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: 1780090567020158500 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 | 63 ++++++++++++++++++++++++++++++++++++------ include/block/export.h | 6 ++++ 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..b6c07f69b5 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,16 @@ 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); + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE, + .u.block_node.node_name =3D (char *)holder_name, + }; + + new_ctx =3D iothread_ref_and_get_aio_context(iothread, &holder); + 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 +173,15 @@ 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); + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE, + .u.block_node.node_name =3D (char *)holder_name, + }; + for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,7 +189,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, + &hold= er); } assert(i =3D=3D multithread_count); } @@ -225,12 +244,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 +275,18 @@ fail: g_free(exp->id); g_free(exp); } + if (local_iothreads) { + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE, + .u.block_node.node_name =3D (char *)holder_name, + }; + + for (size_t j =3D 0; j < multithread_count; j++) { + if (local_iothreads[j]) { + iothread_put_aio_context(local_iothreads[j], &holder); + } + } + } g_free(multithread_ctxs); return NULL; } @@ -269,6 +303,17 @@ static void blk_exp_delete_bh(void *opaque) BlockExport *exp =3D opaque; =20 assert(exp->refcount =3D=3D 0); + if (exp->iothreads) { + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE, + .u.block_node.node_name =3D (char *)exp->iothread_holder_name, + }; + + for (size_t i =3D 0; i < exp->iothread_count; i++) { + iothread_put_aio_context(exp->iothreads[i], &holder); + } + 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:06 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=1780090582; cv=none; d=zohomail.com; s=zohoarc; b=kmIuT/oHx6/37c6nv7CVSUgNGIiL1hKqtW1LowRotHxjasebFTzDuQKjYIlCttRe/8Psz4iMMNswHxKjQ/Y9gYA8i6Xe0THKWOq3TRl31SWNt6CZ70NnYC0D76b5ctqfUH9nXdsg41gPU+5IL1tRsC8clDKvE290w4B2o4FTzFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090582; 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=SPhJtyZeuePVp/bJ9HJteGXBpxV9dgehSXmY6hUppoA=; b=CkFdwx3svVytNXrPzvXqBobOnYmIEHDTdgUzgtwju8XvzDPONj2ybHiY/9qIe/HNFuWOWZ335458SAjysN5iWtw1F1Z1YW2w//E95sh7gi/F0KaHntoUhgOyO1rBWgTvXO2LZg5VRCAGE8Y/a18jAEYu6gBsMXfaM/mEjqUapH0= 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 1780090582126815.7022949526021; Fri, 29 May 2026 14:36:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4qM-0003Kh-Ql; Fri, 29 May 2026 17:34:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT4qK-0003KK-8B for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:12 -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 1wT4qI-0002uM-9K for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:12 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-c855599a77aso1709690a12.0 for ; Fri, 29 May 2026 14:34:09 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090449; x=1780695249; 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=SPhJtyZeuePVp/bJ9HJteGXBpxV9dgehSXmY6hUppoA=; b=nKxYeMRNKtYZzrJnzyM3n0eNWWLyRpWU+W3jOBo6jIsle7zgSiy7hMnQ9wKRvvW0Wu K8IdcGJw8ROU9TgarOsJzghbvsLa95UgPl8QNZc3knXB5N+HNk3OscvWbPgOPWLOOBaT EL73sRJj1t+yPqosomDZ4AvEhYyzevEe0UamEvf0J9HbU2O9A+nyICLc/bJ+pjPBwmth RMl0krSvHrNqMs5h3/hdPOzwyZNapwOTJuMX6fseu503P4ldhCUK0rHstfOyy3WCRoyQ GN8Iz4Fx+qBHAtM7aw+dU5WGZTFErW/GZwXdykFU2+rD8gClAArCu0LUKw8/h2SgdTKI WU3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090449; x=1780695249; 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=SPhJtyZeuePVp/bJ9HJteGXBpxV9dgehSXmY6hUppoA=; b=qIexhsU997g1PuupeivWyiKZ9KbtmmQnB3bAx4Uih/pYcIaMf/ZuHaOIKfQQh9rlFR drY8+TeWCzDB12jUoyhfpzcTqM1DVjLzGosF3aBwyn0/JbD/GTsSkaNxYrXDZHopr1q6 e7sIuGLSy5uMlFRK0NiW0sgjZibgyg6YOY7FgeiYstcQny0hgzsZDDKPur/iiy9st9zi 02UUps/eBf9/7sYYpuAbwHnts+rKTiGeD8Zsgpz/56npTKP11HfkhGH1sHisPAxMPrKJ yhGNgTtVa0gMNjvvbY0nbweBRzI7X34iKflV2k+wIlbcD0sMpPv0xG2ezviHL2+Jnycm L9lw== X-Gm-Message-State: AOJu0YwHu7S624pAdG/uXVbsgseewn823b5Q2Nx4xnQ1WLvWxBbf0tiq DqQydx+k8idWoMJBExdkSZu0ZObDU/Zm9kKFUBhb398V5IDfrYp6F9uPgk4ajC1FkVA= X-Gm-Gg: Acq92OHm2AM+eajPhcA0jDZhqzWFoMkOlOpo4g4d66AbOaHvdfxxRlieotuV3b9XLpk yOcOL3+43C5cr7IAkKm0h6+vAG/R+gkDhgFjWmqn61EA+iKEm2aNjR4h9SZZVA+AtEQTGNa1P17 eLhIRHk80/Vhp5bq5ucf8HDCpQgRzTDzeW+C3Dcf/QEg8KlZSZTSy+E44DRYGx8bJvMABjg1TXr dIfvyJueHfTvpUUYDF26NIImNfzPaZfSKymbdR20gXVkVNd4VKaJWuKGnmqaN6KzdPVnTUwSnox FRGv8eLKQtGa8m7ciZWpnfQn5pLlhzhd0Ow/7+PsCyvlZmLpYGo90g4jvg8TQ2irnZNMEU9hE39 HXX+sO2XZVhIaQzWdAvp4pFXElrgYK0eEK8og9uzS/g+3bGhyYiHE9cF9sMwHsxhh1xsiOk4H5m Jwk7gwY9cGNaxa6Dt7dxKy6lXocniZGMd6xCtSY83Orv7LoUf4aJon7btvHr9v0R6CDwmc4q0GB w== X-Received: by 2002:a05:6a00:1a86:b0:841:89a4:5f86 with SMTP id d2e1a72fcca58-842253d6038mr1154021b3a.21.1780090448706; Fri, 29 May 2026 14:34:08 -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 V8 06/15] monitor: assign unique default ID to anonymous monitors Date: Sat, 30 May 2026 05:33:12 +0800 Message-ID: <20260529213321.96271-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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=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: 1780090583926154100 Content-Type: text/plain; charset="utf-8" Currently, dynamically or implicitly created monitors (such as those generated via '-monitor stdio', GDB stub terminals, or mux chardevs) leave the 'id' field in the Monitor struct as NULL. But the original @MonitorOptions have the @id field. This makes it difficult to track, debug, or associate monitors with specific iothreads or infrastructure components. Fix this by introducing monitor_get_id(), which uses an atomic counter to generate a unique fallback name ("mon_default_X") when 'id' is not explicitly supplied in MonitorOptions. Update all internal HMP and QMP initialization paths to propagate and store this string. Signed-off-by: Zhang Chen --- chardev/char.c | 2 +- gdbstub/system.c | 3 ++- include/monitor/monitor.h | 6 ++++-- monitor/hmp.c | 20 +++++++++++++++++++- monitor/monitor-internal.h | 2 ++ monitor/monitor.c | 4 ++-- monitor/qmp.c | 18 +++++++++++++++++- stubs/monitor-internal.c | 3 ++- 8 files changed, 49 insertions(+), 9 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index ca8b37ed8d..f057247001 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -805,7 +805,7 @@ static Chardev *qemu_chr_new_from_name(const char *labe= l, const char *filename, =20 if (qemu_opt_get_bool(opts, "mux", 0)) { assert(permit_mux_mon); - monitor_init_hmp(chr, true, &err); + monitor_init_hmp(chr, true, NULL, &err); if (err) { error_report_err(err); object_unparent(OBJECT(chr)); diff --git a/gdbstub/system.c b/gdbstub/system.c index e86c5870ab..50f934fde3 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -388,7 +388,8 @@ bool gdbserver_start(const char *device, Error **errp) /* Initialize a monitor terminal for gdb */ mon_chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_GDB, NULL, NULL, &error_abort); - monitor_init_hmp(mon_chr, false, &error_abort); + + monitor_init_hmp(mon_chr, false, NULL, &error_abort); } else { qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); mon_chr =3D gdbserver_system_state.mon_chr; diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 55649a8664..c6ccd34cda 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -19,11 +19,13 @@ bool monitor_cur_is_qmp(void); =20 void monitor_init_globals(void); void monitor_init_globals_core(void); -void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp); -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp); +void monitor_init_qmp(Chardev *chr, bool pretty, const char *id, Error **e= rrp); +void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id, + Error **errp); int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp); int monitor_init_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); +char *monitor_get_id(void); =20 int monitor_suspend(Monitor *mon); void monitor_resume(Monitor *mon); diff --git a/monitor/hmp.c b/monitor/hmp.c index cc4390486e..47f57f69e5 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -43,6 +43,8 @@ #include "system/block-backend.h" #include "trace.h" =20 +static int mon_hmp_id_counter; + static void monitor_command_cb(void *opaque, const char *cmdline, void *readline_opaque) { @@ -65,6 +67,14 @@ void monitor_read_command(MonitorHMP *mon, int show_prom= pt) } } =20 +static char *monitor_hmp_get_id(void) +{ + int id =3D qatomic_fetch_inc(&mon_hmp_id_counter); + char *name =3D g_strdup_printf("mon_default_hmp_%d", id); + + return name; +} + int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func, void *opaque) { @@ -1522,10 +1532,18 @@ static void monitor_readline_flush(void *opaque) monitor_flush(&mon->common); } =20 -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) +void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id, + Error **errp) { MonitorHMP *mon =3D g_new0(MonitorHMP, 1); =20 + if (!id) { + g_autofree char *mon_id =3D monitor_hmp_get_id(); + mon->common.id =3D g_strdup(mon_id); + } else { + mon->common.id =3D g_strdup(id); + } + if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) { g_free(mon); return; diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index a5c4aba306..2060311b03 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -108,6 +108,8 @@ struct Monitor { bool skip_flush; bool use_io_thread; =20 + char *id; + char *mon_cpu_path; QTAILQ_ENTRY(Monitor) entry; =20 diff --git a/monitor/monitor.c b/monitor/monitor.c index 00b93ed612..dafb4ad8b0 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -732,7 +732,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, = Error **errp) =20 switch (opts->mode) { case MONITOR_MODE_CONTROL: - monitor_init_qmp(chr, opts->pretty, errp); + monitor_init_qmp(chr, opts->pretty, opts->id, errp); break; case MONITOR_MODE_READLINE: if (!allow_hmp) { @@ -743,7 +743,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, = Error **errp) error_setg(errp, "'pretty' is not compatible with HMP monitors= "); return -1; } - monitor_init_hmp(chr, true, errp); + monitor_init_hmp(chr, true, opts->id, errp); break; default: g_assert_not_reached(); diff --git a/monitor/qmp.c b/monitor/qmp.c index 687019811f..b210850a15 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -56,6 +56,7 @@ * Access must be atomic for thread safety. */ static bool qmp_dispatcher_co_busy =3D true; +static int mon_qmp_id_counter; =20 struct QMPRequest { /* Owner of the request */ @@ -76,6 +77,14 @@ static bool qmp_oob_enabled(MonitorQMP *mon) return mon->capab[QMP_CAPABILITY_OOB]; } =20 +static char *monitor_qmp_get_id(void) +{ + int id =3D qatomic_fetch_inc(&mon_qmp_id_counter); + char *name =3D g_strdup_printf("mon_default_qmp_%d", id); + + return name; +} + static void monitor_qmp_caps_reset(MonitorQMP *mon) { memset(mon->capab_offered, 0, sizeof(mon->capab_offered)); @@ -513,10 +522,17 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) monitor_list_append(&mon->common); } =20 -void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) +void monitor_init_qmp(Chardev *chr, bool pretty, const char *id, Error **e= rrp) { MonitorQMP *mon =3D g_new0(MonitorQMP, 1); =20 + if (!id) { + g_autofree char *mon_id =3D monitor_qmp_get_id(); + mon->common.id =3D g_strdup(mon_id); + } else { + mon->common.id =3D g_strdup(id); + } + if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) { g_free(mon); return; diff --git a/stubs/monitor-internal.c b/stubs/monitor-internal.c index 4fece49d53..325a559e62 100644 --- a/stubs/monitor-internal.c +++ b/stubs/monitor-internal.c @@ -8,6 +8,7 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **= errp) return -1; } =20 -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) +void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id, + Error **errp) { } --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090513; cv=none; d=zohomail.com; s=zohoarc; b=Qp6R/Td6gBienDbb0ttxuxjqOmW/ZORe5s06EyB6r5AJxiQmYiktlj+odimi+GQ5qJkL/+JoCgwEHuyKAgVJRC2YwBQ796YKjBjLj3b2s4ebHFUW+lfqQO+QCVYFZfd+lJYGCtchozk23OJNKr+qxfHJni9RzgTbkbx3fT8WZLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090513; 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=nS1LvrZ7n9H4oE7uk6w8jMnvHpLvuOluAYzP0hc31/8=; b=Ab6yyylpY49qOF4ehuHm/h2Q36qMptUtxRnKHc6FDlzJPAaEOuZb3+HUfVZ5QWIrXrsOyCbgNP2cXg2zhLd8UMnOtz7KZ02xy/dJq95MGR1qcfFdUzmlJMhCd+PTykUCVn6YwL6XYG46lrSauTJtPMmeEwHi7wkXJIrZXzDcVHs= 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 1780090513403259.8850750178042; Fri, 29 May 2026 14:35:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4r1-0003Vc-Dg; Fri, 29 May 2026 17:35: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 1wT4qN-0003Kj-Uo for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:23 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qK-0002ua-Qy for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:14 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-835386ff122so14141223b3a.3 for ; Fri, 29 May 2026 14:34:12 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090451; x=1780695251; 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=nS1LvrZ7n9H4oE7uk6w8jMnvHpLvuOluAYzP0hc31/8=; b=eYUGgB7oJ/iTqEzJrgIsqV4n5J8ACrUnM0y4CaJaEkUQnQ4FRZcyY68s0XO7oPpyvR MdzCEPsSVRGfdi0euebdLG+mKnmViIFKm1u0dv1hkDzMiQl0wAPdf8RSNl22SDMgcvAo 4OxnUj8P3EGq1O+4xX2peybZgrpSnZc47gMTCe46kDhKYhQrRUUpP8bBkxleI9qYEszW eEluJXjfdVWMMonrEg9EcKoDfDAFBT+9QUrZcR5Nos/iwBlXc3snhgo/RYNsOZrfne73 TyIrkKmAjv/820aoKCWYi5Kj/ZXbLQah8OFwqHFr9UrOr2QDh0Aw6f4RNj8xm+evCczx OQ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090451; x=1780695251; 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=nS1LvrZ7n9H4oE7uk6w8jMnvHpLvuOluAYzP0hc31/8=; b=U/frzoLDmrWo4XtZ1mRCudN2W4wn5IIXD6g1dgywBfohLRqvCh/UDk/cxxbFGquoAc s13QB11gAg6p4c96ubwrKu/+jcN/0rop04HxtMjWbi8Una4IMSg+0lfGe4qwMRda26sU KBfoXPfGAVFo96cm9WY2Qd49dbE8bHM6pGl+OBM37j6HH5IXimFOB4xOuCHfAafPwhtv gd9V50fg29OFYDR2fYkrcgS9VO4Cq2CTzCp2B0BIWhtL2NGfxIXowS7i+iLHbd/zSgXL n1Gv0o636VbzqB4wa75OaMOUrVFYrQgIbJdo6yL08rmL2tjeygyic94fmB5QS1ZRCjsq mgnw== X-Gm-Message-State: AOJu0YyRrnN9NwO5JXVn6jgWdVVfPQdSj2s2yjXXhpkqFAj3suALY8tm CxwR59p2e6rE7K51PQhMSL/OloMZq9tzGehQRPg0bOfWTbX7RmY3o0vSEODjjdcup/Y= X-Gm-Gg: Acq92OFTmnU7okrg4Mkc9/bLHWyg5tbz3HxEjMe/jofLKmHP+Fcf7Sqvik8Q671jpQk 3VifCfVTMlHMBfmL3591N3i/5OrGYOe2aTIOYR6URW6OkXsrb0zXPbS4UTWTCvg3XxkJ743FFZ4 P9hu0HGoAShTAAUZsjesBCmlIhTJHs6wM1fejeOoMJoozkAKIfDCga1Htv3Rox4Bzm3zcf9x7Pw iVL9T6vWR5R1GMqQ3tH1ziJGAxWE474Wh3RJPeFOznXjaJ9yg+nQ0ifTnF6BfQ9b003Z/X2kdyg +4GOi0OLW+9cQq/vUtp109WSj9i+MttVIqlxB24DC4kIn93tg7welvuKZOYyRK31mnNFTJpcR7i rZBu7YWDFTGJeezDlDLFoaxf8PodIn0GLRoMUEZnpLRxSc1CHuNVumgDQ7g5hm6xm0An6M8gB+P AcPZuJJIyTQP6Ey557cjPtlC+9ERWvKe9XNYa1y9Vqs+qEXS0CRDHxpYLaA/12ec4= X-Received: by 2002:a05:6a00:8e09:b0:841:a0c8:71af with SMTP id d2e1a72fcca58-8422543d739mr1156867b3a.30.1780090451554; Fri, 29 May 2026 14:34:11 -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 V8 07/15] monitor: Update tracking iothread users with holder Date: Sat, 30 May 2026 05:33:13 +0800 Message-ID: <20260529213321.96271-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::431; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x431.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: 1780090514728158500 Content-Type: text/plain; charset="utf-8" Based on monitor ID tracking iothread users with holder. Introduce 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 | 20 ++++++++++++++++++-- monitor/qmp.c | 3 ++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 2060311b03..92d7630921 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -127,6 +127,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 dafb4ad8b0..7eec6f967d 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,12 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool= skip_flush, { if (use_io_thread && !mon_iothread) { monitor_iothread_init(); + + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_MONITOR_NAME, + .u.monitor_name.monitor_name =3D (char *)mon->id, + }; + mon->ctx =3D iothread_ref_and_get_aio_context(mon_iothread, &holde= r); } qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; @@ -631,6 +637,16 @@ void monitor_data_destroy(Monitor *mon) } g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); + + if (mon->ctx && mon_iothread) { + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_MONITOR_NAME, + .u.monitor_name.monitor_name =3D (char *)mon->id, + }; + + iothread_put_aio_context(mon_iothread, &holder); + mon->ctx =3D NULL; + } } =20 void monitor_cleanup(void) diff --git a/monitor/qmp.c b/monitor/qmp.c index b210850a15..b67674aef3 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -565,7 +565,8 @@ void monitor_init_qmp(Chardev *chr, bool pretty, const = char *id, 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:06 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=1780090519; cv=none; d=zohomail.com; s=zohoarc; b=TYpWYqEotUpCJfcfGO8FpR+x+JRe3ar1LYFamzHYW2QKHbvyDq+EXkg0kx31F+OLyeiPDnmBrLJkMPCyv2Ml/zdByxh96kB6oE6wWBIQbFQPeEjGk674aI0Cjr7u935L5BLl85dJspYaXLJN76Qy/L3UlZ2B2URYz/zEMjJl4U8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090519; 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=31eqi3lh8ZxCXKz2hnzO9aMe8wTk2WViYcoK9qnefZM=; b=bD+CmyOo+oghis1oW3Kx7CH+97XJ+0LxA14+DY/UX8Mb1+f/YDL0vRZbzYEDtn6tyjh2CLngh9wjekfLTwzpnoKOOlWB5PlB83iCIolFqJAUIfGPZ27rCUwZC1oXiKLbZGTGJ7jybN3R74n5eKcSQftViaYHgy2qbZrCm1chef0= 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 1780090519031896.3522356599802; Fri, 29 May 2026 14:35:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4r9-0003Wx-I5; Fri, 29 May 2026 17:35:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT4qQ-0003No-1S for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:23 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qO-0002vA-5L for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:17 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-c80227b1f6cso5330998a12.1 for ; Fri, 29 May 2026 14:34:15 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090454; x=1780695254; 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=31eqi3lh8ZxCXKz2hnzO9aMe8wTk2WViYcoK9qnefZM=; b=SgCSiMOtpcc52+AH519ZaRXMKkSuy6wEeb/hJ/IpEt6W6kiQlGUgfPU0lIcOAO/iPp 0dDvhyDWmjt5mV5vs9QS2n+rEV8u3jNKr/2mUoCM0cnkm9H8dwddK2xXaL/yHncRvLaR DiceSBWH6tEwpDq5BZARjgEC6QXfj6JW1EHHMYLsFOpAUiDJT8p9ktq3KL6zywbN4ODI NE9mYMEAypui1xOJepDozZZ4bbs2rj+qq4rGHcb4fiX1MQffqSssAaGFEnYWCFpanpP0 f8m4MA2VppFwGE2rgSK86XeMczBWQkirJJSU/3Ne33ixHT67REtTVFYLdgT3UKwKlL9O 993A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090454; x=1780695254; 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=31eqi3lh8ZxCXKz2hnzO9aMe8wTk2WViYcoK9qnefZM=; b=ckjeSCOEIe8iCvXvrjQSsDl1vbHbjh0EPAq8nxyxVMVVhLm8mozh2mHRuXYKdRzWTt EPMFQiQDeNqfz4vH6YGrpN3TaFSELPRW4St/GJpBe3jgiAVrSNuKbucwCrwQB3z6fI7W RfWx8R93CW5Nwftvm6XV+ZOROdrQI24A6j0IelmuuhhFQL0lxZCsnb1fbhoqoP2MYZFj 0mtkOrIhQBs+8e60jBuutPi+d/3vIPwDQgNIgBQG9CSCkZ16VuKWiJpK2rP0BmhlP4/c BdEgyzELAN3deOZ4fpQ9rtHqexr8NAAGU57vgarpAmRM9FnkGLD0fpTRCLO5qrl5aKcD UTxQ== X-Gm-Message-State: AOJu0YyCyM43IpwEHVJUYrr64hXckvVgI0rkn0zNtQucf1vAj5M9HsjV OnTDL3D0W7vohLD+Zlt3AAXolSs0x9z8WF+pPqadYo8pelx11Zz16hZoH/AYjKRqt/I= X-Gm-Gg: Acq92OH3nwqAkiCyArkltD96vCAcYCSejG6tcm+gSXuJpd9kUDzHmZ9mOynQSqPWHnt nX06rrbRgy6/aHyy3L3XXlnoMv4C/jHQRcfXg/VZh0VgbndHMDGMYlafyxItC8EHcAJRTXgdyDW 0NKe3aEy0GnLOE94p9mRaAkhmDHAxpb2w39XbyWhP8HuN2hlTFdlZC4ZKQXOILfyKGZfyZPYAyh w3qkngxLOVsnUbpVo9uxFowvKAao7RhsZjilwBw8fCbIS4ufAKDb/XpIzvW6EHQo2xKE5EFJEwU PVGOdPZk2+X73Y5AcM+0h/BTeUBdmK0eBtu+tFThgilhDpx3evG4vdCSIix3ukkt1mtnowQtg7e 8qclSDa9TBmj59xz+VgILgLSgL77sdiTmir4VUa4WO9oFneFkLX2PmIGoi2KSd/WAbr+2xRQD1S rSKjhFQMtPJlR2N6PdxilFZpz5ns4LZikmGyX4SLY4JJ1suzYQbtZuiObbOb1brps= X-Received: by 2002:a05:6a00:10c5:b0:82a:5ef0:210b with SMTP id d2e1a72fcca58-84225364fd4mr1166264b3a.15.1780090454485; Fri, 29 May 2026 14:34:14 -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 V8 08/15] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Sat, 30 May 2026 05:33:14 +0800 Message-ID: <20260529213321.96271-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::52e; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52e.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: 1780090523082154100 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 | 20 +++++++++++++++----- include/hw/virtio/iothread-vq-mapping.h | 6 +++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 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..2cb48dd387 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -77,6 +77,7 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp) { IOThreadVirtQueueMappingList *node; @@ -93,10 +94,13 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_get_aio_context(iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; =20 - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, + &io_holder); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +124,19 @@ bool iothread_vq_mapping_apply( return true; } =20 -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; + + iothread_put_aio_context(iothread, &io_holder); } } =20 diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/io= thread-vq-mapping.h index 57335c3703..0d39caddf3 100644 --- a/include/hw/virtio/iothread-vq-mapping.h +++ b/include/hw/virtio/iothread-vq-mapping.h @@ -17,6 +17,7 @@ * @list: The mapping of virtqueues to IOThreads. * @vq_aio_context: The array of AioContext pointers to fill in. * @num_queues: The length of @vq_aio_context. + * @holder: The QOM paths for attached device. * @errp: If an error occurs, a pointer to the area to store the error. * * Fill in the AioContext for each virtqueue in the @vq_aio_context array = given @@ -31,15 +32,18 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp); =20 /** * iothread_vq_mapping_cleanup: * @list: The mapping of virtqueues to IOThreads. + * @holder: The QOM paths for attached device. * * Release IOThread object references that were acquired by * iothread_vq_mapping_apply(). */ -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder); =20 #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090569; cv=none; d=zohomail.com; s=zohoarc; b=WY6SihvwE6R1pZmjPtH4UnA2r/fdutd5h0LOcHAtl9et8WQgRM8fPrv9kcl7ry0KScb6E/qHBT4qcUjhTFy28ult9M6esyrkP0YdrSsLpntFyOlMZianIHTrLGYvZRk+ofrMPnBBeF0QD40PQkjdoFsIVgXB39gHjrM5dpam4nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090569; 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=LDuEBYp+d3GMQU4EUX37XSBsPRXEyd9vBacPskZ6gvo=; b=PbJPW2FmfCTsUVp89+qt27TJvRNTLRAALBQ2Gj2BKtBwa70uZWgEQPYrPdEFO1IpUfWsigSBx69149tB/MSchGPTis6Ud425aoaJATihgMvYsifCLL6VZh+0mcTXlf5VmEFDF08JYspbkwhUqXZzFkRB3CMlZLoNiCmPeKs4jkQ= 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 1780090569227108.03036233501666; Fri, 29 May 2026 14:36:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4rQ-0003qr-Ii; Fri, 29 May 2026 17:35:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT4ql-0003Vv-3o for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:43 -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 1wT4qR-0002yk-3F for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:33 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-c8587427468so61894a12.1 for ; Fri, 29 May 2026 14:34:18 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090457; x=1780695257; 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=LDuEBYp+d3GMQU4EUX37XSBsPRXEyd9vBacPskZ6gvo=; b=VkpSL/VpmZIvWc+MRzhrdBuDQLziVk3UI7pT7ZElMSoffZGHN6pL2LYKvuIskd8CnX bGaeQPrIiQCE8rxYCaNvUCUSc/qvfG2vPz2KwMwZC2NizMmVSMayA+XfPBoFHjVMieOk j39zDySQnD2HKokMTp3y5fNPBO15nJdqdLiyPa2kaIdpzVh+af4GagJ2OlBqS01USPCB soHwui/L1zsSnZiF+ajQMDDPq+TFqOcer2AilNoxZMQyHfBGGWcXlioN9dwPV6piX14d pEC5YnZe24Wp6mcLaDOcSCqyvlZ5FTYeo2d75AMJ7zrULdpQudZroR5xkmPhzA9X92XT hmBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090457; x=1780695257; 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=LDuEBYp+d3GMQU4EUX37XSBsPRXEyd9vBacPskZ6gvo=; b=ZFI69TRebW/cvallMa0Fnv2O/HPdr8XK3UA+O5wPocFudTjA2drOw22B0z3/W4eAoy 5WBZf/XHNm0E+emtwKyWESNbEEQk0Au/ze3Timnot5nMu6z4lCYRPy3DwhzqGuw4aFad D99GhgeZYliXDMxc1bbokwp5dACmnmt5Aqml9P0G5G3yRdk8PP8MMqYgnqsKTDNtv+Iz b6lzGetDsLIYroz/ulEBKkLWhVE+ymgBHFk7UT9LkxxjY37Al9H7mt/juTMpNPHdwMYU 9elNVcYNF1/YWbRGnHHWr4kfvsOTX48zWDCGd6yvGPWuupXJT+0sdm0eTTDVQXkwNbT2 Y2BA== X-Gm-Message-State: AOJu0Yysy8ROLNBQ0iONEh+l99ImQWsJtfIQbtioitmKwaYv8NcU11oB 8llJi1pLK1xisi6B7/9TyxJgYljTAALm69zJb0p9Imy366VQWHjCzB33mgkjqF3MOAM= X-Gm-Gg: Acq92OGURkR7SqURpwOSL9hbE/grdjROnGO8CmfpQKHTT6ln65RQbHiswaj5xKlLTFX 3hndKjDMjDt4lJqVksPmAGhm1wqJL40cXnFdUJp+3mxaVyd0EziG1m1OKiYuK5Z5G9uMDz6Gll3 vcPqxfDiBHqJ97884QepHjq5tG5ijZb1Fv9DedxFKRgoUZz1gOBV7u/WnIuD7cAscXHDAup0aT0 8QxNqOq7JxxxOpnlwTED5YdN663PiuVSE601qPL/pJ+a3+k3562IoTOhYvDPPbOXcEasxfX33lO 1Lk0TgPJydicmWyZ06IbcbWjibgKeDIKAvOZhS9FAOihlEYZSWFxfufcLl2vg9e02ATlPRnWBDU ZAnzPBRju71vFy1/laBtlH18FhPgcApeHRl7vBBVzag1DLyvsyPkVZflmyUqNFg0n0h3iiTy3u+ MmPWlE4ojjSayoS8vw79kbtapD1bsa0xHQCjVTG84NyRqivx3hiwu5ZbeUOnG3ZjQfmbDto6BsH A== X-Received: by 2002:a05:6a00:2188:b0:842:21f0:5114 with SMTP id d2e1a72fcca58-84225445d05mr1251886b3a.30.1780090457308; Fri, 29 May 2026 14:34: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 V8 09/15] virtio: use iothread_get/put_aio_context for thread pinning Date: Sat, 30 May 2026 05:33:15 +0800 Message-ID: <20260529213321.96271-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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: 1780090571890154100 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 | 24 +++++++++++++----------- hw/scsi/virtio-scsi-dataplane.c | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 30e9fcf870..d8dc1dd136 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,15 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_get_aio_context(conf->iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, + &io_holder); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(conf->iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < conf->num_queues; i++) { @@ -1520,21 +1521,22 @@ 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)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(conf->iothread, &io_holder); } =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..c71f33b41e 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -28,6 +28,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) VirtIODevice *vdev =3D VIRTIO_DEVICE(s); BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { error_setg(errp, @@ -65,8 +66,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], vs->conf.num_queues, path, errp)) { @@ -75,13 +74,15 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < vs->conf.num_queues; i++) { @@ -94,16 +95,18 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { - object_unref(OBJECT(vs->conf.iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(vs->conf.iothread, &io_holder); } =20 g_free(s->vq_aio_context); --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090547; cv=none; d=zohomail.com; s=zohoarc; b=cjum5taU+4i/rdMu3GwKbGvjiJpWMb3O3XUq4/zbg4mHhtVqqRUFMaPfYDjm7MDghl8oqmqbUT6k8tBUzRSETYTyWjcJyH3hdxhkYe0H7GO+1COOVRc4Ztjct5yYYTV6hbRHeItyCT9CdnwboxT6Ju3p71qc66pzIjq4gsVKJGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090547; 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=e3JgrbyUDIxuz3YPnS0kJVMN3cW2e7N1UfUsJRso3As=; b=cicTjwqFuvfO8lPkYIj6lUK9khWV6LC6FC96ufYD6Kf5gxaT/crywN4bu1t6qy9Yzp/ISrni2LisD2uEpqukix5m0aN44BLD7haNgR9F9scYIqdI1KlAalB7CC8pNkE9zUCj9MStf/aI0PUCalm0fshu3z2PTi9CtgPMlAPHnYc= 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 1780090547557384.1539180930572; Fri, 29 May 2026 14:35:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4rT-0003v9-MH; Fri, 29 May 2026 17:35:23 -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 1wT4r2-0003cV-4y for qemu-devel@nongnu.org; Fri, 29 May 2026 17:35:01 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qw-00030h-1i for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:51 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-837b39eb078so9905497b3a.2 for ; Fri, 29 May 2026 14:34:21 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090460; x=1780695260; 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=e3JgrbyUDIxuz3YPnS0kJVMN3cW2e7N1UfUsJRso3As=; b=q4ps73xYhbEHbYU+WbMji7y6gLVDPDht+aezMH9MtECE4rcFaL/5uAyEtVmFHq26p4 U+ebhIg4N9zF67DT0RWTIkV7fAlEjBJ9do527o2AILzhxRey8aW2aaDXoth8guxulVzU vMmJrCPHn5b7mge3zijnB6FM07azqftMtCdAY7No0K3juQNJ+yjht4wiL235pfl+8SRQ aXPgFfooieX2lRJ85pIG4yX7pXDuj4TrpY7DYu50pgrdYU6QjMNcX85Apbcjwl7gS9no dJgV72pAWvhXIwAEjjye7y+zy9b71ZRrZyZ8Z2bM1lw6KnwQv/X6zXZe8SfO/5pGQAhG XUqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090460; x=1780695260; 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=e3JgrbyUDIxuz3YPnS0kJVMN3cW2e7N1UfUsJRso3As=; b=Ys7knNKk1Q9JPTPtvRwsTd/54zHEjorePYxkzONB+blsDuuNfRfFPqTcmVgknqYj2U Oo2j7C2eVFdoBVJbNu5hV6fU3HlOLymc8vnrxY7f6+qpmHQcpDrDi3tvl0/46j/ut9Td TT4wVIGay4Tg9U+voub83hjQCuqNLTKPdaFMW739zam2gmmqAXMayAkh7LzwPULf+SP8 a2mkDSBr57fzPI4BMmoGAMMu7XYEJuItA3cSWCY3OAYbyKTw3eDr36gvowq/QZ/LAWGp F2zAX2cq7IMwA7FwEi5symlSo71MG8b4LGqgxl0UcaOFwEw5Te2Q2K/nnhb9zkCAIKlL x+dA== X-Gm-Message-State: AOJu0YzNMZJLC4cjuikWkfSQxf0QW2UKhooE2C+T3YFgBlMoXyCWE1Wi kCvCHbkXT48Hwpcss22tZ++kvtF6CbOrXoOYpW97dPBSyC34X5bcvn8LaU71//lSoZE= X-Gm-Gg: Acq92OHTjyGKjbTuwRvrdsdJ+BLbzoZBBhkDAd4SEKTjP105QvaRFrXg/sKDHiZwV5q HxnAELi9zNvkgnd+SqjTXmsn3GjsFoVdmadJGz0HFU3B9H7SWQedY9i+TXPJ3efru32cJAoaMWp MsIB5k4EywYFiagaQW/wNcsVoOn4UwSGGC5fKmz+ZiNaqywfniNl1eEsaznWQcw7sC+nMSra1C9 WpnxH6ytj5HbCdN7N1g8oDeXZlbhihSNiHiQAG6HZD0Uro/pUSJn/255WP9tQ4sfkuVcHupcF1/ VVnSRvjZWFVp+OKAULs5GJS1OGz5Qz3Tskm+96rvu8fxkDv14O29TaoilYIqDCKFpl1Py4nP4se fzk4wviS24ECl8tNEiB/ZmwFseLP/bIPw0+VsLWyqlMB0Xhl0dYxOGCKaAUrtAub7XmcMfG3Djg /Y/9iR0nPYtS/dc0IS/+YApzJ1y47Ocyus+10Ixvw+jMSIRQKHVxPvlPIpuc3NXvg= X-Received: by 2002:a05:6a00:9087:b0:835:424f:6a83 with SMTP id d2e1a72fcca58-842255c37damr1162338b3a.41.1780090460207; Fri, 29 May 2026 14:34:20 -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 V8 10/15] net/colo: track IOThread references using path-based holder Date: Sat, 30 May 2026 05:33:16 +0800 Message-ID: <20260529213321.96271-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::42c; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x42c.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: 1780090549370154100 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 | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 823b8aa323..4f180936e3 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,15 @@ static void colo_compare_handle_event(void *opaque) =20 static void colo_compare_iothread(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - object_ref(OBJECT(s->iothread)); + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + + AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, &io_= holder); + + s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, @@ -1408,6 +1414,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,18 +1441,20 @@ static void colo_compare_finalize(Object *obj) g_clear_pointer(&s->event_bh, qemu_bh_delete); =20 if (s->iothread) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - AIO_WAIT_WHILE(ctx, !s->out_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->out_sendco.done); if (s->notify_dev) { - AIO_WAIT_WHILE(ctx, !s->notify_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->notify_sendco.done); } =20 /* Release all unhandled packets after compare thread exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); AIO_WAIT_WHILE(NULL, !s->out_sendco.done); =20 - object_unref(OBJECT(s->iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(s->iothread, &io_holder); } =20 g_queue_clear(&s->conn_list); --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090546; cv=none; d=zohomail.com; s=zohoarc; b=YEuqX1cnu6aUeOzphmX+vAHH3/+ohqQiqmtcD1VyYSeEpkuK8a1aFJX0pynBEv0bUuBB8WMDS/ePoZ9D9UNOtruF7xs4r4xG1iS4uAz53UfePIw9djDGBmZbMhBHGVEyyJDOLhXcXLaOEcJcJbcM+sNIYZ8dGsUuqFqOu/rMp0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090546; 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=TMWKjSKfCkLdRLDphuftQNsCyWQFXmHbwlzRM8NRv8w=; b=O17SbBrd/wZ/cN2j7jVTbY83szGCogUTNMIZKkKUGyJA5U1h1mtFDUpoBW2kYuTdz6yxvs6ca9Lnht7TePzmyLlwhSG+arfD2RO+y08hGjZTkNZO2v5aBcrK8FixuXF/iMC1XKAO7J9iSiKtNI2CZ+sCclh+uMElTqgkBsQ5Qpk= 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 178009054606845.13688176040364; Fri, 29 May 2026 14:35:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4rf-0004Cx-Ok; Fri, 29 May 2026 17:35:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT4qq-0003WT-5N for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:49 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qi-000318-AT for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:39 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-8422a92b6d6so34922b3a.1 for ; Fri, 29 May 2026 14:34:24 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090463; x=1780695263; 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=TMWKjSKfCkLdRLDphuftQNsCyWQFXmHbwlzRM8NRv8w=; b=ppbG/Kyh3/XCI6rmDz0iST4lDckfEWgjM4g4u1qUagwLzSJ0dNMPUVrD88AMEwpxP1 AF4kb+skfH9aS3s5tVlkdeOgKhjz/+FXvlgD7YOlEXD+j59gh/zyg0Jd8WzELk7w6rHD /ur0eW4d6jvphmGBcj4VfevEmGGkY6hZUFbOH/+rP9v2NCryoBVWsc95KNC76AHE+PVE cd60P3aV9jCBFJmYFplqdjto/gGWhqTqE8S4yWlUzYN0vjMP8g8kzhobLiMkJRo8lWcQ srQyrZ5FA8jf1N9zp62ljWemIu7wgoqTs8d5gNWQoVkZRu9p5rG/Jhz89yhFIPnUEdMo xc7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090463; x=1780695263; 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=TMWKjSKfCkLdRLDphuftQNsCyWQFXmHbwlzRM8NRv8w=; b=VaiuHeZTJo6Umcthu7CV3l/eejyhBjNYGdSoYSElIKAYuFKFj1tvwuVQRjbfQYNEzP uQYOvNFiIWo/9oMgTuqYlcuwlNN05B3q/PDn35FBkG1gzw8oi8y+XHiWfBaKATvS4Qxs mly5KY9uAOWzZYwtqUfoD3xmkIK9SPXc2yqSByblvmqXlnIjjnLtbhZlXF2R5iXUqLoH 0NN/wBUgDst5KYSpX7jFPh6bl8A9tJu/1Hk1O9e5PFhww4Llkzk2RzZryVqjlM4Q0Ig5 U9OB/i+fxQE+KC+3qBXqfSS6gKVGKp+lKPg9o9j+AiEbyS8d6lIyisoe0VQtybiHG8TD 9Eiw== X-Gm-Message-State: AOJu0YwJrHrvHvyvKF335pClYYicxOndq57DqpB06WIToS5eUyAMLEm/ /AjB0oousW5XCNNISfjrsabdE3EmuOXecZtkt8c9NtGs+OMIJxGNha42RwVl3D+g014= X-Gm-Gg: Acq92OFFOjz75MI7X0Ap61WRrg9JCyPTu7oszx8peZVKOu8EStmVxLnYu0tye9wzhzq 2jsFTfKapZ1pXTj7Dbf29g2pQhyF7OURJFcIAgSymFJGLTDfo4av+Q2sTZnkz2NTiMsO5KTpxSK KaxQ4Vey7T51urKKE4Ftx6Wlv8m8F2TELjEe6geCdGFC08ZFZJVamsmvfywD7wvXRp3t4eWjoyX gUB1ITCiCZdgOdljc2/cfR4VkOXYOy80bNk53D72nTMYw31eFY/jBRHOIApBrMes9rUVc6cZeRg 6IWthS3/ysjaNHmsRoJtRU1jpBYKCJKXmBRtG8y/92Cdpze5KGUhQOgOQC83+CEYq+KeyzqAMpc jnnOu1rHSK/0xy+tKUbbNLYXrqQ0lzNIT01RUtWTfeGFVl4FSYyCYL1dWOeSQF6SXO5PaU6OzPW Ia3NgQKvqqGNIMRCMLDaayXYTqGQYJPMVuS0kCdDXdziqkKmlfpdep7lIEsJsgfroPvrwnXiII6 Q== X-Received: by 2002:a05:6a00:e07:b0:82f:7762:3eb2 with SMTP id d2e1a72fcca58-84210b38e3bmr4025943b3a.17.1780090463257; Fri, 29 May 2026 14:34:23 -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 V8 11/15] virtio-balloon: Update tracking iothread users with holder Date: Sat, 30 May 2026 05:33:17 +0800 Message-ID: <20260529213321.96271-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::429; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x429.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: 1780090546878158500 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 | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 4c5f486ba2..e9d023b4ec 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -892,14 +892,20 @@ static void virtio_balloon_device_realize(DeviceState= *dev, Error **errp) s->svq =3D virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HI= NT)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page= _vq); precopy_add_notifier(&s->free_page_hint_notify); =20 - object_ref(OBJECT(s->iothread)); - s->free_page_bh =3D aio_bh_new_guarded(iothread_get_aio_context(s-= >iothread), - virtio_ballloon_get_free_page= _hints, s, - &dev->mem_reentrancy_guard); + s->free_page_bh =3D aio_bh_new_guarded( + iothread_ref_and_get_aio_context(s->iothread, &io_ho= lder), + virtio_ballloon_get_free_page_hints, s, + &dev->mem_reentrancy_guard); } =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { @@ -919,9 +925,15 @@ static void virtio_balloon_device_unrealize(DeviceStat= e *dev) =20 qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + qemu_bh_delete(s->free_page_bh); - object_unref(OBJECT(s->iothread)); virtio_balloon_free_page_stop(s); + iothread_put_aio_context(s->iothread, &io_holder); precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090569; cv=none; d=zohomail.com; s=zohoarc; b=AWCXXiW+wa64PDJqKdeoA/ra0UjPH0tIgzE4zi9uTkIO+OxeNiCaF8HH6E8vbgauc2krmACdGkQTYdSXPaLueGAOs2X9IJRNMO5yu7ZRyj91XAkdvf5uW1WmmrnV3GccE34dkXuOaxe/SeHny8eUA8+Nf9wgv5wRpjeNx34rv5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090569; 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=m3FbloHK6w+/ukY/MY1iEubAmBIssvvNZxFHmduZNWk=; b=W88JERzUjcw4neugJzemxqCXOkbdXKqWcMh5+Ku2SnPtpm9lqa1ytSePGTaiCDV3gw88Sn3mzPGxFfpH3ohIrsdGjaHKT/fmTIc6apak8Hbz+W65hJcyDDA5cCw6Vnawok8C+6gkC0z9rALuUXg/cNsMTNrmaMmuztLsCdnTV2w= 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 1780090569379830.5933157299824; Fri, 29 May 2026 14:36:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4rh-0004Pr-1o; Fri, 29 May 2026 17:35:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT4qp-0003WL-NK for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:49 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qh-00031c-7s for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:38 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-82f8893bff3so6707844b3a.2 for ; Fri, 29 May 2026 14:34:27 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090466; x=1780695266; 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=m3FbloHK6w+/ukY/MY1iEubAmBIssvvNZxFHmduZNWk=; b=YK1O32u4dCi4HdJGw7Vjd7arpwF83UTImrZQy9rSrME0gnur/Sap/RiE1mzEfnWBDa skFkB2RWnzgRe0GWMfowAy4Fj6H0r9DRsQ8Lzzf8TZughdwdyHzrOm3fzpLH9RAQNMcJ CU5F+1evTMHYF7XjYPOyMVgmUp4R2ru5an6gywPqyE4S3+H7dhUBiVBw8558VLju8Emp Z9F7X/yuYf/cnW4/yfK4LtnNE60DayiOY55nD6QS67QswsbvVAtVvBnFNKxpX/NrV3PJ y0nAVIXSvZnRhp52/k1+xav6h1f7Sj1vT3DGRbp0SeBcePMn082l8A/9d29Aa98EoeNq 03YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090466; x=1780695266; 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=m3FbloHK6w+/ukY/MY1iEubAmBIssvvNZxFHmduZNWk=; b=MSRYdjPv6BYULkDy8oS3v9YaAuDcwZfEOoyrn6Ffm7UtncgLO93U2JsdDgAWyopT5a q/Gq0sE3Mu1jhOlDOnseKTEuqHsEDs9EeJTgPqJToqGnD9EytE5qnnfQ4ex8blONh92/ 77sw8PkSmiucaCuj2HJ11fA2PC2ufVbOqoxAo/pSAFertMcMhEVemhxUjD4kUclwqbuS 0X33gLULtQFgHk7XmKmkgxgnWODOFiDqqMs6VXoPVbwpbepDg3rs/WJlvFK9TBismsuC nKNfQBDu526U0nu3Vvn0uLuSq01JmzQ2Txqn4Uj5sdp6A8ACQlZKNNNyTdmlJx/CmsW/ cuNA== X-Gm-Message-State: AOJu0Yx98ELWIaFcbMxmy3KaUaD1g7nL85HR7vKqltNM8ZenBKAU2NRy nygaXxUC8beDYZhJ9JyUryVu/x8cIfpE6usTmCjbIqM5Nf6qjbffKb0Bzx9mVzFKvgw= X-Gm-Gg: Acq92OEwMNuywQ+nYCa5Vh6uFOBTYJ1RjFuuK97o5IopEtRiJDdsWmXvAl6v/sn1Etl lLiG/tYVQi7x/o+y3G3INy85gdA9Nj0zcLcfnJomvHXh5CjhLlC/fYKXc6fi7DLoWlk+DBS7iqu bz/MYjUAW96vf2zRQpnUlL3TBKbmwCR+S53vAjyM6uYXvr0Y+PPARv+esmsN1eilsp1/bbOUQ7B cV8qBJHloauEyuPTjGN4lVkP9BBXqyeAsoMezaAMZ6dl388Jt21FnQ8Uf6uUZSq5QlBTCUaVb6B bLkVs8cegtiBF1Jh3SyLI2xjcG71zRCYb20v6vPte8+U/jvfukswmGclwa6MJhfV02zixLy7ToI eaFmSFNP7rtpj4yQlf6i9NhRIXehwv1T3BKHhkVfkO9e3KCzZkBusD02YQ2k3/+VtgkjflNbUO5 S7Qkr0c/dU7Pj0QNus3Ws53rIBcTPYlfI3Rmvh9sV8bEFKTEltLXy/Y+ytIiiszk0= X-Received: by 2002:a05:6a00:8c5:b0:82c:d7c4:4c56 with SMTP id d2e1a72fcca58-842253ed738mr1178545b3a.15.1780090466052; Fri, 29 May 2026 14:34:26 -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 V8 12/15] vfio-user/proxy: Update tracking iothread users with holder name Date: Sat, 30 May 2026 05:33:18 +0800 Message-ID: <20260529213321.96271-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::429; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x429.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: 1780090570987158500 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 314dfd23d8..756f368849 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,11 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *ad= dr, Error **errp) proxy =3D g_malloc0(sizeof(VFIOUserProxy)); proxy->sockname =3D g_strdup_printf("unix:%s", sockname); proxy->ioc =3D ioc; + path =3D object_get_canonical_path(OBJECT(proxy->ioc)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; =20 /* init defaults */ proxy->max_xfer_size =3D VFIO_USER_DEF_MAX_XFER; @@ -936,7 +942,8 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("VFIO user", errp); } =20 - proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread); + proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, + &io_holder); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); @@ -967,6 +974,11 @@ void vfio_user_set_handler(VFIODevice *vbasedev, void vfio_user_disconnect(VFIOUserProxy *proxy) { VFIOUserMsg *r1, *r2; + g_autofree char *path =3D object_get_canonical_path(OBJECT(proxy->ioc)= ); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; =20 qemu_mutex_lock(&proxy->lock); =20 @@ -1021,6 +1033,8 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) qemu_cond_destroy(&proxy->close_cv); qemu_mutex_destroy(&proxy->lock); =20 + iothread_put_aio_context(vfio_user_iothread, &io_holder); + QLIST_REMOVE(proxy, next); if (QLIST_EMPTY(&vfio_user_sockets)) { iothread_destroy(vfio_user_iothread); --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090560; cv=none; d=zohomail.com; s=zohoarc; b=h5nIrY3yhquJ062OS7zr8hQ5dD1iOuLYXzrIW80rIj9pq2L9iDYvfJ23I65IBFbYZstH4dW63WP6pkCub/x8T6sA6lgc4FXmKUObI89uOfyEN02J5wgbYBT6UwfTlH71jWMKXRjlsCuBnt/rrChDqMQxz4IOmS5jN27CjAkzgeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090560; 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=7t5cTU126FnpUwkoAoirKGUM08oblbAVX84J7t/Z2ng=; b=YH6S9lHg+PloeOaqfPv9wLjonvfzkQzpvgL+4IgOuZ6Dp3zuj/nqZOmS2pmdZ3u/EsUnyAR7UKKgoiybNysjX3wDmmhGZZg2UeVJrakguuA4Ea7YOlSOzxWDybHhyv3evKA3GavLpnk+dBoxmICr9Zp43SF/WWkNtdajT1wfHh8= 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 1780090560601701.2050608649923; Fri, 29 May 2026 14:36:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4s1-0005GZ-Fg; Fri, 29 May 2026 17:35:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wT4r2-0003cj-RK for qemu-devel@nongnu.org; Fri, 29 May 2026 17:35:01 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qw-00032D-1m for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:53 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-82fbf5d4dc2so9889137b3a.1 for ; Fri, 29 May 2026 14:34:29 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090469; x=1780695269; 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=7t5cTU126FnpUwkoAoirKGUM08oblbAVX84J7t/Z2ng=; b=scWAMzRbSzoXGvXN+LOE1IMbJLY2KTBI1CIXLhlE3bG0iaQHU/G/7FBox6J+r0w47k HksjJTSm8ReNXcfG0AcwOJfEPkIctWFmVbn+VGeT5EO7lEUAFW29z7excKB2hIBZCiOU Uk2uYEPCssK7cc4/CX2LT7SauXUqDblif5HxsPiSitYQd6IYUeNl+EW04ypynggfCkvz 3lnuuRE3csr9MCX8Xk3VN245BZMueMM+oJePHJ8IkKWZ38JoTqp1jG2TWYM3pXOkoC8y FgtXfNVQ0Zuo397hotWZ+7wKVsnDwS4zWlhNTYS6FDfGGqU9tQsNXauT1miQxLPC9xEc 1Smw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090469; x=1780695269; 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=7t5cTU126FnpUwkoAoirKGUM08oblbAVX84J7t/Z2ng=; b=HMYWiRscV+nZbslGD5Xs5IQFG5rZ5TW7secUmnRN1NJSHsCT85uJyHQIu+pdikNEdV n3oVDGxIjMkrvRLzzjdBtAHgENp79UULs0EsR93z8a4q8qlaDFBnlh4qU6LKxwQKEzG1 Oj9Dyhz8Ne3ERcNjm/YOd9HkGCr0q7JX6P1cnbw0luhaRThUj7oeQRMxUIql7q8LM4MB cDJbw4U15RDbCTVFQInlfMYLznbCJth1ejTnt4k6vKZgW580PMdtqP0WFBKnD5Rni5qD sV8eV32q+dsBMeVlmqTzOi8QSHC5dlz85M+qx7wnjt0AigRy/G3tn7aI/OUDp/prP/UV G0zQ== X-Gm-Message-State: AOJu0YxLR42HMmF26hf44aJGnDNgtuAk0XbqkLQxicLK5ufdSeEV1uaP 33zF5bFsDkPLi2pt8eleigzVWcz2e04ucmlPBIycRrS6Zwrf8fsB10kxbYBAMAMxvZM= X-Gm-Gg: Acq92OF5RKgsaJRBYjRMVtMZfbV0xoLyBvsCHohcWKJLmRMnVe6m0VJX7lxCHNcttju 7SFFxbVy8nSLrgKvWZfu/cBSj+B1xJuF9GPMm3oniQXwt+ZhhmbcFZkr3AorJhbkTNy3Lg4R1B2 YymnUWDJgUqbiji1MH0HgSvOnoMeuZeM5RLPPhrBmLN9hTKaCAF7bwlgkg1RozOi+veyl+mQajd SUMxf7YFp0DFKQ+Dq8H9vyfzCLWe6l+V6cRwZhU7SMTHzxZPqu20ksyokW4IodcypJoBZkiS7Qy kUxKTIGpnPg4xW3031J0XLTwUhBJO1ekDLKyrpS9/7EQ6AcAgmSqoikCwqAiLLKrZiwbvFU1aDz MTB4Gsz2eXxmnPG7cAdmP7YajjjK+a6nujxZWurTBbJZ4B85MExUREQwBuQU2XJIXgSUn/3N8N6 Ra1GW6W/yRe9O25hBKOftSqjEyAGmIRLlVhhyFMBRoF7DWNgyY5/4NlKd4jgs1HL5ifFTU6oZFi A== X-Received: by 2002:a05:6a00:3317:b0:83e:d996:92fa with SMTP id d2e1a72fcca58-8422535d027mr1224003b3a.11.1780090468907; Fri, 29 May 2026 14:34:28 -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 V8 13/15] xen-block: Update tracking iothread users with holder name Date: Sat, 30 May 2026 05:33:19 +0800 Message-ID: <20260529213321.96271-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::42b; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x42b.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: 1780090560949158500 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 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 48c2e315f3..b5bf8d359f 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -621,9 +621,15 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevic= e *xendev, QLIST_INIT(&dataplane->freelist); =20 if (iothread) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + dataplane->iothread =3D iothread; - object_ref(OBJECT(dataplane->iothread)); - dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread); + dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } @@ -652,7 +658,14 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *da= taplane) =20 qemu_bh_delete(dataplane->bh); if (dataplane->iothread) { - object_unref(OBJECT(dataplane->iothread)); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(dataplane->xendev)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + + iothread_put_aio_context(dataplane->iothread, &io_holder); } =20 g_free(dataplane); --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090578; cv=none; d=zohomail.com; s=zohoarc; b=JqKj+G+gctYEYfnCbb7Nevlt8YXWHAfsu8chaXP/TSjtl2o/3dcRceEzBasCmv2nCedtvLvRvY1Qj6ZPyeE2DitqYE6HT/dBQWXIVuCLDKjXGsX+URA4aZjVuam0jIWx2a8BWZLaCzsf9/YcnX/M692S4irabwZox4vfIn8L1mA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090578; 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=O/uEq0X68vqqCBKpIngN3jhiubOyQKw/LOIJ7bmC9HA=; b=InPlWUbiSDe28IWJ6+0erff5jwiworyeB1qXTPnqdaYJyZrFoqA0N7UgV5jPiWyNnVaU0kCNVqv6lBr6uhX+mPGOkxRWFQr5m+lFXI2Lc0srlecZ4S0rp/wEE1eGao4Q3Ux+x6Oe+duP7caA+ut7lNqtkCfY1bTXhTawMH93Dyo= 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 1780090578082472.74286240113975; Fri, 29 May 2026 14:36:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4rs-0004nc-S6; Fri, 29 May 2026 17:35: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 1wT4r2-0003cW-5L for qemu-devel@nongnu.org; Fri, 29 May 2026 17:35:01 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qw-00032R-0z for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:51 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-8421f91c07eso227769b3a.1 for ; Fri, 29 May 2026 14:34:32 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090472; x=1780695272; 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=O/uEq0X68vqqCBKpIngN3jhiubOyQKw/LOIJ7bmC9HA=; b=sqDu+aG7hfLXqxEpYEFSakdadrAGevwWBvXw/s2ODGb+4qhhmaS1/3JO/HP+OYAKzj XZfv63RQcSsMx7wGQJgS6XmSkZ12MGsfIurDBcmkQPl0HJNDdRn0O6xkZY+oJ2/iRESs qxr6QumtA123wMsurcRcxTnf27SVn+jl3N5yhr7vgZzvXGIiD1/QCg4iVYKZdQg0Ha7D ooO/O7zUNmOv8f/Ap+Rp2S3BlH6SZEeBT787T+i4d50Vt4Y4y/qUN1xYX9jePYQ9+4La GNI7j3XjxpHkPCL+k0Viqr/T0A8Y+a7i/h/eJxto5r7IW+pBqnEBduc1CaZMZleTVJZe ti5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090472; x=1780695272; 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=O/uEq0X68vqqCBKpIngN3jhiubOyQKw/LOIJ7bmC9HA=; b=O4Gul8Gu4nttVo1Tb0malrcHQbblKCDdzDqntkCi5qAqp5nNDUzQUZuynw68Qj3YCN 84Doz7gK0QX4dGaWJYwz7C/Kr0sSDYKIvdBSuby2iHpZwVJMtq1wf+AAyceiiPUMacq9 Fg1exyvSfebQNHHtqGi3fF/LY75qBHHyYHsVc/6LYbwNtXIDDfiukflFhs76h3CNP3gS KAPaHCL4UP2pJsNMpGIQriC/HDdbfio71ApfcqK19jpMNbvzt7iEldyxcK14X3SfRmZC 3WqlNTlOmwV/dHCvAzE7mfyaQ6xpjddgXaF0jWY3fQomb7RjaRHoh9tmJzVpJW5Tzflr vYzQ== X-Gm-Message-State: AOJu0Yy2r3JYgX74n0eEeDjQOWSINbG2Ybc20cLqH6GeMIxmeAn5byOT NI8JvVQX/a6NByuyHgxXdHq58JebjKDHBJZESQiKPSobIRdfWJer661f55rL9CfS2B4= X-Gm-Gg: Acq92OF7MR/fVdRmtd90BNKZwJ8akWxZbExfTWXxs0Xvx6y4H9sww0d273FF4qN3heJ MrkF+BvyPAmSFyy43agNPbs2BRND8n5eIy6uMH8KVo+uyxpA6DfeisPZZvkYx2ZafZZ14l3bzqH tki2KBaNtf2OiT4zzA/Vl+7k34Wpab4Le3sMkB9cfdfsJR/IS5duK9rpjxy6hKq71XtX+i10rbr EZ5gh230N3Z7ELIu2KcxZyORxztBu2SzHY+HJjh2LlybIrPWfXgDKYBPoHtIeuxpZQ/S6O3Wcp1 CoIeP5psNGVS+tpLUirTAPrkXH5usSUfhm80sdoH76iUBHjR+PU17eNS+mQAYfUCyRlYcks+KOi OSw+LdRlD26lAyXwU5VyM5p7CyRCFsA3QEwPnKTXX8NlxUumSRtzq+K9Hxon33wVYrZDG2w4z/6 fEfEJ/njWP7CdnTQeGfCiOxqDOUCti7LSaOAuSs6XV65g7h63AcP1IHadPPSjnDOE= X-Received: by 2002:a05:6a00:4f93:b0:83d:6c12:a632 with SMTP id d2e1a72fcca58-842257583d4mr1098649b3a.50.1780090471786; Fri, 29 May 2026 14:34:31 -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 V8 14/15] qapi: examine IOThread attachment status via query-iothreads Date: Sat, 30 May 2026 05:33:20 +0800 Message-ID: <20260529213321.96271-15-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::434; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x434.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: 1780090579019158500 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 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 | 26 ++++++++++++++++++++++++++ qapi/misc.json | 11 +++++++++++ 3 files changed, 59 insertions(+) diff --git a/iothread.c b/iothread.c index a85e960e45..5949785b32 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 /* * iothread_ref: @@ -119,6 +121,25 @@ static void iothread_unref(IOThread *iothread, const I= OThreadHolder *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; @@ -488,6 +509,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 443b8c785d..1b5883147b 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -237,11 +237,37 @@ 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.node_name); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_printf(mon, "[qom-path: %s]", + holder->u.qom_object.qom_path); + break; + case IO_THREAD_HOLDER_KIND_MONITOR_NAME: + monitor_printf(mon, "[monitor-name: %s]", + holder->u.monitor_name.monitor_name); + 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 d9f82f0922..4c16be3fd4 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -137,6 +137,13 @@ # # @thread-id: ID of the underlying host thread # +# @holders: IOThreadHolder 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) # @@ -159,6 +166,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -185,6 +193,8 @@ # { # "id":"iothread0", # "thread-id":3134, +# "holders":[{"qom-path": "/machine/peripheral/blk1/virtio= -backend", "type": "qom-object"}, +# {"qom-path": "/machine/peripheral/blk0/virtio= -backend", "type": "qom-object"}], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, @@ -193,6 +203,7 @@ # { # "id":"iothread1", # "thread-id":3135, +# "holders":[{"qom-path": "/machine/peripheral/blk2/virtio= -backend", "type": "qom-object"}], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, --=20 2.49.0 From nobody Sat May 30 17:44:06 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=1780090576; cv=none; d=zohomail.com; s=zohoarc; b=dSey8iUuqJJx7rq/7CK9qdeakiqnprr+AX7nr8zYB3UANa51cUko1Hk9XxOE+9YpI9On+ofhexTcoT8njUnFZvxJwV6Uv5FiesIsUhzq8sf26I/0ESPf/+ybBGclqPKqC5CcAWHQZ6cjP5QNceb14kQe10k29HiwhCfGXeKlNzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780090576; 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=jEcYVF/Udwni2eBZbL7aCWlWBBoaU7ySIMUFrl8fTXY=; b=IXESSbJxOWyKpTiD9MoakfOncje1t7QEnT6xPOg60JfvTgjrUrI1vtcTsuKxa4Q0mKd7s3vXOCR1a8IhZFj64pjfUgIMVb+QocAb7TH3cclcOKkOsw2sVTsGBja2qwXa7SOpZh/RudhmMsoR5j0lB3w8tl5ZlFuQ8YW0+jeYkM4= 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 1780090576623910.4507881081105; Fri, 29 May 2026 14:36:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT4rx-0004vj-2E; Fri, 29 May 2026 17:35: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 1wT4qt-0003XB-Qw for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:57 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wT4qp-000330-E0 for qemu-devel@nongnu.org; Fri, 29 May 2026 17:34:46 -0400 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-36c68964315so114378a91.2 for ; Fri, 29 May 2026 14:34:36 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84214affe29sm2779564b3a.3.2026.05.29.14.34.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 29 May 2026 14:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780090475; x=1780695275; 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=jEcYVF/Udwni2eBZbL7aCWlWBBoaU7ySIMUFrl8fTXY=; b=EjQSpE7ZgS51BmMlSGUpqHs3rNyj7UhKrDGNQeurdTQe1QX7+Wcz8eCtnt4tmS81Uk g7gwuyAcyzz/YiDPju7ZSIPSdh/8ADK388ylqhpNeXAr2tNw3JYhtx9SpFaL1p9uipek B9DSEGMRyA7gmJgre3iS2YbHrtGew+gBpKHOV1/ipgSPpxXqyRSI/+cH7d+XlIIT73Aq 0iicivQHHGrsPIFB9MdJBn6HC4tNItCzknxRopFMx+E9LG+pS5GxkNy8KY0K6Pz/jMiz W1P44uOh5HNH4DekkBmX+bWTirWo31Wq/zkQwUZjIsZKXxT/WL80JDyDUH8rDl58B8OA 6pSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780090475; x=1780695275; 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=jEcYVF/Udwni2eBZbL7aCWlWBBoaU7ySIMUFrl8fTXY=; b=EBIHciYYILzSuztfeRLss/51pBLHq6thxZZROrBuz8j4Xgus3ZAAE88FoZMnDXHBra t1fx4u5xmjRjYWsH3+XaTTpYPejafF6B8HlE5fTUbiebrTuOcDDPS2CsyLZ8OAqGze9G ++QW8Bo5cKqr7OZ/k8twAeI+emUTyep9jyTwi+7l0zX0N4t7Y1JelvpnwQsw4Ixw4iZe 82EcUXmyFGp/oQEKGiexoFQb73n7afs9mRG0Q0Vnw2/DfizoOclXrZIsx+h/xBzPB3xt xmqoX8FG79M6/uBaesKq+t9+I3+OBQt4PS/e70FnBalWr175pM6Y35XCtX+iRP2OI0w3 tBIg== X-Gm-Message-State: AOJu0Yy281+8hwt5uNEI3m0khsePXX3ryFq0KDzS472UsB9UpXkr2ssx XlX1hse13aoJk20JIewLDhrLrr4FbJ5rZp9QhCgXcQLvmKta+asU6PctYl7dRqfyz50= X-Gm-Gg: Acq92OFbGEIXYxxYis37my3STOwvu0dMmHPOZ85gJSdXxInNu0eoZ/c61EgE8p3wjbQ P82NS/p5786CpektyDXmYoUQHkXavyb1bWJStKR/VmR4KWjZmD01LQ9apmZxaSIewztUGYfLusM 4kXqtDHARjeh2ZOCTnoeVaVsWgbcWXLkw7HuyEVYpjqTmqjrHKTvOTpQ5mbl/r8a3wKzsiVjwJc nrgohx1FxDq5QpiiT4grO6hzEKDl0FaR3qX2UVzsQNM3c3KHULVClxEWiYKBqBRJOFLnZI2SXOh 38+TAZXD2q2wiATS9MChak8EOVZlZXDK+7tKA6xsZi8V1j4JRgdgfdg1nb39Y1oVnYW0VtVUVl4 OwKYw6fZdkVkEBx3oY6CSNHRRq4KMUtuwUJCF9tZJoaXkU5SuPmxO0Ba5HZ9Pwbqtxx7XUmLP3F cdm9clDxRmd8f39bQXniit0nVcnudHQR9rSFcYN8BPDyT5l6q6zxa8Hea8cdXrtXksiyejXSxmH g== X-Received: by 2002:a05:6a20:9f0b:b0:3a2:dbaa:82ee with SMTP id adf61e73a8af0-3b427bc4170mr1196675637.9.1780090474660; Fri, 29 May 2026 14:34:34 -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 V8 15/15] iothread: simplify API by merging iothread_get_aio_context variants Date: Sat, 30 May 2026 05:33:21 +0800 Message-ID: <20260529213321.96271-16-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260529213321.96271-1-zhangckid@gmail.com> References: <20260529213321.96271-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::1034; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1034.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: 1780090577097158500 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 | 5 ++--- hw/block/dataplane/xen-block.c | 4 ++-- hw/block/virtio-blk.c | 4 ++-- hw/scsi/virtio-scsi-dataplane.c | 4 ++-- hw/vfio-user/proxy.c | 3 +-- hw/virtio/iothread-vq-mapping.c | 3 +-- hw/virtio/virtio-balloon.c | 2 +- include/system/iothread.h | 6 +++--- iothread.c | 9 ++------- monitor/monitor.c | 2 +- net/colo-compare.c | 2 +- 11 files changed, 18 insertions(+), 26 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b6c07f69b5..acd061e86e 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -146,7 +146,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) .u.block_node.node_name =3D (char *)holder_name, }; =20 - new_ctx =3D iothread_ref_and_get_aio_context(iothread, &holder); + new_ctx =3D iothread_get_aio_context(iothread, &holder); multithread_count =3D 1; local_iothreads =3D g_new0(IOThread *, 1); local_iothreads[0] =3D iothread; @@ -190,8 +190,7 @@ 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, - &hold= er); + multithread_ctxs[i++] =3D iothread_get_aio_context(iothread, &= holder); } assert(i =3D=3D multithread_count); } diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index b5bf8d359f..46bfd62f5a 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -628,8 +628,8 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice= *xendev, }; =20 dataplane->iothread =3D iothread; - dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, - &io_holder); + dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index d8dc1dd136..d1d2bd7025 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1502,8 +1502,8 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, .u.qom_object.qom_path =3D (char *)path, }; - AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, - &io_holder); + AioContext *ctx =3D iothread_get_aio_context(conf->iothread, + &io_holder); 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 c71f33b41e..76ab22610f 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -78,8 +78,8 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, .u.qom_object.qom_path =3D (char *)path, }; - AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, - &io_holder); + AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 756f368849..24af3c791b 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -942,8 +942,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, - &io_holder); + proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread, &io_holder= ); 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 2cb48dd387..727358a483 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -99,8 +99,7 @@ bool iothread_vq_mapping_apply( .u.qom_object.qom_path =3D (char *)holder, }; =20 - AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, - &io_holder); + AioContext *ctx =3D iothread_get_aio_context(iothread, &io_holder); =20 if (node->value->vqs) { uint16List *vq; diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index e9d023b4ec..4405a87ed0 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -903,7 +903,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, &io_ho= lder), + iothread_get_aio_context(s->iothread, &io_holder), virtio_ballloon_get_free_page_hints, s, &dev->mem_reentrancy_guard); } diff --git a/include/system/iothread.h b/include/system/iothread.h index 064c05e78d..e5db215954 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -70,15 +70,15 @@ 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); + /* * The iothread_unsafe_get_aio_context() is a low-level unsafe way of gett= ing * the AioContext, recommend migrating to the new API with IOThreadHolder * as much as possible. */ AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const IOThreadHolder *holder); +AioContext *iothread_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder); void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 diff --git a/iothread.c b/iothread.c index 5949785b32..9bc8e359c1 100644 --- a/iothread.c +++ b/iothread.c @@ -469,13 +469,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 IOThreadHolder *holder) +AioContext *iothread_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) { /* Add IOThreadHolder to the list */ iothread_ref(iothread, holder); diff --git a/monitor/monitor.c b/monitor/monitor.c index 7eec6f967d..4d00cf499c 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -617,7 +617,7 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool = skip_flush, .type =3D IO_THREAD_HOLDER_KIND_MONITOR_NAME, .u.monitor_name.monitor_name =3D (char *)mon->id, }; - mon->ctx =3D iothread_ref_and_get_aio_context(mon_iothread, &holde= r); + mon->ctx =3D iothread_get_aio_context(mon_iothread, &holder); } 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 4f180936e3..820ea4d824 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -973,7 +973,7 @@ static void colo_compare_iothread(CompareState *s) .u.qom_object.qom_path =3D (char *)path, }; =20 - AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, &io_= holder); + AioContext *ctx =3D iothread_get_aio_context(s->iothread, &io_holder); =20 s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); --=20 2.49.0