From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED637C4450A for ; Thu, 16 Jul 2026 14:47:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkNJU-0007GN-FW; Thu, 16 Jul 2026 10:43:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkNHa-000604-2u for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:50 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wkNHX-0007Aj-IG for qemu-devel@nongnu.org; Thu, 16 Jul 2026 10:41:49 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2cc97653887so76355945ad.1 for ; Thu, 16 Jul 2026 07:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784212906; x=1784817706; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3QDsfYN2rfgBtltKnnC9maVXXTU4QyxaR/nwD59M78o=; b=sSoHNxS05/GacQDbZa4W5H8uX9N4MzV8sA7h/JiHyPAUTBDZ+/qV/JlAs/dhZG/Fy3 obt9oSAX7aSyGsSbpvK1l5U4wyDFF7Y6fdtDkNd6DzgZjWqaVmED9O30Wqv2yYjxxCQ3 /Ja6UGY1qyLwAXZAmDDdy1rcCRvEqJ4iYHyfJtQWJR4kBToSnB4oEEHMzqLGSfkXeuKQ ul7nagvdKLipZOKlYvWt235/tB6nGh0knuIlBqv6XTncc+FEMCznbuhKrZCJugHWPKCB iTX3mrm30FRNaTFNE+itbcNshCc3siA0YhtwhMVCn+ICD57PjYGgLWY8K3j5ZdzVVLir Nsqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784212906; x=1784817706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3QDsfYN2rfgBtltKnnC9maVXXTU4QyxaR/nwD59M78o=; b=QbjqQABIX/l4HoXEzMJcgw9pujMm4rSNvFB2zfCVcR/IVBod4PrkcNTo/vWmC96+fR KI0ZgjEufSKkjL2XR3NPtMjcrImsId4X34jAQcGaf08LKVDgIJ4o8442dCTHhrcowUuD I4bbmKyNXrpVOZGvwQbA5Ua95Qi7dNP15n1zlucLU0sMwaxS+DcyQM0Y102EMHT23CjF s6sS0GkEuv/0oqDI56byGNgmx1PMsBk/anUkqun045e5Ralh+cZZDtbNKTbJr/qmWKe1 vmQfXMDfwfSltvP/lLd5F2aDBDSZuvO/vV6UgpGWHHzsrg09iqbzIluLMWwUzaoON4j6 KZbA== X-Gm-Message-State: AOJu0YzB+SdJfMgrxyY4ya+Dtci1lRlsp65lSb43VlAZMwpNdgZOVyq0 7qQ+t6DdhBe9FTUAT/jvSVRn603cwKGDofuujJRoPszB+KerCo5mrjtmZha3M4wGNxM= X-Gm-Gg: AfdE7cm3Aqgr1o+cZmqFta0zKsh3aTPBLN1bixwEicb3g3XoYmcbbA8UBPQCBgTiykh L7oFtDtqf6/7LiJHX1Plu+XyRNRtqgUibLjBKURgRRuuXXkG7LMh1a0YrTPsE/BxD4a7Q251mVJ 6Cll8mpm9AHESq36qM7VIVblgQ4CWIdok+1DUoMfXlStuU1tfAcSAWf+8mH7nnrYCO0Tx4LxmDA EYQdnS1ZkTAXQZDmekdpPIbhbO4+lNGyAedylnQAt2iTmmQxrNnZyYFtb+BIGu0ObWcZTepEvjp f1FSp6ooPdBIhyYFcrVuM0LG2bgkTL4Jk+norCHzemsuf1vFSIfqaV0slxNlzC2nlVzWPO5grNv 3winhAjlbCi95To4eAOh07ncy83/zZlqaoKhDsNElWvDq9qEjm+gFLBEBf0Rraf/mBZrNHdol++ FESlhqf6YLT/p6FiK+7aJprQhkarGM32msjzA0Iwsn+Zc4irod2jY= X-Received: by 2002:a17:903:124a:b0:2ce:f9db:a9e0 with SMTP id d9443c01a7336-2cf03ce29a0mr71999955ad.16.1784212905870; Thu, 16 Jul 2026 07:41:45 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::677]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf100e42a1sm20991165ad.15.2026.07.16.07.41.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 07:41:45 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [PATCH V10 04/15] iothread: introduce iothread_unsafe_get_aio_context() Date: Thu, 16 Jul 2026 22:40:29 +0800 Message-ID: <20260716144043.76414-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716144043.76414-1-zhangckid@gmail.com> References: <20260716144043.76414-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Normally the IOThread's AioContext is fetched using iothread_ref_and_get_aio_context(), but there are legacy callers without a clear ref/unref lifecycle. They cannot unref (e.g. because they do not have an IOThread pointer), so provide an unsafe way to fetch the AioContext without holding a reference count. This unsafe API serves legacy callers - do not use it in new code. Signed-off-by: Zhang Chen --- blockdev.c | 2 +- include/system/iothread.h | 9 +++++++++ iothread.c | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 6e86c6262f..baeab3a3e1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,7 +3683,7 @@ void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread, goto out; } - new_context = iothread_get_aio_context(obj); + new_context = iothread_unsafe_get_aio_context(obj); } else { new_context = qemu_get_aio_context(); } diff --git a/include/system/iothread.h b/include/system/iothread.h index 86f02c5a7d..3cce5eeb09 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -78,6 +78,15 @@ IOThread *iothread_by_id(const char *id); * thread-safe and must be called under the Big QEMU Lock (BQL). */ AioContext *iothread_get_aio_context(IOThread *iothread); +/* + * Normally the IOThread's AioContext is fetched using + * iothread_ref_and_get_aio_context(), but there are legacy callers + * without a clear ref/unref lifecycle. They cannot unref (e.g. because + * they do not have an IOThread pointer), so provide an unsafe way to + * fetch the AioContext without holding a reference count. This unsafe + * API serves legacy callers - do not use it in new code. + */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, const IOThreadHolder *holder); void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *holder); diff --git a/iothread.c b/iothread.c index f5d4708b25..157bb4d302 100644 --- a/iothread.c +++ b/iothread.c @@ -449,6 +449,12 @@ void iothread_put_aio_context(IOThread *iothread, const IOThreadHolder *holder) iothread_unref(iothread, holder); } +/* Recommend migrating to the new API with IOThreadHolder as much as possible */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread) +{ + return iothread->ctx; +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail = opaque; -- 2.49.0