From nobody Sun Jul 26 12:38:42 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=1782284969; cv=none; d=zohomail.com; s=zohoarc; b=JiM/z7Cjj/rnpaQHY7soWuvqdQ65wRaDhJ4RZ0Rv6LUiRTD/r/go2r2g1iGEQMs4v85ec//5O250SeGoj78unBFHBfDALNaxLMkki2/QRm1lFdLNU5AS/3gXiwkypcftfre20teuXtOlhNgRaPjDlWJGRes7GNYFw9h6pb0Zm5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782284969; 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=CwLX4d/lTsNvWZmmE8NS5t6jz4zcfdov7waHcU99c68Athq1KOY4asTBwzg5M3oNgz5u0MVS5jzzojh00g+txe1efpQu0wrL+lfuOg3IctJQQdjwbAsgayV6KGPcjWv6iADqJopeBJun/eKxX1L9x1ktU7QbCxcsRTIK9+t1hqs= 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 1782284969696564.8091556162744; Wed, 24 Jun 2026 00:09:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHjT-0004yV-PZ; Wed, 24 Jun 2026 03:09:11 -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 1wcHjS-0004yD-Ks for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:10 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjR-0002vH-6z for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:10 -0400 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-c890110acdaso258274a12.3 for ; Wed, 24 Jun 2026 00:09:08 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284948; x=1782889748; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iQp4e741RWeqANR+AnBnweSrNx7Xk2H8EAfqd4DwHpY=; b=lDeBgAVYcMJQbxB6KeRTc1A1djl7faE67Y3C13PtBbv2ma9ScdDwrwDZy4JTEOkSbp 1LQLNj8poNYDdKj/6HILzoTXP1opx2RhT9I5lgTUuT9wXzCYntCGWh/LDNPKugMk+Fpq 2uM5soMRIfHDckGJYXXZRMwmxJUT4wtoOg0VAH+7jVAEYGeW3x8ww7dgh7I32laMdrpA JtZw/nwiG4Tk6zb28dYhRsLiClkVJcxmFsSTmwqTYcBv/weFIONitgiStktlvg8G6+GB r/qvaF6EN5bzArUhhvQ9tUzQD9tuAUe2Sq3/DPT95d1iacrmGiUeVFYihzZQ0enzkySs 4DxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284948; x=1782889748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iQp4e741RWeqANR+AnBnweSrNx7Xk2H8EAfqd4DwHpY=; b=KhR64Uj6FE0hPK0OIcQySR4nntVEwIT3fdFWStgyEZNaPI6kFkPT9V7ifQMACoAb/+ KGWo+N2mIeToULld/D3HSM/cSft6BDLztSfjYA6HIAqEF/7eS8lR35B490p88sTkL98Z AGB31CJgErYAkXpgQ7Zta1EqXNtZCOZWKl5S8st5tw+cIafX1/5pik8aZ5Fq0OB7lU+h f5Gc8A76MV0uBfwogz01QimpXMmwNuVHbaa5Uf5X2+/6Y0qpRwAx0K1vJ0R3UOBB68G/ vHzl5glOfYZSgdR8OLV4Ka4/zfz6qANLxHwO8ZxM9Y06iiyhCKiU2rvNZys9JhwdpLmk WH2Q== X-Gm-Message-State: AOJu0YztVl4Tdmfmzwfilp1DJtYHmXA7WTMF0LmBfOrlvlTopv4UMRpw hvtIW/8CikmXVjwih1QuskYdpZjjpbipODD7XLPdG0Or7/cBQqPweyp/voNW+Z0TNDw= X-Gm-Gg: AfdE7cn/ro5snsS1Wx+CzIGqONaw62ek0H5fXz7uyK7QTsyMxLx+Ufdx7od6bpKbwrB q0+7fYXY7+ieKvXRiwNirXLVliEsTHetpkBv7gor8UezCiyndC+xdLmSajHes0sIFoLrO9lDCgQ ZSu6++ex17xXqL+XSzfXV88R3e2Ndyc6iZk6q4BlyRf/wddppQWnTSTlrVTZMWy+tbjTjw57N7G oZE/tpsntzIXhBAKaV4HfFb0MSme662pigN7BrtFhN+wiCHn7l8A3m3im92cv+E8wylGmhwYpZF cmMz1cLz3bH2qkE1Z7A1rswkp3yeRWsJyVJMEJXOfNsJNZ+zSe3Bwx47bbqDezUdlxLeZO8CEp5 ni40+rSGIBDzfEuZm6YxYOJtXPdqzZjUYQGjApyF2yIePh80kiCmHhDuQtViM3RAW+03dkwBiVK 1YRWEQJpmRrZRflxSkITYAgobG4eCOatwU+i1zhZmTagKFn7dPQbed X-Received: by 2002:a05:6300:83:b0:39b:89e0:2e37 with SMTP id adf61e73a8af0-3bc51b6c387mr18632164637.14.1782284947662; Wed, 24 Jun 2026 00:09:07 -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 Cc: Zhang Chen , qemu-stable@nongnu.org Subject: [PATCH V9 01/17] qapi/misc: Fix missed query-iothreads items Date: Wed, 24 Jun 2026 15:08:35 +0800 Message-ID: <20260624070851.13342-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-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::533; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x533.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: 1782284970326158500 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 Sun Jul 26 12:38:42 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=1782285227; cv=none; d=zohomail.com; s=zohoarc; b=T3WhMYSzOYaAGAYRf9jU8vgO6JF1Zq+x7vFRbdnPQhdPLfW1ZIyP9Z2WQ0n5Ud2LRw/5L0BIGmFzCcO1wvUzAQdtnANg1BSQdTsQcBjDFh+fMea2T3FY8Ik0oItsywFXfpxzRgJ9MCkIvXOXbgz7Zbx0MAZPQ4GogGduE6rFdcI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285227; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H9zFq1iyzk05zoEMX2h9nWXYnORUY596qmXYMUCTaFo=; b=YdO8k9fv+SQrLEWj3q05smK6OsHXLwG5OlLIGweAhKhFjKsTbrnQg4rW1BMNBK9NjTPmltwoXFphGjPkjaYUWVrgzJ701yUb6ip85tCWzxfj/yfBlByKJ5YZRavYU5lWw3mgj18JjAAj2YU15oEmITZs7y4aDdzoLcJj10joCAk= 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 1782285227070476.9157723332888; Wed, 24 Jun 2026 00:13:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHjZ-0004zO-Al; Wed, 24 Jun 2026 03:09:17 -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 1wcHjX-0004z2-E3 for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:15 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjV-0002wI-3R for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:15 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-c89370405aaso261487a12.0 for ; Wed, 24 Jun 2026 00:09:12 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284951; x=1782889751; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H9zFq1iyzk05zoEMX2h9nWXYnORUY596qmXYMUCTaFo=; b=mPJW1IFlVE2Skr3f1hN4mmiO3kvfpEvqbmXECp99di/0I6D3LS19R0ky64FgzZ+ODO nnFKUZtX4HGZwn1fL0nh2b0oM6f9ibDtiG4pgK+u7xxoLjT9JJUfgA5I+30lO3o2pzJt Ll8W+oI9C6M5fbCDwWGbZMxmPVf2Q8B5nc4pgoPQVwd79deQCnV722bu7n243TY9JjUD 21bgOmYBMf46OLwXOqDpyAMCGGPsYBMVpE/0TDNNrFZ/bPz/T/ue+XczlFB9/5MFdYLG 1nbyBbRWQLfBm6RKAKLLj83VxDIHAAyIEri+g+BP1thQVHaUYFFXqqSadXYgRBkeECTr oy6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284951; x=1782889751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=H9zFq1iyzk05zoEMX2h9nWXYnORUY596qmXYMUCTaFo=; b=bxSQ1BwmmAaadCQ66+PyB4KlA0BoSVV4JtlW9B+dlwN3GhMIs+ylRES9PAo3WaW8ss bt155jPtZUCh0deQTD5QPtAv6/UMtCSP4QA4+s3isuUWhA0GSGVQj1W0knyPuEuRD6Nl eEwGarSldThckQK2J0upWck94IQTOoq5Qb5Wkc6+6uLACknJi7wmKk6S0bbCpILYyrDo KQ8t9kRIr6bUQwMH/AFNTfU62nQ0NGRnsOzil5MLLYFrCAE82Tt49bxBQ+QMTlM7wgur T2OM7IrHAZtjZN1oBT0yRS0DwqjfOfAXyZpJog6MCj/LZLiok7RcwZPgubzKgMmRB04h V1Vg== X-Gm-Message-State: AOJu0YzdhnPI9fkQZ2OlX7XqebfKUWrR2w+7oMI+V42nnRE38ePxXNlG f1vpZL8gC0QOvsseZotIsXUdVuAMhrqY6NLPmliZyBTxBys7DyontzKLc/nVJ74nc4E= X-Gm-Gg: AfdE7ckoFOzW/zIY4O3KmluzqUlL/rqKKOEFB1HjAdbsk3zaTKNpVBw6GNXGHT/mwIU IYPVOgocUnXCFtsWnJHvsyHWMH9sFBDO6ZWSuS6VDPj7WVHI5s9+FOsq1kxI6EL26NV0ul4FoTJ FbU2FMHn6J/NJZSBKJImDxG/0x9WW+STe6wJJJ3Kt5jiym3mKaCGh1vhikujlVthEvtFM5/5QpP pF3cXxFvaUVhcqFPTW8L+dOcJ3fKSZK8iYvV6Cc94DW5/S1DRZkN7k4gOSLw4fst4h/Fr3/SG1y H4uIUOaBjdMqZ9jqF/tOzTd+8u/TG+MteV+GxaSEjeKTpghY0Is4lCkIH6EvTdl63IkBI8o0kRc f/NkHq0XpUtSvf0O0d9ks2Q0Onmx7cXnKcS7EDUF6c7aiG8Ws4ZzJWQrc8dgjcpHruFhe3SGiEp YB0FKepHE7uAVxpY39WLWCR+yglu4XJx7V6pLdJnArGGlxVFAUXIUo X-Received: by 2002:a05:6a21:648c:b0:3b3:1c7b:ff9 with SMTP id adf61e73a8af0-3bd152914a0mr8102967637.46.1782284951377; Wed, 24 Jun 2026 00:09:11 -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 Cc: Zhang Chen Subject: [PATCH V9 02/17] iothread: introduce iothread_ref/unref to track attached devices Date: Wed, 24 Jun 2026 15:08:36 +0800 Message-ID: <20260624070851.13342-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-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::52f; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52f.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: 1782285227790158500 Content-Type: text/plain; charset="utf-8" Currently, IOThreads do not maintain a record of which devices are associated with them. This makes it difficult to monitor the workload distribution of IOThreads, especially in complex hotplug scenarios involving multiple virtio-blk or virtio-scsi devices. This patch introduces a reference counting and tracking mechanism within the IOThread object: - iothread_ref(): Prepends the device's IOThreadHolder to a list. - iothread_unref(): Searches for the IOThreadHolder using a custom string comparison (g_strcmp0), releases the associated memory upon a successful match. - holders: A GList storing the IOThreadHolder of attached devices for runtime introspection. A later commit will add QMP commands to let management applications query the attachment status of IOThreads. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- include/system/iothread.h | 5 +++ iothread.c | 94 +++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 61 +++++++++++++++++++++++++ 3 files changed, 160 insertions(+) diff --git a/include/system/iothread.h b/include/system/iothread.h index a1ef7696cb..b9207ad829 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -50,6 +50,11 @@ struct IOThread { bool stopping; /* has iothread_stop() been called? */ bool running; /* should iothread_run() continue? */ int thread_id; + /* + * The list elements are of type IOThreadHolder, which can + * represent either a QOM path or a block node name. + */ + GList *holders; =20 /* AioContext poll parameters */ int64_t poll_max_ns; diff --git a/iothread.c b/iothread.c index 3558535b40..3301b8d495 100644 --- a/iothread.c +++ b/iothread.c @@ -25,6 +25,92 @@ #include "qemu/rcu.h" #include "qemu/main-loop.h" =20 +/* + * iothread_ref: + * @iothread: the iothread to track + * @holder: the IOThreadHolder object initialized by the caller + * + * Add the @holder to the iothread's tracking list. + */ +static void iothread_ref(IOThread *iothread, const IOThreadHolder *holder) +{ + assert(holder); + IOThreadHolder *h =3D g_new0(IOThreadHolder, 1); + + h->type =3D holder->type; + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + h->u.qom_object.qom_path =3D g_strdup(holder->u.qom_object.qom_pat= h); + break; + case IO_THREAD_HOLDER_KIND_BLOCK_NODE: + h->u.block_node.node_name =3D + g_strdup(holder->u.block_node.node_name); + break; + case IO_THREAD_HOLDER_KIND_MONITOR_NAME: + h->u.monitor_name.monitor_name =3D + g_strdup(holder->u.monitor_name.monitor_name); + break; + default: + g_assert_not_reached(); + } + + iothread->holders =3D g_list_prepend(iothread->holders, h); +} + +static int iothread_holder_compare(gconstpointer a, gconstpointer b) +{ + const IOThreadHolder *holder_a =3D a; + const IOThreadHolder *holder_b =3D b; + const char *name_a, *name_b; + + if (holder_a->type !=3D holder_b->type) { + return -1; + } + + switch (holder_a->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + name_a =3D holder_a->u.qom_object.qom_path; + name_b =3D holder_b->u.qom_object.qom_path; + break; + case IO_THREAD_HOLDER_KIND_BLOCK_NODE: + name_a =3D holder_a->u.block_node.node_name; + name_b =3D holder_b->u.block_node.node_name; + break; + case IO_THREAD_HOLDER_KIND_MONITOR_NAME: + name_a =3D holder_a->u.monitor_name.monitor_name; + name_b =3D holder_b->u.monitor_name.monitor_name; + break; + default: + /* + * This should not happen. If it does, name_a/b remains + * NULL and g_strcmp0 will handle it safely. + */ + name_a =3D NULL; + name_b =3D NULL; + } + + return g_strcmp0(name_a, name_b); +} + +/* + * This function removes the @holder from the @iothread's tracking list. + * The @holder must match the one used previously in iothread_ref(). + * It is a programming error to call this with a @holder that is not + * currently associated with the @iothread. + */ +static void iothread_unref(IOThread *iothread, const IOThreadHolder *holde= r) +{ + assert(holder); + GList *link =3D g_list_find_custom(iothread->holders, holder, + (GCompareFunc)iothread_holder_compare= ); + + assert(link); + + IOThreadHolder *h =3D (IOThreadHolder *)link->data; + qapi_free_IOThreadHolder(h); + iothread->holders =3D g_list_delete_link(iothread->holders, link); +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -356,6 +442,14 @@ char *iothread_get_id(IOThread *iothread) =20 AioContext *iothread_get_aio_context(IOThread *iothread) { + /* Remove in next patch for build */ + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)"tmp_path", + }; + iothread_ref(iothread, &holder); + iothread_unref(iothread, &holder); + return iothread->ctx; } =20 diff --git a/qapi/misc.json b/qapi/misc.json index c71a5fe657..d9f82f0922 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -67,6 +67,67 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 + +## +# @IOThreadHolderBlockNode: +# +# @node-name: A block node. +# +# Since: 11.1 +# +## +{ 'struct': 'IOThreadHolderBlockNode', + 'data': { 'node-name': 'str' } } + +## +# @IOThreadHolderQomObject: +# +# @qom-path: A QOM Object. +# +# Since: 11.1 +# +## +{ 'struct': 'IOThreadHolderQomObject', + 'data': { 'qom-path': 'str' } } + +## +# @IOThreadHolderMonitor: +# +# @monitor-name: A HMP/QMP monitor. +# +# Since: 11.1 +# +## +{ 'struct': 'IOThreadHolderMonitor', + 'data': { 'monitor-name': 'str' } } + +## +# @IOThreadHolderKind: +# +# @block-node: A block node. +# @qom-object: A QOM Object. +# @monitor-name: A HMP/QMP monitor. +# +# Since: 11.1 +## +{ 'enum': 'IOThreadHolderKind', + 'data': [ 'block-node', 'qom-object', 'monitor-name' ] } + +## +# @IOThreadHolder: +# +# @type: the kind of I/O thread holder. +# +# Since: 11.1 +## +{ 'union': 'IOThreadHolder', + 'base': { 'type': 'IOThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-node': 'IOThreadHolderBlockNode', + 'qom-object': 'IOThreadHolderQomObject', + 'monitor-name': 'IOThreadHolderMonitor' } } + ## # @IOThreadInfo: # --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285004; cv=none; d=zohomail.com; s=zohoarc; b=TeBfDD0YLag4IvyQ/TrkFdWf+wFrFCxZMSUKL1pS6V10HM7Mzs37U0/0K0y1PlSeiedQNkXak4WdI2Fz1FEHdUUyQ7zIJ7l44TmwLVvj58Y2lmt7waYNCZZKF1I4R0o0Mvi1RZwUVNElThzkAG2GLT+9VuTAKISWRdbbZAkHE9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285004; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lSVN7N0tEjZKy75a4H0lIBwRWq1dCfq0ezm3QlZHeNQ=; b=EBNX8T9uS2CQCOUcc3wFT/Wji6LRO5ox6nQv5kFbvzHwnPeMwP1eaJKkb+m3e9vyq7NevygvvLPqwDZeIyHtm2AOWJ+6PB8DFmZPjaEGxY97+1HQx8Nydhm5Z9iYLtI3+JUDqocqoGbavZOPFMuBLSE920/XiWdEZTFWm4yELZM= 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 1782285004260999.2534736155712; Wed, 24 Jun 2026 00:10:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHjc-00051Y-Rs; Wed, 24 Jun 2026 03:09:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHja-0004zg-FT for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:18 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjY-00033L-SD for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:18 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-c85822059d8so433210a12.1 for ; Wed, 24 Jun 2026 00:09:16 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284955; x=1782889755; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lSVN7N0tEjZKy75a4H0lIBwRWq1dCfq0ezm3QlZHeNQ=; b=c41jMqpKgaAgWO59aT8PwPzrNWBdew5KhdZF1jd49FADywD/nWeYjX84vhbuuIsjxJ 2Xp/wRquJ1oMlE20S2jY7qKE8OFrzCNPisu2ZH0K5piNupwsoOlUyOYUkvlgpneV88X4 Ziqh/evoD8ATSoqBRMwTeZ/2zSscyklvdp41PqxbTp+KM1yIMLM5MVXy8aB7s7lGrqOU mtl9LT2n7du8piUfLg88jPyJOHejai6V23Fi6PgA16+0KULtMEa3zgFba0hji9cDrHHe p+Pax5ly6yLfklrrZ14DkMlXl1z8SVB8wFuGFSI5iphjB9fjUNnXXJenweO9H20gn+Vx gqaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284955; x=1782889755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lSVN7N0tEjZKy75a4H0lIBwRWq1dCfq0ezm3QlZHeNQ=; b=Iksw8JE0srE863Ag/hNLe6hGy+n8v6I5W5FvVM37E0ltlDM3q9kDpmvBgGQptWF26u 3tvBz7NuWYTntM8FrH6DCJHCPocpv5i9daLlAErs7pCAKi5eER+BSie2kDrCKXPVzCUO xkW6SIVJZfVW8NcRxhwHZ/sxQ7Ye5rAAao3PHzbSJgP/8ngfr9oNYWEt+MFd/TBJohSp MhA47zJkyTEPRbpn7rGdPetLrjPCF3Jl+cypq/VMR2PxGpnmnVQ8uL/2irsCTLSqFFDx 9/tfgHLoZeozKrx7bfb3JRPaPXwhfJtJLwls6mNHOCuE7SPlvTyoM4nJ7Sw7OF0+tUpw Ypww== X-Gm-Message-State: AOJu0Yy9b/PaUKDwGDa99q6yNhPUHRIuoPHH8SVfo+dhELtUcC7XKmd5 6bkIeaK1G28JNGWzlbgKoYb6xF+8X3BlrQq8/621GOtAg+M/s0ociKhRfqnz9vTREes= X-Gm-Gg: AfdE7ckgPFZwvfXcKxcZA9Xke99A33MHRsaLMRvuK/YAl22+YCpF/+x6P1nu/KMIfbB EO7e9f6gZ/CZ3qgm3UgZ1x4fy4WKXlL0+gpV4U4dfSz4erv3nnkZC2WRceG03LCg5JIskUfnYJK hCAU2MiG0lgOpkr2jhaM0Sr8Tuc+jjolUpMH4Pv0zlYbJgCWaocBEZhHpfJkwsPHsN8S3t0OFRt RAW7gt4dkCAN/p9+TtC4Z2xCwHU6y1Gad+a+SV3laQFhO1e1wKBBzOfKwF45TAgs21nL9fUY/R+ XfgB2r/Yzb0R3KdRqG9fqMPnIK7KM0toCf4sbf6SKKmng33qlKRwN9AgMMbibNpDjggCSzmGS1h JIi9XGWrZRyxSkJD90M4avdvF9dG65yyfOI1IB9q7sbXRI6k+B3zoPMFSlmTjdBW6L6G5KJqSpI BcOH+N36OHa/usbKYKaLb9NZTiGuR9NU+XAymun5RJ4YpX8Z9r7jhb X-Received: by 2002:a05:6a21:3403:b0:3b4:93b9:2b91 with SMTP id adf61e73a8af0-3bd2d06a58fmr2620736637.12.1782284955331; Wed, 24 Jun 2026 00:09:15 -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 Cc: Zhang Chen Subject: [PATCH V9 03/17] iothread: tracking iothread users with holder name Date: Wed, 24 Jun 2026 15:08:37 +0800 Message-ID: <20260624070851.13342-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782285006227158500 Content-Type: text/plain; charset="utf-8" Introduce iothread_get_aio_context() (In this patch named "iothread_ref_and_get_aio_context" for build, will change the name in the last patch) with a 'holder' argument and its counterpart iothread_put_aio_context(). Previously, users of an IOThread's AioContext did not explicitly record their identity, making it difficult to debug which devices or subsystems were pinning an IOThread. This patch enhances the reference counting mechanism by: 1. Automatically incrementing the object reference count when a context is retrieved. 2. Tracking holders using iothread_ref() and iothread_unref(). In iothread_instance_finalize(), we now retrieve the source name from the GMainContext to correctly unref the initial internal holder. Signed-off-by: Zhang Chen --- include/system/iothread.h | 4 ++++ iothread.c | 31 +++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index b9207ad829..b483bbfab3 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -18,6 +18,7 @@ #include "qemu/thread.h" #include "qom/object.h" #include "system/event-loop-base.h" +#include "qapi/qapi-types-misc.h" =20 #define TYPE_IOTHREAD "iothread" =20 @@ -70,6 +71,9 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); AioContext *iothread_get_aio_context(IOThread *iothread); +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder); +void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 /* diff --git a/iothread.c b/iothread.c index 3301b8d495..528002c34a 100644 --- a/iothread.c +++ b/iothread.c @@ -55,6 +55,12 @@ static void iothread_ref(IOThread *iothread, const IOThr= eadHolder *holder) } =20 iothread->holders =3D g_list_prepend(iothread->holders, h); + + /* + * This guarantees that the IOThread and its AioContext remain alive + * as long as there is a holder. + */ + object_ref(OBJECT(iothread)); } =20 static int iothread_holder_compare(gconstpointer a, gconstpointer b) @@ -109,6 +115,8 @@ static void iothread_unref(IOThread *iothread, const IO= ThreadHolder *holder) IOThreadHolder *h =3D (IOThreadHolder *)link->data; qapi_free_IOThreadHolder(h); iothread->holders =3D g_list_delete_link(iothread->holders, link); + + object_unref(OBJECT(iothread)); } =20 static void *iothread_run(void *opaque) @@ -223,7 +231,7 @@ static void iothread_init_gcontext(IOThread *iothread, = const char *thread_name) g_autofree char *name =3D g_strdup_printf("%s aio-context", thread_nam= e); =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_set_name(source, name); g_source_attach(source, iothread->worker_context); g_source_unref(source); @@ -442,17 +450,24 @@ char *iothread_get_id(IOThread *iothread) =20 AioContext *iothread_get_aio_context(IOThread *iothread) { - /* Remove in next patch for build */ - IOThreadHolder holder =3D { - .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, - .u.qom_object.qom_path =3D (char *)"tmp_path", - }; - iothread_ref(iothread, &holder); - iothread_unref(iothread, &holder); + return iothread->ctx; +} + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Add IOThreadHolder to the list */ + iothread_ref(iothread, holder); =20 return iothread->ctx; } =20 +void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder) +{ + /* Delete IOThreadHolder from the list */ + iothread_unref(iothread, holder); +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782284986; cv=none; d=zohomail.com; s=zohoarc; b=lwNE0VkYaXQuLjgEEBVCaJPqzYt5K5pxMeDnutcCP8I6hTV04jK04ajRatr5ffeygucVbkupmRnfLX9chrHEPRdlDo7BRkInwy6MxFIEMsj6rz61z9DjRzph9O3xMylmIjn0QiiJtOVjkHW2i86Qr88VWAQJfMaYgEGeEjJLqbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782284986; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tDeHKlljfDpSkFWWN2SnpQW0cIV42Ft5R4hhaWwRewI=; b=MeOEIjUW4b1VUbCt1VReTbjKhHga2t6GnUYvJhxO6NUqfbMgzOj4VxP2tRkd6vW7v2o9LcZw052Kd7v++3XYk6YWkW3qyf2MmraVUkOMLDiN87+Gc61h+kIPaTuAowfSF770nA5Kt1GNAaXB6Rla5KV7Z7p4l0W4EKU16jTmXm4= 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 1782284986864581.8022450780593; Wed, 24 Jun 2026 00:09:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHjo-00053g-6S; Wed, 24 Jun 2026 03:09: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 1wcHjd-00052d-Sj for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:22 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjc-000343-Bc for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:21 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-c890110acdaso258357a12.3 for ; Wed, 24 Jun 2026 00:09:20 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284959; x=1782889759; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tDeHKlljfDpSkFWWN2SnpQW0cIV42Ft5R4hhaWwRewI=; b=j53VQsh3DKsy0WUlHibx8r8PwKOUwMPcHAQhjUbaMHtoDnPQfwRDJhj3V5kmWd0n+3 dupiyO7ie4dvivfonHhjIvOF7KENL4t3z/Kzsl6EFBRrlaDI2UO1MfUwZ+o4ossiQcrn fHTpannKZa5DGKOvwz+ZIVywuEXmI10YIC0atRh6qaAqvOAO9ZbRMY6aTg6JyyG7awQk xwp0YxbxTJL4raPqqNfbgLC5HMNFKLOHYm+ydOEG1AJm460+6G1Nj4m/YulhPXvQD62a mW6vO7GmGRJAPfChmdyPdkdiEo9sGEIybsTVqhLRRZ77iLh7EPpsG57TOq5jTbn0Je0U 4mRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284959; x=1782889759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tDeHKlljfDpSkFWWN2SnpQW0cIV42Ft5R4hhaWwRewI=; b=pXgFYkeFIPWA5Dxoj2KJSHd1pZ/elzmAqRijXjyeF20e8th6LGqhRAvLcRfVcH5ib9 eZAv+TTPwK1tIzamLjQQsS/2GPncz+WrrlsmFwnI96Ve6yZxRItDvaa8usbIVMkTHijn ScOcga75ThLxo5aeO60wDvpYFJFY5QDSL2R7Wnns9MNLRztTp3kLjHTt0Izex7viLhKe mrnl6izm2SfwTA04H1I4c5pcfMHXi8IrYzHCquM4pEzJUlF4qjpqKS77kvOgwsVS/7RG ti77kIH9LZLIFxZ24G/W4lydE5DDffqpc2kugWm2SFLX3ldYRg8nF35hL4UV3Xw15CZc 0Tng== X-Gm-Message-State: AOJu0YzY656PQTbLu2dHUkOoZ4c8q7eOpe7yaoM2MFzR8dKExqORw9KI hW2w6UAjfrN6tuVF9cEH8Q223PNSwbDbYzA4HSILqJw2+I8lyms1nNtKcsFlmOWNHdA= X-Gm-Gg: AfdE7ck+2T6LLPuGdLXzDy6nKqVomCxEwLlZ1jqtlZwv1SL94okrNmd+H9QvmHjzDrw uigngBGik0tGIh3g+FA2H/9sv6TkxGdKtGj00zbYZPpnXf9RxPwLp+j1lrkUmJ8H/Szm5+4AWDp OHYn+gkW6xnm7Du6h+NOV7xR4PA5lYl+iU1xrNZXuy5/WfAQp5nB4Wf9rn6JjnzATiqZrVAQdMD c/bUFadp45YwWQdvu0TAzynpqX2yaDo9RmS7cMq8It8f4bDIpjTBt/Whcq9x74FDGYfnt5NFx3W yXGnDMxOk2VhE0FmQWcW6sE4kXLErC56SUcDsli37cbfJa4Y/ZDzRYWg4vXNihQgzT0o02xAOji dKaL3Qg2dPyLAU86/t5yYUMvKBJ6VDVWefBpvscBjL4JJiCybqyqxx3m7a3PGpYlZ3lQgmgjup9 dRRgxCtJLrYm0YlrT3un7tPIdhFwPfee89EEfqAaOAKR7CT7K1c2Jf X-Received: by 2002:a05:6a21:117:b0:3b7:8e6b:7001 with SMTP id adf61e73a8af0-3bc51b6d080mr21052068637.12.1782284959095; Wed, 24 Jun 2026 00:09:19 -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 Cc: Zhang Chen Subject: [PATCH V9 04/17] iothread: introduce iothread_unsafe_get_aio_context() Date: Wed, 24 Jun 2026 15:08:38 +0800 Message-ID: <20260624070851.13342-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782284988128158500 Content-Type: text/plain; charset="utf-8" The iothread_unsafe_get_aio_context() is a low-level unsafe way of getting the AioContext, recommend migrating to the new API with IOThreadHolder as much as possible. The blockdev is the first user: Every BlockDriverState would need to get/put the IOThread AioContext in bdrv_change_aio_context() or related functions. However, the QEMU block layer has been moving away from having a per-BlockDriverState AioContext. It is possible to use a BlockDriverState from any AioContext (including multiple AioContexts at the same time). I'm in favor of not associating BlockDriverStates with IOThreads and instead relying on their device owners (e.g. emulated storage controllers) to be the IOThread holders. Signed-off-by: Zhang Chen --- blockdev.c | 2 +- include/system/iothread.h | 6 ++++++ iothread.c | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 6e86c6262f..baeab3a3e1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,7 +3683,7 @@ void qmp_x_blockdev_set_iothread(const char *node_nam= e, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_get_aio_context(obj); + new_context =3D iothread_unsafe_get_aio_context(obj); } else { new_context =3D qemu_get_aio_context(); } diff --git a/include/system/iothread.h b/include/system/iothread.h index b483bbfab3..064c05e78d 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -71,6 +71,12 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); AioContext *iothread_get_aio_context(IOThread *iothread); +/* + * The iothread_unsafe_get_aio_context() is a low-level unsafe way of gett= ing + * the AioContext, recommend migrating to the new API with IOThreadHolder + * as much as possible. + */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, const IOThreadHolder *holder); void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); diff --git a/iothread.c b/iothread.c index 528002c34a..a85e960e45 100644 --- a/iothread.c +++ b/iothread.c @@ -468,6 +468,12 @@ void iothread_put_aio_context(IOThread *iothread, cons= t IOThreadHolder *holder) iothread_unref(iothread, holder); } =20 +/* Recommend migrating to the new API with IOThreadHolder as much as possi= ble */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread) +{ + return iothread->ctx; +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782284996; cv=none; d=zohomail.com; s=zohoarc; b=eju7+fEwcOkX/6buBC3GVs+GooO7z1mXR4U3O8jktXXIZuba9awYjs1ffUsJUO6G0krQ8SRriy6p+p7Sxkyko/oN0whWSkwAcuJ94yj8tQ8qySlsfIJ9uLG6rvCOP/gc0uYXX1DZSTGjgaI6G5dzzM5juDWNOg4jza8hKdVmGK4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782284996; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=L2I8RSgxtS6zilF0lFLp60gipvFmJj5Si+EneANHl4s=; b=ZcDSuToDGnrIszdFQtVRiSlNq7qptCujuv8gQ/kSf8cvnItm4nKwXpdWxjpZNtMI/2FRRARj4zaOVSsWZwk+UNCFvBnshF7KhRl+LDn0w9p1ehqFkzEotz3keiP7M4t8K7Ai5VWnoVSPH+FcvkbZLev9InW/53rJ0+tg7OIIQaA= 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 1782284996616421.3180199163319; Wed, 24 Jun 2026 00:09:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHjz-00056E-26; Wed, 24 Jun 2026 03:09:43 -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 1wcHji-00053R-3v for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:26 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjg-00034R-AF for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:25 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-c89fa656ea1so234425a12.2 for ; Wed, 24 Jun 2026 00:09:23 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284963; x=1782889763; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L2I8RSgxtS6zilF0lFLp60gipvFmJj5Si+EneANHl4s=; b=qI8JzDoOi9IpPYr9Bii5TwnTmynVESvSBzsvVwItu21eNocQtvvJJlhS0wgXXBCVOB 0+4KjVAZ7bqg3rav+skPONi4P8fCZbGCoNqGG6pOZ1LTdmA5Sivq3VkhXVktSH14OUao 4aMqfBI/shTVZ6WACQ746MKPuQcrcAYJ+YKadp4eSbPiZW2pz6AmDc85E8/poyaIBI0o xvouUCbFFRdjkWvqJnHGEvzORg2ALzBhfltbY0bfTnG6bwP3iZkDwbfYl3PlPlLY2Ukw tW2vbxFhVtFjhtI2DK6emOHmqBLIBkq/AMggRvRzfF43UTW8t5aFEGHFzXcsVlN7gbMe 3iTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284963; x=1782889763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=L2I8RSgxtS6zilF0lFLp60gipvFmJj5Si+EneANHl4s=; b=JL1NYWCdSwHnNRKnlVkLqLxZIUCCiL4AgYrYZ6xPxf905JQfWcT7coLfpBw+m5e/TC 7VAN1dEazlt7oCVft3Jv714M9hay6tzbzcXY0bLR8DcN+8OB5/wkTcDvgunxQ8uTKjAM hJ1dobrBidLtKGaqB0yO1CdvyCk4L1GARR+nURhyE4g83l0MzYyIGsYtthRqRzMYwPXI nugT44PLl1+LKKwiMZ/ahfVff1uIo5Lr91pkxQWPRK5edb4A2ncfs1weOl8Zbd1OcPky iHK4Fk3kgq+q/C0o5x9vzQkPCpOEXajS6TFTpo7SZKPQ7F+e/yi7cZT3Vju1dqW0CVyU lIRg== X-Gm-Message-State: AOJu0Yx6BacsDWfgw9u4WSCy2/N8YTPM0fpWcRxTBgZS9IrgY31WIv52 UgffVvacMg197VVhJT6Kpblz7516ww+vMQzxoohGlZLhWjX0SiyF564AJcdKvBdRawk= X-Gm-Gg: AfdE7cm1VQG1fhKofQtvsg9coe5qPJmYH6TcZENZ5T0sDbefm6T2MxjI2ipVoQE4CMC GZG5JSBkUnfe+fql2WV7Vm2Kt/k6rZYIs47K74OZMnIE0j3dhImVdnyjmbdx1a9/2JARphYSC29 yKL2VTM1KYfiTRtMQIkNRT/twLFXpaWZ5Q49/8l+9FBqtGeWR4EFLZlwsD3jaKG4W+Ve3fSC6Vi 9DGtSQed/CoP00XHepsjNKaYUMfmZRVw0eEcCngqjp5DC/5NT4oLtpOXlOoI8IsDHur8IdPAQsb qtAZQbEoF2IujjKnseEPBsmEsSn3lw1ksAEWk7yLRIXSvdnMysg6+S+WDVJeyfbXJ7SNdo6UPVn 0ZkqzMDFxvwAW9CTLVkPfdsznWUJuf90YAnsygLS40sldqFBFKY5CO4z4cdThwyVAc30TTUtOGX 8rgH2+ZqJTh9uNZwSUHEuBJdljlxxgwy+TOulUxZySWKBbjerB02ua X-Received: by 2002:a05:6a21:4c06:b0:398:9b42:69f7 with SMTP id adf61e73a8af0-3bc53bf531fmr20143769637.39.1782284962777; Wed, 24 Jun 2026 00:09:22 -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 Cc: Zhang Chen Subject: [PATCH V9 05/17] block/export: track IOThread reference in BlockExport Date: Wed, 24 Jun 2026 15:08:39 +0800 Message-ID: <20260624070851.13342-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782284998519158500 Content-Type: text/plain; charset="utf-8" Users currently lack visibility into which block exports are utilizing specific IOThreads. This patch integrates IOThread referencing into the BlockExport lifecycle. - Add iothreads array and holder_name to BlockExport struct. - Use iothread_ref_and_get_aio_context during export creation. - Implement proper cleanup in blk_exp_add fail path and blk_exp_delete_bh. - Support both single and multi-iothread export configurations. This ensures IOThread 'holders' status correctly reflects active block exports for better debugging and resource tracking. Signed-off-by: Zhang Chen --- block/export/export.c | 63 ++++++++++++++++++++++++++++++++++++------ include/block/export.h | 6 ++++ 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..b6c07f69b5 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,7 +15,6 @@ =20 #include "block/block.h" #include "system/block-backend.h" -#include "system/iothread.h" #include "block/export.h" #include "block/fuse.h" #include "block/nbd.h" @@ -85,6 +84,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Erro= r **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + const char *holder_name =3D NULL; uint64_t perm; int ret; =20 @@ -139,7 +140,16 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + holder_name =3D bdrv_get_node_name(bs); + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE, + .u.block_node.node_name =3D (char *)holder_name, + }; + + new_ctx =3D iothread_ref_and_get_aio_context(iothread, &holder); + multithread_count =3D 1; + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +173,15 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return NULL; } =20 + local_iothreads =3D g_new0(IOThread *, multithread_count); multithread_ctxs =3D g_new(AioContext *, multithread_count); i =3D 0; + holder_name =3D bdrv_get_node_name(bs); + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE, + .u.block_node.node_name =3D (char *)holder_name, + }; + for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,7 +189,9 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) error_setg(errp, "iothread \"%s\" not found", e->value); goto fail; } - multithread_ctxs[i++] =3D iothread_get_aio_context(iothread); + local_iothreads[i] =3D iothread; + multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, + &hold= er); } assert(i =3D=3D multithread_count); } @@ -225,12 +244,15 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D drv, - .refcount =3D 1, - .user_owned =3D true, - .id =3D g_strdup(export->id), - .ctx =3D ctx, - .blk =3D blk, + .drv =3D drv, + .refcount =3D 1, + .user_owned =3D true, + .id =3D g_strdup(export->id), + .ctx =3D ctx, + .blk =3D blk, + .iothreads =3D g_steal_pointer(&local_iothreads), + .iothread_count =3D multithread_count, + .iothread_holder_name =3D g_strdup(holder_name), }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -253,6 +275,18 @@ fail: g_free(exp->id); g_free(exp); } + if (local_iothreads) { + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE, + .u.block_node.node_name =3D (char *)holder_name, + }; + + for (size_t j =3D 0; j < multithread_count; j++) { + if (local_iothreads[j]) { + iothread_put_aio_context(local_iothreads[j], &holder); + } + } + } g_free(multithread_ctxs); return NULL; } @@ -269,6 +303,17 @@ static void blk_exp_delete_bh(void *opaque) BlockExport *exp =3D opaque; =20 assert(exp->refcount =3D=3D 0); + if (exp->iothreads) { + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_NODE, + .u.block_node.node_name =3D (char *)exp->iothread_holder_name, + }; + + for (size_t i =3D 0; i < exp->iothread_count; i++) { + iothread_put_aio_context(exp->iothreads[i], &holder); + } + g_free(exp->iothreads); + } QLIST_REMOVE(exp, next); exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..2bb98aae31 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -16,6 +16,7 @@ =20 #include "qapi/qapi-types-block-export.h" #include "qemu/queue.h" +#include "system/iothread.h" =20 typedef struct BlockExport BlockExport; =20 @@ -89,6 +90,11 @@ struct BlockExport { =20 /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; + + /* The iothreads list for block_exports */ + IOThread **iothreads; + size_t iothread_count; + char *iothread_holder_name; }; =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285067; cv=none; d=zohomail.com; s=zohoarc; b=ZtyjXPTJLhezkHnUbNIgNasYoJ0+9umQA4K8nmqwtik22qp8x76HWcLqfl9l8tgL6xS1clRzCfpPmNZkelBeDbrkbwkNYVg6Op61+p+WVGfSl9XUjYILAKLt/W8dG8jTRpKInS/abHuMWExbsdJeF6Xgl9gaOw+Kr7sOlEMPI6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285067; 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=wF4pvmwVYou3lfdQWayK5t+Io4ErmW/eBy7uJJF0ZfA=; b=VFTQRSsjAJ7d9uNTZd9wgq5GbYpwHkqTrJitvB3sxdP5iVshycyv0xcKqPssf4n99X4hUdPXXxuXU1vxltOfo05+lJ3hFHpbPbhA+6/TMrKk+KkRN0MtmVbIAEtNUz2bIYNI1+FN1+APeVfRZU3Y22fDPnmuUAnp9F/rid37dio= 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 1782285067320712.1861816519573; Wed, 24 Jun 2026 00:11:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHlB-0005og-6n; Wed, 24 Jun 2026 03:10:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHjn-00055Z-0E for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:35 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjk-00034d-FW for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:30 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-c88a4d79ba5so475485a12.2 for ; Wed, 24 Jun 2026 00:09:27 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284966; x=1782889766; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wF4pvmwVYou3lfdQWayK5t+Io4ErmW/eBy7uJJF0ZfA=; b=XZ0yvZ4l+K60V9q/fQW8lKC3GRYGC1DYzH1nNREG3F/Qqka1FmFh8pJH8wtjWHEFM+ g3pPT2rPm/Jocu3XJddrCXk0/D7gesx2s5f6lDUlW+PlDA/Z4fay3WBGoWv02ToEQMos YjWbWm3UwabN9X+jw0gE1bzz4XYRN774gPMr7v7wxfSUXJECm6VKOqJOG6JHhNma8Q/9 gvhJPGLg2fFNAGixqb18pR66duFEzSbTnEZ3WQxdnk4hKWz+RhpcryofmS9Ah3EAlL8r GWjxjdjp1mnw32h2WRO6Ggqnz5kzrXRqPDewrJCe5AX163ACsOTQ27Z0xI7t2PR0tT6J UHWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284966; x=1782889766; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=wF4pvmwVYou3lfdQWayK5t+Io4ErmW/eBy7uJJF0ZfA=; b=eKrQ5ZYWaI8JaJKSqm48/RY7OqSRRoGWu9evRjAPAhGksqHXFq8406++GywsIgtX9R zc0KVFE6obANpqYgrAPm9XEhK5okpaI+A7NHPOod+Pdj1B5Q/NqQCVZT28GriNvdQFAn 3BXKdFtmVUc8b7opsi2QiuK2swEd72JNQBEzX4o+7vAPPt9qKMPGDxXerUoDhrKPDVjM ChY9eHJXzLeq8ChoXNvT7TJS3NpZx0+H31wIKafY05oVjbjGeEsT0ltaDPK34pN7bvpT FRWLBB7HTi0DFUJqkKparruamCrSg0Hgb4VG16yre6bSYv2sHTBwhgOYUg1oZLPnfQYD SeXw== X-Gm-Message-State: AOJu0YzZdARFIAAiJTYl/J182FSrZ0IBkMn1OEaLf/C1ggZzIUgW09Pn uyZ6GzQ7v1zHmuTTKhnTIt4wi4IdwiQTo5ho9btXVzwHQHX7sycYgcMLlVvUesjOhao= X-Gm-Gg: AfdE7clX4JwnWcQ5ELTkzMjZOT5ARCazfb4gLj2GizU1DhO6+vQmIIG71rNcxDdL4uI IT/HoYERMKmlYFQ1mSYzyZktXvJfJJ3oAn8UslsEEkfak2AdcBT/6sdQmKPL9loAcpiKXTAnmTq GLQuFDpZeRAVLNIMRc6rHnRknnjLkwq1RWwqtntl9gQ3LVSGJ7biTWPXl8fbd//pXBHTq3NgZLa e7v3Qhsf31h9+9oo5RXENJnmQctZQPmdD3D1ll42c2idodcxvL6W6PGeh4B7HnbrBSaDvclLp9m rcM4AD8x8jRMIEAUbgu7P5NJ4G1tGws48WaM/IcrH1dUmkkKq7u5CPo1TKsCU0LNhXDRwhr2Fbh iXPG64bPxlZgA0YFTi3f3taH5PVYLM7lcfiK9JOEuX4/Ju5IjLp2JZyfZw48hfRh+0wzYJAvshJ uDhlNhJFO3Oj8Zabhhql9QFXyrOPjXKAilNrq25kFbYBOR4+qjEYeS X-Received: by 2002:a05:6a21:a393:b0:3b4:b2d7:c146 with SMTP id adf61e73a8af0-3bd1513ab06mr8281377637.21.1782284966575; Wed, 24 Jun 2026 00:09:26 -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 Cc: Zhang Chen Subject: [PATCH V9 06/17] monitor: refactor monitor_data_init() to pass ID Date: Wed, 24 Jun 2026 15:08:40 +0800 Message-ID: <20260624070851.13342-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-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::52c; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52c.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: 1782285068826158500 Content-Type: text/plain; charset="utf-8" Anonymous monitors (e.g., '-monitor stdio' or GDB stub) leave their 'id' field as NULL. To allow downstream subsystems (like iothread tracking) to identify these instances later, the initialization paths must propagate the context. Refactor monitor_data_init() to accept the 'id' parameters, and update all internal QMP/HMP paths to pass these identifiers. For anonymous monitors, 'mon->id' remains NULL at this stage to avoid namespace pollution, setting up infrastructure for subsequent patches. Signed-off-by: Zhang Chen --- chardev/char.c | 2 +- gdbstub/system.c | 3 ++- include/monitor/monitor.h | 5 +++-- monitor/hmp.c | 5 +++-- monitor/monitor-internal.h | 4 +++- monitor/monitor.c | 9 ++++++--- monitor/qmp-cmds.c | 2 +- monitor/qmp.c | 5 +++-- stubs/monitor-internal.c | 3 ++- 9 files changed, 24 insertions(+), 14 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index ca8b37ed8d..f057247001 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -805,7 +805,7 @@ static Chardev *qemu_chr_new_from_name(const char *labe= l, const char *filename, =20 if (qemu_opt_get_bool(opts, "mux", 0)) { assert(permit_mux_mon); - monitor_init_hmp(chr, true, &err); + monitor_init_hmp(chr, true, NULL, &err); if (err) { error_report_err(err); object_unparent(OBJECT(chr)); diff --git a/gdbstub/system.c b/gdbstub/system.c index e86c5870ab..50f934fde3 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -388,7 +388,8 @@ bool gdbserver_start(const char *device, Error **errp) /* Initialize a monitor terminal for gdb */ mon_chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_GDB, NULL, NULL, &error_abort); - monitor_init_hmp(mon_chr, false, &error_abort); + + monitor_init_hmp(mon_chr, false, NULL, &error_abort); } else { qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); mon_chr =3D gdbserver_system_state.mon_chr; diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 55649a8664..4a5eb20bea 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -19,8 +19,9 @@ bool monitor_cur_is_qmp(void); =20 void monitor_init_globals(void); void monitor_init_globals_core(void); -void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp); -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp); +void monitor_init_qmp(Chardev *chr, bool pretty, const char *id, Error **e= rrp); +void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id, + Error **errp); int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp); int monitor_init_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); diff --git a/monitor/hmp.c b/monitor/hmp.c index cc4390486e..4ee8cb58d1 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1522,7 +1522,8 @@ static void monitor_readline_flush(void *opaque) monitor_flush(&mon->common); } =20 -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) +void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id, + Error **errp) { MonitorHMP *mon =3D g_new0(MonitorHMP, 1); =20 @@ -1531,7 +1532,7 @@ void monitor_init_hmp(Chardev *chr, bool use_readline= , Error **errp) return; } =20 - monitor_data_init(&mon->common, false, false, false); + monitor_data_init(&mon->common, false, false, false, id); =20 mon->use_readline =3D use_readline; if (mon->use_readline) { diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index a5c4aba306..f651ba6a90 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -108,6 +108,8 @@ struct Monitor { bool skip_flush; bool use_io_thread; =20 + char *id; + char *mon_cpu_path; QTAILQ_ENTRY(Monitor) entry; =20 @@ -179,7 +181,7 @@ extern QemuMutex monitor_lock; extern MonitorList mon_list; =20 void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush, - bool use_io_thread); + bool use_io_thread, const char *id); void monitor_data_destroy(Monitor *mon); int monitor_can_read(void *opaque); void monitor_list_append(Monitor *mon); diff --git a/monitor/monitor.c b/monitor/monitor.c index 00b93ed612..65749f931e 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -608,8 +608,10 @@ static void monitor_iothread_init(void) } =20 void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush, - bool use_io_thread) + bool use_io_thread, const char *id) { + mon->id =3D id ? g_strdup(id) : NULL; + if (use_io_thread && !mon_iothread) { monitor_iothread_init(); } @@ -629,6 +631,7 @@ void monitor_data_destroy(Monitor *mon) } else { readline_free(container_of(mon, MonitorHMP, common)->rs); } + g_free(mon->id); g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); } @@ -732,7 +735,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, = Error **errp) =20 switch (opts->mode) { case MONITOR_MODE_CONTROL: - monitor_init_qmp(chr, opts->pretty, errp); + monitor_init_qmp(chr, opts->pretty, opts->id, errp); break; case MONITOR_MODE_READLINE: if (!allow_hmp) { @@ -743,7 +746,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, = Error **errp) error_setg(errp, "'pretty' is not compatible with HMP monitors= "); return -1; } - monitor_init_hmp(chr, true, errp); + monitor_init_hmp(chr, true, opts->id, errp); break; default: g_assert_not_reached(); diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 0c409c27dc..e49b9cbf8b 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -168,7 +168,7 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, char *output =3D NULL; MonitorHMP hmp =3D {}; =20 - monitor_data_init(&hmp.common, false, true, false); + monitor_data_init(&hmp.common, false, true, false, NULL); =20 if (has_cpu_index) { int ret =3D monitor_set_cpu(&hmp.common, cpu_index); diff --git a/monitor/qmp.c b/monitor/qmp.c index 687019811f..8fd71386e8 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -513,7 +513,7 @@ static void monitor_qmp_setup_handlers_bh(void *opaque) monitor_list_append(&mon->common); } =20 -void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) +void monitor_init_qmp(Chardev *chr, bool pretty, const char *id, Error **e= rrp) { MonitorQMP *mon =3D g_new0(MonitorQMP, 1); =20 @@ -525,7 +525,8 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error = **errp) =20 /* Note: we run QMP monitor in I/O thread when @chr supports that */ monitor_data_init(&mon->common, true, false, - qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT= )); + qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT= ), + id); =20 mon->pretty =3D pretty; =20 diff --git a/stubs/monitor-internal.c b/stubs/monitor-internal.c index 4fece49d53..325a559e62 100644 --- a/stubs/monitor-internal.c +++ b/stubs/monitor-internal.c @@ -8,6 +8,7 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **= errp) return -1; } =20 -void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) +void monitor_init_hmp(Chardev *chr, bool use_readline, const char *id, + Error **errp) { } --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285048; cv=none; d=zohomail.com; s=zohoarc; b=kwXfE7m1ltSMrMCYHiY+BLLDfhr9g5VjpW+meRgniUY62idSFZhGlFKG8D7k8o7IYP9AieTJ5nMDQ3ezxzx2tLdFcscEjthQ0pMuGirOiWtbVtFJnTX8V9vYIPiKc/qXq/+sHaN5b8wWuVLKtY+gyPeA21gJFcVCrN/qlnNZ2jk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285048; 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=8lo3KDUXnmI1WFH1r1IpwCFbofsm72XzCt2U1uX/RYQ=; b=brHhXaSCEdctvQtOJupHC5ygdwU/jA/ZcdyqUAwcrbr8MPUkahWxPg4dcVTtUhqhiGek/3grcV3JDEpVd69tCIcn2RdAI/8eovRnyai8zl6COet8d/iDGqOy0VuGCmCZmueXB5Tgkj7IfP/mAcssTg1LUtCLnxBSLDTFfANV7FE= 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 1782285048322901.9308416540462; Wed, 24 Jun 2026 00:10:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHkE-00058B-TC; Wed, 24 Jun 2026 03:10:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHjp-00055a-73 for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:36 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjn-00034q-KC for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:32 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-84236f9b638so382112b3a.2 for ; Wed, 24 Jun 2026 00:09:31 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284970; x=1782889770; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8lo3KDUXnmI1WFH1r1IpwCFbofsm72XzCt2U1uX/RYQ=; b=HIP2YK3ul+1vsMnNM23am3VdxRLBh+NBILPgoMSBncZQe4LOQPe9Yfp/mDWmilGISc LhJnUmtV9s47nSQsOY79PzazKE9jo7RBIuWn86N6qz6sdE5VuWPuzLDAmMJlUTIRBDbj d4PBmwHx5gCvCPE6pNho6KQykOMjAzvBGZywgOp1DNBbgMmQBRrt+Q3SCpO40uI+E56u xW1IucS/UEmjRv90Mz88lRrvBkRD8cTCYWp9rYJVGcbwZJKQIFCwR1HIJGE499p+a0HR M2iJHj47roQ5lZOuolTzldDCf8jZ0fF4L06R6mdZJonvwXYBaS/8pSIOoT74jWnE44Ql Bldg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284970; x=1782889770; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8lo3KDUXnmI1WFH1r1IpwCFbofsm72XzCt2U1uX/RYQ=; b=lYTHt3Xwp9QitTPXIbfXzPq2lTWHoKiyz/cMkXcJcw3mPPBx10Ki2MCsr/1OREHjXK ka4n91jD00apZMxcodo8eS6SlMMM/p//Gf2cI8CUQFGAt5TjCCNI8M29kmyx6H0m0+bd xz1F7fLdJ08CKGcpdtxsl4Mr4HahfEgQupIsbR+2tyJrc/etZYv3jk4K11ObqhL8yPBp 7KIKE8rmhHCGX9PSh0zVpwQGnVLNgWn2okK4szBUlkmCY/4aTN7/mDxcktqwVdeH3xJM g8OC7q7YOrZzo7UiZA+/Aky+F4rbPZ72vkx2AyP4RHDnjOM5LIPkYqRl+voXXiRHx1Yg TtCA== X-Gm-Message-State: AOJu0Yy+5fT9odIwstuDxQD2dXHVfliEL3UaY/jsdbP81e1eBl+l8s3q Hvv+GeUY0NHMr1xzylm2MeqaJv15lexYbj2lV/AseTDdbEMX1Qk+a5wU+oLFESz84cM= X-Gm-Gg: AfdE7cmGsnkkJj4ot0G4siYLo/fTEYbwDCSBn5KmJbRcSPFc8D10Tbxo96mCPrtLGob NTLzp+PmExkj11F1xBe4kMhrgPYvzVCmVfjHUQVo1Oo/zvNEDX1r4FJoPHcOts/L9ibfkm5iXjG p+KTOXUav9s0FF7uYpPOujSZ4QAoAE9orgWXR9jFzR/HFV8NrUl83EKHoHH+35DeEcqAP8vaQqI hD1m8VYqZ/XKTwgB6eDoaZ5zDGYJXR4/EAnWEK8usZTUHQ7m/i0J1v5vV6Y6ySngKAHeTJPCniM 7xsbdZQFE3zvigp9H2KppIQ+ZcVN0gfpUmE9KfH22rC7/kJ72YbIMBa3Xsi3bVK/k/8D+SLTprN 4yFOiesvkuzBXDMUyOsPZObOYln6JBOYhjmxD+FSnEnqZFWD1i745Rb+YbbsQ9Lw2/7Oy8V/f4s kBI+Mn8lFWuNPTNP9Nsh+2GP1Hm/VKagu97JZ/LWPSTfM03YHlDJgJ X-Received: by 2002:a05:6a00:cc2:b0:842:83d1:ee6d with SMTP id d2e1a72fcca58-845a28d45b0mr3139630b3a.45.1782284970226; Wed, 24 Jun 2026 00:09: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 Cc: Zhang Chen Subject: [PATCH V9 07/17] monitor: support iothread ref/unref for anonymous monitors Date: Wed, 24 Jun 2026 15:08:41 +0800 Message-ID: <20260624070851.13342-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782285050646158500 Content-Type: text/plain; charset="utf-8" Implement iothread registration and unregistration within monitor data life= cycle helpers using IOThreadHolder. When an explicit monitor ID is missing, fall back to utilizing the chardev label as a safe identifier for iothread_ref/put operations. This enables accurate tracking for anonymous monitors while keeping 'mon->id' as NULL. Signed-off-by: Zhang Chen --- monitor/monitor.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 65749f931e..c3eec8c069 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -612,8 +612,18 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool= skip_flush, { mon->id =3D id ? g_strdup(id) : NULL; =20 - if (use_io_thread && !mon_iothread) { - monitor_iothread_init(); + if (use_io_thread) { + if (!mon_iothread) { + monitor_iothread_init(); + } + + /* Setup the chr->label as the backup ID for iothread_ref/unref */ + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_MONITOR_NAME, + .u.monitor_name.monitor_name =3D id ? (char *)mon->id : + (char *)mon->chr.chr->labe= l, + }; + iothread_ref_and_get_aio_context(mon_iothread, &holder); } qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; @@ -624,6 +634,16 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool= skip_flush, =20 void monitor_data_destroy(Monitor *mon) { + if (mon->use_io_thread && mon_iothread) { + IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_MONITOR_NAME, + .u.monitor_name.monitor_name =3D mon->id ? (char *)mon->id : + (char *)mon->chr.chr->label, + }; + + iothread_put_aio_context(mon_iothread, &holder); + } + g_free(mon->mon_cpu_path); qemu_chr_fe_deinit(&mon->chr, false); if (monitor_is_qmp(mon)) { --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285225; cv=none; d=zohomail.com; s=zohoarc; b=VFMUQSP4RojTEE4fLNS5ocBH4Q9GqQj8oYmOZS550rkJA6cyQWWG9+/FS07Dt50aR1V1f65PJY3c6RgZb1PGzc2zUuLneaowjFk9xIaMy6N4h0GVDOKUH4lnQX7selo48joGVaMYtPc/XrROuol95Rn3XCa+Q/DfEkeVkxM0wY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285225; 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=PgKE2S4eyL5USYP8aXntr0iu36Ri7ZI72KioEt4jQl0=; b=AyOKcJ8aXyEjMIrhj3b7mMuIsAYGTVbZ2RJuv8pLOA0zTf5WWWdEY4CVK17KSpZeQIcap5nlJakDF/NnkcpPt+NvgiDe5LBGn/uOHQs6C7TwoXLHfMZqbPM4Bq7uiIOqqAUNHZLST6BdEIKRTHR0vOy8Z5mtG+9r0i9k+ZBYhWo= 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 178228522559238.407955047064775; Wed, 24 Jun 2026 00:13:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHm0-0006t9-1O; Wed, 24 Jun 2026 03:11:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHjt-00055q-6o for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:40 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjr-000358-Cc for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:36 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-c8894387780so224023a12.2 for ; Wed, 24 Jun 2026 00:09:35 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284974; x=1782889774; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PgKE2S4eyL5USYP8aXntr0iu36Ri7ZI72KioEt4jQl0=; b=Q8X6Pr/zbb5AY0MbuX8dArUO0ggl9jzAWbABzHCGrKYEksUmji3ZlN42E4X3U+9r+h 2CQh1JYi1DgAsNf/uPbaOr+D44suO+cVD/F36v0Pd+8X/dbK4S14sVA1RZCHj3NbBSDe PfvDcqBHhA2W0tVxMKXoU6TaOp3lr1VriB+sKU6ssPaqHS9Nd3fqgtF5XLwhMlBS7UIS ZHMoiLMWnuKQHnN6apST20PiaStU1UtrsvFrxKapwSX+sNpGRc63/FPVEtsFscFsvnif jgxXDqqlsjzGcvq+pSoAfxZqqGMHOIiS4k//7AKrh1BzZa3w7LYGpy0ys9hJit+g4adq RxFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284974; x=1782889774; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PgKE2S4eyL5USYP8aXntr0iu36Ri7ZI72KioEt4jQl0=; b=U3TNifuzm2TmJvghTkpuVEZmbA/87DCsJxfVZPGfW70dLISHu5o5rsMSfQ1QB+WjZy m8lN4DllA6+5t1ZYCLZgJod0PT34owyM3bd5qVx/BpjkVwVkIUD+RLBkgQ5LfVI14vOw HkyakowQjg+BMZFy9hMnLioTRU45miSZqM1O7Q56h2ytS8rc8RMJRZF1rORUYoUHfrxs JRHvJZVQ1wQNDl1tumGCt3R56UhlzXK0uWLDpqg+J+kY+oq0xWgRPVYeFGelCe/V7CCT 93U17+CQ3m4QhBMGdkXnUeVTZrj0L6srGySD5AGT5CESNo8f+CgEC0mkyx1ZAEK/7jLq eADg== X-Gm-Message-State: AOJu0Yz0t11RWwCU7JZBQ0mZ8EjRiaeN+HhmoW7Qr7GQPFyCcqTCGaPy 5JVZrCKJPR5chWhGyyt1IaNH+KvDitKKhxygfVT7YShDoOHIYK9jxFgRZN0eY51eYAs= X-Gm-Gg: AfdE7cnqcj+DqVXB0ofmlm2wEny3/hTJcrep0vspM5mZWRSzNChhpgmuplhGvdoYLgD 5TWYkE70MxTWXcLuCTZMwJDmvBo3mvYsD+f2gDdimygLM4mJ9IqHK/gdcvJ/j0AMUyeHznAaUFL C6UpKydgwKa9UhrkIHzyWVt9KKOiHSOJe3xozpLB9GV+I2Xw6PRsQu/0IFALXHpEwKDLjGhz8Lp 6qxnHmB5mIkPXmnzoX2kwZKDMHFH2pwBrF+8BLtu9+uUV3fRdPJtsL9AcC2IPJ0GmVCWkC1GeXZ Tyn8Xmsoo6dqEju4aKc/HwggpZAL8EK9U1RaYQj4YnyqoOdupBeBBGux/HLX0s9AhpZ8O84UjmB d+Ro+m9QFVifJJwBRTp04onrXvJ7v8anChKw/lM0mQ85z8/lzMjDbQDavaWnwzGP2Gkb58msfpw u/JxAAAey79Qs5btOdBuo5Uq3L3dOvVQ1ZH+YytdcAmLiJMUzATihA X-Received: by 2002:a05:6a21:b93:b0:3b3:1b38:d9d6 with SMTP id adf61e73a8af0-3bd2d2ec82fmr2534181637.39.1782284973943; Wed, 24 Jun 2026 00:09:33 -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 Cc: Zhang Chen Subject: [PATCH V9 08/17] monitor: switch to iothread_unsafe_get_aio_context() Date: Wed, 24 Jun 2026 15:08:42 +0800 Message-ID: <20260624070851.13342-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-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::532; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x532.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: 1782285227732158500 Content-Type: text/plain; charset="utf-8" Since previous patches introduced explicit monitor tracking and reference counting via IOThreadHolder during initialization, standard global calls to iothread_get_aio_context() are no longer appropriate for raw context fetches. Switch the remaining fallback sites in monitor_suspend(), monitor_resume(), and monitor_init_qmp() to use iothread_unsafe_get_aio_context(). This aligns with the new safe ref/unref lifecycles introduced for monitor tracking. Signed-off-by: Zhang Chen --- monitor/monitor.c | 4 ++-- monitor/qmp.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index c3eec8c069..98727f3d20 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -529,7 +529,7 @@ int monitor_suspend(Monitor *mon) * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. */ - aio_notify(iothread_get_aio_context(mon_iothread)); + aio_notify(iothread_unsafe_get_aio_context(mon_iothread)); } =20 trace_monitor_suspend(mon, 1); @@ -564,7 +564,7 @@ void monitor_resume(Monitor *mon) AioContext *ctx; =20 if (mon->use_io_thread) { - ctx =3D iothread_get_aio_context(mon_iothread); + ctx =3D iothread_unsafe_get_aio_context(mon_iothread); } else { ctx =3D qemu_get_aio_context(); } diff --git a/monitor/qmp.c b/monitor/qmp.c index 8fd71386e8..3341df19c8 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -550,7 +550,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, const = char *id, Error **errp) * since chardev might be running in the monitor I/O * thread. Schedule a bottom half. */ - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread), + aio_bh_schedule_oneshot(iothread_unsafe_get_aio_context(mon_iothre= ad), monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ } else { --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285062; cv=none; d=zohomail.com; s=zohoarc; b=Dj3Kj+yTJwOaf468nLNC5Poaw1mjxKYXd/XO1iGY31jPupCWP9rFngYyuso82isX9uV61xV7VLeHsxgOXeqzcMjP8h2Kbs5XFVfgL40rEGKvaeI8ETepHyTyFat1n/R0ZySKCk7C7e2bBOKh1HlV6hzTRoOPwy2KLNltx707tA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285062; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=31eqi3lh8ZxCXKz2hnzO9aMe8wTk2WViYcoK9qnefZM=; b=gnKITGnyY31ykL5omaJBrRvHMIPmYjURe77XvKs1r39yFor8BSb8Bz+mr/oDHz3Mq68yE7hzMV3zD5l6S4hzPUOIEvu1xblcUjneCValKZdB446gZIR52bd47/gBHPKKjh3WZ17h9qqVZDasZaCv2l/6WysWtCHqLvy1FsibGDs= 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 1782285062554528.8813888255813; Wed, 24 Jun 2026 00:11:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHkx-0005bt-BQ; Wed, 24 Jun 2026 03:10:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHjy-00056f-3p for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:42 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHju-00035U-Vh for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:41 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-c8b49639fbaso458947a12.0 for ; Wed, 24 Jun 2026 00:09:38 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284978; x=1782889778; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=31eqi3lh8ZxCXKz2hnzO9aMe8wTk2WViYcoK9qnefZM=; b=TncLBJemzOC+5pyJP8Mzmws8tJtT5We3fSrV+ORyimFs01HXm67gVRG8vwEHN6USFk AWnTMsfnrfMzBWlSNfC5saLz/Hw1JrOZTQWcvuCB2Is1bd0Gdh5Lmd3hxu2sWQN7FQP8 XIDMx0QY6uLbB7RnvvGfa5DJrDuHOLCqYKn6YiEdtjFnMyDa3Q5wiZ9ZIQnZaE2MFrKG qTOb+vjfXrbvb8rixdaf3uJf1XGXYgFZqJBJQXrgiGBjKTKgPuIZHjyq132VJQk1lvVC pkLFK07toQgNvkGpzbgcEOYRDN+3w3m3ER2XzDMMzTgx09onORXks/zyyIQs++tb5DYS r7Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284978; x=1782889778; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=31eqi3lh8ZxCXKz2hnzO9aMe8wTk2WViYcoK9qnefZM=; b=QgRxItyUxJoILXIRhJl5YWoZZ89g/GU5hcpJ791Sjq/314O7Oilmycr4yo4DAHWikc JsraFEZn7ON7eJRGCqRzjkRpY+oCss03vYFjytS5ACMwcwsU53SqFMnkZlrrMOaL7jE0 Yy0dX9+r5tCyNEIPoSn4fv6mslsnnelvnd9cSt7oyFaUT9lkJB6kSYySDriC5DugtP7U xoQPzbTdk1Gd/zj9rjODzfUygO6wYSfnkhdXVuvgksP7CWENc7LRcoxowKEe4VW6q164 WaStSX8/p84ovMsnYenwvQY3Ck60dfOVdFfe7aIsAHkiWiB6l8vgaGR4MH+z27x908q9 3WbQ== X-Gm-Message-State: AOJu0YyH5fiKFgL1EN3ii1ch5qgkPWPFBIYzJ/Y9PwXJaUdZhG0dsp3U Hkf+iWTV1LVd16WugNQjwy8etLqy2o0BprTpDwJMYAHgOXXUiuDwaA2jc3Kz6Jk7KOI= X-Gm-Gg: AfdE7cm1ReQfYGHzME8t3ri4VkVyuZkxG292/Ogr77u1G0Gg9p2x7veTWC2Q/YGCk6+ F8ByujlxQFhY04ts58WQIWWOWKCRuE+XR8RTCK9+UU5gAJbn/b4ljgrwGEBwqOQn8ke9DByZq8l qaT+KvNikJYnOMNMH0UL/dVG726gXOO9Bam+4Jro9uTiGq71vAjddOYrsb4/z5zNpb9gDAKH5dA 8zZppcjt08h9ghKMUYPVtO5o5TU4KZEt0hx5h6R1TjzXT2l3vlvSQ35jbJequFJFA0CZViVP6DZ 9b3xd1d4sqK2GTonoaKMHGClrUI3t3Bzqgqmw8hOBGdfhvknYhSgqMHjZCv0oksSZRekIH2kRDs Z5dDUvt+pXB3jwRmI3xDknbHG8NTqf6pMXwG1z7rzQj8KCfmnZBUytuieAFrc6jZ1758+qRoquB KVGBTSqmYl3d2k6M/3B1bDnx44EEg4TpmEKPvjyuOIC/+w+Sew2cli X-Received: by 2002:a05:6a20:c916:b0:3b3:2703:124 with SMTP id adf61e73a8af0-3bd152357b7mr7792865637.39.1782284977684; Wed, 24 Jun 2026 00:09:37 -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 Cc: Zhang Chen Subject: [PATCH V9 09/17] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Wed, 24 Jun 2026 15:08:43 +0800 Message-ID: <20260624070851.13342-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782285064639158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_get/put_aio_context in iothread-vq-mapping. This allows tracking IOThread users via the device's canonical QOM path, improving lifecycle traceability for virtio-blk and virtio-scsi devices. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 20 +++++++++++++++----- include/hw/virtio/iothread-vq-mapping.h | 6 +++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 9cb9f1fb2b..30e9fcf870 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1487,9 +1487,12 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlo= ck *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, + path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; @@ -1521,7 +1524,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIO= Block *s) assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 95f13fb7c2..26ecefd547 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -65,9 +65,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], - vs->conf.num_queues, errp)) { + vs->conf.num_queues, path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); =20 if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 55ce62986c..2cb48dd387 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -77,6 +77,7 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp) { IOThreadVirtQueueMappingList *node; @@ -93,10 +94,13 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_get_aio_context(iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; =20 - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, + &io_holder); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +124,19 @@ bool iothread_vq_mapping_apply( return true; } =20 -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; + + iothread_put_aio_context(iothread, &io_holder); } } =20 diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/io= thread-vq-mapping.h index 57335c3703..0d39caddf3 100644 --- a/include/hw/virtio/iothread-vq-mapping.h +++ b/include/hw/virtio/iothread-vq-mapping.h @@ -17,6 +17,7 @@ * @list: The mapping of virtqueues to IOThreads. * @vq_aio_context: The array of AioContext pointers to fill in. * @num_queues: The length of @vq_aio_context. + * @holder: The QOM paths for attached device. * @errp: If an error occurs, a pointer to the area to store the error. * * Fill in the AioContext for each virtqueue in the @vq_aio_context array = given @@ -31,15 +32,18 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp); =20 /** * iothread_vq_mapping_cleanup: * @list: The mapping of virtqueues to IOThreads. + * @holder: The QOM paths for attached device. * * Release IOThread object references that were acquired by * iothread_vq_mapping_apply(). */ -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder); =20 #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285224; cv=none; d=zohomail.com; s=zohoarc; b=PHCS9AodnJjja+obP9MFFR/gXNslk6mj5TVO6UPzArkPmwdR56a4RjJduf+CTD9lhCZ17P1Na45/DOaQGLBRKH36+IRZbEkQkGFfYIj9Ga3dYdhYuYK82lIDJD4/EwtO9e2Zk9AjyfQLFgK0O7/vPyZYSH5vzpnDI765Hpoymc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285224; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LDuEBYp+d3GMQU4EUX37XSBsPRXEyd9vBacPskZ6gvo=; b=Y2EjVUC/qATG0gwbLuRub8DzEv6kWp0TFWfXDKkDeycYSGbcEjQD2cxeoYzBlJIQiVeafRgE73JA8W1xWv7+LfY10i5uFn0m3gmlP2k7+BFFY8DunW9gYhRh9+UlcXlXi961uCPXcE3BaZNlHn/qQCz1snkanOtCKupUq/h86sM= 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 1782285224069922.3439707475052; Wed, 24 Jun 2026 00:13:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHmf-0007XJ-Ri; Wed, 24 Jun 2026 03:12:30 -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 1wcHk0-000582-Tt for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:51 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHjz-00035r-0y for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:44 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-c85b73ffb52so291694a12.3 for ; Wed, 24 Jun 2026 00:09:42 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284981; x=1782889781; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LDuEBYp+d3GMQU4EUX37XSBsPRXEyd9vBacPskZ6gvo=; b=jTa348YjRYcDKovvR5OcSE8AL4DyFadPIlnV4rCdIf6ryOadFQt/a/QF2o+/T+EBDr a81LfT0D8M6ZgDGz+3MAl1UPfh88gQUmYlbqM9woT8l+TEtGFXwudXgQn1tx8HEudlR2 x4F64eTtzrBPJlqHFGYwmDh2h821a0j6223riUEjd2KhJ2dxF+0VaFr5HncbfnzejVnz y2hkZzvAEfUOIuC2llzhKyC0/ck4OCEs0xYDaWAhRFpuzGUOb2A3j/aDcrUECymtxruE l6eYc8CyK65VXPV88R4V/aegBB1znezyqLqsX3O5c1KwlMNFX5Q6VaccdpoJ0h92mnpU +GDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284981; x=1782889781; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LDuEBYp+d3GMQU4EUX37XSBsPRXEyd9vBacPskZ6gvo=; b=JDuZEcqKa3lRwG/lydFIk9G9RN0/uK/1gp+VmtFHLDGq+dnecx9q309SHl6mSmawkK czFXlPVVS5O3E5KtGrw8DmQDAE8MpuoWAtUS3sIZg00bLPkI35xZCougJzMN7ZGSN+H8 QoJTzlqrO2DDH6Rvw+vmI+eapGqQnosZ0YLLCm886ekTpjsHHleztc0ZtNyZ7UluE/Ts T+ELc5Mi3E1B2qA/wZMlbGPHNizmKivMDhq7/HP4k7LXLm47vDPJjtIEEfIY2ZXXj2Y7 XX/xJDAaxGVTydwhQPOTCZGbHXsWVVdB8eJ3cQmVp1luxyALwR8sSUiT5+Zv8uw3NRMR CtmQ== X-Gm-Message-State: AOJu0YyVXs8K6r1iEvxssFGGVB8UAYkQAj0mz3gmnP+CtpnxcsPXf0Kc xTiJf9K8NoilnUS9bf1tSlISub3IWdrq76z0mUQmKJHOipSqufGMvWijW6Fc0Riutms= X-Gm-Gg: AfdE7cnNvKqSXApxjEdNjly3WiGTj7e6f6RK0R9xG+gFnB6DmFwhxUX+gFwlr8z8yzi 8F5QocjlhHBACNaYRt7O2FESahTDyA3oBH7kQUEvRvSl71mjvwj+eVXed9fhEZP9BNtUYESOxoR YPgUQUm+tHhkrX7yynGbWtIPyzHamExDdWUtkpppFivBX+p18t3kosY5PgbEy6KPYHTA+/8kQ0T 58LeYS+c2IvY/m2o2yFr9qfkC0qx1veh2ixA93mOZTSTdrLhev1ltChxHEm/KQF2DCUIrea0WVF denrDXldRWRXCetnqpahgHhh5aBRMrsFKGsMG0W/TafzGqoRJ0kt+FbjDkcYPNmrYOXaLN/d11u we9SxcRDNZ+P7OwfAZaB3/dvuEZRzosj9UzvCmaLDyhXapUE1Bdw1At7SRRo9nbogjYyfjMHJr3 1RnNe1qyW3E44eKDFOPN5gw08TRj0EToUZ5ZVvOZXQioJdxdwSy6QeDufMX/QL8PE= X-Received: by 2002:a05:6a21:7483:b0:3b4:7e2d:a3bd with SMTP id adf61e73a8af0-3bd2d0c463amr2781870637.29.1782284981557; Wed, 24 Jun 2026 00:09:41 -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 Cc: Zhang Chen Subject: [PATCH V9 10/17] virtio: use iothread_get/put_aio_context for thread pinning Date: Wed, 24 Jun 2026 15:08:44 +0800 Message-ID: <20260624070851.13342-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-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::530; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x530.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: 1782285225772158500 Content-Type: text/plain; charset="utf-8" Refactor virtio-blk and virtio-scsi to use the new iothread_get/put APIs for AioContext management. This ensures IOThread references are tracked via the device's canonical QOM path. Summary of changes: - Lift 'path' scope to cover both vq_mapping and single iothread cases. - Replace raw object_ref/unref with iothread_get/put_aio_context. - Ensure consistent memory cleanup of the QOM path string. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 24 +++++++++++++----------- hw/scsi/virtio-scsi-dataplane.c | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 30e9fcf870..d8dc1dd136 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1463,6 +1463,7 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) VirtIOBlkConf *conf =3D &s->conf; BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (conf->iothread && conf->iothread_vq_mapping_list) { error_setg(errp, @@ -1487,8 +1488,6 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, @@ -1499,13 +1498,15 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_get_aio_context(conf->iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, + &io_holder); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(conf->iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < conf->num_queues; i++) { @@ -1520,21 +1521,22 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) { VirtIOBlkConf *conf =3D &s->conf; + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { - object_unref(OBJECT(conf->iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(conf->iothread, &io_holder); } =20 - g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; } =20 diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 26ecefd547..c71f33b41e 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -28,6 +28,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) VirtIODevice *vdev =3D VIRTIO_DEVICE(s); BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { error_setg(errp, @@ -65,8 +66,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], vs->conf.num_queues, path, errp)) { @@ -75,13 +74,15 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < vs->conf.num_queues; i++) { @@ -94,16 +95,18 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { - object_unref(OBJECT(vs->conf.iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(vs->conf.iothread, &io_holder); } =20 g_free(s->vq_aio_context); --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285076; cv=none; d=zohomail.com; s=zohoarc; b=RCM/8kOYHzNAlkHb+lWAYJRjsl/ULg3fFhyzECKTWhX8ldgLeQ/5dNcizdSkOnBDTsyRlNCaPT2BDvcaVsfqBfvJO+oew+SzA1PsW1G9OenNP448mIIxmhBsniiPEqRkPYZDaVJjc4xDInRJB89tsYiOQZum1wntMl07GfyEBGA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285076; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=e3JgrbyUDIxuz3YPnS0kJVMN3cW2e7N1UfUsJRso3As=; b=DwZAiL2ACqOjx+EIY+zHSMc9xtmAbpPwBr2+/0EL3xjMReNTIz4pnQpb2/4TVXjxJAT+0uPufl2ALi9qZ20NNyW4a/2AhbziYKY6g89bOHiVGsRVBy/hED8H7COYndQfFQNpRo9NMFsdr9w6SmnO/lgsj0jT7fgKWeRWRUP7Pp4= 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 1782285076715373.596226772092; Wed, 24 Jun 2026 00:11:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHlC-0005oY-6V; Wed, 24 Jun 2026 03:11:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHk4-0005CX-CP for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:51 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHk2-00036J-Pr for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:48 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-37c64d34032so906609a91.0 for ; Wed, 24 Jun 2026 00:09:46 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284985; x=1782889785; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e3JgrbyUDIxuz3YPnS0kJVMN3cW2e7N1UfUsJRso3As=; b=jDJfEHHJnZDzj1aj37hhWZdSQq2+2btowVVNuaoYYrzxHeSbEHDeoqzGlKdWjeipjV xsqxekpbpD5AYLqqOwAKQ87jhjSAwORTI2zEj3Ad4RwzMitJ2m8kQwy/HT07YC5AQQs7 Zzm2fB4xvGfM4aErggG3Gfh1+klla+xhL9bqRa3XqdGJSKW7Qh7IfLUEP++MEBJp/GAM jA6+SxUSxvHO/sHzRHtMFq/52F+GcMBPcnolbHscGaULUzd7gpHO6JVvNZalNGgzoVfb CjkTgpiVwAsejg0revKIlP//8nE3p3BfmAbmXZyUPFC7XmaYUsyCvS7d+gK1yeKwdgrf 8Whg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284985; x=1782889785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=e3JgrbyUDIxuz3YPnS0kJVMN3cW2e7N1UfUsJRso3As=; b=dOgd+mT4omOFkjvFhrSRAWmwg/OVyNCY7Ua+Cj2nDpo9AoPqJ6Aa69RGhqIu8so53E 2SU3v6AkPdpUiiHXgBTt+PZ+dRelO6Sif3Qkt5bxhQ/R90VJ7S0F4sk0U4xU6/fpYkjV odLRBOiTSnNnV5xTUu7YEd3AnnDogARolI6tf4rlvaIwoV24RvaInQZDmJVu0QJHNbsf hlt9KoTh0WusfVQd8jbE8/g3e06MQ43zKm3Z5ivdz2ud57Juvbl5MarrZxkE9x+IO9f5 1mK5RfOOYluXf1OniuhkuoCG6XARY7oC456I2HdnpRVTssqZG5HM+RP/7e/JaQFM6Ber oqvQ== X-Gm-Message-State: AOJu0Yxh2Irf+tUvI/iAqUKRcdgo2wKFzCWRaqzf5qFw3blywimz0zEn jqEqAHrDjwdawXPm7dmmSHjZzOsfQvd/T5xb6nJW+ymm9N/3/iYrO8LY8ST1AS7vMsM= X-Gm-Gg: AfdE7cnULkMc7wppmVmEAYtwo0WME7Blqdf/NPgyfbr7km0WqujHHSxDZI6cWzGH4UI oo3DlbJcxyoruFrbcUT6akHCN1noIdWqr2cB7c4yd1mjufI7cSQN3UZOXFJ4HZK6+QwyC6MDeo9 UCevD9vHFthdpvP31e/0FMPnyWtjqjSI722UmJpz67FYuL+b91AZTUrhujmBVuEqTfSSCW4JuXX 5qXD7rqksnaKd/xehqYot/76XJYJGHrsfnStxm7NFMk/yPXEd30XBLcCYJsA6ou4DUvCl/C+f9s 4Hk3VH0D35lBMtrJYhDZqKbDs9klMl/c1akMLpJiFAwl24BWJDxKTbBAFbnj8GPDUM3Yawjtc3+ Rb6CxU9npegQvwzL1BdDfsaDh4DLexG00t4dM/SHryGiy9tpfKvjWS1VHqWe7B/fyseGoHYWYNE pzsyzymrB5B86PiGYIQE2dn5sGHcmwLMykSEmKXjnOb5wYqOl/sXj+ X-Received: by 2002:a17:90b:2692:b0:35a:10b6:1208 with SMTP id 98e67ed59e1d1-37dcd754648mr5862672a91.14.1782284985325; Wed, 24 Jun 2026 00:09: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 Cc: Zhang Chen Subject: [PATCH V9 11/17] net/colo: track IOThread references using path-based holder Date: Wed, 24 Jun 2026 15:08:45 +0800 Message-ID: <20260624070851.13342-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-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::102f; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782285078703158500 Content-Type: text/plain; charset="utf-8" Convert colo-compare to use the iothread_ref_and_get_aio_context() and iothread_put_aio_context() APIs. This ensures that IOThread references are tracked using the COLO object's canonical QOM path as the holder ID. This refactoring improves IOThread lifecycle traceability and aligns the code with modern QEMU iothread reference management patterns. Signed-off-by: Zhang Chen --- net/colo-compare.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 823b8aa323..4f180936e3 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -130,6 +130,7 @@ struct CompareState { GHashTable *connection_track_table; =20 IOThread *iothread; + AioContext *iothread_ctx; GMainContext *worker_context; QEMUTimer *packet_check_timer; =20 @@ -926,9 +927,7 @@ void colo_notify_compares_event(void *opaque, int event= , Error **errp) =20 static void colo_compare_timer_init(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - s->packet_check_timer =3D aio_timer_new(ctx, QEMU_CLOCK_HOST, + s->packet_check_timer =3D aio_timer_new(s->iothread_ctx, QEMU_CLOCK_HO= ST, SCALE_MS, check_old_packet_regular, s); timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) + @@ -968,8 +967,15 @@ static void colo_compare_handle_event(void *opaque) =20 static void colo_compare_iothread(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - object_ref(OBJECT(s->iothread)); + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + + AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, &io_= holder); + + s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, @@ -1408,6 +1414,7 @@ static void colo_compare_finalize(Object *obj) { CompareState *s =3D COLO_COMPARE(obj); CompareState *tmp; + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); =20 qemu_mutex_lock(&colo_compare_mutex); QTAILQ_FOREACH(tmp, &net_compares, next) { @@ -1434,18 +1441,20 @@ static void colo_compare_finalize(Object *obj) g_clear_pointer(&s->event_bh, qemu_bh_delete); =20 if (s->iothread) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - AIO_WAIT_WHILE(ctx, !s->out_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->out_sendco.done); if (s->notify_dev) { - AIO_WAIT_WHILE(ctx, !s->notify_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->notify_sendco.done); } =20 /* Release all unhandled packets after compare thread exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); AIO_WAIT_WHILE(NULL, !s->out_sendco.done); =20 - object_unref(OBJECT(s->iothread)); + IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)path, + }; + iothread_put_aio_context(s->iothread, &io_holder); } =20 g_queue_clear(&s->conn_list); --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285227; cv=none; d=zohomail.com; s=zohoarc; b=lRjnyYwg30CnjWHREeFWwkeH3Dp0lJmQsSGJkS8oiEBWCWl1oXEe3g/iZlWdqm+K4uTGEGV4jzHqoaKK6y5Q5JkBq9o3AWf0bF5YFfKJAba4BL/ckPNeuLvxd91e435paLjY+/pEi0Cgfd1BkCcrVgbsSvH0Zonx6F0dD/1FnEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285227; 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=RPz1vR7qk6BPWmDWRO7X/kEwJu+C7m3lMSDL1o9HxyhxfJs3B7OR8ICktjXsjomSpHOH+NDtUL7aogbddTsH3hSdV3E88uL2lmbGm41QrjTEbltPH49wvrec5VXbpQekeWnXdGCw2YHzPBQ+1voXdVv1GltTARySPwYyHfYla2w= 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 1782285227471191.83107206476757; Wed, 24 Jun 2026 00:13:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHlQ-00069B-Jr; Wed, 24 Jun 2026 03:11:13 -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 1wcHk9-0005J1-Jf for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:57 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHk7-00036T-Mr for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:52 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-c897468a244so218767a12.3 for ; Wed, 24 Jun 2026 00:09:50 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284989; x=1782889789; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TMWKjSKfCkLdRLDphuftQNsCyWQFXmHbwlzRM8NRv8w=; b=UTVmrlz1sSo0mV75uwLwYq2GmAUI5ay1Rtr1r7Qmp67HQpOI4irkzMpA6GlxB8OcCE jPxUZT9Tk/c2mak+y9HARYFnzEZsl0WlUPCVNlRDlY2PvpHPkX6coU6GvB5z0pfKpSNq NhtM1osPq5j3RKvAt7FNvT5yOiqZHi+vxpHcWxdckno5X4CX55UiAkURpZoIIsKQJxia kARu5at/uLIwTOnoy9ETvo889R/6f5UWsctCvh/7/rB1lnJniHdiS2M4Vx12YgdZmBd8 vqX8SS7i9oWcoTS/HoZGaAbRYV4HqxEkVlsWRvbvS4fjh96x03SUhL3tMfmJ24i9ruq1 Sc6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284989; x=1782889789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TMWKjSKfCkLdRLDphuftQNsCyWQFXmHbwlzRM8NRv8w=; b=X4MqcCmY6aSIt15U1LgOPvAhNVeJ3OgW6WFK+vFkvWAinlzcQH9CncMZTCS/KI/79B PXJQfeD9XFj4TDcMZ4p7VL3q64/KE1OBHbMwv84aT+AjAL71IsJhpkZWqM0jKgWfdmgV rBYzsWALp7K42DPXtldsUrVndVZHXJK+vs8lHO4YldNVf0wX3IOjOJOqXSkYEQdsxdH3 9NHwyRuV7xUI7JU9Sxk0PZ4iMHiyPdRk/Ts47kW8YgovV1s/bcK5xaBbcJpLDlEBhVeW PxzleExjJMOvL0UouO5BvoxzHTK1RFAcQRO7SGoQVm9ASpRzSfQNo+yQFQTti7MDcOGd OeLA== X-Gm-Message-State: AOJu0Yw0KBCfTFpd8ilWOoFK5bCoxhZ1U/92Y4ULFfABALWFPXXX+4BS og5ObqtkZiaTLPaLkkqZgr2BfEvIiYcO3ZW91PK8R9D4V351/U3ayqqcwpINy3zib6E= X-Gm-Gg: AfdE7ckbbBwGkdTguzKCi3mGzU66lgxYFLooCA1FO2/NNjPasrGzKo4J+SVgzR93wQt ofzFEAHyOjj/U7bDRUvie0RzMABUYfCgBBVUygGjIVI8uDpuCtD0WF34QX2YzQ9/aex68B1p1CD L2r56/Rg7sRfUhHAxKbgF2aWSM+BJ8zbjt9JMQBkm81evM/ma++PegPRe+u2K9XnDM97bTg8kzr sthtTu+25s0xAYDS9hRugwDR3nAoI1sgAZCdFLarkqu7Kd52yk8frtZjwO3dyEvwnt+GjpI0IqG BiBnCLTTYcfzqXpMtvKBEnXHFTWdCHIyOOHcSSklGCqzyR+ZzJpfgUdimzk4gWRDekDXsbZMXV7 pWWTIjgkYcKuLipO8he+XghefE5cahulvq0ZRim1z6m8sMe5UU7Ef8KNrzbqQvzStzfSZ8tVRP5 tA5LyeLuVCBqJOI/Lb98F4Cs5HFzpgSEJzHyVULYjfY7DRCk6zzgMS X-Received: by 2002:a05:6a20:6a24:b0:3b4:895f:6ac8 with SMTP id adf61e73a8af0-3bd2cfe0277mr2595596637.3.1782284989105; Wed, 24 Jun 2026 00:09:49 -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 Cc: Zhang Chen Subject: [PATCH V9 12/17] virtio-balloon: Update tracking iothread users with holder Date: Wed, 24 Jun 2026 15:08:46 +0800 Message-ID: <20260624070851.13342-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782285229730158500 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 Sun Jul 26 12:38:42 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=1782285226; cv=none; d=zohomail.com; s=zohoarc; b=LFYOeBzFiaQ8l5/uwktYiozugpQ8KsvOOytgAdfkoqAMFVMGGTTvq3oefGgNxlM2FfPggipKNM9eAk2FMqNKudaSh/xmUsN/5I9fdt5Rrhhc1r+y9vRB+032+ufaA28BjlWep/zq77xdg15TN/RwRWRIt/UoE72mbYmxKk5ceHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285226; 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=eCaiTO6FL/cv47Z58+e7iEfxryjTnjuC4EhsW1RUd4OqOQaqK274lwVEgYWuPdGt4QASuoDf3q8EGNgIPiW5hlVr+w7EU/o+86IyjD1WGfpNn4EFSI8F2Tk5qYBe4ACrVUZ/rrOQp/GZlEM4x9MnKsbUxC+NR8Q9JnLopJgqCt8= 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 1782285225953401.54483458059735; Wed, 24 Jun 2026 00:13:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHm4-00074W-FP; Wed, 24 Jun 2026 03:11:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHkB-0005JF-Pq for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:59 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHkA-00036e-9b for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:55 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-37d82f3a244so455098a91.2 for ; Wed, 24 Jun 2026 00:09:53 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284993; x=1782889793; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Led6dtm27lEqwR8zEWN3ior7m9T5nwFBmwYxnZK8iTw=; b=CfuO5E9t83Xzje+KcR+h4K3ZuTf9YQ8wg9iUpTKcjycbQCMV1yBd9t51oquC7Z1SbP J7/AGboeyM9s2AOkL4DPbThrQLLxlHfX2ry7KYvZjULNyC25WvMM7MMHD+xZiV6HzuJ+ 5jAZo9NIQdskRnd4dDHWbsFauNZGvBaB9zf5iLYxZMcrIvV89F19PVgUJsyI4FuE+RmG xM9fW2PjM67a4TaF5SJ8Lw15j8XJQaHX8A/N/zvETHrcsYwPl8gdSeBYcVXzFqdozuK2 YLPy3kHu3Q2fL7Jlg0lHrXHonrLarp9+axDx2/s1g9SkgmIf4T5OohLPtaOUhAHgWR74 FBEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284993; x=1782889793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Led6dtm27lEqwR8zEWN3ior7m9T5nwFBmwYxnZK8iTw=; b=r1UKecNBGOH+qIM7KVmJ27rrQra3ltiJbOInAQ0eLDIe5Aex5t57XlyecVE39TctQU 89XbunE2fHYz+a5oHlP3iA0Kjh84r1qAzn04zAyarAskFgPQYlMGEJo9XhlpNo5Ks6rn KHo80IHYNmGGy9NrsASN5CElgC+OfUOU8uSXyYCFg7NxivKHSHwk9Rz5XokB6aZO7j48 pTnDaF3aYkpcq5Owl0/IeU3W8aQB38U3gyI1dwDsqFdzwE2JNUwtq+O/AkSDPzRouFZH +A+etYYU1AlkTCbKOJaYXDWeEW1emmtJw+ByueupYNe8FouCDODAxOKNj9rA+FLAUS+H MbNA== X-Gm-Message-State: AOJu0Yw4BYkswyYeT7oqLXJKtZWzUzIBCXEf9OVhIosEIea9CcCLvVQA tamqSSi2FnV8hS76tnbEN8iV9uXPdHhFSuQQsW/Mqhs8xP9Elcq+oy0gKtyKhRQmn90= X-Gm-Gg: AfdE7cn9cc8+a7x2bHcbVoxDwjEosTvZej3VxBj/QWuY2rI1d5iTToePyckzR5DUWIp Jb9aHRWEKqa5zOEQc+YjFyrILDlqbuZXnLsqAyp5zmyaJ3++RANND3JM02YOa6Qs7la9WTegVh2 1cEF+Y8knxuHQbrwnysV/zGqG4JACbuipvKRRlmJ+L0DKwP2jC62hbZ0oU2RfMosDZkzrip1Tzm rwFQ9I8HsiOOiZf7GXMqfbCWNVpxUUInANCApiidvxz2HihYFmvT0NZKnrsRP4SZn8EhUzUUQSU +81CUZ5Gs0PmeEXW9EHdOoAW824QiFnHkUI5VjepzjxZBvkFPnd66mV6ciY7jO4AZuntMSLNof1 Q8y7LAeQ1NpE82x5NFMe3GHJ6MSm8+hQySusu/RdyWjIO9GV1sf9O3XC4/kefSUYOrlYYL1pTIo lLoQo85GsvraFH/bWahArsWH/sqPYkloWjT8GMoTm6SD3sOtlv3fr3 X-Received: by 2002:a05:6300:83:b0:39b:89e0:2e37 with SMTP id adf61e73a8af0-3bc51b6c387mr18634900637.14.1782284992793; Wed, 24 Jun 2026 00:09:52 -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 Cc: Zhang Chen Subject: [PATCH V9 13/17] vfio-user/proxy: Update tracking iothread users with holder name Date: Wed, 24 Jun 2026 15:08:47 +0800 Message-ID: <20260624070851.13342-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-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::1033; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1033.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: 1782285227772158500 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 Sun Jul 26 12:38:42 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=1782285087; cv=none; d=zohomail.com; s=zohoarc; b=ha90tEKqE2k4wP/ZiT369+xxl0ailYJXl7VzJNXAWu4gqk+08S1cDVs2n+4Y1F5L1QOnFgPTF95mDC9FYKWK4O2YUXRhVIha9U/h0izBuYK+IUmHgSi85oIXnMMz9aEiuZVkyCQLZTmxIgAObLtz+RJQBc/m6hZCDV/5H39Z6vk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285087; 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=RwmIlIgkswtkc3nWQc0jH+ge9zhm6DWkbnuL/jVW5DXBfXESJ4HG+Fr1fRh88/R93HuApg7Ruu5IE32qqa+MTWg/QkfUx56V7w9zoEsiSXHeGGXGYvvS7chdp9dS8EzgEUbJto0rzclOJfDpDML7N17/XSBIiiI3EoP7huLp3vQ= 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 1782285087768571.3841380855063; Wed, 24 Jun 2026 00:11:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHlS-0006EJ-FL; Wed, 24 Jun 2026 03:11: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 1wcHkF-0005L9-7e for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:10:00 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHkD-000371-L3 for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:58 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-c8ce8f2e235so412842a12.2 for ; Wed, 24 Jun 2026 00:09:57 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284996; x=1782889796; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7t5cTU126FnpUwkoAoirKGUM08oblbAVX84J7t/Z2ng=; b=IxQxmtPHAzTEP/1jhGpllS4sujqpY+VjpW8qRJIUyw2O0OLZp4cnnuYxXvCHFY5Jxg P9cbQJeLX9Nigcwu+1a55XxNPGg/Y2r7/K2M+BZX/0jyyYlthbmV6GEZjwd6JnfyalHu sceI4Df6DN7mvnPlVvf0WoHI4BSndthbz++yDHcH+bFTycBuldH5reOKXbjQ8ErQqlbw SyPT7BZs9fiJ2eMlDGC2nJSMpV1PpHFTMmpb4BPh4aEuqXeI7Dcl5okpRcX4mnItW3Ey bc0PGwehQ16p60EFeWm7ZE8wL0e6wWfEmfTkhnVJTuAwt5i2adMjAkuJS2dAkmJWD8Xm KLaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284996; x=1782889796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7t5cTU126FnpUwkoAoirKGUM08oblbAVX84J7t/Z2ng=; b=mfNJe/fdzoepetIJV2YiaBZS0uUzxEWRMF6z1qOj6ONbSMnHs1JP4O5SWqRPuO7cik O/RNN8Vwzf+OyuPJetvwGKAqC0iNt7sUBDF17g6wZ4P7RptVsjP6NqqhSXy8MByi4ijS cTqBw9dHf1eVpntHhMCNPE6nKrUvfYvqK0SnJ1Hq1dVJ2rzojc9YIGBT0AqDPzhHrlNE fyD8bZVIRBdhQry0EAx9WjoZwScbk+l0OF1TXB0yK+90sWFBbYwBdE9uyM5W1dzC+uZ8 swSj5yFYD1A2PWOYU6tRDOjqY1wIHEI24yhrqUmRf0KynoMPnzsVw6hTDtSrYmzb/OZ0 KwXw== X-Gm-Message-State: AOJu0YxUtSTPBGWSultLhFqR5bzd+eE7ifjqP7PVpbUqePMJ2XJfTqFR p/QzQ02zOES/kfDr0mQuhDgszbvzbcThs3FdHf4Spai4SxfZdWU7He7XEkB3DCSYCsw= X-Gm-Gg: AfdE7cljCD5GFTOUg+iOaqGCG883iqr+RaecbXPw4kQ3kKQGQ8mHSg0saqwxdETAhJC CMsajoxl4oObbJt+x8dzbjdcfqpgQ0Ob82w0Ij7XhXkxSskMKbzB4uhliVjCCefcdo+BVyvyZOJ KPouLWGRk9S4UYGfasCh9UVkyivXcDCQwCN1BgNj/SlO4Kr8M4A/Z+a+LdbUFGUtl6D0WrQDAMB eRYBfYuoSOODKBoKzpUZM91PMgSIISZx+AdYMUGd+WCZqFGw+ohyGjN+PEokvaEmNGKFtraLMR8 bkBP2Nk+JJnHvXKtDz05WHIkOS2fgdtXtMLKWfvPaNMgbe+EUZpiPisFiJjstGR1nVx/DnFkn3f 92nXS2s7Al01Lt1z1WgTpmPTGxTHny6mY3LX1kXEMuVej8FHjsXU5+VW7Pm8SK7a4Gope9Snb2I XIom1yu6mfH00a7307wGbWJrLR0ABvf4xU3Gf6r5vYwKbxXCqpr/CM X-Received: by 2002:a05:6a20:3d10:b0:38b:eadd:449a with SMTP id adf61e73a8af0-3bd2d2ec5d7mr2686736637.38.1782284996465; Wed, 24 Jun 2026 00:09:56 -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 Cc: Zhang Chen Subject: [PATCH V9 14/17] xen-block: Update tracking iothread users with holder name Date: Wed, 24 Jun 2026 15:08:48 +0800 Message-ID: <20260624070851.13342-15-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782285088679158500 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 Sun Jul 26 12:38:42 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=1782285208; cv=none; d=zohomail.com; s=zohoarc; b=MwdXYAdHGsrq/mBtuyWtfRTBIhrUCp3w9ZlXN0JJe+HeOLBr/RUml2BX6Yud6VHeWfjljqFD+7dQzptvMzHvk3yArdHgxE0JnqX6yyexSvFrmLoCXyhF4887OWK47WEBJZt6lTRV6LMBH/hsmpeg360OzcanLIvUmm0M0KA1Rpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285208; 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=71CuRIyESyO5quaZSuqFa09qzy2utu3KI73qQbYqwt0=; b=ZVqQWxmCLEF3EingbzjhBttH15dlQNj43uDDD6SBodKKGYstgr+5THZwk/GcLtYFdivjd4k8vaeeU88FZzJVodpmGNY+wxROBnght3UDIZRXTjHbAx+BiwzQEZSEpCY2U2Bo+87JbnW8KxnJGMDrT1U024NsDavJ5VCTadakHFg= 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 1782285208211939.1085304812732; Wed, 24 Jun 2026 00:13:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHlp-0006ms-5m; Wed, 24 Jun 2026 03:11:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHkK-0005OA-Dg for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:10:14 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHkH-00037M-Iu for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:10:03 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-84232e83ca9so338308b3a.2 for ; Wed, 24 Jun 2026 00:10:01 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782285000; x=1782889800; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=71CuRIyESyO5quaZSuqFa09qzy2utu3KI73qQbYqwt0=; b=R4t0MBVvyD/8udSo6qE3ebkRDke+rYmRb8PNHGhQx9bJTfYMspyPO9IVfS0EEslHN5 pM/Nb+xJpBiRNyVRiARFssg29KEwPuWSNNrYdndDi72NjQ6RRf6ElVaiuL1e+aMhXqez /AkT5jfuq7ZXGDGOUxBdTVA0c+iE1PijxUYLOWBeM8IMt7WaZW7iz9+grTOZYxIjnET5 SQme0MqYssf+CJhhFFgp4jdofKAPjiozMcNGr6faqa4h3EpuC9KYTizN+x6DSVtjznwN B361sgIli4I6siwMie5Die+XobNYPKIhtxUpdaG1MSk8Jc0KyfafBO/2Q06v7SPZNoY2 ALmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782285000; x=1782889800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=71CuRIyESyO5quaZSuqFa09qzy2utu3KI73qQbYqwt0=; b=U9ruxket9E28kEcaoN3uUIDFsiH2AT/eCVcl8vh/A34779MZzUAp5WnxF1R+kP7Vq0 2lRaCxB+/Hbu7CS+cmp589nH7jJ/cI8NmcQJ9FT1P5hromU9quVWyoj2NsTu7uFxJdRs DF2cyi0zAU2b8DV9dybcBgq6ke/Eu8NX9ov744MsV2OwP5q80iUfvLIn2kSPueGQTX+D j1DeGLRPMHN1oJgO3wLgvBrp9Td81g5PuwZ4dBDUsxDQQ86kknMstQ/Vn8EXRGQYpGBz JyOWgtVX5/0UYltP0Pm8zry//3mJQHZzxAog/q0EAf6ouh4KxzVg9QwbZuPMLbe2F4au flEA== X-Gm-Message-State: AOJu0YywsBKgo1jhaXNigQ3t2mcjx1FI+Ryg1K+uP6zmKGYo9ezkmBop jsaZc1gGiHMzjjCvLQdn+Q2nyO0JRWY6Y29gG1af5/g9mcEP1XYtVbCAv/bGfp/g2Ik= X-Gm-Gg: AfdE7cmYkAo+Alfcyz8yGtrbTYd2WTuk2vEKd4R4sX2DJiMTpkdzPyU9E06aSdKD+BD q8Il3WZ5VbJd+XffMTQbT2hh3DVO0iVz5fqX9p9L0hIZMixQACRhEnRsVdy6/UoJOVEh6gkG5Ie aePxSxgcPlH1B2wb7vhmZV+mr2RWiH1Zwmh7BbNx87eRtI0wjUloHqoYZ9ljNLZSribmdt5iTAv kDSt1dhl806sgw3KEseoX1D2qr5AGOEyN+blblG+Kxn9Z7B+YqcMfp685Tr1GFhHxQUpUafjO/A odNA6XEs4kYZ8WdUZ8vsEmDqxGY85wLCbZKCwuN18JbL2ZfcpOyjsBtPsNpB+HlluHg6Xd5P6cS k0ppLRi4kfDr1hUDpPYShMHUTvJYsREDLbWyUEzouHYSfWVY57/xB2Yd6nP7M/gZdgNkEc3/2vG N80XK0Ou4rUV7wXg6FhmIY6QwzwmHe2GoXwLK714fZh9Oqj1u/iPNE X-Received: by 2002:a05:6a20:918d:b0:398:c0ba:9ceb with SMTP id adf61e73a8af0-3bd14f5b67cmr8101002637.12.1782285000249; Wed, 24 Jun 2026 00:10:00 -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 Cc: Zhang Chen Subject: [PATCH V9 15/17] qapi: examine IOThread attachment status via query-iothreads Date: Wed, 24 Jun 2026 15:08:49 +0800 Message-ID: <20260624070851.13342-16-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-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::435; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x435.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: 1782285210016158500 Content-Type: text/plain; charset="utf-8" Extend the 'IOThreadInfo' structure to include attachment metrics. This allows users to monitor the associated devices by identify them by their QOM paths, block nodes or monitors. New fields added to IOThreadInfo: @holders: IOThreadHolder of the devices currently associated with this iothread. Users can pre-allocate multiple iothread objects to serve as a persistent thread pool. When a device is hot-unplugged, it is detached from its iothread, but the iothread remains available, allowing future hot-plugged devices to attach to it. (Since 11.1) These fields are also exposed via the Human Monitor Interface (HMP) command 'info iothreads' to assist with manual debugging and performance tuning. Signed-off-by: Zhang Chen --- iothread.c | 22 ++++++++++++++++++++++ monitor/hmp-cmds.c | 26 ++++++++++++++++++++++++++ qapi/misc.json | 9 +++++++++ 3 files changed, 57 insertions(+) diff --git a/iothread.c b/iothread.c index a85e960e45..5949785b32 100644 --- a/iothread.c +++ b/iothread.c @@ -24,6 +24,8 @@ #include "qemu/error-report.h" #include "qemu/rcu.h" #include "qemu/main-loop.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-misc.h" =20 /* * iothread_ref: @@ -119,6 +121,25 @@ static void iothread_unref(IOThread *iothread, const I= OThreadHolder *holder) object_unref(OBJECT(iothread)); } =20 +static IOThreadHolderList *iothread_get_holders_list(IOThread *iothread) +{ + IOThreadHolderList *head =3D NULL; + IOThreadHolderList **prev =3D &head; + GList *l; + + for (l =3D iothread->holders; l; l =3D l->next) { + IOThreadHolder *src =3D l->data; + IOThreadHolderList *entry =3D g_new0(IOThreadHolderList, 1); + + entry->value =3D QAPI_CLONE(IOThreadHolder, src); + + *prev =3D entry; + prev =3D &entry->next; + } + + return head; +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -488,6 +509,7 @@ static int query_one_iothread(Object *object, void *opa= que) info =3D g_new0(IOThreadInfo, 1); info->id =3D iothread_get_id(iothread); info->thread_id =3D iothread->thread_id; + info->holders =3D iothread_get_holders_list(iothread); info->poll_max_ns =3D iothread->poll_max_ns; info->poll_grow =3D iothread->poll_grow; info->poll_shrink =3D iothread->poll_shrink; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 443b8c785d..1b5883147b 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -237,11 +237,37 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qd= ict) IOThreadInfoList *info_list =3D qmp_query_iothreads(NULL); IOThreadInfoList *info; IOThreadInfo *value; + IOThreadHolderList *h; =20 for (info =3D info_list; info; info =3D info->next) { value =3D info->value; monitor_printf(mon, "%s:\n", value->id); monitor_printf(mon, " thread_id=3D%" PRId64 "\n", value->thread_i= d); + monitor_printf(mon, " holders=3D"); + if (value->holders) { + for (h =3D value->holders; h; h =3D h->next) { + IOThreadHolder *holder =3D h->value; + + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_BLOCK_NODE: + monitor_printf(mon, "[block-node: %s]", + holder->u.block_node.node_name); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_printf(mon, "[qom-path: %s]", + holder->u.qom_object.qom_path); + break; + case IO_THREAD_HOLDER_KIND_MONITOR_NAME: + monitor_printf(mon, "[monitor-name: %s]", + holder->u.monitor_name.monitor_name); + break; + default: + monitor_printf(mon, "[unknown]"); + break; + } + } + monitor_printf(mon, "\n"); + } monitor_printf(mon, " poll-max-ns=3D%" PRId64 "\n", value->poll_m= ax_ns); monitor_printf(mon, " poll-grow=3D%" PRId64 "\n", value->poll_gro= w); monitor_printf(mon, " poll-shrink=3D%" PRId64 "\n", value->poll_s= hrink); diff --git a/qapi/misc.json b/qapi/misc.json index d9f82f0922..6486c62ab5 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -137,6 +137,11 @@ # # @thread-id: ID of the underlying host thread # +# @holders: the QOM objects, block nodes or monitors 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) # @@ -159,6 +164,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -185,6 +191,8 @@ # { # "id":"iothread0", # "thread-id":3134, +# "holders":[{"qom-path": "/machine/peripheral/blk1/virtio= -backend", "type": "qom-object"}, +# {"monitor-name": "compat_monitor0", "type": "= monitor-name"}], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, @@ -193,6 +201,7 @@ # { # "id":"iothread1", # "thread-id":3135, +# "holders":[{"node-name": "fmt_qcow2", "type": "block-nod= e"}], # "poll-max-ns":32768, # "poll-grow":0, # "poll-shrink":0, --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285225; cv=none; d=zohomail.com; s=zohoarc; b=gd1SOGVoCMo08Btzj6jpKIQOZUglsi2k84LQhy0UdaCkIwQnrHbtyig6dzE4BtbKb+Z+1N1VqAm5jhh7l2do/HaVjJ81o5c31eOsxvXWTroQ48ALnC20YVaEdAX1FWYwgOmBgzKaDtBPdn0XKHBWam1hrj5055kp2QWi291eRdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285225; 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=yajFGcoHm9h0GZaIRtI9B2CHBQnTxVVpKNwZ6WZ6HJ8=; b=ZgVjeFSx1vo2NJE8mUWTyJsFqIwqTaKOhlzGp2hGoxDG8utsEwScteZRLnv3SR/NAFu6PcPu1/o3KfVvLz7zqImepOpA3ocN0tfZzys58BmLWmumgYQw+FS6N0b759QN5he5SUkDtvZq5wsAOeDEB7j9+yxV21FfxWgumhjCkl0= 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 1782285225304997.0178216239744; Wed, 24 Jun 2026 00:13:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHlh-0006ir-RW; Wed, 24 Jun 2026 03:11:32 -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 1wcHkN-0005OP-Eu for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:10:17 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHkL-00037v-D4 for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:10:07 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-c88d4606ec8so246256a12.0 for ; Wed, 24 Jun 2026 00:10:05 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.10.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782285004; x=1782889804; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yajFGcoHm9h0GZaIRtI9B2CHBQnTxVVpKNwZ6WZ6HJ8=; b=sYGmSXlqPU3vLH9ngs1ucrfHb/Vzw+yifEAiqlthvnQoE+g+Y4lfrC8xLC8Vf4whbu u2nHWJabgLx4P7iUAtLvkvr/FVgbiwtJwOQLsbI7ep+BvhZ+BUc6qcQCSwmjBuSFJRUx L1np2OHSukCs3sfuMe5bJsnFWkCKjCEdmpq+GAcoFVnVgneO/ObYVh0RacRNFS6zi22U Sk1Kp83JrSyXq+GU5xcEhMedWfRCKiquxvqI0ECy3xDM512cZRrCQIIG1G4XW/Sd+Jw1 EH0j2fPG8Acc/o6j8LqZMKOg3QgwyqYH3VlZBsfhxlsdpFC9n+tyPuOLOF8+RjaQlXPY dChg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782285004; x=1782889804; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yajFGcoHm9h0GZaIRtI9B2CHBQnTxVVpKNwZ6WZ6HJ8=; b=qHjWDCaT3Dxuw+/vHilS7o2f33KyhvKT+LRx8G6jq/sOO+i5pWBrHySSlaOfStegCP FKs8FUd6xYoV/qpWs0vP759bS6Xl36jefpNRRlp2yNHjxTnw/vM6fJ4Np527/hUnI1Vx I1EhG0Ly6EqYErtuRPsq99LTl2pmnvOVALBJXbi222nIEJO95UUHTKT6LN+ZF1bv4Kvb iqFud7DHi4Jkt6k+D32boP6E6ofzkfWp9qfJ2QuDWRO9gCBvzR4XkdghnqUJepc3scC8 utC29fUslrR+C1zQxINpba3jCeW5Nc1GGiEvq4f7gA9PbRqMfphHlx2zEt4HVcDhV6n/ oKdQ== X-Gm-Message-State: AOJu0YxjqAZcrNhi3Ls4nrDZZ8pTgX+12Gb3SpnEUlcfs6Lm4GQEDOOC 70dzW3lTwTi73XKzi+OVcx/fCccZxgxXAlAE9ex0UK/J6NATFvaeFxNTDkXV4WrW8BQ= X-Gm-Gg: AfdE7clz31WdC9wm+wn9CfOlhUG/oryDPE06SCda8XLd7tZ7C6UTOlAAxg1qq9qGru7 ApnS/6RnUiOXRSQ7tdXD7VH12vl8zRHYrXFRxpKQ3OkcwZc6gAbn7wDtNbCViPCp9+BMTy69SkQ tVeuA7JR0PIEfQLJyDrdo1iOswe9Eg6EVbyMGUopIK4pQwCrEJjI7DQso1vBzbd+fe8xg6RJhAn r0EcXFqe5S78x1dMfmPnOBL9S7LfwNsmowm9D263T7L7f560ze9G3NaRC7pi3lqBGRVkDkdEowT bE7me9II5aVxo3ncCdnP6Y892b2p58wYUiwIpDoGlvPmtGZkKR/SfBktbdLk3qFqdlAj6ourHxH 0gjd+v4QevxkfRxSbBFCXFbu8B2xdQTKokny5O+7tPhBtfA6ib20P/J+MgTEdpqEv0oFYFjXGuO 8KExae4k1tk3f2UCAyK0SRlakSNcbA7YwpT1eY2iGkVb4rk9OfsYBp X-Received: by 2002:a05:6a21:7481:b0:3b4:85db:1bd0 with SMTP id adf61e73a8af0-3bd2cee4c4amr2617232637.12.1782285004000; Wed, 24 Jun 2026 00:10: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 Cc: Zhang Chen Subject: [PATCH V9 16/17] iothread: simplify API by merging iothread_get_aio_context variants Date: Wed, 24 Jun 2026 15:08:50 +0800 Message-ID: <20260624070851.13342-17-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782285225836158500 Content-Type: text/plain; charset="utf-8" Simplify the interface by merging iothread_ref_and_get_aio_context() into iothread_get_aio_context(). The updated function now requires a 'holder' parameter, ensuring that every retrieval of an AioContext for long-term use is automatically registered in the IOThread's holder list. Update all callers across block, virtio, scsi, net, and monitor subsystems to match the new signature. This cleanup reduces code redundancy and improves the reliability of IOThread introspection. Signed-off-by: Zhang Chen --- block/export/export.c | 5 ++--- hw/block/dataplane/xen-block.c | 4 ++-- hw/block/virtio-blk.c | 4 ++-- hw/scsi/virtio-scsi-dataplane.c | 4 ++-- hw/vfio-user/proxy.c | 3 +-- hw/virtio/iothread-vq-mapping.c | 3 +-- hw/virtio/virtio-balloon.c | 2 +- include/system/iothread.h | 6 +++--- iothread.c | 9 ++------- monitor/monitor.c | 2 +- net/colo-compare.c | 2 +- 11 files changed, 18 insertions(+), 26 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b6c07f69b5..acd061e86e 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -146,7 +146,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) .u.block_node.node_name =3D (char *)holder_name, }; =20 - new_ctx =3D iothread_ref_and_get_aio_context(iothread, &holder); + new_ctx =3D iothread_get_aio_context(iothread, &holder); multithread_count =3D 1; local_iothreads =3D g_new0(IOThread *, 1); local_iothreads[0] =3D iothread; @@ -190,8 +190,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) goto fail; } local_iothreads[i] =3D iothread; - multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, - &hold= er); + multithread_ctxs[i++] =3D iothread_get_aio_context(iothread, &= holder); } assert(i =3D=3D multithread_count); } diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index b5bf8d359f..46bfd62f5a 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -628,8 +628,8 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice= *xendev, }; =20 dataplane->iothread =3D iothread; - dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, - &io_holder); + dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index d8dc1dd136..d1d2bd7025 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1502,8 +1502,8 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, .u.qom_object.qom_path =3D (char *)path, }; - AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, - &io_holder); + AioContext *ctx =3D iothread_get_aio_context(conf->iothread, + &io_holder); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index c71f33b41e..76ab22610f 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -78,8 +78,8 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, .u.qom_object.qom_path =3D (char *)path, }; - AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, - &io_holder); + AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 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 064c05e78d..e5db215954 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -70,15 +70,15 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, =20 char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); -AioContext *iothread_get_aio_context(IOThread *iothread); + /* * The iothread_unsafe_get_aio_context() is a low-level unsafe way of gett= ing * the AioContext, recommend migrating to the new API with IOThreadHolder * as much as possible. */ AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const IOThreadHolder *holder); +AioContext *iothread_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder); void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *ho= lder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 diff --git a/iothread.c b/iothread.c index 5949785b32..9bc8e359c1 100644 --- a/iothread.c +++ b/iothread.c @@ -469,13 +469,8 @@ char *iothread_get_id(IOThread *iothread) return g_strdup(object_get_canonical_path_component(OBJECT(iothread))); } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} - -AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, - const IOThreadHolder *holder) +AioContext *iothread_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) { /* Add IOThreadHolder to the list */ iothread_ref(iothread, holder); diff --git a/monitor/monitor.c b/monitor/monitor.c index 98727f3d20..07f2f4dbe2 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -623,7 +623,7 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool = skip_flush, .u.monitor_name.monitor_name =3D id ? (char *)mon->id : (char *)mon->chr.chr->labe= l, }; - iothread_ref_and_get_aio_context(mon_iothread, &holder); + iothread_get_aio_context(mon_iothread, &holder); } qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; diff --git a/net/colo-compare.c b/net/colo-compare.c index 4f180936e3..820ea4d824 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -973,7 +973,7 @@ static void colo_compare_iothread(CompareState *s) .u.qom_object.qom_path =3D (char *)path, }; =20 - AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, &io_= holder); + AioContext *ctx =3D iothread_get_aio_context(s->iothread, &io_holder); =20 s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); --=20 2.49.0 From nobody Sun Jul 26 12:38:42 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=1782285225; cv=none; d=zohomail.com; s=zohoarc; b=mwtri0F0KS/KgqymX0MaMADHWN+nvvqx72a1IsrNJM8ystb8WesoXjrGAqcCqhSI48pPsXZ+HdzyJk5DjTxCqqTgGzK7JAt+Lc0hfCcy+oq37zTMhqpYDS6sEqPU4xhDXlEfcwYXZTr1HB7GDw9+1Gn3IDMG/6inUpuYABDVOiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782285225; 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=UkUF9X4N/zvsN3BCVzFRUfS4katE7lDON7K/8UacfzpP/+Qrf3HD5OIGU8gR0oev3gh1jDbW3y3mkQ+qAnLK+/J3FhGbwEMBdUtEjaUTFPSdoYxwxVEcS4JUwzXx0NzgdrNNKYG1enJBRU/rqyTspTbiE5IbMlAgbmdrHW+hS0k= 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 1782285225295271.765657120451; Wed, 24 Jun 2026 00:13:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHm5-00079q-MS; Wed, 24 Jun 2026 03:11:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wcHkT-0005Rf-IQ for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:10:22 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHkR-00038R-Dt for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:10:13 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-c88b59bfba7so276613a12.1 for ; Wed, 24 Jun 2026 00:10:09 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.10.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782285008; x=1782889808; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pjpcTIVOjjU2T3U84XrTlI69hFe/P5txjri+hVbKO1s=; b=o4GYFbqa4rFOG1XcCteEzJywCEzIKR1WszZ9hy+H0dFnbZv+jD1m4tXzSiKnkHQIxY wsu0aePXtVz9VF+ftFMwN7/PkNyi8NtzMHl9lvfsYKu6uuJU4i5sAgECkGssaS6aA728 bE0tDaX1tuujK4PeBOKvM31obfUcOwPTaTZVxl6LkQJmgQ2YGkeQGhZikIiZKFm1RHfj sMyvHksz+2XJEieiaFfAk/ytm++gbpalCCL7dg/nZA6heVo+CMkvH1/j1S1VZFYm/VxQ aLlxTukKw9v1ZHdHOKtFZjEqtgzITaKzQl52j1XZDqzVdabpkY2EmcRItayyVQW+LhQe G9mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782285008; x=1782889808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=pjpcTIVOjjU2T3U84XrTlI69hFe/P5txjri+hVbKO1s=; b=lIcrE+Ia1kFfoEwx2Rbbe0WYmhFU2NT2dQhYNBtBhx+6NJkDu6HSvH9ynWjvylxTPb CkuycegEgkQ6vgNJuP9+0qCdOqFUMrzFIy/avtLVrPivkdnrY4h3NDkb+McY9fcSNMko a1eiSljPh9WuYU75hkV7b/+BvoA6U2CkKI5jPFerVRJUJlcXAcnlFQZaREXTdZaeHdAi igBnJZPgqEuD17TpJkltFYjlPXW1blAnS7rEU1mFqji955orXFZg1nsx6J755772dlac OujD2dseqMFSdExP5+axH3rdcX/qARXNFrUCmi5uqbknCpq3Jh5Z/MY8p/ckQlGdo5id y1Pw== X-Gm-Message-State: AOJu0YzrW3p6EiGLd/6xGpNsVB5jvreWyX8A+TNablVtD3Xrwyt8cQ0N n23bLo573Actt6LHYj4F7J0lgNKIpRI7jgGwRAiwdD5w2WFClc49De5Bvlq2aHqInP0= X-Gm-Gg: AfdE7cn7ufhMHQCWatCrrjwg5viuCopkiBOPg7GaV9cVZopH7WiH5YP223r/WKGxRtl kq3gsA0qm85uhjkXCMV5PWF9ffRWjx+cO5mM+D/mncN6/AgqXjdqTmvukviOc13SdZmpGRhtTiM /+j+IgzwRfUIzu1qOJO53zMieF3j8H8USxJ7aP3tQqsHjDjjkurjM8PMaL11leN3NJfGkaqJZTL guH/vZhEFrI1fl0Sp0mj9LrHQnnE6tHNXYRXf/HC/REUq/2qOg25i+u1DgRr3+AystLqGXteA6O iYFjPyGVBbsg/Tn9+8frwm34QzfTq4gQCsbMRYlrrelPkgJQ6Z5COtphI2K819nIhJ6WzPJhKQU B6TYvdBcVFo6ULTytXuxxu/2ECWtN6Y5uNElLNxVSYxGgWt1Yf4oWGsdfkmspMh7zZGG0vXOx2M 2avhVqhM+0pxky7MF49gLFKBt7gq5CuM6puOUv//DQXfSviamdCkyo X-Received: by 2002:a05:6300:670a:b0:3a1:ed2a:1a4f with SMTP id adf61e73a8af0-3bd2cef5684mr2763547637.16.1782285008035; Wed, 24 Jun 2026 00:10: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 Cc: Zhang Chen Subject: [PATCH V9 17/17] tests/unit/iothread: Update the iothread_get_aio_context Date: Wed, 24 Jun 2026 15:08:51 +0800 Message-ID: <20260624070851.13342-18-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1782285225823158500 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