From nobody Sat Apr 11 17:08:52 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=1775833568; cv=none; d=zohomail.com; s=zohoarc; b=IgDmlrmHxQqJfMESwg2+LREGtMtg5IFUOEVqvsDcZKpLL9JzZx9PO/6mOYyJez1NL3vuBpjCp475Ylv0fX0eaZXKpQdkMXdPe1jNbpk6EtOlv1pGseLBPnnrV0STJqElztd1LwJLBxQPIbS5d9Hl+nAhLtk73K0JPrMxwAzWEUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833568; 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=B2QC7hLfF9zjfQ04CPizme4X1fY5wq+GdA4jvJ9NH8A=; b=aiDZ4Uf+nEcZKILEYsup7Xe7zdfctan9DUIplE0rXcGqlDwUV0Gx4ImI75lSaFERCmLIofG3zZjez4sYIJT3kXQDIowH2tGsFn8pN7ZATuoaaaMUliGsdqK6AsF6C/n8Pi2eSGeoCNVMbp4JwmirYN9H/q1tdjUzLDKehJ9NfpE= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833568509208.51337335945675; Fri, 10 Apr 2026 08:06:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQ8-0006TY-Mb; Fri, 10 Apr 2026 11:05:20 -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 1wBDQ4-0006Jw-3l for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:16 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQ2-0001zX-Lu for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:15 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-35da1af3e10so2247647a91.3 for ; Fri, 10 Apr 2026 08:05:14 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833513; x=1776438313; 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=B2QC7hLfF9zjfQ04CPizme4X1fY5wq+GdA4jvJ9NH8A=; b=NSFIk5H5CA5PqAvF7LQHNWQ5rVRunjvS2KBTRikjER2/kL3UjS7s6AQfr+K20CzCw8 /+FZbYD5ZUc4cwpuhxd7Xg9QoXYy66vqYVHZAWTeD33ZQzDN0sh12sm+YSk+bvrYyXOl F2sqksNIrC4BEvuWrgYFatzZCifl3nF2/LgNwAkAF6fhBN/xIaVIDNLLlS3InF/qbitD FMCrGros/McjM/+Xf5x1S7BH8CSU34lrU+8ptV7ieYtgvug6OuzXEB1mvQbWkQdNWHAl NSelYMfUxqVDWzxePpCuqPKPEHjcM9rpGMdnRDh1WFTo9IHB0P9oVU3n+b6hX8tLQ8nT mSHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833513; x=1776438313; 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=B2QC7hLfF9zjfQ04CPizme4X1fY5wq+GdA4jvJ9NH8A=; b=bZKDln1KpOhBcPhNT1ZtG5wguChsDWzYS3JsLGscMgrpeSUH5f6oM8Okp+y0ulHD+x dHW5Ulsxvxo1GH6yH4FRlWKnu0+p0QsVczs25oEJkbHxDSLU04+z9menlpDs6WCB16+B QLw7rNH1KTMXMbhppsuRL6BQeK1/9nEgs8kvXBETWOz4CNFisnDglldY8aVWowQUTWyC kmpXRCIe3Btm/zuK1gNzPRCb9FKymoWYVWhNOp7vmx/Ljp3bJnG4IDwPENd33hvhZD07 euEw88UXw9v9c+wvuoqn2rVoI9bjgsb2TJqMSIueTwkI3/6h+sJ15GfmcW7Gmhv+m9Sr p+JQ== X-Gm-Message-State: AOJu0Yw0f+NnkRiftctKpffspwqZo0pvszAwTlg6ytgtI1SbkXtKvogR 7l2qZziUm12clyCnU2Bvz/YSL4YK4BKC89MfFbH7YK4SoEr1QnEAgOcJhLi/3bhn X-Gm-Gg: AeBDietpzai4703K83RpNqDrJ816S+XFOy10WSmpip4HnCVw5DyXDVvYt+gEhMRSF0B n+UiqZHK/iig8i9fWFnsrySXCCKn53xw3mPoeyOgRboNuSs2AwsTeQ0Bh4ANnaEYbkUp89xeNFM yKjydjv/V5O0vtUWAEyC7uItF8P51hhk7Ombgr2EythvRJm7IyLI3KDpnF+SyDPNZhm6WoclkoD QOuQF4Js4ddX7Q1lFSlFid4ZSL4yheCRuy/sFqkmnsyswVRTnsL463LlIiOIW8lFBwZDU3r6uUA lKSKGuMTRostjjk/vjjFE6JTr/v1nha6jmsEgoj904HNm9h7/E/2YzHZSyXPyqGQBxWSNhDeXAr /zOHN36+66PQW9sKI7FgFBylwMvytSN+F2y8eP31d8MZnACIwQGRVv6UPNTeytPcLS13ghgdPtE x535MzD86wjpujrzREtJ+4iCZEhDYRs76PYop7QaNBB6oSBE3e9xTD X-Received: by 2002:a17:90b:28d0:b0:35c:30a8:31f with SMTP id 98e67ed59e1d1-35e4276a26cmr3554636a91.2.1775833512341; Fri, 10 Apr 2026 08:05:12 -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 V6 01/14] qapi/misc: Fix missed query-iothreads items Date: Fri, 10 Apr 2026 23:04:44 +0800 Message-ID: <20260410150457.85190-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1775833571723154100 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 28c641fe2f..1f5062df2a 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -117,11 +117,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 Apr 11 17:08:52 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=1775833585; cv=none; d=zohomail.com; s=zohoarc; b=ThrunLFwG0MakLIKn+VfDwdWvfx+QvD9dBZFTmpMI32sP6fy9lQnEt//OZe1cjNGU+dPPkM+pt+CHoibJtoeLYRTLG//oecDOPZYk3nn/uBGqvHeH4cV1DCb4//HTvGY1IxMXJtS7D8KcRP3ivy6CRz8vvJ1JcFxGYNfc+iAbNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833585; 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=zbuB4mhESeHjR1sC4osJPiNIB/gMNHKxCFvIHqQzq6k=; b=jRWxCUa3Mx2alSMCvE1S4JCpwA5Q7z0UH0QUOLAece77GdRiB6qIPwVlZZ7VARkRERFfPFKLVpOwf1kO+L76sRP5rSNKffb6vL95Q3xxeP9MzGlfOco2zCY+BwWIxq5ZTgP8i1EbQhVX19pja4ZzlXnn37oEkN0TiErWb/iIitE= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833585867526.3745254022442; Fri, 10 Apr 2026 08:06:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQF-0006ad-7j; Fri, 10 Apr 2026 11:05:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQ8-0006Rr-7v for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:20 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQ6-00022W-Dy for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:19 -0400 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-35691a231a7so1549744a91.3 for ; Fri, 10 Apr 2026 08:05:18 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833516; x=1776438316; 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=zbuB4mhESeHjR1sC4osJPiNIB/gMNHKxCFvIHqQzq6k=; b=jqNpYybiH6sQEYeJOcR7uPoVureRgkhNyZU/t9ZQ/+GpnTWJthtkV113zVCrsEfntR 9NcRSxd/+4aUjwaqK2KVmvOuHcXJgeQZ40TGsu0fmoKqa94KoEiY9m0FBu48xHGbKOVa xahZLxSgAGj3XEun6xY70IapwjDN/9agABqHnl5bwPXvt2y4GW7t4tYroctqRMxLvleP XpBuJ1zTL6CaTNuxSgQMdXmAD1/t7DioBefJ0zq5N0UTrQRBhWgpKJrkpgL8/zf3advt yT+pkdc0Gvawx9Bptk8KJG46hoAE4jInCNJWd5f8H8xjXY/HbP6TWq3NIFRWyZZluscX sLuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833516; x=1776438316; 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=zbuB4mhESeHjR1sC4osJPiNIB/gMNHKxCFvIHqQzq6k=; b=goKJOIQu8/ZW61hlMfUuCKUuHZ90Wp/8vXzjojv7gkKBumPt4KcAZfvzgwf6Frqksm 1Z6JopVw0Fm/qU5hDlDgoC5+pQSqh20AoiGF6g6mFlc9eroDbEIObtdh9wBgKW8PnrDe kDPSCo727ySgXFlDU04YFwQLv48pv8ZJ+GBs2fnCCgTULq2jrX0028UAhlV9+La+60dl TzeAKR01tA/slUwwbwgvMruOwp2YjROlwoQ9RbLN88tKhFJ3HYlXsOruRKw3eNe9K/KL BJ5QG0itBGJVX8qmg2kfGjPJD3+tr9lO1mGf7LXcf3IAkANQUXXdXUrjUnjXCoSyiK9N TfNQ== X-Gm-Message-State: AOJu0YydJYe0x8xdHGTISpETKxVR4hSQOdPV6bxE4eaq3p3XaIki04jC 9D1ikfm6mgyZDA7aYSs664MH8BY7n+3pKvBRLqwi1TjniC/GdXGFz3NgQslLhSuS X-Gm-Gg: AeBDiet4bEhd7XI6h2hfjywPnUsa/o0vpTDb6A9X2cofmeND7QL7ug+XcCZLtQ5jMxc VB1KxlkByXjzgQfs6s+uJTI8KzQu8eCmCbbmExYrjeCoAz5AU+kFWMuKvcPHL3DnU2LWZ28FBWk 88nts/NpNcZb9Qla8ch55tyz0EkAcjX0VmaI9C9iE3jJPBLk6CdTNskE9DJcogfwCSUtvib7+z7 YayT+IxTRx2i7wvyVy3OeAK35s7yWIX0hsPl2AmLDD7gyXWuDQ5eqPGbhe+qKk8DW6DiqzA/HOl ko9/28sCzuc9T/gzFUGju09eCHIFafGmOfc/5Z1IT5Q2m/yEUFpaSYiQcKb7UwxfwYGPRPiTSJk AV6FOSr0C5wNWXl7kF0P9NuHnS+wTjTd5cNn095nlYPUREThsjCcG9E1UvgVOjt8/uukjXt3YhG gWVopI5S7ZVpiSmK5CGpFo4eiePsf8DFcN+D8tf7lirncTNAQcmHpg X-Received: by 2002:a17:90b:4a04:b0:35b:e550:e68a with SMTP id 98e67ed59e1d1-35e4254fb13mr3695835a91.3.1775833516088; Fri, 10 Apr 2026 08:05:16 -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 V6 02/14] iothread: introduce iothread_ref/unref to track attached devices Date: Fri, 10 Apr 2026 23:04:45 +0800 Message-ID: <20260410150457.85190-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1775833587785154101 Content-Type: text/plain; charset="utf-8" Currently, IOThreads do not maintain a record of which devices are associated with them. This makes it difficult to monitor the workload distribution of IOThreads, especially in complex hotplug scenarios involving multiple virtio-blk or virtio-scsi devices. This patch introduces a reference counting and tracking mechanism within the IOThread object: - iothread_ref(): Prepends the device's QOM path to a list. - iothread_unref(): Searches for the device path using a custom string comparison (g_strcmp0), releases the associated memory upon a successful match. - holders: A GList storing the QOM paths of attached devices for runtime introspection. This infrastructure allows management tools and QMP commands to query the attachment status of IOThreads. Signed-off-by: Zhang Chen --- include/system/iothread.h | 1 + iothread.c | 56 +++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/include/system/iothread.h b/include/system/iothread.h index e26d13c6c7..21a76bd70d 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -33,6 +33,7 @@ struct IOThread { bool stopping; /* has iothread_stop() been called? */ bool running; /* should iothread_run() continue? */ int thread_id; + GList *holders; /* an array of QOM paths for attached devi= ces */ =20 /* AioContext poll parameters */ int64_t poll_max_ns; diff --git a/iothread.c b/iothread.c index caf68e0764..c43266b191 100644 --- a/iothread.c +++ b/iothread.c @@ -36,6 +36,55 @@ #define IOTHREAD_POLL_MAX_NS_DEFAULT 0ULL #endif =20 +/* + * Add holder device path to the list. + */ +static void iothread_ref(IOThread *iothread, const char *holder) +{ + IoThreadHolder *h =3D g_new0(IoThreadHolder, 1); + + if (holder && holder[0] =3D=3D '/') { + h->type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT; + h->u.qom_object.data =3D g_strdup(holder); + } else { + h->type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE; + h->u.block_node.data =3D g_strdup(holder ? holder : "unknown"); + } + + iothread->holders =3D g_list_prepend(iothread->holders, h); +} + +static int iothread_holder_compare(gconstpointer a, gconstpointer b) +{ + const IoThreadHolder *holder_node =3D a; + const char *target_name =3D b; + const char *current_name =3D NULL; + + if (holder_node->type =3D=3D IO_THREAD_HOLDER_KIND_QOM_OBJECT) { + current_name =3D holder_node->u.qom_object.data; + } else if (holder_node->type =3D=3D IO_THREAD_HOLDER_KIND_BLOCK_NODE) { + current_name =3D holder_node->u.block_node.data; + } + + return g_strcmp0(current_name, target_name); +} + +/* + * Delete holder device path from the list. + */ +static void iothread_unref(IOThread *iothread, const char *holder) +{ + GList *link =3D g_list_find_custom(iothread->holders, holder, + (GCompareFunc)iothread_holder_compare= ); + + /* We don't support unref without a link */ + 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; @@ -115,6 +164,9 @@ static void iothread_instance_finalize(Object *obj) =20 iothread_stop(iothread); =20 + /* We don't support finalize without holders */ + assert(iothread->holders =3D=3D NULL); + /* * Before glib2 2.33.10, there is a glib2 bug that GSource context * pointer may not be cleared even if the context has already been @@ -336,6 +388,10 @@ char *iothread_get_id(IOThread *iothread) =20 AioContext *iothread_get_aio_context(IOThread *iothread) { + /* Remove in next patch for build */ + iothread_ref(iothread, "tmp"); + iothread_unref(iothread, "tmp"); + return iothread->ctx; } =20 diff --git a/qapi/misc.json b/qapi/misc.json index 1f5062df2a..d65d8012b2 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -67,6 +67,54 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 + +## +# @IoThreadHolderBlockNode: +# +# @data: Block node name. +# +# Since: 11.0 +# +## +{ 'struct': 'IoThreadHolderBlockNode', + 'data': { 'data': 'str' } } + +## +# @IoThreadHolderQomObject: +# +# @data: QOM path. +# +# Since: 11.0 +# +## +{ 'struct': 'IoThreadHolderQomObject', + 'data': { 'data': 'str' } } + +## +# @IoThreadHolderKind: +# +# @block-node: Block node name. +# @qom-object: Standard QOM path. +# +# Since: 11.0 +## +{ 'enum': 'IoThreadHolderKind', + 'data': [ 'block-node', 'qom-object' ] } + +## +# @IoThreadHolder: +# +# @type: Current IoThread holder type support QOM path and Block node. +# +# Since: 11.0 +## +{ 'union': 'IoThreadHolder', + 'base': { 'type': 'IoThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-node': 'IoThreadHolderBlockNode', + 'qom-object': 'IoThreadHolderQomObject' } } + ## # @IOThreadInfo: # --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833577; cv=none; d=zohomail.com; s=zohoarc; b=j2E7pefCLYHy4uhm7fZ8up3KC/YlKhfXfUX5LcuGH/V/tyouiWaKoeiss7tSKJJWrLHpUVijO148f49HapsmY8Sn3c3bciIuJBASa8EWvE7znLE6UMXQ7NWowj5H1ONqOusKl8U3/VRSwQ8q3DtBeBG21sIPTYqkcl9LxPE2AxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833577; 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=mPLKHQIKiWNj5QAnc2OyjCMMfWZ4IzzJUVCAIUexiKU=; b=UUKHRwgRDrvvPPmpg9aqtlEsa7sVtAVeacikle2oHTv0uyHGkrj1wyQ/J4qawnHyZ7GybxgmgPlQvkVslo2rUKGA/TipMHl092vXEfdpHa/kyhfMtJndhboih20+bUH+gSlSxF/EUFgzo3bpskOC0W1J/8jk2T3+i5IBKDznBSo= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833577738982.1530599970068; Fri, 10 Apr 2026 08:06:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQF-0006dl-OW; Fri, 10 Apr 2026 11:05:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQB-0006YX-UW for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:24 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQA-0002Ce-3y for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:23 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-35da2d35eccso1777732a91.0 for ; Fri, 10 Apr 2026 08:05:21 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833520; x=1776438320; 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=mPLKHQIKiWNj5QAnc2OyjCMMfWZ4IzzJUVCAIUexiKU=; b=S4RVruJFr2YltKKsJ8tuhTFK1lUaKEYB0biUEaMxZbiZrJV/i/7PZXisQgfICSsBeR XPJgwL6OcuDRgmmL67KXXLfHMB/d59/p2wbXy9by9Z7eTzBx8Rn7BkuyeDKGkCrxg8hW h3NMZNbCZGCp6o914sBH7NBuADyhsfmeK0isbgNZMnI5XQXkcEsgHxvBryjleOVKmNMP mCIHuEjNqmBAnHG4kahzkYOaklWurTKTWc4/x/lvW4CmHaL3cdIrwrM7uIrO0RwweAsw 5ZH+k3BA1GqYmsYIj6QSR9FiyD/zQcfug7mE678bvWcT6GNhjT36QSAWiA0MeOEGxK/U K0rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833520; x=1776438320; 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=mPLKHQIKiWNj5QAnc2OyjCMMfWZ4IzzJUVCAIUexiKU=; b=W1OjpdfDlJ5yrtqQ3OdOgK5fFSZNnSuL1QirjdiMNILZI0lAqlKjbj5QZWlSOt1hgK 1fQVcyFY8x5HtSsQp9uIU/Phyvm/zuMDrKfsLakkDCcYa+WV6z/+EiqSRC7Ng5W1+mXV Zynnl/4eZ1W9ptO3wYd7PjZ5JZ8b30TGTbY/l2ALgPYSaIlu9uu0Ew+l2En1+n0YPxmZ 4el2O57yX0m8X8p8EJ+RUA8jEF8AIrxIgSWyoJfhB5ZIN9aZQTH8uu5oCj+vyeb/oSNh VZDPK/Yx2DTaa0HgvrdAsOFcxEFEzIx6JsUGVHNasIJM6Phoj6xpaYxFVycV1wxTeZ9P nw3Q== X-Gm-Message-State: AOJu0YyJrV/1c+5lF0IyteyMtzSAZ8sqhwAoH/fRZSOW0mg/cXGJo+kH Jv73TF5MzZXp5rhL/FBqyKNyhhpuA+wws0N8x9lvu1bxuk50HQvIfFvWDwJkLa3o X-Gm-Gg: AeBDietEQO5u6oUkyG570QCU8p8x4fSRllSgVROOHKFp4Nqm32L2sRqAA3Abt3OkEAT APsUcRDGTjLMb4xCMaU4w9xQOYqpBv59JM6Xf0EdTu/d1s2Ez9mgKOu15tjJJKxrKNhIYOhJAfm eGVvsmqz/0BCTwadfnwPpi+Y2tgiEanSo7XEsmZurmkuUfG0F//Ncq+OuoWrN//WAe1b1F5EBBa YOors4s2qz0atZpFACqrs4Y4X/BQi7LwYe1/Th1Brt97NwBDNCKy5HJoWOqigDWY+8JRXKR+B/R 8q7V5x+cS1ea2mjF6PU14is8+KwYOIxW4AmODsZu4dHfHCfgjflIAJUzl+BagcPzlX7EXDVFQjY CkDfCwJRsc6PD2tof6AMv7JZptINJM2s5XojXO+HZkYtCWeS8HDyRZS4+v8S17XijGDFiEneXZN ba0zNo+X0+WHoihhir+mCgtJHlmISkxWaNwK15k+44KLnNlHx9KU0YIiEuDjj2Cv0= X-Received: by 2002:a17:90b:350b:b0:35d:a2d3:5c44 with SMTP id 98e67ed59e1d1-35e428581f9mr3562718a91.28.1775833519753; Fri, 10 Apr 2026 08:05:19 -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 V6 03/14] iothread: tracking iothread users with holder name Date: Fri, 10 Apr 2026 23:04:46 +0800 Message-ID: <20260410150457.85190-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1775833579666154100 Content-Type: text/plain; charset="utf-8" Introduce iothread_get_aio_context() with a 'holder' argument and its counterpart iothread_put_aio_context(). Previously, users of an IOThread's AioContext did not explicitly record their identity, making it difficult to debug which devices or subsystems were pinning an IOThread. This patch enhances the reference counting mechanism by: 1. Automatically incrementing the object reference count when a context is retrieved. 2. Tracking holders by name using iothread_ref() and iothread_unref(). In iothread_instance_finalize(), we now retrieve the source name from the GMainContext to correctly unref the initial internal holder. Signed-off-by: Zhang Chen --- include/system/iothread.h | 3 +++ iothread.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index 21a76bd70d..dbada8249c 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -48,6 +48,9 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); AioContext *iothread_get_aio_context(IOThread *iothread); +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const char *holder); +void iothread_put_aio_context(IOThread *iothread, const char *holder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 /* diff --git a/iothread.c b/iothread.c index c43266b191..60a024f770 100644 --- a/iothread.c +++ b/iothread.c @@ -52,6 +52,12 @@ static void iothread_ref(IOThread *iothread, const char = *holder) } =20 iothread->holders =3D g_list_prepend(iothread->holders, h); + + /* + * This guarantees that the IOThread and its AioContext remain alive + * as long as there is a holder. + */ + object_ref(OBJECT(iothread)); } =20 static int iothread_holder_compare(gconstpointer a, gconstpointer b) @@ -83,6 +89,8 @@ static void iothread_unref(IOThread *iothread, const char= *holder) IoThreadHolder *h =3D (IoThreadHolder *)link->data; qapi_free_IoThreadHolder(h); iothread->holders =3D g_list_delete_link(iothread->holders, link); + + object_unref(OBJECT(iothread)); } =20 static void *iothread_run(void *opaque) @@ -196,7 +204,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); @@ -388,13 +396,30 @@ char *iothread_get_id(IOThread *iothread) =20 AioContext *iothread_get_aio_context(IOThread *iothread) { - /* Remove in next patch for build */ - iothread_ref(iothread, "tmp"); - iothread_unref(iothread, "tmp"); + return iothread->ctx; +} + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const char *holder) +{ + /* + * In some cases, iothread user need the ctx to clearup other resource. + * When holder is empty, back to the legacy way. + */ + if (holder) { + /* Add holder device path to the list */ + iothread_ref(iothread, holder); + } =20 return iothread->ctx; } =20 +void iothread_put_aio_context(IOThread *iothread, const char *holder) +{ + /* Delete holder device path from the list */ + iothread_unref(iothread, holder); +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833618; cv=none; d=zohomail.com; s=zohoarc; b=U7LtKFx2RAmUZU4lz+dbW8y60HBN0y2QmQlDTgPOwA/YsLNqYjCW9V8F0zPuZ+qEH9lhubgjf6p2nlA/dc1CI0Dckv2jxwLD/JNLOUpfPJJp89PU82T3idZbODySlOtZWIHUd2TnWQEmvKEav/cz4IpmSF6AX2veJFW/kpiON+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833618; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4l9Xr1hbjH1tyACtoEoX12/kjkgfEPIxAbMNxctooNw=; b=FaGeQ0ShnpOy69U3rFYYahx4A7ISX0KZMYaEx9SyuXc3rTky/uCXkqvHZvD2Ubbk49GGg8y0ZAUJnQIV3pcIcQUn1dXoQFouwk/KCQHgVajdRdcD12/rzZwrRKBmCF3Krad8FGCb9+OkCAfyFvCdhSHJgcZFoCfx8S14E/gWZF0= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833618252381.4151529330379; Fri, 10 Apr 2026 08:06:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQH-0006jM-KF; Fri, 10 Apr 2026 11:05:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQG-0006g4-H3 for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:28 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQE-0002IH-VG for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:28 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-35d9f68d011so1484103a91.2 for ; Fri, 10 Apr 2026 08:05:25 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833524; x=1776438324; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4l9Xr1hbjH1tyACtoEoX12/kjkgfEPIxAbMNxctooNw=; b=VD2kRAQicJ2apLSjS3dc9r1RBstwYrOwfswsNIpcjB/n10qQ1JuR76/cU74XEGCDu7 V8DwxA0sIMBKlv7j9r2q9eSDWwix2lJ3y1RX0qYkx+prWYVTzpO2ofzpOJNPzRELnQMD iN2rLZtyr1xy4a9cTunTSoX8ilOvn99rXt7WKgBZvD6jX3tTGHR2riLxMIvB3rpImAVl o5/4n6f1gSUn28DamlzgIlXIM5y+l5UMREY1DlrnXRUY+KKw+04XHmSGr9Isc/bpy3/q X32NeN2dt+vnhzg9uL8tZ2CoXsNjAz0ugHAZHeyrPb1ipRUe65rdjRYBm9Y0iwxxT19N XygQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833524; x=1776438324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4l9Xr1hbjH1tyACtoEoX12/kjkgfEPIxAbMNxctooNw=; b=m/ipLvNEXyYgPMlBwS74ns9SeFiVLt893Ydv9Of80FW4cYQqbaZNBKS4TKGRdX3qXh AI2b82SnUkkKUgZF5NEFlAmnOCP+DkYHsQXhvLN+9FFeA+4Ep5rm2xvOkvz0+Q5EVJCc y8/NCkDqp/5VnQNKYAvwCzbSShnpwSsx4TevkXS/+PE7wUG4pCeKzYtJqDY9SJNYwqLc +DXtpvoOJkAsoFRh8ntS5fo+C5nh3KEW4JKXm+9CcxPHoKeujeip056nvD1xb3drhhJc c7P0SLAvcP7InJYma97V9ycmAApD7gR/VJHeuKxS3Vxmsrjfh484L/uY+rAdi7yrvOtv 4vrA== X-Gm-Message-State: AOJu0YzPtMZ2U9YQ4I4WyuQ0KasAKDKZLxCnLBn7/u8H1414cuHeX4la ikpTUBRXqdippLKx9VYwxzu+gVSK4kD55rPjXm0B6OQ0ZAbSbhROzrZHaZs6WEaj X-Gm-Gg: AeBDievRSwkb8Qmky+IU7b4kkHL9dT61vK9oTIJlNDOMnW1h9dxRWWIMYqjk7VuPbj5 07U7SnpYVPsoe9pEtpglIlC/hsBd9Ge8mXh+3ZsUieNK5PBxOHWDrXWJmlWpgoneeIjcA5H3PtH Uv6kjzFlU/4Ow5/AMGQ3JOjLeowtq/gJtnzDIvWoL+NId6GTRupDPe87a+2/0whJnPr05LtvOUJ 4hBGBFugR3pdRsCa9TgjiqFIKFSqnOYM8R6+mv6d9wht/4XgiG004MiupUYDipkGDUThjUm0A81 ZRwwTFMoa9D+EjzsBp8ZizFn8m/jdtmBMnfNnNsoofMiqaBhk4vhcLnn+Leq6tSBNqB79c+xLIX XtgWlwFuX2ODUK18Tp4CBnaH1UNl1P7W0aUVyZHLCApydQupg8l1akTisbjC/nIhzqArQEX90wk 38o8j2kFgmx4tpS/7TiuRKSlOKZpfhrt3R6Zz5GkfVPZ9t8rpLpGWU X-Received: by 2002:a17:90b:4d83:b0:359:8a78:569c with SMTP id 98e67ed59e1d1-35e42827fd2mr3755164a91.25.1775833523456; Fri, 10 Apr 2026 08:05: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 V6 04/14] blockdev: Update tracking iothread users with holder name Date: Fri, 10 Apr 2026 23:04:47 +0800 Message-ID: <20260410150457.85190-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102f.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: 1775833619579158500 Content-Type: text/plain; charset="utf-8" Currently, x-blockdev-set-iothread changes the AioContext but does not track the IOThread object itself within the block layer. This makes it difficult to manage IOThread reference counting (put/get) during dynamic context switching. Introduce an 'iothread' field to BlockDriverState to store the current assigned IOThread. Update qmp_x_blockdev_set_iothread to perform proper reference counting using iothread_ref/put when moving nodes between an IOThread and the main loop. This ensures 'info iothreads' (holders) accurately reflects the block device attachment state after dynamic migrations. Signed-off-by: Zhang Chen --- blockdev.c | 6 +++++- include/block/block_int-common.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 6e86c6262f..6e20579187 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,8 +3683,12 @@ void qmp_x_blockdev_set_iothread(const char *node_na= me, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_get_aio_context(obj); + new_context =3D iothread_ref_and_get_aio_context(obj, node_name); + bs->iothread =3D obj; } else { + if (bs->iothread) { + iothread_put_aio_context(bs->iothread, node_name); + } new_context =3D qemu_get_aio_context(); } =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 147c08155f..6edaf53377 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -1101,6 +1101,8 @@ typedef struct BdrvBlockStatusCache { int64_t data_end; } BdrvBlockStatusCache; =20 +typedef struct IOThread IOThread; + struct BlockDriverState { /* * Protected by big QEMU lock or read-only after opening. No special @@ -1289,6 +1291,9 @@ struct BlockDriverState { =20 /* array of write pointers' location of each zone in the zoned device.= */ BlockZoneWps *wps; + + /* Track the iothread for detach aio context*/ + IOThread *iothread; }; =20 struct BlockBackendRootState { --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833610; cv=none; d=zohomail.com; s=zohoarc; b=FuzvbfFbygTB1Dp0f6o320L66hT1bNq65fWhkWu3maZuPRH+x5Ng/eCFFH+e62H4xYrM5VesJvrQz2VS6Ix1nyMpOn9dZUxmTyuaKjP1Tkk3SbP1z0YVZ80OY5b5HMq/fu6LYod4ibXGXsaZ3tM79BqjVQLcZwXbML9opvIQr48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833610; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=EymO5tSqFtAwi/vz20IiHYVc4pwCZ7EUNbbZ4yCKKnOSiJEyBgY8dV+ulCmm8nNOlUpv60hPBwL2sIucO12ItyWYx3wNGiv+m41F0ZYWSTRGRuchvkylDR4LvKE8aF8WDLdpsCfPVk5cbYe7+bbXxuCBrSNJU0nw9RB67Vu4YRM= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833610151304.59498666814125; Fri, 10 Apr 2026 08:06:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQL-0006pF-EQ; Fri, 10 Apr 2026 11:05:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQK-0006l6-0w for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:32 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQH-0002LW-O2 for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:31 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-35d90833cacso1542931a91.2 for ; Fri, 10 Apr 2026 08:05:29 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833528; x=1776438328; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=Livk5s4iJrbYf9+e4iZU96kPP0FKJVmXw1n5roxOrimeuMn7p5b0irMjci7BP+rs5b JzkRSC8Tis91gWmWHEi4W6Js3FXSYgtwySMIRbin9VPVc7kXNeeZNCycyPjufEvcqG0e sdCoSLAtfbwtB9VquJ0TJ0jPQ+qoAxtT+oVs83cOeUsETu5veDM7wD0A1mL1s15g3B8s 3g0RkEqURNJyLshI0skHEkP+2Bg++E5KKJe9V8yRAn595jAJZibmcIeXYCR+Lrie63xJ 8Rntfd2yT6wrmzt8UHl59Onv/eMr6m9XuUehjPercT/0Wz1RsifGzL9XlWkF6EvTWP25 9NyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833528; x=1776438328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=NeSh3xm3f8NwznlBZzMHzlIyn2tu0YjCM+qdkMAXppHWelkhGB2ASrP3J2y8zZoqK/ H7LFD8wPEgK7p6BBTg06BJdRVWmP3IB1pMjsNPBzmZa1iP0K00jZtuL4H8Yu4QLRmD13 O1A9N6Ag010qtlyma3EZs3fnOKUfEHsnj/czMCt6iH4Tgm3oWDRfIUD3O9stFyK4r87F twa6mBW8PmmlAdNnJvSfS2HVxcVUAIym+3VIHxEWOckyftKEdLmJbTmCHKvcZ7IjuSmL Jf2zbwMPLl3Q+L2vX2q2eEfmcALf6AND2oVUB8PQ5Rf2jBOUDhLFpbPmWI/XrVSjy2q8 Ma5Q== X-Gm-Message-State: AOJu0YyNeJyjMzNv3iMxVPRuFdEs/x72BaoElfbFFwWFRNEj3rnmNl6g CaCTT2xMUGdVMM+e7sI9QjxvK/DN5+48Yp9LI7BG1QvNwFUW9TPc1m9E3TiV5yWE X-Gm-Gg: AeBDiev9o5iHqNN3Cdyx21Jt+3qhGyLLihu/vw0EjxkPUuw6KnC3VSMgF7EXguTt911 CBcG34Xu3FZGQMJPzscSufPqSukh/bIdMyHbAlec/sPUuSXyJ1LvHBcfzau8uz2S2+QEAAKIfM/ SFDpN8g4OCsaNLeDuDqxZ1SQVOw7/xH+ZfDm2n727RRwtd06vo/gPJTf+mQtn71mzRdq26f9MkL XIPhvFZEMl9zk5Xustx4RsRG9SB4546b10jYdPkUUV2vpzLUY26B+Vu/dtsnQclAUxrkeEq5WKb gZhGlNMh7ubi5EJDuWBDhD8uqkyubWB+xadLTWfA4VW3IcuhkrUvJ/UK3+2vENHtndgF/Bh5XY5 Cf3dKSxSei1PyrPWTtQ3Ii4hT60wbnHbi2IMKqMT3SfBIGlGivbJrWn8zFCQ2u72iJf7b+Bo15Q FZtFVKk8De94Y2ytGEc/0Df/XKO6Hn8l4pNdRUV+JARzD5jjCeUmAr X-Received: by 2002:a17:90b:3c48:b0:35b:e690:c5ad with SMTP id 98e67ed59e1d1-35e42849e8cmr3830790a91.25.1775833527394; Fri, 10 Apr 2026 08:05:27 -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 V6 05/14] block/export: track IOThread reference in BlockExport Date: Fri, 10 Apr 2026 23:04:48 +0800 Message-ID: <20260410150457.85190-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102d.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: 1775833611554158500 Content-Type: text/plain; charset="utf-8" Users currently lack visibility into which block exports are utilizing specific IOThreads. This patch integrates IOThread referencing into the BlockExport lifecycle. - Add iothreads array and holder_name to BlockExport struct. - Use iothread_ref_and_get_aio_context during export creation. - Implement proper cleanup in blk_exp_add fail path and blk_exp_delete_bh. - Support both single and multi-iothread export configurations. This ensures IOThread 'holders' status correctly reflects active block exports for better debugging and resource tracking. Signed-off-by: Zhang Chen --- block/export/export.c | 44 +++++++++++++++++++++++++++++++++--------- include/block/export.h | 6 ++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..636633c324 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,7 +15,6 @@ =20 #include "block/block.h" #include "system/block-backend.h" -#include "system/iothread.h" #include "block/export.h" #include "block/fuse.h" #include "block/nbd.h" @@ -85,6 +84,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Erro= r **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + const char *holder_name =3D NULL; uint64_t perm; int ret; =20 @@ -139,7 +140,11 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + holder_name =3D bdrv_get_node_name(bs); + new_ctx =3D iothread_ref_and_get_aio_context(iothread, holder_name= ); + multithread_count =3D 1; + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +168,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return NULL; } =20 + local_iothreads =3D g_new0(IOThread *, multithread_count); multithread_ctxs =3D g_new(AioContext *, multithread_count); i =3D 0; + holder_name =3D bdrv_get_node_name(bs); for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,7 +179,9 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) error_setg(errp, "iothread \"%s\" not found", e->value); goto fail; } - multithread_ctxs[i++] =3D iothread_get_aio_context(iothread); + local_iothreads[i] =3D iothread; + multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, + holder_n= ame); } assert(i =3D=3D multithread_count); } @@ -225,12 +234,15 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D drv, - .refcount =3D 1, - .user_owned =3D true, - .id =3D g_strdup(export->id), - .ctx =3D ctx, - .blk =3D blk, + .drv =3D drv, + .refcount =3D 1, + .user_owned =3D true, + .id =3D g_strdup(export->id), + .ctx =3D ctx, + .blk =3D blk, + .iothreads =3D g_steal_pointer(&local_iothreads), + .iothread_count =3D multithread_count, + .iothread_holder_name =3D g_strdup(holder_name), }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -253,6 +265,13 @@ fail: g_free(exp->id); g_free(exp); } + if (local_iothreads) { + for (size_t j =3D 0; j < multithread_count; j++) { + if (local_iothreads[j]) { + iothread_put_aio_context(local_iothreads[j], holder_name); + } + } + } g_free(multithread_ctxs); return NULL; } @@ -269,6 +288,13 @@ static void blk_exp_delete_bh(void *opaque) BlockExport *exp =3D opaque; =20 assert(exp->refcount =3D=3D 0); + if (exp->iothreads) { + for (size_t i =3D 0; i < exp->iothread_count; i++) { + iothread_put_aio_context(exp->iothreads[i], + exp->iothread_holder_name); + } + g_free(exp->iothreads); + } QLIST_REMOVE(exp, next); exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..2bb98aae31 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -16,6 +16,7 @@ =20 #include "qapi/qapi-types-block-export.h" #include "qemu/queue.h" +#include "system/iothread.h" =20 typedef struct BlockExport BlockExport; =20 @@ -89,6 +90,11 @@ struct BlockExport { =20 /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; + + /* The iothreads list for block_exports */ + IOThread **iothreads; + size_t iothread_count; + char *iothread_holder_name; }; =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833577; cv=none; d=zohomail.com; s=zohoarc; b=gDDAoIH/CagMZkmc+On5tuBqU8wT95HqhdzfEbKF3bojEIGZzRWUHU0FOZznz7EIvRDxDyX1PQyOEFF/HhGxsfOs7uCvhchB1GxzNhuxmn5z2rhlTDyJgf5KD4LylMWRwYtm9SzseejzzuwIcLXlgjxYIRx5fAWRqjsGChfys/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833577; 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=x69ooA9/Ciku7C9KOIVP3A4OcWl7JOZ863rt2HmRx3I=; b=fRVMxpTDq/2zZdRHBHHp2mPLBb2nd4ykRLKTaiNEmkWhVmqpPN4nFQnv6UqraSLQVLzvwN2Esy3Iem5mrFBePC7MfFV9kiIBjC2GVOF4rNfct9iKKKBDDQ/+PQLjexMsBMdUKYPQ5N0rAJBcVmY1Ee8Y7KxGI+nW15t5IbYiU1c= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17758335773776.2028049837365415; Fri, 10 Apr 2026 08:06:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQO-0006yv-Ty; Fri, 10 Apr 2026 11:05:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQN-0006yX-6e for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:35 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQL-0002S0-Gy for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:34 -0400 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-3590042fa8eso1729726a91.1 for ; Fri, 10 Apr 2026 08:05:33 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833532; x=1776438332; 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=x69ooA9/Ciku7C9KOIVP3A4OcWl7JOZ863rt2HmRx3I=; b=a1FslxY2KL7qIN8v4urhyxoTiSB8Eg6C5Bvd1Gzt/gAgdfwYdCOaguX9bf2kW/Be9k 7qQ2kODsxP92AbAhPRVSozVNXwtom6GYhhkJjTEtA6x/FfriIUnSdRTDA5Y1holLjcCP nBqao/7qDrh7S2Ms1eutxqpRKkTVrZA+fvtZVxiWL+Qkl+8veYaCDlbf17JT7JfIn3+k OwL2WjuvMwWSGbdJ90CY0uwX8UZELBhFHDhEcwNqfISAMLHxxvZZaCeJCgj1UaBmaLmm 2aqqFD0lYxXDz/K7lIbzEuHaEac4Fn4mT67yXlMjqwQD83BLKLt2ZzKgBg/FFrC/zD3s ckdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833532; x=1776438332; 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=x69ooA9/Ciku7C9KOIVP3A4OcWl7JOZ863rt2HmRx3I=; b=dEFIQMOLsaMebT8zUbKuwBaQGr0/BJMJWxNh+LjeaTY2Fp13x3H7K+5ElUBAWfAFm9 mVaWZRvGIdANmrSU9jxHxiooh7kxOAgMlWuDlmg0hNLfRSRQ4AxIdSxxCuEF+ixBSRSN w6LNufpZSQD6Xqw9/c2jPErmwCMFL2X6AO3Av9IY3JCA000xw72qzAnhpDh4XwIGuxzY kORngbT7hMHqpe8m0gKawja8BnPMZB4nxqMTNy8i5TUXFD4dxxyG7DRcmUGX6EiAIGl8 LAzANRiH0QsL7OuqVJB1JUItTWtPfvSN3w9WnGuvSNjlo3YaVs0GyvBbsfnhZbE95k1b KKaA== X-Gm-Message-State: AOJu0YzqTdWGuQoe0zf4SKrNpxvjJlHp6BEvJ2sqP72ipKP91XhkkrFl V5ksaj+/M3d3XpKkA6EJ1W25NFPHlYY668EuhOrKs3bSBTgFw5/UF88OJ206UeCJ X-Gm-Gg: AeBDietEMkzYHSfgEUHeiswluUAGR4NIj0zOGZCR//Yr9zIdJupWvtvzQ4guskC8hOp VutF0KQ3iH/9K+qOJP+YLU6lLq92ufBki82agvpxd1ih0zaliUGd5L/V5Q8kDwjhOWaloFQel8D XTxFPJinm303tsf8ipNU+qYjDQ7zJ3sGdzPp+gdKrpHYtY9Qy9tsPbV6X3EWS2cBaTv1hKI0B7k Y5UIgkt102tg7+rPIyp+nWUUCB8s5g2/fyLO0DmS8wS9mXC+BnC3LKMfusn+1L0s2YurcivWTvr 4Oypu7fqwZuy9ZxAAxYugyoEX2xFBRMnX1lrFeieQ68gVK36vI0nfgot1DnBWLkxWi7na0+hL8o rl8KxFFfKNfex2lZN/+20YCt2Y9jHz6O+0JJx7ym7HuFGQeR6q9W5b7fFl6BehCoqy2Wqqu10JD uNPG7u8GDCSSWhpv1eQyOdSyf1vjQx0V3EdiNe1FhuBF7sZx3MWKUm X-Received: by 2002:a17:90b:268b:b0:35c:30a8:322 with SMTP id 98e67ed59e1d1-35e4245a667mr3694581a91.0.1775833531337; Fri, 10 Apr 2026 08:05: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 V6 06/14] monitor: Update tracking iothread users with holder name Date: Fri, 10 Apr 2026 23:04:49 +0800 Message-ID: <20260410150457.85190-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1036.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: 1775833579376158500 Content-Type: text/plain; charset="utf-8" Since the Monitor struct is not a QOM Object, we cannot use object_get_canonical_path(). Instead, this patch uses the monitor's name (or a default type-based name) as the holder identifier. Cache the AioContext in the Monitor struct to avoid repeated calls to iothread_get_aio_context() and ensure symmetrical ref/unref during monitor lifecycle. Signed-off-by: Zhang Chen --- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 24 ++++++++++++++++++++++-- monitor/qmp.c | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index feca111ae3..51cedf90e4 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -116,6 +116,9 @@ struct Monitor { guint out_watch; int mux_out; int reset_seen; + + /* iothread context */ + AioContext *ctx; }; =20 struct MonitorHMP { diff --git a/monitor/monitor.c b/monitor/monitor.c index 00b93ed612..b6efe776d6 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -529,7 +529,7 @@ int monitor_suspend(Monitor *mon) * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. */ - aio_notify(iothread_get_aio_context(mon_iothread)); + aio_notify(mon->ctx); } =20 trace_monitor_suspend(mon, 1); @@ -564,7 +564,7 @@ void monitor_resume(Monitor *mon) AioContext *ctx; =20 if (mon->use_io_thread) { - ctx =3D iothread_get_aio_context(mon_iothread); + ctx =3D mon->ctx; } else { ctx =3D qemu_get_aio_context(); } @@ -612,6 +612,18 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool= skip_flush, { if (use_io_thread && !mon_iothread) { monitor_iothread_init(); + /* + * Because of current Monitor is not a QOM Object, + * so using OBJECT(mon) is undefined behavior and may crash. + * Try using a hard-coded future implementation of the qom path in= stead. + * (Like the name of the "mon_iothread"). + * long-term solution would be making Monitor QOM, after that chan= ge + * here to: + * g_autofree path =3D object_get_canonical_path(OBJECT(mon)); + */ + g_autofree char *path =3D g_strdup(is_qmp ? "/monitor/qmp_mon0" : + "/monitor/hmp_mon0"); + mon->ctx =3D iothread_ref_and_get_aio_context(mon_iothread, path); } qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; @@ -631,6 +643,14 @@ void monitor_data_destroy(Monitor *mon) } g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); + + if (mon->ctx && mon_iothread) { + g_autofree char *path =3D g_strdup(monitor_is_qmp(mon) ? + "/monitor/qmp_mon0" : + "/monitor/hmp_mon0"); + iothread_put_aio_context(mon_iothread, path); + mon->ctx =3D NULL; + } } =20 void monitor_cleanup(void) diff --git a/monitor/qmp.c b/monitor/qmp.c index 687019811f..8e4a775fac 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -549,7 +549,8 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error = **errp) * since chardev might be running in the monitor I/O * thread. Schedule a bottom half. */ - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread), + Monitor *mon_p =3D &mon->common; + aio_bh_schedule_oneshot(mon_p->ctx, monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ } else { --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833587; cv=none; d=zohomail.com; s=zohoarc; b=Wrv35APlnkhZ0R8TZ4uo5sfmR5IKWLRCPwIoICTTZuEmINZGZCl/2uISYPbU/chIcOWajFtFlcUZ5WSwqcJ+kZTOIEQH5jj8t5EuvtASI/HD0dRfiShKmZO+a/1KzlDPkI/V3OUTarSeSuiZBZKTKk1aJDx1QUsA5qkaDlOqPMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833587; 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=+ccoofNrZf0b3d/nWoo3fwp+WZHm2ASoYUOnT7UOhwQ=; b=RckA9au4s4zAeSektNxtYkgUp5chU6EG7ylgznDtIOHDaHHSfJzYabjGQsU7zQ5lSimdnhDgb86F/mHmFslxRRVn+1VqOQsHJfRSPfVOR5KUaYDPAEDwZX8NEecv0n/+9TPSiz69SQn0iIpcd42ZHgT1YoJoam22fTHB9Q6FLTI= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833587934295.2265064050646; Fri, 10 Apr 2026 08:06:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQT-00076D-4b; Fri, 10 Apr 2026 11:05:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQR-00070q-EG for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:39 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQP-0002W2-Ln for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:39 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-35da2d35eccso1777941a91.0 for ; Fri, 10 Apr 2026 08:05:37 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833536; x=1776438336; 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=+ccoofNrZf0b3d/nWoo3fwp+WZHm2ASoYUOnT7UOhwQ=; b=Wqo4meYbFzIIyHs55rxrX2HdZ/l+khCiP60xVrx21mGvWZYnY/YEpI7N2SDn6Zi+Ss voYYTyBIiwhwMQQW6x4XRJ7FMyWqK4lh7M3opb3OLNZt6ydixL4JDoxdtkoRTJyoIbVC 6lrqA7PU1bTMltmiZrgT2F3QJEzAHUoBGraAymxVLRMk9W2QnHezK3ImaKGB6w0OBBA4 7vHC8dPIBHsommiQzy1K3T1jO41v1XdPbFfKSsgaFGUGVwQfy6F7WicXjRyrsco9iIQP SB2jwllp2aVDeaKFHf4Ht5SOtRQQwnnvdRG96Uz69GXxVbo8GvXUo27QOXW3MOqKT7tF kAXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833536; x=1776438336; 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=+ccoofNrZf0b3d/nWoo3fwp+WZHm2ASoYUOnT7UOhwQ=; b=E4wxWPL9aDSqzUw4ubeGmvmCRfLABYQQk6vd0EJGqp0j9PaL9YFdRIquqdPyszfaKs +aaBFH/sIRK6gDR6u9inS5qf4dVgkWjETWKY+vENWgzji2SiEJx2Vh8W0E4d0cKHxSTn 7evu5OxqMKtv4s0R6Ee7cAXaA6El7ryVWqU/r+p1nczHcl+mE95QOYFXgSgUt6CXn1kj YTojivtJO1mLXe3dbt+v4nt+UfDTOUPzB/HPgoGeuhyH733ex2gvbCfTtWMr/9bFr2Qq qk4ypAOmNwpeIbo/6+k+/26PrDU/FXR/+kcSTTZUObmeeTqdIkq09D7j2kDfjDJr+4Ue FYKg== X-Gm-Message-State: AOJu0YwDRPEnmC0stKrB9v0ASl4cVEA4zy/c/XjLfJexPNkpOromz3Ix SwWe2UCZ6OuOErf++CcFc464BPhZp0wG2RDUX6d2qDgl4Sb/vroabYZNIgC76El+ X-Gm-Gg: AeBDiesjRqi2Pgz2dnmkDoqHSlA+YVOMdxLMMk2pQOZRZBL+7KpkLSvMqpgtRtOqkuE MVUNsNx6wicI7l91sm3i3Z+oHczMOJ4iUu6Yy3Tl4wUooXSsKN60+k1jJIWes9dssXD0+EXpwZB 1omvse7LmqwtgfV7UFyHl8NrJ8ZGhXzzHAvfg3sjyeRAXM0Kh6ooWbdKsvTR0IaqQRAStOxp0iM Tg3wdnsczfbSFWcbniVCCHiqiys2zNe4pUfh2+Eg3c9tAQHAH70rwzCMJWEKhyfnDpOkXwzuvln eP2rr0lytEUJPoK5eKPDuzKbiI0YgmJf9p1NqSLKEsSLUeC4MvNO2YMfCEj5gUbrpmzxTor5BDA DXu6rqC9GtblKtlRX/5qehzioX/CfgHIkqpH/L2a4kSfzPSNglxfKUodG5Dj1cHp6dGch5/OfH0 jvJEE5WYGMl0QDGKzZCojYqmqIWUzy4bcSGvN0+z3g58wI+HJhlsqV X-Received: by 2002:a17:90b:2684:b0:35b:e4f8:7ac5 with SMTP id 98e67ed59e1d1-35e4276f4fdmr3702742a91.7.1775833535521; Fri, 10 Apr 2026 08:05:35 -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 V6 07/14] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Fri, 10 Apr 2026 23:04:50 +0800 Message-ID: <20260410150457.85190-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1032.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: 1775833589842154100 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context in iothread-vq-mapping. This allows tracking IOThread users via the device's canonical QOM path, improving lifecycle traceability for virtio-blk and virtio-scsi devices. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 11 +++++------ include/hw/virtio/iothread-vq-mapping.h | 6 +++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index ddf0e9ee53..762714f4ba 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1453,9 +1453,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; @@ -1487,7 +1490,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIO= Block *s) assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 95f13fb7c2..26ecefd547 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -65,9 +65,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], - vs->conf.num_queues, errp)) { + vs->conf.num_queues, path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); =20 if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 55ce62986c..c993281d7f 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -77,6 +77,7 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp) { IOThreadVirtQueueMappingList *node; @@ -93,10 +94,7 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_get_aio_context(iothread); - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, hol= der); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +118,14 @@ bool iothread_vq_mapping_apply( return true; } =20 -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + iothread_put_aio_context(iothread, holder); } } =20 diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/io= thread-vq-mapping.h index 57335c3703..0d39caddf3 100644 --- a/include/hw/virtio/iothread-vq-mapping.h +++ b/include/hw/virtio/iothread-vq-mapping.h @@ -17,6 +17,7 @@ * @list: The mapping of virtqueues to IOThreads. * @vq_aio_context: The array of AioContext pointers to fill in. * @num_queues: The length of @vq_aio_context. + * @holder: The QOM paths for attached device. * @errp: If an error occurs, a pointer to the area to store the error. * * Fill in the AioContext for each virtqueue in the @vq_aio_context array = given @@ -31,15 +32,18 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp); =20 /** * iothread_vq_mapping_cleanup: * @list: The mapping of virtqueues to IOThreads. + * @holder: The QOM paths for attached device. * * Release IOThread object references that were acquired by * iothread_vq_mapping_apply(). */ -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder); =20 #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833624; cv=none; d=zohomail.com; s=zohoarc; b=Gc707F6iEdfrhsDitpxp5XMfdGw6bXbrABWjp630i1bHtBHeAapQCXGaR+90a4L5yFcRdBjrM9ewUWKRBcrX7uRJ0RKoJpTNkEgCZnY4TLHmnXRcQTUvoUdM/L3w1gB8DXs1gfaBMwHjlB8P931YWJjgdUXwXmOqEzvjoXAwTAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833624; 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=ZF3Zfhgg1+dMZbKh+1FfG0J0Eo/81Bufn7es25E8QL8=; b=HCMf+kVxBr8wHw6lrnIcgSIPH/n6wbPSd03daCJdvmzo4Yg46kG1CjxelJVMtheaOIORQDJ9TI/0Zmsxbrp/hijRHXQPy/dV+/SIUvz0Rji+SzKBVw7sQeVkVhqh5sMFvX0KWw7U1eYzm2YwHjU194Q8ULDXmosfYkU409vQf48= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833624700727.5912926140943; Fri, 10 Apr 2026 08:07:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQW-00079K-N6; Fri, 10 Apr 2026 11:05:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQV-00078M-EF for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:43 -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 1wBDQT-0002XR-MT for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:43 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-c76eea1672aso798083a12.1 for ; Fri, 10 Apr 2026 08:05:41 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833540; x=1776438340; 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=ZF3Zfhgg1+dMZbKh+1FfG0J0Eo/81Bufn7es25E8QL8=; b=Jpj2arBbdkkXMQ37iSs19A3axuxn67y6YIqvu04KfxDs2Lo2LYYrs9JdkhemKVlap4 sFPlGsZubmRZdJLbUYTgj+GDPPEYWdggpnvVGKzDZ8JPoXHd9frNPp3VkDCjtXnoh89m VaOmUoK0bWZXre3xHx9fntVmuqI1A+S3H7lFOY9LdOkP6Im3uoNAHS2inmlRXKkK/PVN MJl89wMtEgc2dF4y4zytlpk7iOLkR+NSm1Ls1GFFG0cpyjYqsq++1BN3laBNHbgkXF8f dlwoyICqZzG5KdIDJTH683fTmoch641cj9KuBifaHhevuILIQSJqCwK4sgm/BmF9P4Iw zzmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833540; x=1776438340; 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=ZF3Zfhgg1+dMZbKh+1FfG0J0Eo/81Bufn7es25E8QL8=; b=d87e+Q1XqkHgJ8H6TIxr0MQsnkOJeBCGg4I5a5fPrApKp99g05WDKMfYTEh4osChsY /urCYz/N5+yINYsXiaPQf4v8xsGu5wAVAPZQUnseSftR7HMIFHJ+2GvkJw6McZHD1d+f fsskqtAt4FbfglGJcQTZ4DSoKBmYUtlqeMPH4MZ5n1SmHACnNaDmA9PLa7Ha6n2EuOxM GEBLYlIE+Zmg/J+iP0v2QuhZTmIXE1hT23t5PyK8efKo5B7W04uvpt4tGtPVBoFFE9pS I69YfHvG7Hwy/4WmQz38hVDoTGW/XC+JzmTD/20HXMhoxJeZnZPTJcYjdMtCH8G/zNY+ /yVA== X-Gm-Message-State: AOJu0YzK1aG7rIFTAeetPYGfzM8I0TCTn+5ao9DC0VtjZd0LS5cSkSix yHTE6lqdHxEK4saLPxF4lAhROJQomKgrT2+ZR3qS4gKn+W1SCDGzu2e2To9x3koQ X-Gm-Gg: AeBDievSr15qzo3u2FhgaJ/oljyP07y0Be3zadxdioqT86Ax3gxtsl/qfRfjU5QpP0a XdVSnfbFTiWsSla5pqwWUMeFAJjdziXrIfrWNBP/KmYVU6xHqNZo7izDCAIRCB0LLy6zm67PjQ/ wfjp//2SpKz2GfSIeaQgaSktU6Ih9LKFx3whtcjVijA6p8KKEmcWLhDmH0nz4KGVyP7OO55C2gf m0bUjMJo0ykMt2XQZsQF3Q/IQYC3zGoQW5RqTf2d91b4g/faQda+XsiUdub8PFT43vkKxwnldOg Z51aOvEdtlwho6x2QTTLXiwMY5kJFel77XJNMJFPZgKm2xjHOBvksPF6qcpo/qMiMPSHNODLUZF szBxdYdw/mjyJtCTGCO5f09cdJ2eacLKv9twm6gp8KU9baEADa03irtiH0fnfhwzLzmt8BTTD10 SdBN8okSBUhfyMd3gNhmuY8oxlgLTMltA/fgX3M1Iv+gsdZiPxvqh1 X-Received: by 2002:a17:90b:3950:b0:35e:30bc:804d with SMTP id 98e67ed59e1d1-35e42846535mr3353354a91.15.1775833539525; Fri, 10 Apr 2026 08:05:39 -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 V6 08/14] virtio: use iothread_get/put_aio_context for thread pinning Date: Fri, 10 Apr 2026 23:04:51 +0800 Message-ID: <20260410150457.85190-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.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: 1775833626352154100 Content-Type: text/plain; charset="utf-8" Refactor virtio-blk and virtio-scsi to use the new iothread_get/put APIs for AioContext management. This ensures IOThread references are tracked via the device's canonical QOM path. Summary of changes: - Lift 'path' scope to cover both vq_mapping and single iothread cases. - Replace raw object_ref/unref with iothread_get/put_aio_context. - Ensure consistent memory cleanup of the QOM path string. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 16 +++++----------- hw/scsi/virtio-scsi-dataplane.c | 15 +++++---------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 762714f4ba..70fc85bdde 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1429,6 +1429,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, @@ -1453,8 +1454,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, @@ -1465,13 +1464,11 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_get_aio_context(conf->iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, + path); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(conf->iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < conf->num_queues; i++) { @@ -1486,21 +1483,18 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) { VirtIOBlkConf *conf =3D &s->conf; + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { - object_unref(OBJECT(conf->iothread)); + iothread_put_aio_context(conf->iothread, path); } =20 - g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; } =20 diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 26ecefd547..cc318162f5 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -28,6 +28,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) VirtIODevice *vdev =3D VIRTIO_DEVICE(s); BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { error_setg(errp, @@ -65,8 +66,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], vs->conf.num_queues, path, errp)) { @@ -75,13 +74,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + path); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < vs->conf.num_queues; i++) { @@ -94,16 +91,14 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { - object_unref(OBJECT(vs->conf.iothread)); + iothread_put_aio_context(vs->conf.iothread, path); } =20 g_free(s->vq_aio_context); --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833614; cv=none; d=zohomail.com; s=zohoarc; b=iAcwtTpAq8sadfHB1j16WGHg6RkKojePbTq8LZdkYwm1yYFy+5sOdIbqOSd3LJyOEtbyK/xzrqKEVRz7tSe3rIFcJkhPQsHIQ+bFiKm3NLA57ef/7D6hRSiSO1p936zK0isNdRhBPxnJCxjdDM/y6gEW2DppsgdBCmb/pQ5ivSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833614; 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=a1Kh3XSHSeM1ZEixAaGnsOegNSycBCR3GL6VS/B2SVg=; b=mv1rstVZA+lKRyr4IReo2xgMuqeZY49DAlMOoRS3Ej6v0B//mLU23uDOp96iANol71yvuOlExWZwfaM7ocTDmCuNx7VjxQKgbBVDnNn/LuhL20B3jtI1GNPrxNWBCiNZAHmTa8Q4MxERXwd1Lzq//l5PvxScKPUwCKb7AdfUYl8= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833614946543.1835136021532; Fri, 10 Apr 2026 08:06:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQZ-0007AA-QH; Fri, 10 Apr 2026 11:05:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQY-00079j-Ey for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:46 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQX-0002Y1-0s for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:46 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-35c238f1063so1608781a91.1 for ; Fri, 10 Apr 2026 08:05:44 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833543; x=1776438343; 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=a1Kh3XSHSeM1ZEixAaGnsOegNSycBCR3GL6VS/B2SVg=; b=DdL5ohiIU1IvTFomJgwbItORplh48Q4AGjuD0lDDPFPfI6BKwKIrC6vpArhMldJVrW EaoMqpOipG81p1c80M7kQT1xaqYV1dt71xn7RoXCRcFawQWKEtBAvct0VQ8HVDh7T7bA jsWnid5zVx+XMF2JTcGgFT+NL+SB5MF4OWRDa6vi09ecKuoyG39c3Dhm+EEZ0xd2XzMz LundSR+si0PCy5w3N2psXo1rfhETKY7XjwK6u68eYy/I/TXuY7rtZOh4iHgBYg6nFyro 3bdIOCN94WtILAiOsNDliQ7nbwcctYu7nZORxpbfp0wr+a2vlDFJW5i0js0c4aXD7gR1 U/WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833543; x=1776438343; 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=a1Kh3XSHSeM1ZEixAaGnsOegNSycBCR3GL6VS/B2SVg=; b=gyGMtQj4CJyEutV8lECrUDE4lUWhFMcfw/ocsomrAyIMwxakieokugdEwb7h5BHJrM vrpl05RbRtJV7CzLIrD9P/EkG+9CxwTGrPiPBFgdousVG7UYaHVRJ/bQbmsbhbYOqmEo QRkzFawel7d1sJqgh/sZlv1EYrc5HjvmPnbgUcmM/fCYBeW77ppBfN7YcM1cEXGse14Q Jfdlf6tW6uxlgSOuTn7l5Yn7UHIZxdjZ7ET1uLfiEivS84cYa4fRyu57mWvuqVPJDdNm I+pdkmuZ+RfcwVy1E3/q5QxnoTppzugAuSb5bkTYS6SH3XOCp48MhowNQWzrs3LWa9SW iIZw== X-Gm-Message-State: AOJu0YyE7q+iFt8idBZXEaHgJFINm7llExH4vN8V29Dcd7zQjr1/PqJL S/rIjpLvfO65X6BxNBFv0oZPHjuXmjH66WZNM92eRxtKI/iLdUUrv43hF9U4QMMz X-Gm-Gg: AeBDieuvx6kV1s8+AXo/h634XJXzMXs2eY1K01tKm6dGFN5Glx6MsFwvz4Ykjh0Xn4z fkzq5n31cfYRJFnV4ZGoAlYbkiO3yzU6e3cUfFjD/htC66zZnosjMQOKUkR2j71Nyi77hXkKqyM qDb4A7R478TTuhwFllMwAkNz9Wxlg8eoQWaVE8tRmi/uCRUKUo2lThD/Sq6xDL79j6J+SXA9JID zkR9UQoqCpWVn94ETeV4UEtVT/ZDWEQCn5kNC9LXWm79WuEzT8l6gfEcNElFMzoQpPKMH1rPbkT 7Pt0uCFZPHIM574/26UP/sHT5QL2ZQE69dXdsZm/lK7SGD7Samfl8wi5WxoPXplFlWUjhxfWFvj p+PEUymPAZ2CUAgeZn5GM0SWATcO2+Ylg9H5zVQpLoq3lPrZWvdGFNXy5MwpnDRt30bCfpaZilu w4abo6424l88GyfPFjiVGLzrhay0cNRDsWXzEKRiV3nh2AlGliTY10 X-Received: by 2002:a17:90b:2e8c:b0:35b:a7be:ae47 with SMTP id 98e67ed59e1d1-35e428321d5mr3767159a91.21.1775833543121; Fri, 10 Apr 2026 08:05:43 -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 V6 09/14] net/colo: track IOThread references using path-based holder Date: Fri, 10 Apr 2026 23:04:52 +0800 Message-ID: <20260410150457.85190-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102a.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: 1775833615589158500 Content-Type: text/plain; charset="utf-8" Convert colo-compare to use the iothread_ref_and_get_aio_context() and iothread_put_aio_context() APIs. This ensures that IOThread references are tracked using the COLO object's canonical QOM path as the holder ID. This refactoring improves IOThread lifecycle traceability and aligns the code with modern QEMU iothread reference management patterns. Signed-off-by: Zhang Chen --- net/colo-compare.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index c356419d6a..f3231257d2 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -130,6 +130,7 @@ struct CompareState { GHashTable *connection_track_table; =20 IOThread *iothread; + AioContext *iothread_ctx; GMainContext *worker_context; QEMUTimer *packet_check_timer; =20 @@ -926,9 +927,7 @@ void colo_notify_compares_event(void *opaque, int event= , Error **errp) =20 static void colo_compare_timer_init(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - s->packet_check_timer =3D aio_timer_new(ctx, QEMU_CLOCK_HOST, + s->packet_check_timer =3D aio_timer_new(s->iothread_ctx, QEMU_CLOCK_HO= ST, SCALE_MS, check_old_packet_regular, s); timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) + @@ -968,8 +967,10 @@ static void colo_compare_handle_event(void *opaque) =20 static void colo_compare_iothread(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - object_ref(OBJECT(s->iothread)); + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, path= ); + + s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, @@ -1408,6 +1409,7 @@ static void colo_compare_finalize(Object *obj) { CompareState *s =3D COLO_COMPARE(obj); CompareState *tmp =3D NULL; + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); =20 qemu_mutex_lock(&colo_compare_mutex); QTAILQ_FOREACH(tmp, &net_compares, next) { @@ -1434,11 +1436,11 @@ static void colo_compare_finalize(Object *obj) =20 qemu_bh_delete(s->event_bh); =20 - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - AIO_WAIT_WHILE(ctx, !s->out_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->out_sendco.done); if (s->notify_dev) { - AIO_WAIT_WHILE(ctx, !s->notify_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->notify_sendco.done); } + iothread_put_aio_context(s->iothread, path); =20 /* Release all unhandled packets after compare thead exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833616; cv=none; d=zohomail.com; s=zohoarc; b=S6dLRXitB//qQ5xH35+ZJAlvAQuHL+wopNCO71EEu41c5e5MFcI5Krj/26lA52VcLgWcsNStBururOjIdaOBnqOWf6QceQv2a3jGGorVyltSRmFf97E2KLEfAiSIlNum8D6CV/UXlTACv8d2kQ9y9uV4KcTIJiMBvgqS3dqDh4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833616; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=23F2qkNukByaUJQk9pbl2bbnzE/ZXLLhOxWd32Zs67g=; b=MbhL3IrJPWrwaVSPENNNWFyLkIScgQQeXuG19NaJw/9Knlh8GcCYXoQgpCd3OFdoW+j2Lx66R7vchW+PbI8CYM44idySQA/GssIE+bubVf0MbENA11bBgnatz6SnEuHW2KtAy0dtT7kccwkY25ZeZ1ylq5ku/G713O9X1pceu+s= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833616294653.3714571587157; Fri, 10 Apr 2026 08:06:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQe-0007Hw-56; Fri, 10 Apr 2026 11:05:52 -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 1wBDQc-0007DM-RG for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:50 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQb-0002YQ-D0 for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:50 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-35d932cc948so1558922a91.2 for ; Fri, 10 Apr 2026 08:05:49 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833547; x=1776438347; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=23F2qkNukByaUJQk9pbl2bbnzE/ZXLLhOxWd32Zs67g=; b=W6Jjm37tW5CCR7sEIjp8ea+Kof/SrYYfjWlDOnsSoxN7aSbjObtemRxW87MMYBqJXH VfcVmqXTboESP0wU8TxFn5qGaON8cD8PRh3ZZs8/f9YgbvSLEflRrRqAf57NayEwhNWm ps5SnWGouMqH67Jz9bu6BP8hBqgid9OHaREBvZUYmkmsX+oOpSi3ru0pLit5o4k5foZR aNQToUO8ll/Y7E7v/1est8PwpEIXhLV8OEv//7uxzTpa/C730wHZQhiJxeBThil6uY3F xRbiM7xzPCQodnRVVMfbVMIDsGqcoIihHPWdmLa/tGKh/fIGpyCdIDiZAp5qft35M0ax OEkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833547; x=1776438347; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=23F2qkNukByaUJQk9pbl2bbnzE/ZXLLhOxWd32Zs67g=; b=fTGFtiTZ62dv0CiXzpCSYIAGf7rT5GM+XS1c8UV5fgNBKbEZlWhdVMSVs26WXEeQMr TD8n7SBunfXspmbzVdSwZfk4r2B1V4eJSytw2LLPbttGviVXSdsa4/vP/2rlhBP1uNHO sSvBTOnCoox1+md3SqV1B2xRPYpwVVFL4YvKGFdEV8ss7aRoVHCCl49ms2wjnv1BNWut syF+x63A+BftBxj3GU3cjVwYFTUdPsUsRAjdPPOMh08Oyl01936h8ER8hpHHmLMcKwBV l86qlUvzU+SugkiIXpckgd6JFgj+YDmVvq9XnCzr/r4uBgciD/X5Pew7uc5tmfCg1xUl l6Xw== X-Gm-Message-State: AOJu0Yw/6WUBomRPIy0HszHp3Nd9LviC4S214Kd4JzR0j6Qdt1m8Zm2G p906zitKdWoGOl2gmAXGR7XSKNGmvDrA6+gfWMI1qc7ED5OhD4ymtmhNWLBUlVPS X-Gm-Gg: AeBDieucZOCjejLro0cKIfEDx6Q0TqfpctHHH7J7rM+wXqiuvMuFw7Q99JPHsV07Bhd J8/b/G7vYmAh9H9Qhrszk4qyThTMe4uioszGKcPNhfHDrPoOwxL+stFAkkiYHK2Nr7sQum17lr4 WxyUOH+tjUPF5U/ypqtZACglgZGTJgChDNCWCiwIYTBL051/8udJJlA4SkDqQywwDyHOAjTgC7y cvEgTpOnI2+pCDwF6P9iQuf/A2oJ2aZewMhJkBamgrgmOvjmRlYwbFchz/olZsUR9bzaI5cg1nx 3rl35u0XN6EH+hK+GAKXTMaYyKsm9gibEnKprQv116EasFYPbFAzswrPFrfw3yeRHw3m5mfDq2v 28pOy9rqLzUcW3CYB9O9PVhGKjr//XB8AswlM4xAXWurTxZzUnP1KcQJgmOJKKCJ+lQ1uYkoQYw /uRC0hrBVc1/6tMmiJTsrp7GbEH2svskqbp0Cq2v28RsCezJy0RrVDs3Y9OPHt9uI= X-Received: by 2002:a17:90b:48cf:b0:35b:91e1:e110 with SMTP id 98e67ed59e1d1-35e4285b82cmr3225326a91.20.1775833547281; Fri, 10 Apr 2026 08:05:47 -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 V6 10/14] virtio-balloon: Update tracking iothread users with holder name Date: Fri, 10 Apr 2026 23:04:53 +0800 Message-ID: <20260410150457.85190-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1035.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: 1775833618274154100 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/virtio/virtio-balloon.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 4c5f486ba2..8a4494905a 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -892,14 +892,16 @@ static void virtio_balloon_device_realize(DeviceState= *dev, Error **errp) s->svq =3D virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HI= NT)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page= _vq); precopy_add_notifier(&s->free_page_hint_notify); =20 - object_ref(OBJECT(s->iothread)); - s->free_page_bh =3D aio_bh_new_guarded(iothread_get_aio_context(s-= >iothread), - virtio_ballloon_get_free_page= _hints, s, - &dev->mem_reentrancy_guard); + s->free_page_bh =3D aio_bh_new_guarded( + iothread_ref_and_get_aio_context(s->iothread, = path), + virtio_ballloon_get_free_page_hints, s, + &dev->mem_reentrancy_guard); } =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { @@ -919,9 +921,11 @@ static void virtio_balloon_device_unrealize(DeviceStat= e *dev) =20 qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_bh_delete(s->free_page_bh); - object_unref(OBJECT(s->iothread)); virtio_balloon_free_page_stop(s); + iothread_put_aio_context(s->iothread, path); precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833614; cv=none; d=zohomail.com; s=zohoarc; b=AMgWGlDFIUKE6sWduR2ImQbaZg8sF0mARkay5bRSaJM5lf1Um0TV4GcsOKWvqh4lPy9ntkZXbI+z3x1A4cCJQ2yWivLey/HF6XDha1x3agp+4Usj3b7GXHrlb58grRp5DrjY/q31+JxSPIGn5sE5yes7upzakjHEM5gkjRfkJHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833614; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NsI6Qqs4AUchAJ89hl2uKc8SPPduRq1NaW8uY3dlWFc=; b=KWmYL3eqawrYA2i+YmK5u7y9nY/RH/Ic1mSm3K6/CK9LO4LyfkKpitcTb80L/uZ/F93TcgHnQ/Ql6ffm64nEMrU3PDPrAsZ3UdvXymUQSSpXxZMFK6iiV1ZdISa+OxhguoJUIvWwVuMI4kGHeUzbZiSbHCaZHfTWOGXb6YU4d5k= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833614195234.93368064601066; Fri, 10 Apr 2026 08:06:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQi-0007g3-JE; Fri, 10 Apr 2026 11:05:56 -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 1wBDQg-0007ZZ-RQ for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:54 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQf-0002ZS-7C for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:54 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-35d9f68d011so1484460a91.2 for ; Fri, 10 Apr 2026 08:05:52 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833551; x=1776438351; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NsI6Qqs4AUchAJ89hl2uKc8SPPduRq1NaW8uY3dlWFc=; b=NAx1VusIavEVYH71AKS53+0NttJoaN4wraqCp1sWHQhVeRgqi2IgyqZUKKvdwwkmQz U2ainIB3UuPA5Y2LGUbUieEcFVfJ2qpqnBcwjjQJo383rox7LdV40zZa2vxU/OVF0gXE ldX36jFTo4IFeqpMLzPICq60BHVVoj/HVHeSK4vbAG2xKXiYV9n3VC3bapSoWxHBzpu0 +jj0bQWrkeX7zURUyPimeZg5L/dvZGegkPNdCnlKKoRa/gxpuRFOTo5UiYeTNOOK5Yy7 PDp5Q1iSKu+Ohn5LfH/HFvYxyBnfTiMl2MP7K5xylP4x9JERygdmeqaXcE5ynYXkvCHt tQ2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833551; x=1776438351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NsI6Qqs4AUchAJ89hl2uKc8SPPduRq1NaW8uY3dlWFc=; b=SXd7FGZi+dqHol84mKsc0kpP6vCWCjlRuX+w5OQnAhutZpekv/nwp61gJQMIn1zN2/ cuZO311YO2uZLM2RYW1eIoxkFQ0cfGvKiTsXS+CdfC9V9CvptPKjBo88fVrkczv0ZeAD Sui8Gl5vRgppgPAYsPRddvKZPvLQiURo6/ondgiP/pEpZHXGPOHPTr1t0KKmnoS0Cqsb xuZ8QuRsUnp0WNG4GUoYEOxpqZX2t0wIOqoW5GMJiiuY4qYmxnMjj1Av83YJgbUvSJS8 OEVeeL3x0r9V+It1KZjvblJ0oGWAbOYejexr1W6k8SRkFTNC7lWuw1ExnTRZCsfpcRhU j08Q== X-Gm-Message-State: AOJu0YxktFmpEb5+5pZw8HR+pizxJLfzaMOG97Gq541BBqGIacsWJZdr xEJMvns7QOfHg9dmisicB30H1Y2fFVaFdYuX8z8SQiB6hsKGi4LgssOJrnCuCp8Z X-Gm-Gg: AeBDieuQthZSEpeUsKrjvFNG082CCv+EW6n/M4ndH1yWwkIM1d0i1SY3Dxm8qmr+E4+ teP8addlAgBgLQ5R6ZPznuS936wisH72wHWd6dcAiYBIkrkeSY/FwsWxNuWzNA+4+GFxcQ8ie2u jBE0b+NLRjdVBHkjFVFiu/VkwDVML33+agZo5j819r2tRCdHkYDoECHMlTz6AoXy0Fa5Snaords CMFtHvULKHLOe4y+cMA/KauCiWK0hVwFuQUuGC2ivPW+kgklAD0FGetrWuJzqcUZjh6+4cQPTAx 7O9WolfuS9H9asby+RcTNIL8uIzSTfzXlDx0XxMxONAe8ivWxa+iljVG6Jxapzkth9i/rnhSKY0 EoSqdI3mm0FVNJvSj+s+b6ITwKf+CHaW5xZQ2PuVBwtUoEM+o0adALe6IISILoEAqBeI5c2HGGL TpiJOFFQFNGrgiHcLzVdi6Q5aPRb2URrsl+oKA3a+k3H7xjYFeGQaP X-Received: by 2002:a17:90b:17c9:b0:35d:a87b:ef69 with SMTP id 98e67ed59e1d1-35e4283ddd4mr3769800a91.28.1775833551167; Fri, 10 Apr 2026 08:05:51 -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 V6 11/14] vfio-user/proxy: Update tracking iothread users with holder name Date: Fri, 10 Apr 2026 23:04:54 +0800 Message-ID: <20260410150457.85190-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102a.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: 1775833615576158500 Content-Type: text/plain; charset="utf-8" Add object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/vfio-user/proxy.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 314dfd23d8..eebe202c4a 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -898,6 +898,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) QIOChannelSocket *sioc; QIOChannel *ioc; char *sockname; + g_autofree char *path; =20 if (addr->type !=3D SOCKET_ADDRESS_TYPE_UNIX) { error_setg(errp, "vfio_user_connect - bad address family"); @@ -917,6 +918,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) proxy =3D g_malloc0(sizeof(VFIOUserProxy)); proxy->sockname =3D g_strdup_printf("unix:%s", sockname); proxy->ioc =3D ioc; + path =3D object_get_canonical_path(OBJECT(proxy->ioc)); =20 /* init defaults */ proxy->max_xfer_size =3D VFIO_USER_DEF_MAX_XFER; @@ -936,7 +938,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("VFIO user", errp); } =20 - proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread); + proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, pa= th); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); @@ -967,6 +969,7 @@ void vfio_user_set_handler(VFIODevice *vbasedev, void vfio_user_disconnect(VFIOUserProxy *proxy) { VFIOUserMsg *r1, *r2; + g_autofree char *path =3D object_get_canonical_path(OBJECT(proxy->ioc)= ); =20 qemu_mutex_lock(&proxy->lock); =20 @@ -1021,6 +1024,8 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) qemu_cond_destroy(&proxy->close_cv); qemu_mutex_destroy(&proxy->lock); =20 + iothread_put_aio_context(vfio_user_iothread, path); + QLIST_REMOVE(proxy, next); if (QLIST_EMPTY(&vfio_user_sockets)) { iothread_destroy(vfio_user_iothread); --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833633; cv=none; d=zohomail.com; s=zohoarc; b=W13N4o8Bd2TC1mgE3Dq5YyN4atmaakl8/dGe0Ay4XON9zbhdZP5Vxli7CrGiZ2eFxSzo2bI+txNlL0N+d5Q1/7js0aTgpwkjoh7eQkFvGucmrjI8+V8Ib2W3Oh+fqpkvWm4/7Di+moFzhpINR9AJ7DXh2S7mJTAvB97UnyN1nN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833633; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2bylwVIvheE4A13Mb11/ZHCJxDZDhKuXhRjY1sr2Fkk=; b=cDAUq0iL8lNxqLuuYmQlpw7535+YXlyWlM+1zuJCdf/IZ7SGNeSctEcPzERRZNGN8Jx24d4VhgjvGWTa4XMHC6TnpUIaWyaC33saFp98AlU5Pp/K+g3iBzS/KF/6lYu8JBn+LQBvG78+HAXa9xzjDRMH9jksb76YfIKDxD44aC4= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833633771880.2685960993025; Fri, 10 Apr 2026 08:07:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQm-0007vm-38; Fri, 10 Apr 2026 11:06:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQk-0007mb-37 for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:58 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQi-0002a7-Jv for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:57 -0400 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-35d971fb6f1so1965006a91.0 for ; Fri, 10 Apr 2026 08:05:56 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833555; x=1776438355; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2bylwVIvheE4A13Mb11/ZHCJxDZDhKuXhRjY1sr2Fkk=; b=PmxZkZdS9fQUBYI/Q4aeeVpovfi1C+z/8ipsFvPhu6PxeYS+FDmsZsXJjYL4Fnqb5c EktAT2m0wpxyeWRTiYAXnIb6ar+0S/8CI7tnMsbUa3I2TXBCDa8mRBAmR/cUQZeMkAn9 eem+dz6iZnAnifPjdSucm7CkWst1Lh1+cMf4B3SYecL30cEg/5Jv+xMPBIT9/5Mylp7h 8tVqdz3DYLhXlZXkdTRFSrQGHD5eoFqYuM5F0Fb+WXQqTyx8W/rz3vb3CzhkPYoQZstu cOSXa5bKK3hiyrUtbBdVNQ+wtdZvaL+PFd7NUv2OdWUCpqMa5LnU5aUixhIxM3osH7Rv LkSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833555; x=1776438355; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2bylwVIvheE4A13Mb11/ZHCJxDZDhKuXhRjY1sr2Fkk=; b=d6kEkUuP2O4kls4gl883N9LEdQ2yC4yX0fBf5TYMfglXtNxS6jIp3PsdBfBnB8gDxD QsWkZRdCwrfjVi3wC6Wph99WFm0l2o6X4V35zj4s3pilB1BNmQPfjTGdB4zLVQQXQdFa idagOg59X4Wj1mCBpOpNiRkJJRtVDZGZ2501Pz1Y6n1B6jGhg5x65+PgUeD9Kb+kcOYb 7QUohoat+1QSHqkn10/cJW5k8dTbh8PgQ8RqtBYMVVzq3PfTF4fszGhm0IO56dHKTiPg AKbV9A/KIHpb0IDCH874Pyshy6+meKqC1KAaDp33BLX01juko8jmglY4JaEWane0q9lW s/Eg== X-Gm-Message-State: AOJu0YzfybSuBIFyacerwYp1e7bJGhi1LpY7f1/zstn23bMw/SCaEI5E 1/dY9LHEHs3hgPGfh+dv7kqqX3mJWPGR2YusEzEZfkkqzQ8SqUxkU/GDaUbCr00V X-Gm-Gg: AeBDievql9vNXoxxNNYhB9avCb8ukTwakWcIOOKKpAJJo+gexc2B+DjMQFluXiOCDnT 3Q+9BzVDENmc8ayKfnIdX2p+zEsIk/LCRp2VDY1rrVx5VMq5NWAT9AvA30J0piNYGqVH8e9i0qL xk+R40wINuaa9lix8Z94fny/Gcc5LaGQenH8Q8YGDAzVFMnWvitWc9r1LfMM+vCreHqNSRS6TPY Qq1THANrhaEhxZwrB2eOCldU1M3MbjlxFPguv3kh0DSH7oauXwYySG2wOp8PbScB9g/DAT1ZTCP XBidt6DfOnzgozl8z7z+dLB6EArqFqlfyQrbjPbdtpL/zVOjeslalqp8PQud+C4B8aLFxVorFtf bMRqDfoi4+YqXUF/kIylFyVSCRgtUNfXu+VDslHa/yTxjmZ9IIBk+a6bI0Lr8yZAICmupG04Owh zbmDWcwHzOnkeZvx/6py+U9KRttEqexkhIFLpoq5bL8tJurFPjKaeT X-Received: by 2002:a17:90b:5104:b0:34c:904a:d92 with SMTP id 98e67ed59e1d1-35e42859e97mr3983969a91.26.1775833554755; Fri, 10 Apr 2026 08:05:54 -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 V6 12/14] xen-block: Update tracking iothread users with holder name Date: Fri, 10 Apr 2026 23:04:55 +0800 Message-ID: <20260410150457.85190-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1029.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: 1775833635684158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/block/dataplane/xen-block.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 48c2e315f3..552bd8b039 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -621,9 +621,11 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevic= e *xendev, QLIST_INIT(&dataplane->freelist); =20 if (iothread) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); + dataplane->iothread =3D iothread; - object_ref(OBJECT(dataplane->iothread)); - dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread); + dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, + path); } else { dataplane->ctx =3D qemu_get_aio_context(); } @@ -652,7 +654,10 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *da= taplane) =20 qemu_bh_delete(dataplane->bh); if (dataplane->iothread) { - object_unref(OBJECT(dataplane->iothread)); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(dataplane->xendev)); + + iothread_put_aio_context(dataplane->iothread, path); } =20 g_free(dataplane); --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833566; cv=none; d=zohomail.com; s=zohoarc; b=JUBDZqIxTA4niF8uG5RvJP3qa2CEavwbaCxU3RjWJ9MsqcGLnBn3Le8gwgzHa8g22VObvKNkwUazllJF7x+BaZMtAW++2oNOv43qDViCWXwAuHcHta8Ph44kFWvRdOGHdH77IIfzQDO7fG3I9/W8YWuAE4SJKj4usKJFAYbmz3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833566; 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=RQnCW2Bu1yv/B7cGDrJMYN0CGO9ZnuxGzsyVppnfZAU=; b=Uk6TcE9y67CJTkTPQZDjqfGWVZKUEPuKUi2g+C/s4m3DrGltRlERPb+0NiI2I/MD0cFc5EEevpxPknsfFDZIflI+39EO7aVFOwKFvtrwfBaG52o6StF6p4u4+kNZ6Q+4PmFtIdnKzEmcsSrYbKlcpO6i0K9VFNOmBydW3Ocv66M= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833566932830.9459604073738; Fri, 10 Apr 2026 08:06:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQp-0007xW-G5; Fri, 10 Apr 2026 11:06:03 -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 1wBDQo-0007x0-1N for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:06:02 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQm-0002b7-8E for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:06:01 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-35da01fc0baso1410096a91.2 for ; Fri, 10 Apr 2026 08:05:59 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833558; x=1776438358; 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=RQnCW2Bu1yv/B7cGDrJMYN0CGO9ZnuxGzsyVppnfZAU=; b=OIJBjZn5kfXeiuqcp4cwfONmtQi1QlAJJqhrgIFjChCIY+pTU+/cIpville1z9twoj 4uyFihNryUz8vCXP7ftR6rxlhuDEgmSX0A/w3qbDnNKeHrkvFV2W10+Dhr1weDsWpMh+ 2zlG0r09WqxJGaOyXeqjahmqQZqxuQ+OjPvwASzSGIVOuODO2IQnNjocZoTx5U65C4yA Q3l6I70sp7nnudb+CbfmJAaniz6tnnra7z2+uBcNq84aAVMF/K9ZBwOVsiK5gJz/nmx7 ra2TpaK3HtLRYkP7IKSGE7g+4RN1T6Is6EhbSLQ6GoojmJ2O+eFbWSLAIJzpjJAY7IPQ ia5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833558; x=1776438358; 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=RQnCW2Bu1yv/B7cGDrJMYN0CGO9ZnuxGzsyVppnfZAU=; b=ePViVxhmfT28mFkOx/jH4RW5tZ4CFWpO7WSmTZGh1mdHFVqLXvzjavPRANkG0fgl6S oK4nTt7U8BgUvUEE+ugP1Huz6Fx/+lHZMrt5tbeqn6WOeK5dp1WOLz4XxvAowmYH6uP/ Ur34rdHpA+osWpw43s+IQseGG8vpw3dNaS/xN3ij8JFKPy/CEwcredodRgn/HTumpyOe 0O6adWFIbzNCtOW4SvbBsawMuLUVo91dCHo1hki5Rgar1g92pErSV/VSrlNhUZYNPzS8 45+cgmqteyR8p63+FV0GmRi0AJwkTbl5kwwqY42hb/FlZHKGvrDfIf1+SamgZxdimbcO AAZQ== X-Gm-Message-State: AOJu0YxR22gStdrTxRnT/Ibgfs8lmCB36dnqRhntyKdw3hujASdjoWDl xcec6YBHnBkKXgv+6Gv7QaLucnX4iZYBR5LbOuRBpWY9JX5oKLCr/SmpjG4nN5CF X-Gm-Gg: AeBDiesArshEtvIUWJKUIF/Dimu9eqoljTgeyyLhxWJzbRhx0j6QKjs28HghV79s1L1 PnXwVHQozysbAVsp0YVbKtmvXSww8HbF9WSTvOYF2PJpxLIGT7XDJmIL3Xk1R08SPFtVIkQlkXQ wPAFiHbTx5k60UJrEyUjhiS6kxGDOSjZ3MQIs+8/tssXJ9kOgnxi3tSTSErKxzpfQY19G/O3zkX e/pNQqwI9E/Vhwm0DkJOPXJI3k8YWMSVEj6XKpXInZ8zlted74q16uRH5ue8otBqThTDfumylkQ oe+AzqkIFWoeqF3tLHi3MTfGuVhcZQEP1HFqi3qHhHP3cIH4QxR+tql6mByUGyzFyBmeCETo4Jv hh5+hGgFjktXT+whTGCOOje53hBWDzuH6ygAFNGU3oMmsVh5ZyeXbrA9qL9R89ftpdlPUtjrhxq +oC6zoUViz45a0TxMotY0XIc+FKoElQiWOQ2BSvz5QZ6wRktN1mha6 X-Received: by 2002:a17:90b:3dcb:b0:35d:997c:8ec0 with SMTP id 98e67ed59e1d1-35e4282bdb6mr3792959a91.18.1775833558292; Fri, 10 Apr 2026 08:05: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 V6 13/14] qapi: examine IOThread attachment status via query-iothreads Date: Fri, 10 Apr 2026 23:04:56 +0800 Message-ID: <20260410150457.85190-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102e.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: 1775833569527154101 Content-Type: text/plain; charset="utf-8" Extend the 'IOThreadInfo' structure to include attachment metrics. This allows users to monitor the associated devices by identify them by their QOM paths. New fields added to IOThreadInfo: - @holders: IoThreadHolder(QOM path or block node name) of the devices currently associated with this iothread. These fields are also exposed via the Human Monitor Interface (HMP) command 'info iothreads' to assist with manual debugging and performance tuning. Signed-off-by: Zhang Chen --- iothread.c | 22 ++++++++++++++++++++++ monitor/hmp-cmds.c | 22 ++++++++++++++++++++++ qapi/misc.json | 16 ++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/iothread.c b/iothread.c index 60a024f770..70bc5fb62a 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 =20 #ifdef CONFIG_POSIX @@ -93,6 +95,25 @@ static void iothread_unref(IOThread *iothread, const cha= r *holder) object_unref(OBJECT(iothread)); } =20 +static IoThreadHolderList *iothread_get_holders_list(IOThread *iothread) +{ + IoThreadHolderList *head =3D NULL; + IoThreadHolderList **prev =3D &head; + GList *l; + + for (l =3D iothread->holders; l; l =3D l->next) { + IoThreadHolder *src =3D l->data; + IoThreadHolderList *entry =3D g_new0(IoThreadHolderList, 1); + + entry->value =3D QAPI_CLONE(IoThreadHolder, src); + + *prev =3D entry; + prev =3D &entry->next; + } + + return head; +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -434,6 +455,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 bc26b39d70..344eaf330b 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -198,11 +198,33 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qd= ict) IOThreadInfoList *info_list =3D qmp_query_iothreads(NULL); IOThreadInfoList *info; IOThreadInfo *value; + IoThreadHolderList *h; =20 for (info =3D info_list; info; info =3D info->next) { value =3D info->value; monitor_printf(mon, "%s:\n", value->id); monitor_printf(mon, " thread_id=3D%" PRId64 "\n", value->thread_i= d); + monitor_printf(mon, " holders=3D"); + if (value->holders) { + for (h =3D value->holders; h; h =3D h->next) { + IoThreadHolder *holder =3D h->value; + + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_BLOCK_NODE: + monitor_printf(mon, "[block-node: %s]", + holder->u.block_node.data); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_printf(mon, "[qom: %s]", + holder->u.qom_object.data); + break; + default: + monitor_printf(mon, "[unknown]"); + break; + } + } + monitor_printf(mon, "\n"); + } monitor_printf(mon, " poll-max-ns=3D%" PRId64 "\n", value->poll_m= ax_ns); monitor_printf(mon, " poll-grow=3D%" PRId64 "\n", value->poll_gro= w); monitor_printf(mon, " poll-shrink=3D%" PRId64 "\n", value->poll_s= hrink); diff --git a/qapi/misc.json b/qapi/misc.json index d65d8012b2..e173d54a5e 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -94,7 +94,8 @@ # @IoThreadHolderKind: # # @block-node: Block node name. -# @qom-object: Standard QOM path. +# +# @qom-object: QOM path. # # Since: 11.0 ## @@ -104,7 +105,7 @@ ## # @IoThreadHolder: # -# @type: Current IoThread holder type support QOM path and Block node. +# @type: Current IoThread holder type support QOM path and block node. # # Since: 11.0 ## @@ -124,6 +125,13 @@ # # @thread-id: ID of the underlying host thread # +# @holders: IoThreadHolder(QOM path or block node name) of the devices +# currently associated with this iothread. Users can pre-allocate +# multiple iothread objects to serve as a persistent thread pool. +# When a device is hot-unplugged, it is detached from its +# iothread, but the iothread remains available, allowing future +# hot-plugged devices to attach to it. +# # @poll-max-ns: maximum polling time in ns, 0 means polling is # disabled (since 2.9) # @@ -141,6 +149,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IoThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -166,6 +175,8 @@ # { # "id":"iothread0", # "thread-id":3134, +# "holders":["/machine/peripheral/blk1/virtio-backend", +# "/machine/peripheral/blk0/virtio-backend"], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, @@ -174,6 +185,7 @@ # { # "id":"iothread1", # "thread-id":3135, +# "holders":["/machine/peripheral/blk2/virtio-backend"], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, --=20 2.49.0 From nobody Sat Apr 11 17:08:52 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=1775833624; cv=none; d=zohomail.com; s=zohoarc; b=UNi9ZxLf/XgPJmFhH/ppynd/MgD74Cgs29FjX1neB0IkvkRmOPQHYI9z4D4oOM/Awb/VP8VXfx5drtB4SmJ+MZg3YrN545Qlffk5zb01UcDorVuYcSTOjFmOXY5/6ZgxsH+Wn6MM2SvJS1hwBSTpqPJROPtb6mnkttquAdEziHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833624; 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=Y84HVOhRdFiTx4rK3lNBeuuJYVZj1WfUlmRssgWUGlo=; b=eng2CKJFTbBeSvHTSq6QNJtaju9kPbfgrZM+J5Samc6Od1Ojz8xLAVOowzrOR43gJgof+xDYuC+YzqPYeC83a+LrVw7cAbL6DPycNhjRnm6SJr46s77Y/87TfQ4ek1hlPe7bpV9F5zQaTiyVHjpKUu4ion2W37T3Ts7hqJad+Yk= 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 lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833624692380.60975426430116; Fri, 10 Apr 2026 08:07:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQv-0008K5-1W; Fri, 10 Apr 2026 11:06:09 -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 1wBDQt-00089Q-F8 for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:06:07 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQr-0002bx-3b for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:06:06 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-35c1a131946so1333525a91.0 for ; Fri, 10 Apr 2026 08:06:04 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833563; x=1776438363; 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=Y84HVOhRdFiTx4rK3lNBeuuJYVZj1WfUlmRssgWUGlo=; b=dma3fokmW1tnDkriQi0emVjvnf4Uhph46UbJS7CjsTHSFo6bO8Z0y6dKWSyMP+dy0Y gB1g82KpKrSpIgsrO6ZHEv9dI8V3SXQp40q9hE7OVV4BwsAuCMKt+Gk4u8ZWKH57+PNO FcivUrk2SMNFJMX1bvRxZ3cnpUFr/M/LrPeXyjPVcVg2WAE2KYXEwvJZRH42dAcBXF8n oRFFcZ5MbxDO1Q9YgVl/RVC9dxhbgqdRf4FzQGzkJm2BRb8CEI7bRXtBCuEJ+rsdwbAq BsdBnPeZPbvpzvq4IVHks7mrrA/JMQMv4t/XDkPYeLWJgm81LdOO5hF5t7EQcF0xxEPx YwCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833563; x=1776438363; 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=Y84HVOhRdFiTx4rK3lNBeuuJYVZj1WfUlmRssgWUGlo=; b=H3/EzJlGdvlt5MPXnUXrJDGQkxzONGvRKxptd2a+EVAsZvcgCgxKo79EvHTkAfpv5i tDcqSfe99na0HS9JwCID8ta/UUtbRr2eNY+C+Ch7PcjYLeRuTl44sWftCRpVC3Iwi3LZ km1LbhoWT9d57ra/bG1W+6BGJKSwdelw6qVfv+/RYEX5fZywBC5qhzx1Fke/zqQgCunO uEyUNj4tDj4OWgNIuf6XlO4ufQHJRwy7AOjdg7n+e4CHhSg8Y7Bz6OiT5NIqEeA6vBZu P6GijClzD9eu7k/l/u2VncoOh9TS1pEGmYtDkJQbZ0oAGLvVw97CiXAVF+39QU7g7Zd7 Vljg== X-Gm-Message-State: AOJu0YxxGJ+zKzRFnt+TMQXuSU2I9CJ5jRZtQF+d7m8Mk+kuOIWC1+67 yrvU6rwrXQQJ4xzRhSwt1My0O5dUwY8Z7soCxuRQ7b+2xxftHgp4/0IlxI4uqmKc X-Gm-Gg: AeBDieutigLJLSsf6r/HDt2YA1WUbTFn3VjYGjUwuUAat9mmyFMzugSIrDWRsYhz72S T3SpV/zAf/Akx06sj3kyeR08b3fcAW5KfImf6KjUTeCdiHfRgAbhM/BIkVAzNXnf6MA6lRKxTh0 V86O08lHF4fGaGhzflZI2jphkIOekQoxZWYN6uWl7ZThIUjwFzH1WxjM8nXVkPGV03aTpe97Qg+ vzOHG4bPNr4tOI5xKwCwXePObtd79jkvLx0/z0Kvh5KabEC3qGWHpoyGTjg9mumvtUr7Zc8B0xF PxjR/kdQXicgfrOu/X8DQpdt043DnQqKkp8FVmWbsPOIrMeP3N/X5mCPlQr1ZJjJ8ElFvsrpLvJ rEddVXBmXI2WQWmHXuYB77NmlVVJvFxSok447lF1h8hzHge0sP3FheT/VF3Vd0D9Y/oarJ7ijlx W6k46asC09ImubYWcvBo5V4sVlUaQ+pAyharA317KcnjxiNTh1vBYx X-Received: by 2002:a17:90b:2fc7:b0:35d:9276:eba7 with SMTP id 98e67ed59e1d1-35e4302d8afmr2719702a91.7.1775833562973; Fri, 10 Apr 2026 08:06: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 V6 14/14] iothread: simplify API by merging iothread_get_aio_context variants Date: Fri, 10 Apr 2026 23:04:57 +0800 Message-ID: <20260410150457.85190-15-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1775833626499154100 Content-Type: text/plain; charset="utf-8" Simplify the interface by merging iothread_ref_and_get_aio_context() into iothread_get_aio_context(). The updated function now requires a 'holder' parameter, ensuring that every retrieval of an AioContext for long-term use is automatically registered in the IOThread's holder list. Update all callers across block, virtio, scsi, net, and monitor subsystems to match the new signature. This cleanup reduces code redundancy and improves the reliability of IOThread introspection. Signed-off-by: Zhang Chen --- block/export/export.c | 6 +++--- blockdev.c | 2 +- hw/block/dataplane/xen-block.c | 3 +-- hw/block/virtio-blk.c | 3 +-- hw/scsi/virtio-scsi-dataplane.c | 3 +-- hw/vfio-user/proxy.c | 2 +- hw/virtio/iothread-vq-mapping.c | 2 +- hw/virtio/virtio-balloon.c | 2 +- include/system/iothread.h | 5 ++--- iothread.c | 9 ++------- monitor/monitor.c | 2 +- net/colo-compare.c | 2 +- 12 files changed, 16 insertions(+), 25 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index 636633c324..37bcb4f4d6 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -141,7 +141,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) } =20 holder_name =3D bdrv_get_node_name(bs); - new_ctx =3D iothread_ref_and_get_aio_context(iothread, holder_name= ); + new_ctx =3D iothread_get_aio_context(iothread, holder_name); multithread_count =3D 1; local_iothreads =3D g_new0(IOThread *, 1); local_iothreads[0] =3D iothread; @@ -180,8 +180,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) goto fail; } local_iothreads[i] =3D iothread; - multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, - holder_n= ame); + multithread_ctxs[i++] =3D iothread_get_aio_context(iothread, + holder_name); } assert(i =3D=3D multithread_count); } diff --git a/blockdev.c b/blockdev.c index 6e20579187..7eb206a02a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,7 +3683,7 @@ void qmp_x_blockdev_set_iothread(const char *node_nam= e, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_ref_and_get_aio_context(obj, node_name); + new_context =3D iothread_get_aio_context(obj, node_name); bs->iothread =3D obj; } else { if (bs->iothread) { diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 552bd8b039..f5984c86e9 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -624,8 +624,7 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice= *xendev, g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); =20 dataplane->iothread =3D iothread; - dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, - path); + dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread, p= ath); } else { dataplane->ctx =3D qemu_get_aio_context(); } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 70fc85bdde..8c6a3eaa1e 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1464,8 +1464,7 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, - path); + AioContext *ctx =3D iothread_get_aio_context(conf->iothread, path); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index cc318162f5..7b37e3d223 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -74,8 +74,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, - path); + AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread, pa= th); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index eebe202c4a..9a9059290f 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -938,7 +938,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("VFIO user", errp); } =20 - proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, pa= th); + proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread, path); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index c993281d7f..7dadc43c44 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -94,7 +94,7 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, hol= der); + AioContext *ctx =3D iothread_get_aio_context(iothread, holder); =20 if (node->value->vqs) { uint16List *vq; diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 8a4494905a..bd47ba8256 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -899,7 +899,7 @@ static void virtio_balloon_device_realize(DeviceState *= dev, Error **errp) precopy_add_notifier(&s->free_page_hint_notify); =20 s->free_page_bh =3D aio_bh_new_guarded( - iothread_ref_and_get_aio_context(s->iothread, = path), + iothread_get_aio_context(s->iothread, path), virtio_ballloon_get_free_page_hints, s, &dev->mem_reentrancy_guard); } diff --git a/include/system/iothread.h b/include/system/iothread.h index dbada8249c..fde80f4149 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -47,9 +47,8 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, =20 char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); -AioContext *iothread_get_aio_context(IOThread *iothread); -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const char *holder); +AioContext *iothread_get_aio_context(IOThread *iothread, + const char *holder); void iothread_put_aio_context(IOThread *iothread, const char *holder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 diff --git a/iothread.c b/iothread.c index 70bc5fb62a..470f267901 100644 --- a/iothread.c +++ b/iothread.c @@ -415,13 +415,8 @@ char *iothread_get_id(IOThread *iothread) return g_strdup(object_get_canonical_path_component(OBJECT(iothread))); } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} - -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const char *holder) +AioContext *iothread_get_aio_context(IOThread *iothread, + const char *holder) { /* * In some cases, iothread user need the ctx to clearup other resource. diff --git a/monitor/monitor.c b/monitor/monitor.c index b6efe776d6..0f9642f11a 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -623,7 +623,7 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool = skip_flush, */ g_autofree char *path =3D g_strdup(is_qmp ? "/monitor/qmp_mon0" : "/monitor/hmp_mon0"); - mon->ctx =3D iothread_ref_and_get_aio_context(mon_iothread, path); + mon->ctx =3D iothread_get_aio_context(mon_iothread, path); } qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; diff --git a/net/colo-compare.c b/net/colo-compare.c index f3231257d2..ff58ea9e0a 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -968,7 +968,7 @@ static void colo_compare_handle_event(void *opaque) static void colo_compare_iothread(CompareState *s) { g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); - AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, path= ); + AioContext *ctx =3D iothread_get_aio_context(s->iothread, path); =20 s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); --=20 2.49.0