From nobody Sat Jul 25 15:51:59 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=1784213022; cv=none; d=zohomail.com; s=zohoarc; b=ciEOqX+MlBScKB2vzaCaPdwfN5BrwVt/M0YM2gjoReYTq9jBvA21vzvOLQrCB1N3EX7aSVIwYdkp/y+Pr9Avb8gJ/EfmCkgyaBkHn89kHsQ1VLcuqi5DLOnBxnhnWE3bVSrTR/gJ9F1vAt1TYKs1SlMiBPX+fHpC6v+2W1FHDr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213022; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iQp4e741RWeqANR+AnBnweSrNx7Xk2H8EAfqd4DwHpY=; b=kPFdlYAisMR17677JZXqJu/veW9DzRoMxX0EerHMe4qfJUY9X7tfibWCAIu4BSEoNy/xv0eYnqKdmSKJtgbCpAnMID5noosPLw062g6HdBeIJNAWlp9aKKEedJy98rsf/1A9fAsJyydw4qM8YWCY6rEBATcP5jKKwwoxFsoOFF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178421302288183.5076414289133; Thu, 16 Jul 2026 07:43:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNIw-0006j0-UF; Thu, 16 Jul 2026 10:43:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkNHM-0005qZ-9r for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:43 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHK-00074w-KQ for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:36 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-38175907a56so302718a91.0 for ; Thu, 16 Jul 2026 07:41:31 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212890; x=1784817690; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=iQp4e741RWeqANR+AnBnweSrNx7Xk2H8EAfqd4DwHpY=; b=pFkLSBJxvycleYeuqPbFsa7qlnEYNaP6ld1HCm94OEMWpd8Lb1Tk3EGok3BYz+PYpj M15FddwB2NYy8jnjmFhC1ImdZWa86spVdWlWl/YoTm5LcCNhJuujiDg+zJ1s5qidPN3s tT72o1Nii2Kr4MkHYCyh6rSaaqREj9KwxJjJi99/JcTy/wYHFEVINYJI2sJ0h9qlgtuO jMcGWcFGt7iRR9tlnGTvnyuYhGE1iM6SeXctaU7xovF9DK8S/+vDjnoy6N1cVyBFPS+8 VaS7rd9MuysYLqppwtlwz2Y+yaMLKa5ibsL7RNWNRMCuhGrBgRX9oEL8hasvvyNUxFeP PYGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212890; x=1784817690; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=iQp4e741RWeqANR+AnBnweSrNx7Xk2H8EAfqd4DwHpY=; b=QA/BWCJs0xkCGpxpSzHjZq5dxcJQQRI58yVablzrGlYZ1DSeCwXT2t6qqxpCadQQ/E I9UPzVL494ljglrmLwV3ezHLmLKTBxPOZW/uH+UbQKykxJtSWdB7QlnJ/8j0hIMrAPUD 4ZCK9VgQqZzEH6ZhfMDzBLNRRHN43gczD5A8+TdG3E33mUqEISCsW2c5CE4W5nhZ/nz2 RcwrIJCM6RIq09BLTfw8UfZM1kQ8qIOEKAnlWNOW2O1WmW/sSm3B2mpmJhkXVqHHuJr7 ZOYO8So0+uiXfC21AtNpkf8NOxJXh9yrtI38wZKM367mxLjKhvSQD/p7SrV2YjkZxvSR Ygkg== X-Gm-Message-State: AOJu0Yx8U+aeLYNJgtH9aHaHv/whLMd3yAOvHao15Uzlrs5JtzXmc6xl h7BCMva/FJ1hPJ8hm4wsablXWPaSnl3V6ExbQf2uKSwqw4ljmbbP+WoaC9/WMzYKRVk= X-Gm-Gg: AfdE7cm5IZ4brABwhvD8V8VWU9SeT8+XHqjIJ6BEQAk6x2mnzCuZyinAnEJP98vcvPy 52xX+cJa3YVwEoWX38jMLvIAPM2YpHgDO97lqnMxs7z0FB1oHv1hAFuy4U6mAxR2n4xr4jag71O x6h7xYl84GQj381EvBvdelALwr2XuxRC54XZv76YXdlSeMBEQLOgSpgCn18oZ9lHuocqPzouIQF l2N/gNYLzkhOkq2FZT3ahAt+ZFi8FZgHQ33vihZ0+iSJF2rHWeMcEL51gJSb8rkL+/d7ME7XFXu G8i/ozRYvbyB05gbYr/VxRmCab644HZotRtXTCHyNK98XOxvCv9uUKnaDazJngQcbkpWWQVlOZU svD39a5q5xA0ZElfMoW4+4N5lYgdJckwqLEvWW0BtaA5UQ3bZU+FfTa/yaF5kQF1gN7I0ws8ftX mi4dofw40zstK/9kLyarHTvfDzXhXO6IsHZsTelKPn X-Received: by 2002:a17:902:ea07:b0:2cc:841d:cd7e with SMTP id d9443c01a7336-2cf1f5710f4mr32356905ad.21.1784212890179; Thu, 16 Jul 2026 07:41:30 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen , qemu-stable@nongnu.org Subject: [PATCH V10 01/15] qapi/misc: Fix missed query-iothreads items Date: Thu, 16 Jul 2026 22:40:26 +0800 Message-ID: <20260716144043.76414-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102b.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: 1784213025150158500 Content-Type: text/plain; charset="utf-8" The example is incomplete: it misses members @poll-max-ns, @poll-grow, @poll-shrink, @aio-max-batch. Messed up in commit 5fc00480ab1 (monitor: add poll-* properties into query-iothreads result) and commit 1793ad0247c (iothread: add aio-max-batch parameter). cc: qemu-stable@nongnu.org Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- qapi/misc.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index 22b7afed9f..c71a5fe657 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -123,11 +123,19 @@ # <- { "return": [ # { # "id":"iothread0", -# "thread-id":3134 +# "thread-id":3134, +# "poll-max-ns":32768, +# "poll-grow":0, +# "poll-shrink":0, +# "aio-max-batch":0 # }, # { # "id":"iothread1", -# "thread-id":3135 +# "thread-id":3135, +# "poll-max-ns":32768, +# "poll-grow":0, +# "poll-shrink":0, +# "aio-max-batch":0 # } # ] # } --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213021; cv=none; d=zohomail.com; s=zohoarc; b=mTiWUP/W7F3qOtAqS7MnAhmsXhwQ8w0YcfpkVWsvd30bWAyHCNPqDzuLWrJG9j1OXEJA5G/mhix4gFoaU48xymlIvdOLJmxS4MnXYuTlcg/Dpg9GeDfuliBkMcejTZ1Y4P52brI6xCK8LOWi1VHPimjsGi48E6xrJley1qt4/B4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213021; 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=EWnksNoYUxBUrwcSM/xM8wvQyla6RML0UmckypoRO1Y=; b=KRNef+17B2IwEhl3/12Xw9ackqAdjQvfDJz6eM4Dq3gZCCG08BWqWwFAGHdz84842gihcm+ajZuyY0TufMAC+dqOi1no5r59o53KYNdRJsjfuXfj4lCTlfWAf7ZA+6uddjIlUsmZ/geOvJ92NS4fcFAap0kPggVpfn+oT6AQleA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213021834567.9794259072212; Thu, 16 Jul 2026 07:43:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNIw-0006fy-Dy; Thu, 16 Jul 2026 10:43:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkNHQ-0005sC-9a for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:45 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHO-00077T-7f for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:39 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2ceb096e675so61034075ad.0 for ; Thu, 16 Jul 2026 07:41:37 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212896; x=1784817696; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EWnksNoYUxBUrwcSM/xM8wvQyla6RML0UmckypoRO1Y=; b=cKtpJiKAS+9vB+Jj/ozDKG/nrm8/thZgA+304A7jOXIjSXpHhK6Sjgp8THPauV3wZg Cm7iC+47OCl1vsPebWd1ImrMER0UpjF9zAtq1/lYu0PCMXEuzsQ8pKBTkSfX/SnFtUGN X3BqKK7CNwC4noG5Vg2PJq9byZjp7T7GbfPL/DUfhve7Y4kfotaNY2IngBDrlput0dZ2 yHgKW9Wc0/f1qssVp5sjtgvei/J4CiewM1KaACLz7LQ007CAThwzKFg2zGM3Tb4BCQ5O o2kJ/0dQ+jTcRQ+xn/yVcjXMkygS8FfT03meIkdyHdeHcF0v+8XkPGg81egu8Fgqq++a dcHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212896; x=1784817696; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=EWnksNoYUxBUrwcSM/xM8wvQyla6RML0UmckypoRO1Y=; b=AzQmrNSax4ebzG5UtL78GZ3XVOGdBRCx0XlaAzb45SvsAarBt2wlMCBcmm1ZDNSnPa WI8oHYrKoRcVfd1iqoJjDveZ/nwVHP9bYdkoyeKNWTS0WGpGdUIHfX/hFfUCbTQ/h+VE cL9fXRgR+Z8qbyeyMsbeMafA7w5SvyUBecQbsXnAGLaHp5e4GsyxYCZttYJoYg8bl65D eKDEe02wt00SakXbUgWi0VK6i9EbExrIIVKYV9t5y5yesxGAqESog+WyOl0ao8C+Lh6s wWL/W/ePk+UnY+GGSrFK3nalW6wGKPALsCBjLev0zqi0BrFK+uAVp/n1GprXcek72kL5 yVaA== X-Gm-Message-State: AOJu0YyVgxBSZIQGXr7lziq5FNJhbvFemSGk468gk8BJKxpHyvzKgdOO sx60CeVSZzFDO5LmiUjv+jfncJUiplh/xKtrCKm4LsKZ/bApm+ao2hFCnYSt8PGFcs8= X-Gm-Gg: AfdE7clUhczk+v+NlQkf7pbL8DwoR0qjD5skZbYHfOwsgD9wbDFy11xYuL04927KQVi 7Jy0HiD2F8q/b1r7CFBeO9Q+c8SFttNQWPDeTphrtEXaLvXZaQzwFx9xsP7LLnqBstbeYWbxPSH xsMUCcQKDBmXwEfESVrFcJLJThTXPi6YTaFvobNKYJBBp2ian53r3K0a/1Xf3WHKy82p6W/7hFD THtU9wXHuwLdEXmn2EQY4+ICwiP8ShURqHMHVT7BM4Jk1O3ocB+frv1e8NBHQQvGxhuTwwkwr8g 6PmdAz9xNlSamJyPSAOpzAcac6gv4Rt4N10Iydu1WbPShBKn1VmRLwDFnlEF7GhbDKvLFGbB9O8 SjRJ9xEn5F9UO0+qXvnt/kRWCUAbqNHsB6Ts1KJtVF9K2NTvQx0775t3VFOjaQHiDp8Vmg65a5L 6eZeIwz2qUS1EQu/CxczgmSuh7MCyVL93LG7w1j9qT X-Received: by 2002:a17:903:1a45:b0:2c6:90ec:f601 with SMTP id d9443c01a7336-2cf03bd51b0mr76449825ad.8.1784212896245; Thu, 16 Jul 2026 07:41:36 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 02/15] iothread: introduce iothread_ref/unref to track attached devices Date: Thu, 16 Jul 2026 22:40:27 +0800 Message-ID: <20260716144043.76414-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213023418158500 Content-Type: text/plain; charset="utf-8" Currently, IOThreads do not maintain a record of which devices are associated with them. This makes it difficult to monitor the workload distribution of IOThreads, especially in complex hotplug scenarios involving multiple virtio-blk or virtio-scsi devices. This patch introduces a reference counting and tracking mechanism within the IOThread object: - iothread_ref(): Prepends the device's IOThreadHolder to a list. - iothread_unref(): Searches for the IOThreadHolder using a string comparison (strcmp), releases the associated memory upon a successful match. - holders: A IOThreadHolderList storing the IOThreadHolder of attached devices for runtime introspection. A later commit will add QMP commands to let management applications query the attachment status of IOThreads. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- include/system/iothread.h | 11 ++++++ iothread.c | 70 +++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 59 +++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) diff --git a/include/system/iothread.h b/include/system/iothread.h index a1ef7696cb..ef0b2f9648 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -38,6 +38,9 @@ #define IOTHREAD_POLL_WEIGHT_DEFAULT 0ULL #endif =20 +typedef struct IOThreadHolder IOThreadHolder; +typedef struct IOThreadHolderList IOThreadHolderList; + struct IOThread { EventLoopBase parent_obj; =20 @@ -50,6 +53,11 @@ struct IOThread { bool stopping; /* has iothread_stop() been called? */ bool running; /* should iothread_run() continue? */ int thread_id; + /* + * The list elements are of type IOThreadHolder, which can + * represent either a QOM path or a block export name. + */ + IOThreadHolderList *holders; =20 /* AioContext poll parameters */ int64_t poll_max_ns; @@ -82,4 +90,7 @@ void iothread_destroy(IOThread *iothread); */ bool qemu_in_iothread(void); =20 +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder); +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder); + #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 3558535b40..38f273c0e9 100644 --- a/iothread.c +++ b/iothread.c @@ -21,10 +21,78 @@ #include "system/iothread.h" #include "qapi/error.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-misc.h" #include "qemu/error-report.h" #include "qemu/rcu.h" #include "qemu/main-loop.h" =20 +/* + * iothread_ref: + * @iothread: the iothread to track + * @holder: the IOThreadHolder object initialized by the caller + * + * Add the @holder to the iothread's tracking list. + */ +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder) +{ + assert(holder); + + QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder= )); +} + +static int iothread_holder_compare(const IOThreadHolder *holder_a, + const IOThreadHolder *holder_b) +{ + const char *name_a, *name_b; + + if (holder_a->type !=3D holder_b->type) { + return holder_b->type - holder_a->type; + } + + switch (holder_a->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + name_a =3D holder_a->u.qom_object.qom_path; + name_b =3D holder_b->u.qom_object.qom_path; + break; + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + name_a =3D holder_a->u.block_export.export_name; + name_b =3D holder_b->u.block_export.export_name; + break; + default: + g_assert_not_reached(); + } + + return strcmp(name_a, name_b); +} + +/* + * This function removes the @holder from the @iothread's tracking list. + * The @holder must match the one used previously in iothread_ref(). + * It is a programming error to call this with a @holder that is not + * currently associated with the @iothread. + */ +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder) +{ + IOThreadHolderList **prev =3D &iothread->holders; + IOThreadHolderList *curr; + + assert(holder); + + while (*prev) { + curr =3D *prev; + if (iothread_holder_compare(curr->value, holder) =3D=3D 0) { + *prev =3D curr->next; + curr->next =3D NULL; + qapi_free_IOThreadHolderList(curr); + return; + } + prev =3D &curr->next; + } + + g_assert_not_reached(); +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -129,6 +197,7 @@ static void iothread_instance_finalize(Object *obj) iothread->main_loop =3D NULL; } qemu_sem_destroy(&iothread->init_done_sem); + qapi_free_IOThreadHolderList(iothread->holders); } =20 static void iothread_init_gcontext(IOThread *iothread, const char *thread_= name) @@ -373,6 +442,7 @@ static int query_one_iothread(Object *object, void *opa= que) info =3D g_new0(IOThreadInfo, 1); info->id =3D iothread_get_id(iothread); info->thread_id =3D iothread->thread_id; + info->holders =3D QAPI_CLONE(IOThreadHolderList, iothread->holders); info->poll_max_ns =3D iothread->poll_max_ns; info->poll_grow =3D iothread->poll_grow; info->poll_shrink =3D iothread->poll_shrink; diff --git a/qapi/misc.json b/qapi/misc.json index c71a5fe657..096e418b7a 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -67,6 +67,56 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 + +## +# @IOThreadHolderBlockExport: +# +# @export-name: Name of the block export. +# +# Since: 11.1 +# +## +{ 'struct': 'IOThreadHolderBlockExport', + 'data': { 'export-name': 'str' } } + +## +# @IOThreadHolderQomObject: +# +# @qom-path: Path to the object in the QOM tree. +# +# Since: 11.1 +# +## +{ 'struct': 'IOThreadHolderQomObject', + 'data': { 'qom-path': 'str' } } + +## +# @IOThreadHolderKind: +# +# @block-export: A block export. +# @qom-object: A QOM Object. +# +# Since: 11.1 +## +{ 'enum': 'IOThreadHolderKind', + 'data': [ 'block-export', 'qom-object' ] } + +## +# @IOThreadHolder: +# +# The block export or QOM object holding the I/O thread. +# +# @type: the kind of I/O thread holder. +# +# Since: 11.1 +## +{ 'union': 'IOThreadHolder', + 'base': { 'type': 'IOThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-export': 'IOThreadHolderBlockExport', + 'qom-object': 'IOThreadHolderQomObject' } } + ## # @IOThreadInfo: # @@ -76,6 +126,11 @@ # # @thread-id: ID of the underlying host thread # +# @holders: the QOM objects or block nodes currently +# associated with this iothread. When an associated component is +# detached or destroyed, it is removed from this list. +# (Since 11.1) +# # @poll-max-ns: maximum polling time in ns, 0 means polling is # disabled (since 2.9) # @@ -98,6 +153,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -124,6 +180,8 @@ # { # "id":"iothread0", # "thread-id":3134, +# "holders":[{"qom-path": "/machine/peripheral/blk1/virtio= -backend", "type": "qom-object"}, +# {"qom-path": "/machine/peripheral/blk2/virtio= -backend", "type": "qom-object"}], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, @@ -132,6 +190,7 @@ # { # "id":"iothread1", # "thread-id":3135, +# "holders":[{"export-name": "fmt_qcow2", "type": "block-e= xport"}], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213277; cv=none; d=zohomail.com; s=zohoarc; b=UJOy40CZVUQJb8/Gxf8vSajG9OkLcIJcFMd+m55uiD0Qe+APd+Dv8r4Gntjh4dnjVj3ooNvwpbMfhCIy9LAlcdebNpO0eBDEu/FQORm+YItd5As+sJJDkbWmfJCsbfdfZ5xZUl94xCUoWVWEhgQOHI0/byh87OU7bBr996vxb+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213277; 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=HCRIGz+meMvB1Fw1XaOb2hIZjHMSMXvcXe7z6nBrirk=; b=aL0UIkIgLZb8jey4CV+UD+k0djn1qro+TfykvK8q1AR6/mVJ3NUMlLOQJJ0X/mNV+IrJvGCwewk32DNCe7WJfCLWJNtSxk2eAUckN09+MEN/dkQd1JA4CgeCfgonP6q4jxnVCy05MrGfQTuLyAw7MvyWCdPeC6RKEarlWGAPf5Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213277517771.3610163635308; Thu, 16 Jul 2026 07:47:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJT-0007EP-7U; Thu, 16 Jul 2026 10:43: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 1wkNHX-0005ut-OD for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:49 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHU-00078l-3P for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:46 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2cad4170e8eso85460395ad.3 for ; Thu, 16 Jul 2026 07:41:42 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212901; x=1784817701; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HCRIGz+meMvB1Fw1XaOb2hIZjHMSMXvcXe7z6nBrirk=; b=G7QOIu1/P6Fu0tx4WMfLkRRAFQeMrg6hVfMe/H6IPB35KC/Z+9a1BbXvNes0Esqrk4 dEwCqVDlUqw9Zg3Y61/Zzn4L4izcYoKVxrt79U6vGmx2UfSSiD2H8GywNQYlRxxr1CsW bmzhc3EGL+w4EHCTwlyvPMENhmvVeejlkpSU/rtNPXK1Es7X3eCzKxBcEnmt+rcfp3D1 mO+T/a+VunX1gpvnkARNuXM24L6enjc2jKemRvpNSvbAhobdGj0xoiTvbsdeuLHd63tP hEpxPFXXSZ+Ogem+9/fvB1zZsUJSKVtbMu9DA/Xt39q6uiKnGd1E7Ec6mJ1TPQ5250Ac QcOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212901; x=1784817701; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=HCRIGz+meMvB1Fw1XaOb2hIZjHMSMXvcXe7z6nBrirk=; b=afIc2oF8VnjrJWnG4q+W/PMQXB64HQoYvJiWv2NTMUrFRcOt6QaxZQvuPe4T5nS18d CLhYYZclpVS3p8TubA4aed61ne92tk1u1MFdAlk0/N7UFQGfFA/NMYpNNzWGqrDeZl3F cHps2LhDPwICaOMMwAeZG3Ci0bdN0dcCPOJQ0fpWIez4m9e4ZwOZYGnxHUKlHJZqkOGJ R2EimHvsvCwYVIKH0WjO+juVZ69olOYauq9jMxGZc/Rm58U/g3ke3fROivgZQlDQ65Es bSVxKSKDRkr7r2Z5SoBWO953kJlf93Gl/Rnm++9CW7I987m88zV86wOmftlvFKoWv4RG Aq+A== X-Gm-Message-State: AOJu0YzwQOZNAz/NDMZNJ36tjqDz9h3ZPKKRgJLgKb6dE83NDTzb1Sr2 YDa4iimUx6lF3qE7tFtJchePt+fLo0SWsDokrz5nbZ3ElcWZXSFKr0OnPPwpIc1chvI= X-Gm-Gg: AfdE7clkblGL/YubefNmAUnj4T2IykNzuB/RjC7ujgPGmwPewrQXJY4tQ0Tpz07jnLb o7kxDBEnZAeK8DnnQtWI6d9BPHQv0jtgUQuJcr/k3CuEA/G5GxjaKeQf+roPf2bzzlo8VJWrBeR BhCJUKEEqpzEYIY42HrH9YeDI7ZCHGuiHtmeVdaYUn22GsrkgIwiTKn9gHpz8mZ/6VnBsXpcY46 lNrAsXCcSFRgzROdCsEgz+rCNZ3zBFVNrTbtTl/38dgm/AczMsbMrZhkqlPmM/2m5knRCgmLMFp cKeQW6cgSnkYBWaK471ZN1myS/KwwicRYN7QvAIjWzER8V/ccb7OV+q8zoY4zQ7r2yoeJkrST/j UtQk1LIJrusboQeRSbBCJ6Vz+EKf41NAkCUc58P3F06gq26XNwlXnCs+3OuzAhXtHb8UiQNV7iE 0IGd8Fop6KH3VXWUVNNz+vs7bdl5FKY126DdvQgon5 X-Received: by 2002:a17:903:1a0d:b0:2cc:6329:b7ba with SMTP id d9443c01a7336-2cef1328355mr124745345ad.16.1784212900985; Thu, 16 Jul 2026 07:41:40 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 03/15] iothread: tracking iothread users with holder name Date: Thu, 16 Jul 2026 22:40:28 +0800 Message-ID: <20260716144043.76414-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213279139158500 Content-Type: text/plain; charset="utf-8" Introduce iothread_get_aio_context() (In this patch named "iothread_ref_and_get_aio_context" for build, will change the name in the last patch) with a 'holder' argument and its counterpart iothread_put_aio_context(). Previously, users of an IOThread's AioContext did not explicitly record their identity, making it difficult to debug which devices or subsystems were pinning an IOThread. This patch enhances the reference counting mechanism by: 1. Automatically incrementing the object reference count when a context is retrieved. 2. Tracking holders using iothread_ref() and iothread_unref(). Signed-off-by: Zhang Chen --- include/system/iothread.h | 8 ++++++++ iothread.c | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index ef0b2f9648..86f02c5a7d 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -18,6 +18,7 @@ #include "qemu/thread.h" #include "qom/object.h" #include "system/event-loop-base.h" +#include "qapi/qapi-types-misc.h" =20 #define TYPE_IOTHREAD "iothread" =20 @@ -72,7 +73,14 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, =20 char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); +/* + * The iothread_get_aio_context() and iothread_put_aio_context() are not + * thread-safe and must be called under the Big QEMU Lock (BQL). + */ AioContext *iothread_get_aio_context(IOThread *iothread); +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder); +void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 /* diff --git a/iothread.c b/iothread.c index 38f273c0e9..f5d4708b25 100644 --- a/iothread.c +++ b/iothread.c @@ -39,6 +39,11 @@ void iothread_ref(IOThread *iothread, const IOThreadHold= er *holder) assert(holder); =20 QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder= )); + /* + * This guarantees that the IOThread and its AioContext remain alive + * as long as there is a holder. + */ + object_ref(OBJECT(iothread)); } =20 static int iothread_holder_compare(const IOThreadHolder *holder_a, @@ -85,6 +90,7 @@ void iothread_unref(IOThread *iothread, const IOThreadHol= der *holder) *prev =3D curr->next; curr->next =3D NULL; qapi_free_IOThreadHolderList(curr); + object_unref(OBJECT(iothread)); return; } prev =3D &curr->next; @@ -206,7 +212,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); @@ -428,6 +434,21 @@ AioContext *iothread_get_aio_context(IOThread *iothrea= d) return iothread->ctx; } =20 +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Add IOThreadHolder to the list */ + iothread_ref(iothread, holder); + + return iothread->ctx; + } + +void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder) +{ + /* Delete IOThreadHolder from the list */ + iothread_unref(iothread, holder); +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213275; cv=none; d=zohomail.com; s=zohoarc; b=QPDjb2O4gWw21NyNgw9asv+V7o04RW+D9eLOUVbkjEQduvx5orR3NRAoqAZO9IIlNQw285VHTO+3dStyeHB3NfCxhoTAAurP9z+55CORXg5K6Pe6MnqZlh/jiqqiA5uZr9CZw4JFrbmv7KonvH9yaeeNQ1IMVcgCOezHEOv3L7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213275; 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=3QDsfYN2rfgBtltKnnC9maVXXTU4QyxaR/nwD59M78o=; b=KcWOa9VwxtwzkCK9ZfDYPui4+d7Yeku8EaxiCsVT9s0nGLoYzl4c6vxUnMidktl1K93g/BdIogoEFV4HvcmHClSbhvxGUQ4uFEcVszbCH7/DpaMboyMmvUAXB2CiDrWuNEVT+LFIfhJijjIBsw75BT+qAPAnYBHX3+EdIwZPoW4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213275953448.1797517305637; Thu, 16 Jul 2026 07:47:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJU-0007GN-FW; Thu, 16 Jul 2026 10:43:48 -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 1wkNHa-000604-2u for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:50 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHX-0007Aj-IG for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:49 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2cc97653887so76355945ad.1 for ; Thu, 16 Jul 2026 07:41:46 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212906; x=1784817706; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3QDsfYN2rfgBtltKnnC9maVXXTU4QyxaR/nwD59M78o=; b=sSoHNxS05/GacQDbZa4W5H8uX9N4MzV8sA7h/JiHyPAUTBDZ+/qV/JlAs/dhZG/Fy3 obt9oSAX7aSyGsSbpvK1l5U4wyDFF7Y6fdtDkNd6DzgZjWqaVmED9O30Wqv2yYjxxCQ3 /Ja6UGY1qyLwAXZAmDDdy1rcCRvEqJ4iYHyfJtQWJR4kBToSnB4oEEHMzqLGSfkXeuKQ ul7nagvdKLipZOKlYvWt235/tB6nGh0knuIlBqv6XTncc+FEMCznbuhKrZCJugHWPKCB iTX3mrm30FRNaTFNE+itbcNshCc3siA0YhtwhMVCn+ICD57PjYGgLWY8K3j5ZdzVVLir Nsqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212906; x=1784817706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3QDsfYN2rfgBtltKnnC9maVXXTU4QyxaR/nwD59M78o=; b=QbjqQABIX/l4HoXEzMJcgw9pujMm4rSNvFB2zfCVcR/IVBod4PrkcNTo/vWmC96+fR KI0ZgjEufSKkjL2XR3NPtMjcrImsId4X34jAQcGaf08LKVDgIJ4o8442dCTHhrcowUuD I4bbmKyNXrpVOZGvwQbA5Ua95Qi7dNP15n1zlucLU0sMwaxS+DcyQM0Y102EMHT23CjF s6sS0GkEuv/0oqDI56byGNgmx1PMsBk/anUkqun045e5Ralh+cZZDtbNKTbJr/qmWKe1 vmQfXMDfwfSltvP/lLd5F2aDBDSZuvO/vV6UgpGWHHzsrg09iqbzIluLMWwUzaoON4j6 KZbA== X-Gm-Message-State: AOJu0YzB+SdJfMgrxyY4ya+Dtci1lRlsp65lSb43VlAZMwpNdgZOVyq0 7qQ+t6DdhBe9FTUAT/jvSVRn603cwKGDofuujJRoPszB+KerCo5mrjtmZha3M4wGNxM= X-Gm-Gg: AfdE7cm3Aqgr1o+cZmqFta0zKsh3aTPBLN1bixwEicb3g3XoYmcbbA8UBPQCBgTiykh L7oFtDtqf6/7LiJHX1Plu+XyRNRtqgUibLjBKURgRRuuXXkG7LMh1a0YrTPsE/BxD4a7Q251mVJ 6Cll8mpm9AHESq36qM7VIVblgQ4CWIdok+1DUoMfXlStuU1tfAcSAWf+8mH7nnrYCO0Tx4LxmDA EYQdnS1ZkTAXQZDmekdpPIbhbO4+lNGyAedylnQAt2iTmmQxrNnZyYFtb+BIGu0ObWcZTepEvjp f1FSp6ooPdBIhyYFcrVuM0LG2bgkTL4Jk+norCHzemsuf1vFSIfqaV0slxNlzC2nlVzWPO5grNv 3winhAjlbCi95To4eAOh07ncy83/zZlqaoKhDsNElWvDq9qEjm+gFLBEBf0Rraf/mBZrNHdol++ FESlhqf6YLT/p6FiK+7aJprQhkarGM32msjzA0Iwsn+Zc4irod2jY= X-Received: by 2002:a17:903:124a:b0:2ce:f9db:a9e0 with SMTP id d9443c01a7336-2cf03ce29a0mr71999955ad.16.1784212905870; Thu, 16 Jul 2026 07:41:45 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 04/15] iothread: introduce iothread_unsafe_get_aio_context() Date: Thu, 16 Jul 2026 22:40:29 +0800 Message-ID: <20260716144043.76414-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213277241158500 Content-Type: text/plain; charset="utf-8" Normally the IOThread's AioContext is fetched using iothread_ref_and_get_aio_context(), but there are legacy callers without a clear ref/unref lifecycle. They cannot unref (e.g. because they do not have an IOThread pointer), so provide an unsafe way to fetch the AioContext without holding a reference count. This unsafe API serves legacy callers - do not use it in new code. Signed-off-by: Zhang Chen --- blockdev.c | 2 +- include/system/iothread.h | 9 +++++++++ iothread.c | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 6e86c6262f..baeab3a3e1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,7 +3683,7 @@ void qmp_x_blockdev_set_iothread(const char *node_nam= e, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_get_aio_context(obj); + new_context =3D iothread_unsafe_get_aio_context(obj); } else { new_context =3D qemu_get_aio_context(); } diff --git a/include/system/iothread.h b/include/system/iothread.h index 86f02c5a7d..3cce5eeb09 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -78,6 +78,15 @@ IOThread *iothread_by_id(const char *id); * thread-safe and must be called under the Big QEMU Lock (BQL). */ AioContext *iothread_get_aio_context(IOThread *iothread); +/* + * Normally the IOThread's AioContext is fetched using + * iothread_ref_and_get_aio_context(), but there are legacy callers + * without a clear ref/unref lifecycle. They cannot unref (e.g. because + * they do not have an IOThread pointer), so provide an unsafe way to + * fetch the AioContext without holding a reference count. This unsafe + * API serves legacy callers - do not use it in new code. + */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, const IOThreadHolder *holder); void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); diff --git a/iothread.c b/iothread.c index f5d4708b25..157bb4d302 100644 --- a/iothread.c +++ b/iothread.c @@ -449,6 +449,12 @@ void iothread_put_aio_context(IOThread *iothread, cons= t IOThreadHolder *holder) iothread_unref(iothread, holder); } =20 +/* Recommend migrating to the new API with IOThreadHolder as much as possi= ble */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread) +{ + return iothread->ctx; +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213176; cv=none; d=zohomail.com; s=zohoarc; b=LV2RiIDQIvwEvMIhfGNnB28gB/xqXkG9LLjZRdP3/9eFDmD8luhK/sq/dJLf5JWMNfs+L2zcQYeJLV5lJFUCiFSS0Js5XFeHWxvLkYFP3+OqpVfT5tVECasjcERMlToiDc3kCunD70wgQ83k7gMqJ0VPBxSq1QBG3CaFBSuLNNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213176; 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=DpwjeH9GaZsYh/eToeeS9DaxY2sr+39n/RM53e5yVAo=; b=kB2iJt4uaXFn4w8l3SAGC4tG9YN0hDILay+G+T1J7tGOOWnPFJ5usmRpeHCQy4+ORYBTDjDkRbyvoMjCuNUy7874ue2ako68gtLnOOAUK+Jf6tMEaMky8Gt8pPT2mLB1/aL258w/HvIVno3H3c3CQ3rDrtFavuOpmStcMLay81o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213176514797.9342226545232; Thu, 16 Jul 2026 07:46:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJV-0007H2-6V; Thu, 16 Jul 2026 10:43:49 -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 1wkNHe-00064r-4d for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:56 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHb-0007Da-W2 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:53 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2cab973140bso81607075ad.3 for ; Thu, 16 Jul 2026 07:41:51 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212911; x=1784817711; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DpwjeH9GaZsYh/eToeeS9DaxY2sr+39n/RM53e5yVAo=; b=WpJrfdMTUOzR3eop4Anoexqvo7FCZs2zWEF+pRW3aF9wwuz6JZrkhawhhG6bErVeCF e293zgZLbQ7MvS1zWDEoPk7vBOlUoBgPyJE/z41X+8jAGClQIWJlG8H6G9K72lcORoOz aPRUzqMKb6NLoLFxmanabp8f+2FLd7t/MJRMAB16m+byCpHHmGg7skxOCy9gtBO/hWXn EP4kgDw7RgI4dQK5HVGqCjJoc2h8WIkrCEJNsPJ3QSBacsRa74R54R5OodNI+XXrnfNR inHvnlcu8NB6kpD5chn5CX06mac85zImdeeirdohRXoZKEp6e7mgeVdQQyLcSc8bNYlH iViA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212911; x=1784817711; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=DpwjeH9GaZsYh/eToeeS9DaxY2sr+39n/RM53e5yVAo=; b=LptCJOTwQQceBA4KhG2GRlMHnYbd3iboBpmlGuBAkEknKDqUodECYI7sKnVo/+B04a uDjSeLwTpVC6/UOBKygF9javRNgDiOy8+KBQm+R6apkjWzS0g3dDGZrm9I2+6WWR3U64 HvqA40TtTDXyQnEJjXoCbltKK/BYx3VVg1yO50C5RmhDBFHW9vsbMY8vFz30MWLPW9Af BYHnunYv6mGRnjC5TmEVmBjlVnli3U7eFf1+vuHuOwMj6i+gewKmubfR8Uzh+oYOT7bV Bafh43bHXvAgIjFacwRK6w5whzAwgPSL+oxda0WfGN5RD+2PPjNHE5fUCPFtQRBYC87J 6hrg== X-Gm-Message-State: AOJu0YzC/43LrEO9S6Dq3X3Z5N1YD3ffdJ3cJNLh/XSkIu/aw1SnJQpM IaG3lxfCEc+yGIxNJe57wCx1wOecVFo+mLCWs+2FfxV3CzgnD4e3Tvcwk0hrv0qHC2Y= X-Gm-Gg: AfdE7cltm+208PHefmNO5FKRoU1tiVgloxjxfNQ5g4UJbduxGMjBioo1g39yrwfbsJJ g1PRdBwNOF3/xYEI1xrPVqnKnZeQOWaL1yPz6JQ9+MNTxwl2UGOA+kXeeHaVgi6zY32uBdyiFTl a63M5p/BUFrqSGgy+UjKWnB+8wZ3dIXIsa6yi5gUXnRH1XU8HPfORd/mLuqkeFtW0gP0dZ3GGGm AAYn2zBvLaTXOlRnxGKioFeWlRJv2nnSdkpkmKv7X9DQ3n+TSBkJh99ZmTlaAZy3Nh7tXCfhD6P y/1ieEawHiqID++U4ib/OjK+Si3TrjCj4H41+6+2/7ReKYspw2ejF83mlHmjMfvYYxFG4KdZrBd qDI3BxT77BbovhkwXidL93jijINyauxyrHZhpL3iU2PxNdlcG4bSFS4oXPnjgalzb5lRRS4bgiq pJ9Sltncu6uZmSHM3pibpxYc0DkNsW3tcG3JVd22/y X-Received: by 2002:a17:902:fc4e:b0:2c9:b8e5:5741 with SMTP id d9443c01a7336-2cf03d21be6mr65822655ad.35.1784212910651; Thu, 16 Jul 2026 07:41:50 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 05/15] block/export: track IOThread reference in BlockExport Date: Thu, 16 Jul 2026 22:40:30 +0800 Message-ID: <20260716144043.76414-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213178289158500 Content-Type: text/plain; charset="utf-8" Add an iothreads array and an iothread_holder_name string to BlockExport to track which block exports are using specific IOThreads. During export creation, reference the associated IOThreads using iothread_ref_and_get_aio_context(). Clean up and release these resources properly in the blk_exp_add() error paths and during export deletion in blk_exp_delete_bh(). This supports both single and multi-iothread configs. Signed-off-by: Zhang Chen --- block/export/export.c | 79 +++++++++++++++++++++++++++++++++++++----- include/block/export.h | 6 ++++ 2 files changed, 76 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..4dbd71de6a 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,7 +15,6 @@ =20 #include "block/block.h" #include "system/block-backend.h" -#include "system/iothread.h" #include "block/export.h" #include "block/fuse.h" #include "block/nbd.h" @@ -85,6 +84,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Erro= r **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + const char *holder_name =3D NULL; uint64_t perm; int ret; =20 @@ -139,7 +140,16 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + holder_name =3D bdrv_get_node_name(bs); + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_name =3D (char *)holder_name, + }; + + new_ctx =3D iothread_ref_and_get_aio_context(iothread, &holder); + multithread_count =3D 1; + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +173,15 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return NULL; } =20 + local_iothreads =3D g_new0(IOThread *, multithread_count); multithread_ctxs =3D g_new(AioContext *, multithread_count); i =3D 0; + holder_name =3D bdrv_get_node_name(bs); + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_name =3D (char *)holder_name, + }; + for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,7 +189,9 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) error_setg(errp, "iothread \"%s\" not found", e->value); goto fail; } - multithread_ctxs[i++] =3D iothread_get_aio_context(iothread); + local_iothreads[i] =3D iothread; + multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, + &hold= er); } assert(i =3D=3D multithread_count); } @@ -225,12 +244,15 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D drv, - .refcount =3D 1, - .user_owned =3D true, - .id =3D g_strdup(export->id), - .ctx =3D ctx, - .blk =3D blk, + .drv =3D drv, + .refcount =3D 1, + .user_owned =3D true, + .id =3D g_strdup(export->id), + .ctx =3D ctx, + .blk =3D blk, + .iothreads =3D g_steal_pointer(&local_iothreads), + .iothread_count =3D multithread_count, + .iothread_holder_name =3D g_strdup(holder_name), }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -250,8 +272,32 @@ fail: blk_unref(blk); } if (exp) { + if (exp->iothreads) { + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_name =3D exp->iothread_holder_name, + }; + for (size_t j =3D 0; j < exp->iothread_count; j++) { + if (exp->iothreads[j]) { + iothread_put_aio_context(exp->iothreads[j], &holder); + } + } + g_free(exp->iothreads); + } + g_free(exp->iothread_holder_name); g_free(exp->id); g_free(exp); + } else if (local_iothreads) { + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_name =3D (char *)holder_name, + }; + + for (size_t j =3D 0; j < multithread_count; j++) { + if (local_iothreads[j]) { + iothread_put_aio_context(local_iothreads[j], &holder); + } + } } g_free(multithread_ctxs); return NULL; @@ -269,10 +315,25 @@ static void blk_exp_delete_bh(void *opaque) BlockExport *exp =3D opaque; =20 assert(exp->refcount =3D=3D 0); + QLIST_REMOVE(exp, next); exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); blk_unref(exp->blk); + + if (exp->iothreads) { + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_name =3D exp->iothread_holder_name, + }; + + for (size_t i =3D 0; i < exp->iothread_count; i++) { + iothread_put_aio_context(exp->iothreads[i], &holder); + } + g_free(exp->iothreads); + } + + g_free(exp->iothread_holder_name); qapi_event_send_block_export_deleted(exp->id); g_free(exp->id); g_free(exp); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..8b5002ca84 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 utilized by this specific block export */ + 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 Jul 25 15:51:59 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=1784213282; cv=none; d=zohomail.com; s=zohoarc; b=R5PZwjh4ewsqUYUYK+sOpThY+5lYGV47N5Kke6gh4tyc/bYH/6E2ndjtIDeglA1FtMmw8DaQxb/iAyzC3Aw14Mmj2jU/zc0Rto5mXkUG65548Bra5/ArcTkIA9aIOts+j++s+Tbq89HwN5lvl1y3LFpigoYiVA6CActw0BVRbpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213282; 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=LkZHHRIwKtbhpEos181LrxPQpvEgii7xeo4G7ZrlJIo=; b=BrU4z4qBWIj/1wddNzA330pEWC+b+uLI7dR/SpWEiq7x033t+r8Pe+ovBMwKVmmEXke16XbbZaMacCLCC+zICspS4liYEQcwiDvR8FHWgfp7BdnxVDXBA4O9v3Dm5e8qmsFXuGJ6TBuKtMj2EXyGT9oHMurY0cyJyPF1Ae5G8Cg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213282421869.0371254192694; Thu, 16 Jul 2026 07:48:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJU-0007Gr-QO; Thu, 16 Jul 2026 10:43:48 -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 1wkNHi-00066L-9Y for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:58 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHg-0007F7-K6 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:58 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2ceed7018c8so22350475ad.1 for ; Thu, 16 Jul 2026 07:41:56 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:41:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212915; x=1784817715; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LkZHHRIwKtbhpEos181LrxPQpvEgii7xeo4G7ZrlJIo=; b=RzP0SjJTsWjsw0K+g8OflhMVohXA4iJo71vP/TDUSk7yleTSmY+UIWkvVYCcvL5PmZ eM6sRauRdamScbfNlcgvMLpL6uj1D+o6dAqo9p01Vq3yubIzhEMx9lMq689nqj2FVDRt qrgg7HXqY65Q5warIFyZOKsi2E833UFFTIJkY0nNlJUlsoM3HqGrdn5vQvYtNdKS7lgj FZnLYIfISmnUEg79RTfSAm9IKPichPQxaM/Pky6h91hPJMRClZCTgavSplhaBoqHUU0R eBHKPr0ljSNLe+R3lGpIfpOLkNJRoZSOOOGthGd4rWW//F7CPgIH7b/U8YsWoekitEy9 qfhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212915; x=1784817715; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=LkZHHRIwKtbhpEos181LrxPQpvEgii7xeo4G7ZrlJIo=; b=JtTliHaT3L3tHf89eyPCyxibMxUCxxgY3rNbNKRyMzoWvIekKB6AikwC/1D8ZOBVvt Md1a4q/Gxd5St8MvrwjP/jz2KFzfdR6bgSykRf+Wp8uyR5v5n0Blvg/hHZVQ1diVz7uv s2wiqzUQCbnjaFQun7SJPC4i8cqFx7Nr76hAaKYSefs5c+tJgXgbIP0X9VM7P+sK2B6a 1lQlnrVmzaAgDoOyUlsC9VmO0pdvj5ZaRXpJhyGEnLMlK2+Bbq6FrkCRK0V4+WH35b/9 rSvBF+hIThIpbyep1MK/VIje15Fx5Wh+rFaNj8MDNmZbKevVSOxUiOX0GRqIIehtCtM4 a7qg== X-Gm-Message-State: AOJu0Yyz2cZPxPislgour+6kvm8Da7pK/hW67HNNAy+TFch4qyvbhnzx H21Dcg5NyHg18j+BeyJJU2BUh6VwXJ0mxva03viMv2f7DTr9rH35+BlTKYI1pATrYxI= X-Gm-Gg: AfdE7clgCDyltciPZpR3dSnCgU3YtjLbFOmPGnicmmvyTEgw522/fPuSrJnH1WvWM5u 4o6PWWag5YitBFXUjB8IhKnVPirM+TLps46BHw4XSd4s6Ere6M+3nmXxVrv7HzMlCOjufS2Hq7J HPMv50pfYfJUFp+HcsUT63aVsXtZC0LzYU8ZixoiK4pNGku3/jjN10Qzp9pzzCUaPGk7ut6ERqU Nu+URuYg+jkbNa8NGSYW0XYKYlsaG7UxyBfih+mvbmED0awnB4RlS3qT4ipJJXoS7unfgt7pJrq KTjw9lQ/XojYqvED/PBTm36EnJev4YrFVXkRSzXQZ9BllpPMOWpqfR53DYQnMU080U2sA0+xDiS ji/DK9I1LK+jOqSOKvNGcJIrhXktQzdFLda/9L/w+i9SpR09n2h5Y8SBhFki0wcCuc/5rg84JJJ a5B2YNdBy8fBK/RSAjKqn3fKN/shntKRwCBSbK43au X-Received: by 2002:a17:902:d985:b0:2ca:bf8e:35fe with SMTP id d9443c01a7336-2ce9e9ac9b7mr206948305ad.16.1784212915057; Thu, 16 Jul 2026 07:41:55 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 06/15] monitor: Update tracking iothread users with holder Date: Thu, 16 Jul 2026 22:40:31 +0800 Message-ID: <20260716144043.76414-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213283105158500 Content-Type: text/plain; charset="utf-8" Based on monitor QOM path tracking iothread users with holder. Introduce the AioContext in the Monitor struct to avoid repeated calls to iothread_get_aio_context() and ensure symmetrical ref/unref during monitor lifecycle. Signed-off-by: Zhang Chen --- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 22 ++++++++++++++++++++-- monitor/qmp.c | 5 +++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 23829f32f9..caecceec93 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -153,6 +153,9 @@ struct Monitor { guint out_watch; int mux_out; int reset_seen; + + /* iothread context */ + AioContext *ctx; }; =20 struct MonitorHMPClass { diff --git a/monitor/monitor.c b/monitor/monitor.c index ed195fd97b..688bb85c81 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -573,7 +573,7 @@ void 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); @@ -668,6 +668,17 @@ void monitor_cleanup(void) qemu_mutex_unlock(&monitor_lock); monitor_flush(mon); qemu_mutex_lock(&monitor_lock); + + if (mon_iothread) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(mon= )); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + + iothread_put_aio_context(mon_iothread, &io_holder); + mon->ctx =3D NULL; + } object_unparent(OBJECT(mon)); } qemu_mutex_unlock(&monitor_lock); @@ -732,7 +743,14 @@ static void monitor_complete(UserCreatable *uc, Error = **errp) mon_iothread =3D iothread_create("mon_iothread", &error_abort); } =20 - ctx =3D iothread_get_aio_context(mon_iothread); + g_autofree char *path =3D object_get_canonical_path(OBJECT(mon)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + + mon->ctx =3D iothread_ref_and_get_aio_context(mon_iothread, &io_ho= lder); + ctx =3D mon->ctx; } else { ctx =3D qemu_get_aio_context(); } diff --git a/monitor/qmp.c b/monitor/qmp.c index 223e0643c2..b16bd77688 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -732,7 +732,8 @@ static void monitor_qmp_complete(UserCreatable *uc, Err= or **errp) * thread. Schedule a bottom half. */ mon->setup_pending =3D true; - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread), + + aio_bh_schedule_oneshot(MONITOR(mon)->ctx, monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ } else { @@ -787,7 +788,7 @@ static bool monitor_qmp_prepare_delete(UserCreatable *u= c, Error **errp) =20 /* Synchronize with in-flight iothread callbacks. */ if (monitor_requires_iothread(mon)) { - aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread), + aio_wait_bh_oneshot(MONITOR(mon)->ctx, monitor_qmp_iothread_quiesce, NULL); } =20 --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213193; cv=none; d=zohomail.com; s=zohoarc; b=KH8MF7usoryEKNUT/4tBPjRERqbxSH77+k33d0uxYHwxpLUqaD/eU+0uPHuq0s4ZBASYaqAlE8lBh7mkZCY6l2WEIFjvPX7pHyoyU7fx+NfB1csgKori3iT7tu3uRJgM1Sf/BuxJ7O2J8c5V8cfYWUNxxMyhD1pAS3FGIexq5qA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213193; 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=Vofx6++HVZY0FzLW3bkJYmJyIUfer41/IX34Kj5nCyU=; b=Zmy2rQnmBxOMTEIqGHgsYgJ1xNbnsNHfKn4HPex5WdUWVm8nEPA30haEznwEz8BaKkJANpq/Yq+JdW6QlhWt9mrxcVcb/jvLtRr4v7ERbbLacb4I0YjIPii577SVPnZXYPmUsxuLdNoTSPc7bswjlXo3mKrDUdTrbWDmRveLsxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213193176161.40482531643966; Thu, 16 Jul 2026 07:46:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJd-0007aA-2I; Thu, 16 Jul 2026 10:43:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkNHo-0006Eb-Br for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:04 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHl-0007HJ-By for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:03 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2cee9b74ee1so32527555ad.3 for ; Thu, 16 Jul 2026 07:42:00 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212919; x=1784817719; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Vofx6++HVZY0FzLW3bkJYmJyIUfer41/IX34Kj5nCyU=; b=ANtivbbVTIIGBUUolmiYcVpynpIgZ2J9zSba+nvVNRcyOq9pDCxaGyWsKIq/hGPlFd GTpmGkOBJB/BbUOUzCldTQGJ/yuorQmvd5h4q9YRaAw0LNR3Cqj7UdJxD2Dz6vMsqtQH iR36lz0iLChckvW7g//9WSjFIh39rcHAZ8h/1N5rGDJacH9dSNoPOLK2Q0EDhabSPqHi nQiSFUWExfRFa8tuKcg/BV6f7Sft+mlL2PQ5O6gNLV4VkQIzcZFPEvtoDvHzMEi7uRKJ /rYTPuJoX3tm5nEMBAHvxz68vMrUpfvwu0vXGuKDP9UYBaJLTR5cTrDZLAeUesAeStNe Lujg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212919; x=1784817719; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Vofx6++HVZY0FzLW3bkJYmJyIUfer41/IX34Kj5nCyU=; b=NhPDatgFiy5ShdVaxSxHw5tGF+/ApFunsKzuKV0Oa08MC1QAB8D+u4knaWetrbIfNA zJ7wqdl9LfJRMrQTaZa21R+AMRE0vjprwr/PbQVh+z9JWJYqTYiE0eGlgLPuNStiym85 utIKRnROclvaeRkY8m7pYCJdyt/oS7emN0zje8jA2oSnifmu340Kq4Xq1fHr6yoJkUHE tOB6P550m9FBHr8XFsr9hslu3NKfU4qRKRVngOoXg03W2OHcq55fx+dNNg8o8NnlwN1x MY4op0OUyQqEe51IoVKAoRhdx0s0MeEsXHJSzqoORHXgPceGxonNNuJhiTsvfHA+plIh G/oA== X-Gm-Message-State: AOJu0Yw0BSfDQvL07vMa9LshXNPn9sd5cnQx/MOHlRzlNPwCwDZwsvLy BS6CYfDCAPaiidKa7/v7MPWa3hTYtYVNc0M9gNRq79MGfRwnkRMH9mll4dcDEGaTUVs= X-Gm-Gg: AfdE7clFPHQHmnG6SyZlz4hmbU45jDqkudqg8UOeX1nXITPAiBi/xS1zm7JlzNMkRRG 7YmZpae3gkFUGJErTCDRr7zQYTgHx6gHX0vuz/Oqu5Tz03X7EiJeX7upzdG/RAWwwXH8bO7aDw7 cYlVaPVk/g2iKfnX+CnDocYJxP3UBwOJVCpVfQhM++Il90gN6s5RmvWizxIRHvNW5BAg/N8QeZu th01kh50SGrOGcvHbXXv0Xw5lsiIOnEe2OCenCxulWIUJmgN3a5QnLmyC8Ja9RDwNlV4+l5kyoK txmpzImN7BsfE+c6nZmjVSUROAWBHpriXBUn0pZdkD2ZlY8DxfgrpBd9YJ05SlfOZ+m8ej/3Sjg 4Hl9WPL2vdxaXrPohdHPom7FzbEZb2MRtLxM+YOhobJWAVniwwOwAEys+MyvdawNZNeVzzdgG6Q Qf4SitM8TYkbYXM+I+9B6sumMI7ObOGW2v+vtmVw6O X-Received: by 2002:a17:903:350f:b0:2be:3850:297e with SMTP id d9443c01a7336-2cf03da25a5mr71471665ad.31.1784212919520; Thu, 16 Jul 2026 07:41:59 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 07/15] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Thu, 16 Jul 2026 22:40:32 +0800 Message-ID: <20260716144043.76414-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213194472158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context in iothread-vq-mapping. This allows tracking IOThread users via the device's canonical QOM path, improving lifecycle traceability for virtio-blk and virtio-scsi devices. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 20 +++++++++++++++----- include/hw/virtio/iothread-vq-mapping.h | 6 +++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6b92066aff..4b2cf3d52f 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1493,9 +1493,12 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlo= ck *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, + path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; @@ -1527,7 +1530,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIO= Block *s) assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 95f13fb7c2..26ecefd547 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -65,9 +65,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], - vs->conf.num_queues, errp)) { + vs->conf.num_queues, path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); =20 if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 55ce62986c..2cb48dd387 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -77,6 +77,7 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp) { IOThreadVirtQueueMappingList *node; @@ -93,10 +94,13 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_get_aio_context(iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; =20 - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, + &io_holder); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +124,19 @@ bool iothread_vq_mapping_apply( return true; } =20 -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; + + iothread_put_aio_context(iothread, &io_holder); } } =20 diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/io= thread-vq-mapping.h index 57335c3703..0d39caddf3 100644 --- a/include/hw/virtio/iothread-vq-mapping.h +++ b/include/hw/virtio/iothread-vq-mapping.h @@ -17,6 +17,7 @@ * @list: The mapping of virtqueues to IOThreads. * @vq_aio_context: The array of AioContext pointers to fill in. * @num_queues: The length of @vq_aio_context. + * @holder: The QOM paths for attached device. * @errp: If an error occurs, a pointer to the area to store the error. * * Fill in the AioContext for each virtqueue in the @vq_aio_context array = given @@ -31,15 +32,18 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp); =20 /** * iothread_vq_mapping_cleanup: * @list: The mapping of virtqueues to IOThreads. + * @holder: The QOM paths for attached device. * * Release IOThread object references that were acquired by * iothread_vq_mapping_apply(). */ -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder); =20 #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213183; cv=none; d=zohomail.com; s=zohoarc; b=HCZeYsZ5HqUN/1MFliQv9f0zI5lR4zUa/Xb1ppd9OLAtK0N6CbMFS9DX2J/ln3VYfPdJwKFNPZnBQcBF4x/Tm54SvY30OWruXTjHu8xhTGs6mIrVl1G1Hh5Fsykki+1kD31lxPK8YYF8ImqfOqkuEa4YHVuMRJFhvl04U8eMJmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213183; 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=j0mhc/RYVCfvpLXWToM2n3L+ExBKX6NiykYMZhvUJag=; b=Roi53BZCFTzCB0aNGLAVEJjdUJHu5O5pvKGE5mkl1zMJNjM3bD6Vod4MWjEb03FiUKwV3PkUgObbueIjgyoVPrRcLTKHMCVa6QRpsBOuR48pLSshr2jlpxBdBc7+emnvbySOajJUiXhDYqSaBSV2I+V9uxpQQs6EdCBvpEFrBb8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213183703225.7323761571996; Thu, 16 Jul 2026 07:46:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJY-0007Lf-Aj; Thu, 16 Jul 2026 10:43: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 1wkNHt-0006Mg-NL for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:14 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHp-0007M3-R3 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:07 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2ceb096e675so61040825ad.0 for ; Thu, 16 Jul 2026 07:42:05 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212924; x=1784817724; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=j0mhc/RYVCfvpLXWToM2n3L+ExBKX6NiykYMZhvUJag=; b=ZLwhHV/s9m16jpIOkQz9cgIPSJzCitu/w6a56ah7o8yPdzVBBiUYDmoJFcrR46G1cz rhRsyaIRMdUJgDOK5Etr/2fZZX4MtHI2lMdhiUInNrjjotRSVis1Dj4QstLVDz3yG6pu qmd3OJq+oRwYZsaImIep/+Qn5XQdyb5RIQq+apGRjaNe06BJY3helBrVxEeGa9K/18ao kTuHY3oph/8cv3t84APkeUf9A7XOHvw9FAff3fOjW1J72hlWghbKHLnT1YKRN5uAfDGD dDsYe/RiznLHojBMO+ChcOOQakUaVtfP+0mkHSkH2HEaPjniOidYTOSkwLKlc7bcyP5s X+pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212924; x=1784817724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=j0mhc/RYVCfvpLXWToM2n3L+ExBKX6NiykYMZhvUJag=; b=E/oLbkfhiJW627VJd9t/40lS3hbKhqTMjShnp0vfUaE8T7WLVICmeDCjL+ZQFpSwly GtGOVIrlB2czzItGB6nZzW50iaE+wPBMMB8iYBKoFeTxs0oQEoTToUOz2n2Jvaaf13Wn YrU0GHuB6ZSv4vBlIZ0wEzhShKbzZN3/u+NYjkU184aZA9BMpRL1nX+dPxv5HuJI6Cq0 CJuPKrExNiC5oRbBjhGZeOs+Td0H6p6yH8PY59yljUVGINLt8dSaIr9Z26mIxN/MkpVv pNeAmIY8qq6oDlwEcGOJQg2GWxQsLhWs/9cgrdy+NDBUKD6lKpaXQDpFeHBOUB3i6v5K dAAg== X-Gm-Message-State: AOJu0Yz+Khp1IMb5tu/IfGZEWghdZ2z4RXUVj6kHvUBu7SRxzaQ5VaxK 7jqOCfEqDGEE8YMtR5vwm94L7YzmmDM/U0swwsFM7eAyaav3koqWEN6q9bUisyOCzd4= X-Gm-Gg: AfdE7cmKaSDSOg9UFdNDBQWFhhm6NMnV1aUaT+Y+wss7l1OjGMk5pfm+kg8OUm3Mtft wgvC72tDR11uj75VpxSS/80ZEbr9qoUx/K0kAmJPJoRkV+P/F8e45Kfu5wjBQne09IgSiKXSmQY 39m9YDCC33OGGroIL3c+NsHYaLmnRV0RsPF/uotXF1KBNt/umbryIb1EKi8sdi80rnGTGQVFQRx vmffBg2Rpt99vjZ6w8idmNY5LpkBqkpoUcJjBxDAHy+kBgGBYOEGc6l7opMjverre6zt1nzQfXx cArUh5kE71l/mifbwDC7szO9ltrowy4sJS8bWk9GEePPYc9XeDzb+kEDmPkidfdN86zzDdaaUK1 KeEYznPoFdszwWx4uAwx11/z1AwKQOBnElegl04b4mZF/xsCk1RaaG4I9HELuGl3CsAsRRPOLFF bSBk1EUdusbxNaqheb77sErvyvO+jfBpfbLXSp2/y9rOEyTcvdTjM= X-Received: by 2002:a17:902:c951:b0:2c9:ff83:41fa with SMTP id d9443c01a7336-2cf03cef367mr70187315ad.24.1784212924329; Thu, 16 Jul 2026 07:42:04 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 08/15] virtio: use iothread_get/put_aio_context for thread pinning Date: Thu, 16 Jul 2026 22:40:33 +0800 Message-ID: <20260716144043.76414-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213184354158500 Content-Type: text/plain; charset="utf-8" Refactor virtio-blk and virtio-scsi to use the new iothread_get/put APIs for AioContext management. This ensures IOThread references are tracked via the device's canonical QOM path. Summary of changes: - Lift 'path' scope to cover both vq_mapping and single iothread cases. - Replace raw object_ref/unref with iothread_get/put_aio_context. - Ensure consistent memory cleanup of the QOM path string. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 24 +++++++++++++----------- hw/scsi/virtio-scsi-dataplane.c | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 4b2cf3d52f..1865890fad 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1469,6 +1469,7 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) VirtIOBlkConf *conf =3D &s->conf; BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (conf->iothread && conf->iothread_vq_mapping_list) { error_setg(errp, @@ -1493,8 +1494,6 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, @@ -1505,13 +1504,15 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_get_aio_context(conf->iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, + &io_holder); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(conf->iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < conf->num_queues; i++) { @@ -1526,21 +1527,22 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) { VirtIOBlkConf *conf =3D &s->conf; + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { - object_unref(OBJECT(conf->iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(conf->iothread, &io_holder); } =20 - g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; } =20 diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 26ecefd547..c71f33b41e 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -28,6 +28,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) VirtIODevice *vdev =3D VIRTIO_DEVICE(s); BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { error_setg(errp, @@ -65,8 +66,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], vs->conf.num_queues, path, errp)) { @@ -75,13 +74,15 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < vs->conf.num_queues; i++) { @@ -94,16 +95,18 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { - object_unref(OBJECT(vs->conf.iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(vs->conf.iothread, &io_holder); } =20 g_free(s->vq_aio_context); --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213175; cv=none; d=zohomail.com; s=zohoarc; b=O7osaJBAzQyY7QrPXjTRkt/9Q6t/fnPdhzXzTncHdKzU72E1FB2aaX+/Q8yw9Mop6I/s/NrgYWPvV1VuFvAtaRjGKfMO0sK89RW88vQpX5UanExxS2MaHLP9pFYNbS87e8GN1ZSluVZ2uRykLNrqOp91SCvatbULqyLgE0RD2s0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213175; 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=Jep4VeB1HvWI8khcgjXgo2Z4gQjRgVcwsTHAZ6Dz3LU=; b=X6WnJR1ihDAKz3NT411rmLzUbVDiVx/dCB6ZTNdr9mIWpZlj4XIdkjcs+QPTM1U6vsGG+SNhjJf3Rh9P4tCzk+MsWIuh+Vn/dG/MuR3L/x7+cdDeVQH5dLZKcdOSMCQeO0c+apGR1hskTnYHNtqJ6eaDZlhU8KOpAIu0Yl7lBh0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213175944487.4865047317313; Thu, 16 Jul 2026 07:46:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNK4-0008Ge-0Z; Thu, 16 Jul 2026 10:44:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkNHy-0006Nl-G7 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:14 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHu-0007Nj-A3 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:11 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2cc6dd436c6so41358925ad.2 for ; Thu, 16 Jul 2026 07:42:09 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.42.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212929; x=1784817729; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Jep4VeB1HvWI8khcgjXgo2Z4gQjRgVcwsTHAZ6Dz3LU=; b=WCU+SYvHVA3t+M+cxi+TFVGUvFRXnUDECXzNGmEieZajuGhgNgFs/Uo7Opu47GVWP6 8SA/ADRBjDnnQMHflqAV+kJpHiNwOIwkzdgog5tFtnOENeBclgPtRcH4E5dsTzu62cz8 bvxXYK7bOS8L/Dzsd3EtYwoZIRaEwNL5Fl49whng++gh3iAo6orZ+2GCoBz9ATydECYo gN5SpJA4T6Wh/J9egiTG0L+w1qhUHG+4xrdB3LjSSe7j3+2WXFx7714s1Cp9KfwTAZeE EZ8ZnRg1xgb7Etjgequ3h474eq4cO4uRaRtuRPUl5z8T2JGQfMyZwndIyzMBmyps9+66 jAqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212929; x=1784817729; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Jep4VeB1HvWI8khcgjXgo2Z4gQjRgVcwsTHAZ6Dz3LU=; b=dOAxQoPLKt2VWqZzOMPfnKU53hcCHz0jl2pb7BEl813WfhOsqQt5XKtUTlfBcH6iV4 zonVRWWsfUGlbsiwk6X/RWF4RQKnnNsxx8WwR3ZOAXPVBkI8+Lk/aHahzUcfbh8zcw3S Zc3TXqfNMwrUgUF/+AO7TDCYUUyL2bscQJPVEijjUae04wXduRD80aEmAfICsBXPz9q1 vgaHf8mfIVc6yKYyFM62jCIbB/XNeseR+mn0mdSFYFktChkElMMpxkmNWkrHwgMIb8A2 lk+W5VYEsnMGd9H6GLq2W94yzbaommarYmoyUQd4dtgsYihyjNFeMRcqx1R144FMxxLh XeHg== X-Gm-Message-State: AOJu0YwB4biQjeXUh42qDFPWL728lawr7ebQybslPE+l6/rWYjfrjp0z gOY/LE732APRmGN0I3Snsp1UoB/q+T4fRbBXZ6elAU+WbLC5L+IURpl1A0MAZEMfjRY= X-Gm-Gg: AfdE7ck5QX2tIR7kBHDmYINHq6HfXSiQrncR1te+quh15EqfnGhZ/dIAuOlHqzs9YAv dPm/sHxWvvRCa1fePKmJoSr2R+TNCXIynXCgMxTxnouAsM22DnRnTIEWXUO3G9qLw71y5po4idQ A+6YYd2xp0dYhaDsdNmdvYuR9bQJWE/mfahl+WFCN3jiMqm5QjZlfWjKTxLYKxSG0hx4SK9RCvf DaMJmCie9ZygGvCw/jF3/wd3NYZNhhNOKHg6EFqI0KqAyJyVj+vixreqbNlMoJ8afLvs8zwLgK0 5JHNQhl4aJnJhBW582qS0KMyTalbrcvioRT01hStKQOm9Ih/i7vO0PLbN9124YJ+/BCPKseacT+ 5recViJ9FSOnKe+vpzSaNKeysqB/nwqGD++pJPWWlep0TfY2e0gp6bJuhMMxPu8xJXDG0wbjZvO rZvGg4dwkNu/JOMGIKK9d2xwJkcLXxCIMggu/Fka7RbdEtXRVOuS8= X-Received: by 2002:a17:903:13ce:b0:2c9:e5e6:8621 with SMTP id d9443c01a7336-2ce9f28515fmr223474305ad.25.1784212928810; Thu, 16 Jul 2026 07:42:08 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 09/15] net/colo: track IOThread references using path-based holder Date: Thu, 16 Jul 2026 22:40:34 +0800 Message-ID: <20260716144043.76414-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x635.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: 1784213178243158500 Content-Type: text/plain; charset="utf-8" Convert colo-compare to use the iothread_ref_and_get_aio_context() and iothread_put_aio_context() APIs. This ensures that IOThread references are tracked using the COLO object's canonical QOM path as the holder ID. This refactoring improves IOThread lifecycle traceability and aligns the code with modern QEMU iothread reference management patterns. Signed-off-by: Zhang Chen --- net/colo-compare.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 5986fb1e88..a7bbb1056d 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -130,6 +130,7 @@ struct CompareState { GHashTable *connection_track_table; =20 IOThread *iothread; + AioContext *iothread_ctx; GMainContext *worker_context; QEMUTimer *packet_check_timer; =20 @@ -922,9 +923,7 @@ void colo_notify_compares_event(void *opaque, int event= , Error **errp) =20 static void colo_compare_timer_init(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - s->packet_check_timer =3D aio_timer_new(ctx, QEMU_CLOCK_HOST, + s->packet_check_timer =3D aio_timer_new(s->iothread_ctx, QEMU_CLOCK_HO= ST, SCALE_MS, check_old_packet_regular, s); timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) + @@ -964,8 +963,15 @@ static void colo_compare_handle_event(void *opaque) =20 static void colo_compare_iothread(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - object_ref(OBJECT(s->iothread)); + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + + AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, &io_= holder); + + s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, @@ -1404,6 +1410,7 @@ static void colo_compare_finalize(Object *obj) { CompareState *s =3D COLO_COMPARE(obj); CompareState *tmp; + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); =20 qemu_mutex_lock(&colo_compare_mutex); QTAILQ_FOREACH(tmp, &net_compares, next) { @@ -1430,18 +1437,20 @@ static void colo_compare_finalize(Object *obj) g_clear_pointer(&s->event_bh, qemu_bh_delete); =20 if (s->iothread) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - AIO_WAIT_WHILE(ctx, !s->out_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->out_sendco.done); if (s->notify_dev) { - AIO_WAIT_WHILE(ctx, !s->notify_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->notify_sendco.done); } =20 /* Release all unhandled packets after compare thread exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); AIO_WAIT_WHILE(NULL, !s->out_sendco.done); =20 - object_unref(OBJECT(s->iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(s->iothread, &io_holder); } =20 g_queue_clear(&s->conn_list); --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213111; cv=none; d=zohomail.com; s=zohoarc; b=Dk0qDT1TGYvBLU4nuZisx6VPvp46x2Em1GpzOcLKXGqyiFFtjnNMC7vvWuolkmPzVk8aop1JJ2Jqe3NqMYemhP6k8SP2RXx5RkXGImJrrxNlAe9Z3dkpVSVz0f9giEz2OLjhSVyfsIzGuwoFS2DPUqvNkEmMi77R8d0hS/ghee4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213111; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TMWKjSKfCkLdRLDphuftQNsCyWQFXmHbwlzRM8NRv8w=; b=e0idbeKmTwCQmaRyKQDLWOcqik4oyV3nUJRnznmhMFvtUL5+Qux5YceZ6Yt/8aFNZ4xfsQJMQF5f2NFwlJhk39tPtZUYZ6S83NqG1e029qUTQ+ri1Apr6zIR6EsUghLCd0nPG0i3wewXh8NXKnHozoWgL0fzJVrmSOrnt5nCVzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213111171565.9344995651273; Thu, 16 Jul 2026 07:45:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJb-0007QE-Jt; Thu, 16 Jul 2026 10:43:55 -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 1wkNI9-0006Tl-Ak for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:32 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNI2-0007Rk-JG for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:21 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2cc73e322dbso81959015ad.1 for ; Thu, 16 Jul 2026 07:42:15 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.42.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212934; x=1784817734; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TMWKjSKfCkLdRLDphuftQNsCyWQFXmHbwlzRM8NRv8w=; b=VrGh4TzBH0Mshr3pzCQY6ZbQbELVkmD/dmyk4VZGjT6IACs/o84exCu7p5tbWk/dFN /cUFwG6lDqhSjBnifTDqnKpoO41ChFY4LHHSjjYr1eYl5vqCUffFRuMnp9f1F0pRqDJh rSE8vELdwmkdKHbgoG4qSMXuEdLdG4We+rlmtp/6T0rbr2cVL+RhgcgMsDwYfq3JpyL5 oxHLRhFtzuJtA8dtb2Y77vi3SvIp1sxKIULXTl7UL1Tt16RyTyQ5rSVmVEyoEVbAUGRv 0+CveGR5aPPtVSutABF7nhwLnVkgZuN/poa+MyetjMkmlhbydPN5Zow5UZ0WRZJ4BRj+ dhog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212934; x=1784817734; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TMWKjSKfCkLdRLDphuftQNsCyWQFXmHbwlzRM8NRv8w=; b=oOdVSD8k1FiAZT/M3URDrALL5GFSfrh0RKM0Ne/8ANVMUrZEKxN073oc+536I2ARd1 fSyjvykyeYC2xvPiWybeZvk2Gf3liVDhJdrHRfYqfHajIUrbbJabgjpU+KCLFtZswhK1 jC/bajnF3bTUkgNvKzi0R6BuwrVCFzQOh51a5ug+T+5KBsLaCfXoowQGN5vm4SY3nQ5z EsoS9z4+3m1NCkeSEhjay5dRjRbrIXQ7+KawLFSCvjC48CVhzaoYqoi89xtLZf+8+BV3 UMTA0oZdILbOXYR5200DNzelUIuKrItczRglo70upPeZ5Ws5MCFRx4frc84KeBlRfbxn vZ7Q== X-Gm-Message-State: AOJu0Yw/+Q2uHy0BE3rOHjx/x+Htdcc+EVz7Wp60iltkPPw6SZbnkdO4 jMxFwiBDEyZGIEtu3mqs3sroyDCySO5XAUGNyjGk8k+E3Ye00ZdJpQOjSCU1G42jqFI= X-Gm-Gg: AfdE7clLzmflxwTWUaufCLC2cSkuSSgWegOrpv55w24Zzptu2w2HoRxbJkC4vhrQGmD Ve6HFhxsuwpXodFpLWyIYLswhZYzCyjKNge60Zfeo8TeYZih9YbF8/PoAkurCID9x4BjyEIBtQX vbdJtRaxd/UMT5lKlUgf8zoY6w7Omolxqx2a8iWUuqH0apYzq4xEpicMywsxNtQFiCuSCVcZtyK 69GDONh51Dr1ZG66tZERIJQRIYM7DbDrL5fmOCVd+aqXYT14FfDhPahQD3CrmsXRo8/aVTKBZsU AroqNXQr2oaFN5uIaKQlq9yCmV87xso/WzlqOMoKPiUI+uDoFhnb+T8PBEFCKGGyb7hIefOYPV5 oPVmZG5v/cTnfRHfIt++oiEyWFZbb2h5YBNVn97MOOMq7dimW21CdihkOBrkYEBmGxIH3vadByM 5qZtRO6GQkd7MQ1YQH85JR+sHxeov6aRVqCncfGeTl X-Received: by 2002:a17:903:8c7:b0:2c8:1f56:9fc5 with SMTP id d9443c01a7336-2cf03d93757mr71087935ad.35.1784212934450; Thu, 16 Jul 2026 07:42:14 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 10/15] virtio-balloon: Update tracking iothread users with holder Date: Thu, 16 Jul 2026 22:40:35 +0800 Message-ID: <20260716144043.76414-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213111903158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/virtio/virtio-balloon.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 4c5f486ba2..e9d023b4ec 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -892,14 +892,20 @@ static void virtio_balloon_device_realize(DeviceState= *dev, Error **errp) s->svq =3D virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HI= NT)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page= _vq); precopy_add_notifier(&s->free_page_hint_notify); =20 - object_ref(OBJECT(s->iothread)); - s->free_page_bh =3D aio_bh_new_guarded(iothread_get_aio_context(s-= >iothread), - virtio_ballloon_get_free_page= _hints, s, - &dev->mem_reentrancy_guard); + s->free_page_bh =3D aio_bh_new_guarded( + iothread_ref_and_get_aio_context(s->iothread, &io_ho= lder), + virtio_ballloon_get_free_page_hints, s, + &dev->mem_reentrancy_guard); } =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { @@ -919,9 +925,15 @@ static void virtio_balloon_device_unrealize(DeviceStat= e *dev) =20 qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + qemu_bh_delete(s->free_page_bh); - object_unref(OBJECT(s->iothread)); virtio_balloon_free_page_stop(s); + iothread_put_aio_context(s->iothread, &io_holder); precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213089; cv=none; d=zohomail.com; s=zohoarc; b=bnNLxs3uQwKGHwB3+JD/wPJ6W1zb4NYfdePVSzlohuJWva14m0sI2h3IN0kbCgudZUzcHu1Uy46rg4EqQZ89N93QyqCKcegLjtwStu+AhhwJs7kbetXy+djhj/C+eff6Ez/gwTGsEIBRue8ulO6kpR9vihebWxuLSJYbT0P2EDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213089; 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=Led6dtm27lEqwR8zEWN3ior7m9T5nwFBmwYxnZK8iTw=; b=cEcCa+0x72rzhLmjcj8lKvNVVbnkFlVnm3xCKbQu8bl3TJIgJuJhFgBTA2hSbxgowYGe5HSLHVXRBHdpmBEpK2nOddVuk4ULWG7DNPa8zE3MM5Li24ggDlvf85UcyuAf5F9sg8+iqnR6m2LvqUPu9ikWmdmmi3jJFPRQ6lG/c10= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213089157849.8282021309251; Thu, 16 Jul 2026 07:44:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJa-0007OU-AF; Thu, 16 Jul 2026 10:43:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkNIH-0006Uz-57 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:41 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNI8-0007V5-Tv for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:31 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2caced6038eso9179815ad.0 for ; Thu, 16 Jul 2026 07:42:19 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.42.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212939; x=1784817739; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Led6dtm27lEqwR8zEWN3ior7m9T5nwFBmwYxnZK8iTw=; b=ptIZSLFXYB6b7Qdrvv2Jm53I89BgVQNM/wmgjhdDyoVPDTUt+LUb7MQ7utN5RadDqN SkIz9B7tY5Dfq/U8EfOV12SZUpbjuBaurHDxW+X/rkqDozr74UaWPGnDQDE3hEvBpj01 jvYZrqG+XoaOpCY5yoEL6GLxKGmp6AsPxdENr//PLipQpeH0WHhtU41Z5QbceoWE7nY5 NfXTroHOeImjVVqi2RllqPg+6DH4mHh1t3jU2ISiGRWOuMYzPf4GE39MxAfLqFHWv1R1 JCTMn0ChTeoBDCLo6j7v2Q6sRBEvBzrRUG7knKI7VSs/AEIWXkwB1TfMB3A+WzAmo0lx HBOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212939; x=1784817739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Led6dtm27lEqwR8zEWN3ior7m9T5nwFBmwYxnZK8iTw=; b=JSMuBM/2uZmuirze4q5Uw1hpUITn5B80PEl0V/aPh+a0N2GhzU43VshYLGjSwqoZfR Q8x0GSrwxZwY86qq7pUzQc0ojkmhWR1U/KK19YW/JHI6+mSihJ8pgAt2E9JxQQiXNSZI 5pA1Nkl3SksyRrzn2BTi6wr3J8mgxGESCJVfgRTR1hUTs7zHEXNpidYPBilTcoAgNj7n SJRC3uV40E2zXBvr6y1vaDd131oASfLWGQEyDJlNyjwdfs2KXXXEg6mH+Rjv9gRstZTp Nwg+RINUBUcgCSpgnQevCNnDlgn0kGhv3PQJDdMjoPNd6QKXh0YM0BbtIzdmn3OSJXeU 4k3g== X-Gm-Message-State: AOJu0YyfHBnRBHrlhGQkJP9Q2/OELVAVik42xhIIa4CoI90Fv84Mi3le Rxg0bkkqii+oRBX96jKr352T9ddNasWSrzq34j7nIsbzEbUC5MkC+TY8FyNIAT7Kg08= X-Gm-Gg: AfdE7cnTDUNp3CWPg552cV35+s7pdfMXs+voi5hw63eW/YvV6QTas8gpb+7N8B9ffBp dqoHutSOQv8y4gVY5B2GxKLU7xCemDE0gAplrLJJbNB4Z4Cg6uMme5DiDoCGFqBhVoMXQGAFol9 zMBwvg+Nm0UNOI8YUwSvdLWZ9ppIMqSjrSePqU0XkyLjzL3ZEaedn7ftRUY43EDLfGtdRUCB/X6 VQ1QWSGBgNWLcLn/Oh1L5dFvK6Xpk60P2m1h923AnzPKYOp5EHUitDNjZbm3VqiJZaAji7KaWm+ LxdVBKeSC/T0bPFdW4gRxnViGmEWXTnlAZrLuflkmgHeF+waRfgrDR6fNPuR7TmLRGLfE7HzXuF wqtLvPoDJYFS/FVuD+clQaGHHqyi9tI8JG4wFyyzoPhlI5ArpYDWLhDULF5MiLJMR7Z3o7ylpkM COTlXm6BTqrqdXNtsR1I4qe8F7up/8L9yP7LTxXT0A X-Received: by 2002:a17:903:1a0c:b0:2c9:ece2:822b with SMTP id d9443c01a7336-2cf1f280732mr27567615ad.3.1784212938802; Thu, 16 Jul 2026 07:42:18 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 11/15] vfio-user/proxy: Update tracking iothread users with holder name Date: Thu, 16 Jul 2026 22:40:36 +0800 Message-ID: <20260716144043.76414-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213089579158500 Content-Type: text/plain; charset="utf-8" Add object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/vfio-user/proxy.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 0f7d8425d6..b4f749f245 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -898,6 +898,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) QIOChannelSocket *sioc; QIOChannel *ioc; char *sockname; + g_autofree char *path; =20 if (addr->type !=3D SOCKET_ADDRESS_TYPE_UNIX) { error_setg(errp, "vfio_user_connect - bad address family"); @@ -917,6 +918,11 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *ad= dr, Error **errp) proxy =3D g_malloc0(sizeof(VFIOUserProxy)); proxy->sockname =3D g_strdup_printf("unix:%s", sockname); proxy->ioc =3D ioc; + path =3D object_get_canonical_path(OBJECT(proxy->ioc)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; =20 /* init defaults */ proxy->max_xfer_size =3D VFIO_USER_DEF_MAX_XFER; @@ -936,7 +942,8 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("vfio-user", errp); } =20 - proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread); + proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, + &io_holder); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); @@ -967,6 +974,11 @@ void vfio_user_set_handler(VFIODevice *vbasedev, void vfio_user_disconnect(VFIOUserProxy *proxy) { VFIOUserMsg *r1, *r2; + g_autofree char *path =3D object_get_canonical_path(OBJECT(proxy->ioc)= ); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; =20 qemu_mutex_lock(&proxy->lock); =20 @@ -1021,6 +1033,8 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) qemu_cond_destroy(&proxy->close_cv); qemu_mutex_destroy(&proxy->lock); =20 + iothread_put_aio_context(vfio_user_iothread, &io_holder); + QLIST_REMOVE(proxy, next); if (QLIST_EMPTY(&vfio_user_sockets)) { iothread_destroy(vfio_user_iothread); --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213199; cv=none; d=zohomail.com; s=zohoarc; b=ZZroENPMaSShQnErY8dO0WqBba4XiQA4hURNOvRZ7jcC6noQq0oozjpyfAF//jE/qu8On3lC4hNRVgY2tb1ayHWe6Dr70YRBg5HzJfkvvpuXKnzEWS7NznaCxsI0ZivlBpZqiNtzPXvd27foeTVPXd82hwnkdIOntyOOEywv48s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213199; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7t5cTU126FnpUwkoAoirKGUM08oblbAVX84J7t/Z2ng=; b=IMpQTqSZG3kXbAOjka4zjf9hH1MYMm4R2eaQpFE6nwjxq9AL4HcPfL8dfnFAki9bFpP9EkVGGTkpDO2yaJ8xDrGgHv0JgzrkzAgNCZKMhlHHqOkko1p8LRUjG2rNkyYOb6DqixdGCH+TdSVeL4KZN8kR9gGcELNt/1+WxkB+HR8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17842131993711014.6590285055585; Thu, 16 Jul 2026 07:46:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNKE-0000NU-KB; Thu, 16 Jul 2026 10:44:34 -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 1wkNIH-0006V0-6A for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:44 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNI8-0007bx-U8 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:29 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2caf228a910so52217825ad.2 for ; Thu, 16 Jul 2026 07:42:24 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.42.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212943; x=1784817743; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7t5cTU126FnpUwkoAoirKGUM08oblbAVX84J7t/Z2ng=; b=K9MeHOQ3kfrt1YCJ7B9SAvk98HRbesL0E0fehZienqaM068g33pH+F6ordCaWdSydl PXJK7bL/L2qKnUml3Xj7ESjvElfiwlP8cgF8hjJlm6EE1q4b7dM2eemmDvMcn2fHtbrA 3QFmkYAz5DFZYIZ3tROtrFbFNiPg08kkqo/sgAOuZTrlvyJBXAbq2uRwJWdj3cH1XsmZ wrh/4xK2EBp/Rnufk6KDYg/tJCzVxM9lnSo8BPKVIfOdD9XlBN4tT5X+PyEq2JJ3TLo8 1P9tLxNt1+KGc7S7/0g/dykb2z0XM3SZQEG8sa1nVFWtkM3lKybpFT4ze+Jw03aUkUps GEOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212943; x=1784817743; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=7t5cTU126FnpUwkoAoirKGUM08oblbAVX84J7t/Z2ng=; b=YKtDC5VhGO3mt2xtM9uA+W7afhQy1uJCBWUiLIagduX97qOio/lF0/K0GIVyfmTwxn qo5EvbpqYfx0I3HnUogu3+3qrRq7ELXx84djCy7PVUZTRPccrW0ij8FiVrotW/f6TJ08 cu68BTOeCU/2FqGls0fQVnHoBesHMfvssAEaJVnjOd9TssU0cNM0TyVQeTIxjlUUARTk KeNHA3Y7U0UQYLeDnSpIidmdrzAnQrtP+VxLfe3480FyblCJrxUpD27b19FoqpcU6QVd ToqcWUkeDdHeuNslyZF6o0K4u80RK4k9I2dAuOEc7TYOakfSsIVLXDnIZR7MdiZtCpPn AVzw== X-Gm-Message-State: AOJu0YyrGO8GcgATv0ignr3FZYx8fYEbCIQOQa3VhlSA75fJFSk8kBcP W6C0e3i2GR10lQv8Asq9nArxMe2ClVlIzIbkyUVYaFG0LU3F3tDz6b1J0Fac1xYws/M= X-Gm-Gg: AfdE7ckw49HLCCzqpRFH3RugJK5aVPmpUQE4gfjcahnNzG+Pl/W0WDGsF/Gk3lREpk6 +lzcXX+eUYOcownczUtEPvTaHlLih57FIww+rwlcVV4GbJLzl0qxcj8myzMFa7JDWl3NbTZDwjo phW6PgZxPqN/Ii2lc4XiR8EnL0JKUqZROp62FjsuGickVI5Sy4727EqF9DjRpY4i/41HN1wLmf9 S7I4VBL6JHKvFrYv0bD9Oh6zbLjfP1PgBnvdbBXQc69CSUhYeEGJHLAvcceFkM8gbNu3lfXPbQN euyjlmlSmuEh7BkiLauuK98tSxYtFcBMVA8Yrkc3WoFz3CYoOu3nsO/GI5NhlTeeYWml0K2EPh5 eaRgrMLzf1SCXK3NRuRDQP0ohDPtKFPVsS9VcsJqgllgJo4u/TlA+VscB5Zkbnpwu3BMYfbAUjl ufz43MsvFnGQTjTmSRBYXD1nwbakASrUmlVdlUkwgn X-Received: by 2002:a17:902:e883:b0:2ca:e565:7b15 with SMTP id d9443c01a7336-2cf03bd5282mr75551645ad.10.1784212943238; Thu, 16 Jul 2026 07:42:23 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 12/15] xen-block: Update tracking iothread users with holder name Date: Thu, 16 Jul 2026 22:40:37 +0800 Message-ID: <20260716144043.76414-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62d.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: 1784213200451158503 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context. Signed-off-by: Zhang Chen --- hw/block/dataplane/xen-block.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 48c2e315f3..b5bf8d359f 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -621,9 +621,15 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevic= e *xendev, QLIST_INIT(&dataplane->freelist); =20 if (iothread) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + dataplane->iothread =3D iothread; - object_ref(OBJECT(dataplane->iothread)); - dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread); + dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } @@ -652,7 +658,14 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *da= taplane) =20 qemu_bh_delete(dataplane->bh); if (dataplane->iothread) { - object_unref(OBJECT(dataplane->iothread)); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(dataplane->xendev)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + + iothread_put_aio_context(dataplane->iothread, &io_holder); } =20 g_free(dataplane); --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213267; cv=none; d=zohomail.com; s=zohoarc; b=XmIDyT3GMyzD8b++qH60GSYDEJfAXnLkbulpCbgo8cvK7HvJmPvbQhyLewg92ic7A4kLz1j3yWJCxpeDG/jNuOqSwLfozPFnU9/oko2f3+J5uR3cX1OepCVUZT1e97eB4eckV3bSfEPTcyOPWrqhnfqlvLwcWmMUuJAWcfvSn1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213267; 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=/RpLsNVoi9MP1a6H+NZ4QnrSsQSxyH85XlPl91aINz4=; b=J7/fnOc+k8vjHHGbDOblb8X8ZGsjOd8suyXZmW9VdJoGY09fNUJs36EL1Q+riUq4x5rxHq78M2t/VUYQTeS3Cw1RzvncNo2tCnhvApTUJs921x74lHrhI2fjLs82l65kEmcZhOkyxwvyKaLPTomqYZy41uwtvsebUDi91KRyiOM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213267519237.2829356585131; Thu, 16 Jul 2026 07:47:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNKF-0000YD-RE; Thu, 16 Jul 2026 10:44:35 -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 1wkNII-0006V6-Fl for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:44 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNIG-0007e6-Sd for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:34 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2caea3f742bso81219735ad.0 for ; Thu, 16 Jul 2026 07:42:28 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.42.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212948; x=1784817748; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/RpLsNVoi9MP1a6H+NZ4QnrSsQSxyH85XlPl91aINz4=; b=HprA2TYpRZ46WLsY3/7ZsP7YjiOtsc4f1RzTe5U4WJqChsbu0drrfrpfzWOGyrLbfA rO0QvXtJf8x0hLHxjDVzFl+jtcVsoJnIM+GKNEcIy04ZOOFxU+V9f/BQKsV4CRe7k1kj RSJsqxbmzsTXqo7phlgKn8SEt6YWXykhlRfoHtzQuQ9ERAexM5w6G84+zjEZLnRtX1dy r2s121cFfH+P18DIaX6/Hs66J8vCySYKjBYm1y8Zltx+CxdpbAvqLckAky8GO6y/abhw 6Yqi+4+yVeJ2YqcHemkbOc/wa/d7ZHE/fn0YPq/l8tArcy4n+non26nPIPZgCClG7WHw 8L6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212948; x=1784817748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=/RpLsNVoi9MP1a6H+NZ4QnrSsQSxyH85XlPl91aINz4=; b=nx/cwmQEevpqYSfg5VswVSPutQ9quTrn4dG1jj3bpqFnk0AvxG0FW9hLJaJ5Bl39hO JbUWcLh7wHNSd31fGck40gn2gE0xTwgngIY7DlWrGbprwaUUJTs90NOy+hS22COlu6Re 6JwvQgBXaahTF+KggGeAtjrybhXN0kZd5Ma0I0UulECKJCcuEmkJQGjZAOfgXdQWtCy3 3SdYuUToZ/3GaJ+8Dri9QDWPZujKyEx3mi0zF1jXcqMndLfV01AdooJFZ/BgLTVJ8+d5 tsiKpGdrNWFs90czYPEChD/4GvwbzZIJdlKo9lohqhK34bQ6axM2KjGCIFLcf/PMAxKO 6z2g== X-Gm-Message-State: AOJu0Yw7oE5SwYlCrcZlCbkcv3i5VYOYsL1sTfbFYqfB7X+ZZrmI+6Zp oKDMDfk6QA9o201VuAdlyDVHcQ627tTcGrMcsuOKCW4J2Zc0apVMfqTYznEEn1oZFOE= X-Gm-Gg: AfdE7clmUDwzj36fvbXoRMjPHOG3r1h5cSkOm+4QemEOzL78Sp+rdPf2o3Uq4XDNzsS DDQfezi+35HwF1NW7QGqNOnyosQ7yUEgSRcuI/oeUEPDlf4GybfWK5qzHcrjw9/XW0jojp4mF2u LhEbMvlBESeO2rKqnd+guUEhce5dYrXhQt7aMIYz0MTN7ib9iHieVb7zRP8SW2ujhI2ZoOONYwb KHge1kU2OayAne7gFB33zqHzY/oxOcYmS9SyZXlPqQgG/DCzEKm+knUVxoi0plSDvV5IExdR6Cp oMiWzGpa5b6Z033n5e3fsI56JOVYLkkdYdvZFz3NgTKRTu/2sQIVTs8Xg8ADSr61VIZfbV8NhKN Rpq+15/4smmb2IX28b/E/4pBdL2IssV2rgKAxeG/NkHWEZ9PhObz+okJ1BgoZ9GjAyWiyoWZEpE TTAcAzCgIZ70ylqIabtmdJZBGAhH1bSDWOLWDI7MAHCBqmAxNHL0s= X-Received: by 2002:a17:902:db06:b0:2c9:e86e:aa0a with SMTP id d9443c01a7336-2cef0f05baemr107223255ad.0.1784212947666; Thu, 16 Jul 2026 07:42:27 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 13/15] monitor/hmp: Add holders support for hmp_info_iothreads Date: Thu, 16 Jul 2026 22:40:38 +0800 Message-ID: <20260716144043.76414-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213269032158500 Content-Type: text/plain; charset="utf-8" Exposed the iothread holders via the Human Monitor Interface (HMP) command 'info iothreads' to assist with manual debugging and performance tuning. Signed-off-by: Zhang Chen --- monitor/hmp-cmds.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index e9fb8d827a..cd2d9c1d59 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -240,11 +240,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_EXPORT: + monitor_printf(mon, "[block-export: %s]", + holder->u.block_export.export_name); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_printf(mon, "[qom-path: %s]", + holder->u.qom_object.qom_path); + 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); --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213183; cv=none; d=zohomail.com; s=zohoarc; b=hoaSucIsZFdTinVBuLMIWe4aBKeqpUKWfhUvNOmAAd3HiNiwEPOUbxSA0IWRKkDy17NdQNWUHIHomkUe8k+avNwDgucmqYPZzWzu3lAYkH3rGcbjVBX97BypTSklkWPMVFq6/jh6K/y2SiikYqwAPUiVm2C99uAgCoOEF1gW3X8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213183; 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=QGDmrbz26I1WMwGFs2MTG5M/5fYQsJGL+TfR/qEpu9s=; b=F/qbBzig9mQlCILOaoS0IRKaEnHhKOIi/PNlYfFE8Wf/Jd335gH9uRVtt+Jr2YdW8fH/kAI2aoihzIJfy//U83jPGUtAl8eLo1AnTFTlWU4DusviO6ahabR1Ia4pRWqWW1CBaUnini760zxubGL4uE7ZzDqit19asnndNa7wbJI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213183295484.43251441423695; Thu, 16 Jul 2026 07:46:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJa-0007Pc-UE; Thu, 16 Jul 2026 10:43:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkNIK-0006VE-34 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:44 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNIH-0007eN-NZ for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:35 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2cc7ef7ec27so76857975ad.1 for ; Thu, 16 Jul 2026 07:42:33 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.42.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212952; x=1784817752; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QGDmrbz26I1WMwGFs2MTG5M/5fYQsJGL+TfR/qEpu9s=; b=YiRDpi30dnSYT146kvRW9aNEtVVOy0ps3iyljbjP/MPI6zltOTcdlweYij4DrPwkpI lypNjMK18hnXlJjSxAGONefIzis/btS96i2/RE1f6oLQbJXaCjr/Gwj6juibgtXRel2n wUOCi6iy5H5X1tgNUkW9j7EyDFlELlkWHLwOPSYrLU+udtcNSwE5ffeOemPtppvQhpNo +RhdbEQy54BjpfGcf0iiT4VO9AwWOiW3XntyVKeAGllsH551h2IepvpY/xB7ZnINevA/ QGlyJ3vTFmJmee+K2u4vgsLkV69moK3RTGcILnuosW0g7CJZAx+uD97h6qHSof5B0L1E kj/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212952; x=1784817752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QGDmrbz26I1WMwGFs2MTG5M/5fYQsJGL+TfR/qEpu9s=; b=WmraD8wjn4wqdazkhMZCwxC8EmFIlkLIKEvCuzBazLf32YC1azFvnNHnNYqi2lrSIH Hd7wRywXIvVAOlrzyB632JAR2xtFyjSCsK17jBWLE6IpZrLhCGwu3CUYSYh2q3w/R9Sy t7lfQjEuOWs/NH+bSMAAWkiQxaZJ37i4Gf1lyIde7nK7bLiK+3/8sS3KKEWvS2ZNPgIt mXSpo0aSTHJLILMBWBBp3AUS0lm65D2V9CSvJ0cGiwNFMqO1cdOK/85CDOMPjJeseHTe VSMVYdhsUCpiiez/IfZLDWI17pWHeNPslvnly+SGgzwk3DORscBVMCUN8goQgZkITz1p andQ== X-Gm-Message-State: AOJu0YwDNC5lkGSkAnuaMzRZ8d/i+JCikeJMXCQn+wBgFoCub7/UBSFq UfE3AOun6Sxl0v8An7tTFllZJ/OjXT0w8iwKDoRtUi+QCRc3ol4ki+Y563AlQXfe0CU= X-Gm-Gg: AfdE7cmQjPVeRLUSQ05tPFXRRgSCPxCBcrhqc6W9klwbRjxAjAMjDMhyZZLKt6FGrDg CTjFLopfFQiWaSzRp8yoNrnwD8JqaUavAAwDhHZeRZwnkMRrzpBKD/x6clNUA5oVo8FKGqjz22A Grg2WSpRZNWcajrufb3rjRR42zi1UMjah46eUfP2+Yb2OOj27UlCSQ5qbBht1Kip7APzLkqgvkQ M40p2KRmjNI3itnhHlXiow2aFh1UwJo1kqE4eeBu01jGBBU8EsDX5iTKMe6mz4UNc6I3NstDQcm ZEf7Qb/V/92PMSNq6igxK5Ps3bsrLsyKDxupwBAZwN827SIihTqsptrZc9C0qnQXayX3GiqDaxp zeSVsvkzF6g+mlgBgrfM/uiGrb8UwwSFLCyO3UjcyW5KIKoaXAeMVGWV9IL8BoMOYHejUL3wanx kkWQAflryvOPedJ5N8UFBwJymI+Lq0s7ngltTmuRS1 X-Received: by 2002:a17:903:15c3:b0:2cc:6817:d9bc with SMTP id d9443c01a7336-2cf03d51383mr63003345ad.38.1784212952253; Thu, 16 Jul 2026 07:42:32 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 14/15] iothread: simplify API by merging iothread_get_aio_context variants Date: Thu, 16 Jul 2026 22:40:39 +0800 Message-ID: <20260716144043.76414-15-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213184391158500 Content-Type: text/plain; charset="utf-8" Simplify the interface by merging iothread_ref_and_get_aio_context() into iothread_get_aio_context(). The updated function now requires a 'holder' parameter, ensuring that every retrieval of an AioContext for long-term use is automatically registered in the IOThread's holder list. Update all callers across block, virtio, scsi, net, and monitor subsystems to match the new signature. This cleanup reduces code redundancy and improves the reliability of IOThread introspection. Signed-off-by: Zhang Chen --- block/export/export.c | 5 ++--- hw/block/dataplane/xen-block.c | 4 ++-- hw/block/virtio-blk.c | 4 ++-- hw/scsi/virtio-scsi-dataplane.c | 4 ++-- hw/vfio-user/proxy.c | 3 +-- hw/virtio/iothread-vq-mapping.c | 3 +-- hw/virtio/virtio-balloon.c | 2 +- include/system/iothread.h | 16 ++++++++-------- iothread.c | 9 ++------- monitor/monitor.c | 2 +- net/colo-compare.c | 2 +- 11 files changed, 23 insertions(+), 31 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index 4dbd71de6a..32c7ef7d28 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -146,7 +146,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) .u.block_export.export_name =3D (char *)holder_name, }; =20 - new_ctx =3D iothread_ref_and_get_aio_context(iothread, &holder); + new_ctx =3D iothread_get_aio_context(iothread, &holder); multithread_count =3D 1; local_iothreads =3D g_new0(IOThread *, 1); local_iothreads[0] =3D iothread; @@ -190,8 +190,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) goto fail; } local_iothreads[i] =3D iothread; - multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, - &hold= er); + multithread_ctxs[i++] =3D iothread_get_aio_context(iothread, &= holder); } assert(i =3D=3D multithread_count); } diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index b5bf8d359f..46bfd62f5a 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -628,8 +628,8 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice= *xendev, }; =20 dataplane->iothread =3D iothread; - dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, - &io_holder); + dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 1865890fad..2c296986ee 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1508,8 +1508,8 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, .u.qom_object.qom_path =3D (char *)path, }; - AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, - &io_holder); + AioContext *ctx =3D iothread_get_aio_context(conf->iothread, + &io_holder); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index c71f33b41e..76ab22610f 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -78,8 +78,8 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, .u.qom_object.qom_path =3D (char *)path, }; - AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, - &io_holder); + AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index b4f749f245..8ad0f4cfd3 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -942,8 +942,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("vfio-user", errp); } =20 - proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, - &io_holder); + proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread, &io_holder= ); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 2cb48dd387..727358a483 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -99,8 +99,7 @@ bool iothread_vq_mapping_apply( .u.qom_object.qom_path =3D (char *)holder, }; =20 - AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, - &io_holder); + AioContext *ctx =3D iothread_get_aio_context(iothread, &io_holder); =20 if (node->value->vqs) { uint16List *vq; diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index e9d023b4ec..4405a87ed0 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -903,7 +903,7 @@ static void virtio_balloon_device_realize(DeviceState *= dev, Error **errp) precopy_add_notifier(&s->free_page_hint_notify); =20 s->free_page_bh =3D aio_bh_new_guarded( - iothread_ref_and_get_aio_context(s->iothread, &io_ho= lder), + iothread_get_aio_context(s->iothread, &io_holder), virtio_ballloon_get_free_page_hints, s, &dev->mem_reentrancy_guard); } diff --git a/include/system/iothread.h b/include/system/iothread.h index 3cce5eeb09..3a6010b9f0 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -73,22 +73,22 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, =20 char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); -/* - * The iothread_get_aio_context() and iothread_put_aio_context() are not - * thread-safe and must be called under the Big QEMU Lock (BQL). - */ -AioContext *iothread_get_aio_context(IOThread *iothread); + /* * Normally the IOThread's AioContext is fetched using - * iothread_ref_and_get_aio_context(), but there are legacy callers + * iothread_get_aio_context(), but there are legacy callers * without a clear ref/unref lifecycle. They cannot unref (e.g. because * they do not have an IOThread pointer), so provide an unsafe way to * fetch the AioContext without holding a reference count. This unsafe * API serves legacy callers - do not use it in new code. */ AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const IOThreadHolder *holder); +/* + * The iothread_get_aio_context() and iothread_put_aio_context() are not + * thread-safe and must be called under the Big QEMU Lock (BQL). + */ +AioContext *iothread_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder); void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 diff --git a/iothread.c b/iothread.c index 157bb4d302..9d278efc45 100644 --- a/iothread.c +++ b/iothread.c @@ -429,13 +429,8 @@ char *iothread_get_id(IOThread *iothread) return g_strdup(object_get_canonical_path_component(OBJECT(iothread))); } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} - -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const IOThreadHolder *holder) +AioContext *iothread_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) { /* Add IOThreadHolder to the list */ iothread_ref(iothread, holder); diff --git a/monitor/monitor.c b/monitor/monitor.c index 688bb85c81..0b75f9f69b 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -749,7 +749,7 @@ static void monitor_complete(UserCreatable *uc, Error *= *errp) .u.qom_object.qom_path =3D path, }; =20 - mon->ctx =3D iothread_ref_and_get_aio_context(mon_iothread, &io_ho= lder); + mon->ctx =3D iothread_get_aio_context(mon_iothread, &io_holder); ctx =3D mon->ctx; } else { ctx =3D qemu_get_aio_context(); diff --git a/net/colo-compare.c b/net/colo-compare.c index a7bbb1056d..6cd642d0b7 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -969,7 +969,7 @@ static void colo_compare_iothread(CompareState *s) .u.qom_object.qom_path =3D (char *)path, }; =20 - AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, &io_= holder); + AioContext *ctx =3D iothread_get_aio_context(s->iothread, &io_holder); =20 s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); --=20 2.49.0 From nobody Sat Jul 25 15:51:59 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=1784213278; cv=none; d=zohomail.com; s=zohoarc; b=Q9fgZS/aAX1coGIgfP88RP8wI9Km4UA5o9xMPdlCl0inaZwVMha/VJu075bRS1hWxUk6gu2vYPH4d8foEK90mKdpQJXmbHQCwHVrIV4dqxNZzORyDSU8f36NyHylvm58tpR5NIIJADTTPGGhgJ+/4K4SH+tQksVX1YV8wtWkC2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784213278; 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=pjpcTIVOjjU2T3U84XrTlI69hFe/P5txjri+hVbKO1s=; b=C7cqUZ07G0HX758R2vBrtPBUev3HNcU9oN7ifMDuUBY+BCNA8RdrWlXrUVUebPs8QIL9tGg5POjEhjY6RScljrkDzCetBXcnoPXeNF9bcSMWVEXoqVEGXraqp6Mt4Tco4vO/KyNIsPfuKCGvGEg5ZpS/gPjNbG/2neRLQ9aGVGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784213278476365.26448526436104; Thu, 16 Jul 2026 07:47:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNKF-0000TI-AG; Thu, 16 Jul 2026 10:44:35 -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 1wkNIO-0006Vn-3l for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:45 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNIM-0007fG-2Z for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:42:39 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2caced6038eso9186875ad.0 for ; Thu, 16 Jul 2026 07:42:37 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.42.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212957; x=1784817757; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pjpcTIVOjjU2T3U84XrTlI69hFe/P5txjri+hVbKO1s=; b=A9FHkQV1iOTdkvzjJYYTkdjxOtfYIrfXfeSX5UibOgg5EjLwmtc8oUiZkvahxQBM0u rz0TSDGltiOh1lZuW/zIPBWtn7WqsR2R09cBmn5lTD9G4Zlfa4Hpa3Bfrtd6br9Pwby8 dhFkdW2J/sm0hZ91CPzZbJkWEemkSR5LcQP0yo8ZFaNA9sLo/rVLfnKZa9o+1e918HNB GJx24rWF8QzA8sdpcluZ8BRXJ2mgCzWAa10UMJG1AKrjFkjSTBRfKSEsUWmhuwr7e97G cvKTnix1yp+14PnXThvfCpMxqEvwWqDCqOczb+6vnpbubkoN0c19mCgUHI8BSVF1fyn9 wzNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212957; x=1784817757; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=pjpcTIVOjjU2T3U84XrTlI69hFe/P5txjri+hVbKO1s=; b=ssnNeN2Udu4SbOFvCZ5NIIEVWgxWGCL4qn5qCD+MUNTsr9bG14M+yqY6Fr2lYul/er Xu8tPSAsuuvkX2kVT6p+KGGr9hE4QmvZeqj8pZH5sqP5g+wXJJ5XsBDK22YwDDwF8/0+ Nrb0bMXdSNJYg5QzJO/rP+xPRYwVX0dIwWeXBieXIP1J7WHKwCRRfxFasTL2vnQvktTR nkf968KH5MT0CHVeWHcfQ5tMGYPVP+UR9Eii1dSB7nmhdTG3zDHYWUDqFBJ4REeu1njl VazGM4OnWKse8ppmqG2LAUdlnP2PbrwItl8vhGpRPkxSstCs59XHfbjHqUX2HHJiknL/ PHkQ== X-Gm-Message-State: AOJu0YysZBxvC6V4ZYdFgIt55nHkZzcRzTaJN/HuxBvWhIyLqhkg8qUJ zG6rxPLdhxIbNr3Oy/2MX3atmmuPWD6BPCdN6urwQyzmtU0Nz2dHh+vHNCAwpZEvs9w= X-Gm-Gg: AfdE7ckOZ3+8yUfFT5CQb153UUcBJTgY98qmd168PKvW4YLBeEjmCzu6sLlqchdvPWE zWYeC7A4t5asyJQpJkKLisZwy31T5E+/+v9ixtAS8eNdh18vMnukEpjB9npWMLxeOWXBYCul+59 Ue/45RBjkPCmcECD0QnyBCYS6pMnVr5AcQl6rFqIj4mnYNGFoyzcbIWYzXnJrW1MM5ds7jpaUm0 xcA/4crMPZnd8HTJq7mgjynJe6OoBOmHkqs/NnXCtXdoRNGCsyS5XdQh76s9IZaNI64Xk9gW/dm ZIhp1BW7eaYZrXvq0dBaCCh7pKiUFjTqGYVuHbS6kjsRDIEDQ5FbkeSOK9S8VCjx0b1FweI+QQ+ Ny2wIImBPviHOx0/1+cQ3GNFdDIO7dCEaDSSRAyBmIFShrDDgbe8vSbxJPGoYgL54UZnpTYMXYs Cqr12KFVmzD6OaHR/STbEf8cCYHj4JBR6jN5WwrBwN X-Received: by 2002:a17:903:1a0c:b0:2c9:ece2:822b with SMTP id d9443c01a7336-2cf1f280732mr27583385ad.3.1784212956750; Thu, 16 Jul 2026 07:42:36 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 15/15] tests/unit/iothread: Update the iothread_get_aio_context Date: Thu, 16 Jul 2026 22:40:40 +0800 Message-ID: <20260716144043.76414-16-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784213279220158500 Content-Type: text/plain; charset="utf-8" Update the iothread_get_aio_context and the iothread_put_aio_context for tests. Signed-off-by: Zhang Chen --- tests/unit/iothread.c | 16 ++++++++++------ tests/unit/iothread.h | 6 +++++- tests/unit/test-aio-multithread.c | 5 ++++- tests/unit/test-bdrv-drain.c | 18 +++++++++++++----- tests/unit/test-block-iothread.c | 21 ++++++++++++++------- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/tests/unit/iothread.c b/tests/unit/iothread.c index a363bf8f70..6cac850035 100644 --- a/tests/unit/iothread.c +++ b/tests/unit/iothread.c @@ -30,12 +30,21 @@ struct IOThread { bool stopping; }; =20 +AioContext *iothread_get_aio_context(IOThread *iothread, IOThreadHolder *h= older) +{ + return iothread->ctx; +} + +void iothread_put_aio_context(IOThread *iothread, IOThreadHolder *holder) +{ +} + static void iothread_init_gcontext(IOThread *iothread) { GSource *source; =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_attach(source, iothread->worker_context); g_source_unref(source); iothread->main_loop =3D g_main_loop_new(iothread->worker_context, TRUE= ); @@ -113,8 +122,3 @@ IOThread *iothread_new(void) qemu_mutex_unlock(&iothread->init_done_lock); return iothread; } - -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} diff --git a/tests/unit/iothread.h b/tests/unit/iothread.h index eb4d0c77f8..42992c171d 100644 --- a/tests/unit/iothread.h +++ b/tests/unit/iothread.h @@ -17,9 +17,13 @@ #include "qemu/thread.h" =20 typedef struct IOThread IOThread; +typedef struct IOThreadHolder IOThreadHolder; + +AioContext *iothread_get_aio_context(IOThread *iothread, + IOThreadHolder *holder); +void iothread_put_aio_context(IOThread *iothread, IOThreadHolder *holder); =20 IOThread *iothread_new(void); void iothread_join(IOThread *iothread); -AioContext *iothread_get_aio_context(IOThread *iothread); =20 #endif diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multit= hread.c index 9179cdc6a3..92fa210ddc 100644 --- a/tests/unit/test-aio-multithread.c +++ b/tests/unit/test-aio-multithread.c @@ -69,7 +69,7 @@ static void create_aio_contexts(void) =20 for (i =3D 0; i < NUM_CONTEXTS; i++) { threads[i] =3D iothread_new(); - ctx[i] =3D iothread_get_aio_context(threads[i]); + ctx[i] =3D iothread_get_aio_context(threads[i], NULL); } =20 qemu_event_init(&done_event, false); @@ -87,6 +87,9 @@ static void join_aio_contexts(void) for (i =3D 0; i < NUM_CONTEXTS; i++) { aio_context_ref(ctx[i]); } + for (i =3D 0; i < NUM_CONTEXTS; i++) { + iothread_put_aio_context(threads[i], NULL); + } for (i =3D 0; i < NUM_CONTEXTS; i++) { iothread_join(threads[i]); } diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 43b0ba8648..05e52e89ac 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -537,8 +537,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_get_aio_context(b, NULL); =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 @@ -612,6 +612,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 bdrv_unref(bs); blk_unref(blk); + iothread_put_aio_context(a, NULL); + iothread_put_aio_context(b, NULL); =20 out: iothread_join(a); @@ -762,7 +764,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, AioContext *ctx; =20 iothread =3D iothread_new(); - ctx =3D iothread_get_aio_context(iothread); + ctx =3D iothread_get_aio_context(iothread, NULL); blk_set_aio_context(blk_src, ctx, &error_abort); } =20 @@ -892,6 +894,10 @@ static void test_blockjob_common_drain_node(enum drain= _type drain_type, bdrv_unref(src_overlay); bdrv_unref(target); =20 + if (use_iothread) { + iothread_put_aio_context(iothread, NULL); + } + if (iothread) { iothread_join(iothread); } @@ -1398,8 +1404,8 @@ static void test_set_aio_context(void) BlockDriverState *bs; IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_get_aio_context(b, NULL); =20 bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, &error_abort); @@ -1410,6 +1416,8 @@ static void test_set_aio_context(void) bdrv_try_change_aio_context(bs, qemu_get_aio_context(), NULL, &error_a= bort); =20 bdrv_unref(bs); + iothread_put_aio_context(a, NULL); + iothread_put_aio_context(b, NULL); iothread_join(a); iothread_join(b); } diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 5273ff235a..8b7ac6f980 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -466,7 +466,7 @@ static void test_sync_op(const void *opaque) { const SyncOpTest *t =3D opaque; IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; BdrvChild *c; @@ -493,6 +493,7 @@ static void test_sync_op(const void *opaque) =20 bdrv_unref(bs); blk_unref(blk); + iothread_put_aio_context(iothread, NULL); } =20 typedef struct TestBlockJob { @@ -549,7 +550,7 @@ BlockJobDriver test_job_driver =3D { static void test_attach_blockjob(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; TestBlockJob *tjob; @@ -595,6 +596,7 @@ static void test_attach_blockjob(void) =20 bdrv_unref(bs); blk_unref(blk); + iothread_put_aio_context(iothread, NULL); } =20 /* @@ -612,7 +614,7 @@ static void test_attach_blockjob(void) static void test_propagate_basic(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_verify; @@ -658,6 +660,7 @@ static void test_propagate_basic(void) bdrv_unref(bs_b); bdrv_unref(bs_a); blk_unref(blk); + iothread_put_aio_context(iothread, NULL); } =20 /* @@ -676,7 +679,7 @@ static void test_propagate_basic(void) static void test_propagate_diamond(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify; @@ -736,12 +739,13 @@ static void test_propagate_diamond(void) bdrv_unref(bs_c); bdrv_unref(bs_b); bdrv_unref(bs_a); + iothread_put_aio_context(iothread, NULL); } =20 static void test_propagate_mirror(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockDriverState *src, *target, *filter; BlockBackend *blk; @@ -807,12 +811,13 @@ static void test_propagate_mirror(void) blk_unref(blk); bdrv_unref(src); bdrv_unref(target); + iothread_put_aio_context(iothread, NULL); } =20 static void test_attach_second_node(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockBackend *blk; BlockDriverState *bs, *filter; @@ -840,12 +845,13 @@ static void test_attach_second_node(void) bdrv_unref(filter); bdrv_unref(bs); blk_unref(blk); + iothread_put_aio_context(iothread, NULL); } =20 static void test_attach_preserve_blk_ctx(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; =20 @@ -871,6 +877,7 @@ static void test_attach_preserve_blk_ctx(void) blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort); bdrv_unref(bs); blk_unref(blk); + iothread_put_aio_context(iothread, NULL); } =20 int main(int argc, char **argv) --=20 2.49.0