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 3EEC6C5CFCF for ; Fri, 14 Aug 2026 17:50:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wuw2H-00052l-RC; Fri, 14 Aug 2026 13:49:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wuw2F-0004xc-LY for qemu-devel@nongnu.org; Fri, 14 Aug 2026 13:49:39 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wuw2D-000822-Gu for qemu-devel@nongnu.org; Fri, 14 Aug 2026 13:49:39 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-38e07ebd263so970140a91.1 for ; Fri, 14 Aug 2026 10:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786729775; x=1787334575; 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=+Gr8St5EO1BsnpFz32ySg27QNFhY9T+mtmb4DDOFigs=; b=Ww/JQLxfs0esSKTu0HIDVF+BB15aHogQyWzcpiJ8d9uHv+PJtOwa0unOdJuVlkKANw eJDVsLWm0BXpFLsL3TJquKKlASf9jQVgjnPI76jpcRqBxslEb6DxK0uOIgyFM3qeU6FQ Hpyii7znpxF2eb50u4v+OkQkoNyxyB4pgd8P/EIA1Of9pgOLL+agVqmssjNGiQI1CPz3 uUoc5yn6YbVZ2N6gxZq46QTxS6Qp2dFaMeSM2p/6QBE+kkcUvNQHQVXXpFdh4DsVwoED t/5SjMEkY8kN857tlJXeocYmUZfXmEV53DfpfvObAyFRt9nMbC59wKyo/8GnCx3G4Wkt IaIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786729775; x=1787334575; 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=+Gr8St5EO1BsnpFz32ySg27QNFhY9T+mtmb4DDOFigs=; b=HFTe5Y8FfB8rataN+iuC6jT6QKwQf4tOywQhVst4bQTgUHlMHPSIg76H0MWrsins4A wJyCk9vsJB7Um8LNCojT0cB+TbAfR1vc6F4tzW5vQJusICcGWGAXDzva49+3W58VpTg8 /MShxz3YILHpWQzkKPegPJbXoBrsyGHmzI+bSgLqkJP4SZNmLySO3LHLMY1QFxTsRJff q7paBG9I4qVpcOq+gvyV//YpkFzJcTBX0t27jmLgZ+cq6TunmbHdHEHWsPeUriI1gMDw Y7hJGlvwLN3FkPmG2/izo9rs0KytXwtBCv9LwbS8L+ET3CCxE6aWZLreoAGyoTiQILZ1 6nmw== X-Gm-Message-State: AOJu0YwpVe+SmXRphxAm0FIM8wtWl2w/HJtTQvnoWQ1Q2tk6d1ZnBV9A xrcyulxBe3oHW451wV7CqQGbdAE40FLeaPfmCp0OG0cDTheoDM1/ExPN6PFwZg== X-Gm-Gg: AR+sD13e+XP9mjxwkYUvNeJMFbKH/1e1Dg+LUZu/UpJ/l7GSEkv41nwrgTnyKEK6ADn i2XyGSPMdCCxPmwy+p/ciC2WfyW8lrbxkDrr2u0ccbPpZHSnfCrXdCKiyl1FNrF5M5G9oYfTPjb qrvjvJ2gtSWMITfwIbtRUmlXsAxAsx16B0MGy2Fsjn4jn9POjvLgzuJ+kBXkQFn2tI23scBV2Mh RsZQPujNChC670GBjBBrOjR8/+8zY1fTpyl8G5/HLfBP/n9B5mvaGSOEOLUD0DlBQpx2HGK6oJ+ IRZAyCT06CahVjs5oiZEkDdNr1Rr6KPVHaaJ+9hEp0dRakdInN/lRuSg7bdkiv06W1C4/GX7f0i kmF3+MRLRddplus8X5t9GpUzU232mWulDCWujjsPMH2oIzhtUlqE9q51xjbhdnlcIgCqNVA439B XxiszuBED1Lq2uPY4vNXwopUpHdiBxAP/HXXwdivQNbgg23p6/PMi87DO70ZEql6U/2luCwKWwl o1tXBAVbDiOSv5TDv0= X-Received: by 2002:a17:90b:264c:b0:38d:ddc2:7ccb with SMTP id 98e67ed59e1d1-3933b714f34mr8518678a91.1.1786729775373; Fri, 14 Aug 2026 10:49:35 -0700 (PDT) Received: from catgo-fnos.taila0cd24.ts.net ([104.28.233.73]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320e9df03f9sm6708081eec.19.2026.08.14.10.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 10:49:34 -0700 (PDT) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V12 15/15] tests/unit/iothread: update AioContext ref/put helpers Date: Sat, 15 Aug 2026 01:48:29 +0800 Message-ID: <20260814174830.1691540-16-zhangckid@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260814174830.1691540-1-zhangckid@gmail.com> References: <20260814174830.1691540-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102b.google.com X-Spam_score_int: 26 X-Spam_score: 2.6 X-Spam_bar: ++ X-Spam_report: (2.6 / 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_BL_SPAMCOP_NET=1.347, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 Update the unit-test IOThread stubs and callers to use iothread_ref_and_get_aio_context() together with the matching iothread_unref_and_put_aio_context(). Signed-off-by: Zhang Chen --- tests/unit/iothread.c | 18 ++++++++++++------ tests/unit/iothread.h | 7 ++++++- tests/unit/test-aio-multithread.c | 5 ++++- tests/unit/test-bdrv-drain.c | 18 +++++++++++++----- tests/unit/test-block-iothread.c | 21 ++++++++++++++------- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/tests/unit/iothread.c b/tests/unit/iothread.c index a363bf8f70..790cd2dce7 100644 --- a/tests/unit/iothread.c +++ b/tests/unit/iothread.c @@ -30,12 +30,23 @@ struct IOThread { bool stopping; }; +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ + return iothread->ctx; +} + +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ +} + static void iothread_init_gcontext(IOThread *iothread) { GSource *source; iothread->worker_context = g_main_context_new(); - source = aio_get_g_source(iothread_get_aio_context(iothread)); + source = aio_get_g_source(iothread->ctx); g_source_attach(source, iothread->worker_context); g_source_unref(source); iothread->main_loop = g_main_loop_new(iothread->worker_context, TRUE); @@ -113,8 +124,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..9bdac074c0 100644 --- a/tests/unit/iothread.h +++ b/tests/unit/iothread.h @@ -17,9 +17,14 @@ #include "qemu/thread.h" typedef struct IOThread IOThread; +typedef struct IOThreadHolder IOThreadHolder; + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder); +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder); IOThread *iothread_new(void); void iothread_join(IOThread *iothread); -AioContext *iothread_get_aio_context(IOThread *iothread); #endif diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multithread.c index 9179cdc6a3..66ba5a466b 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) for (i = 0; i < NUM_CONTEXTS; i++) { threads[i] = iothread_new(); - ctx[i] = iothread_get_aio_context(threads[i]); + ctx[i] = iothread_ref_and_get_aio_context(threads[i], NULL); } qemu_event_init(&done_event, false); @@ -87,6 +87,9 @@ static void join_aio_contexts(void) for (i = 0; i < NUM_CONTEXTS; i++) { aio_context_ref(ctx[i]); } + for (i = 0; i < NUM_CONTEXTS; i++) { + iothread_unref_and_put_aio_context(threads[i], NULL); + } for (i = 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..05c31ffca8 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) IOThread *a = iothread_new(); IOThread *b = iothread_new(); - AioContext *ctx_a = iothread_get_aio_context(a); - AioContext *ctx_b = iothread_get_aio_context(b); + AioContext *ctx_a = iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b = iothread_ref_and_get_aio_context(b, NULL); QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); @@ -612,6 +612,8 @@ static void test_iothread_common(enum drain_type drain_type, int drain_thread) bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); out: iothread_join(a); @@ -762,7 +764,7 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type, AioContext *ctx; iothread = iothread_new(); - ctx = iothread_get_aio_context(iothread); + ctx = iothread_ref_and_get_aio_context(iothread, NULL); blk_set_aio_context(blk_src, ctx, &error_abort); } @@ -892,6 +894,10 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type, bdrv_unref(src_overlay); bdrv_unref(target); + if (use_iothread) { + iothread_unref_and_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 = iothread_new(); IOThread *b = iothread_new(); - AioContext *ctx_a = iothread_get_aio_context(a); - AioContext *ctx_b = iothread_get_aio_context(b); + AioContext *ctx_a = iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b = iothread_ref_and_get_aio_context(b, NULL); bs = 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_abort); bdrv_unref(bs); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_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-iothread.c index 5273ff235a..fc9735d056 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 = opaque; IOThread *iothread = iothread_new(); - AioContext *ctx = iothread_get_aio_context(iothread); + AioContext *ctx = iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; BdrvChild *c; @@ -493,6 +493,7 @@ static void test_sync_op(const void *opaque) bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } typedef struct TestBlockJob { @@ -549,7 +550,7 @@ BlockJobDriver test_job_driver = { static void test_attach_blockjob(void) { IOThread *iothread = iothread_new(); - AioContext *ctx = iothread_get_aio_context(iothread); + AioContext *ctx = iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; TestBlockJob *tjob; @@ -595,6 +596,7 @@ static void test_attach_blockjob(void) bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } /* @@ -612,7 +614,7 @@ static void test_attach_blockjob(void) static void test_propagate_basic(void) { IOThread *iothread = iothread_new(); - AioContext *ctx = iothread_get_aio_context(iothread); + AioContext *ctx = iothread_ref_and_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_unref_and_put_aio_context(iothread, NULL); } /* @@ -676,7 +679,7 @@ static void test_propagate_basic(void) static void test_propagate_diamond(void) { IOThread *iothread = iothread_new(); - AioContext *ctx = iothread_get_aio_context(iothread); + AioContext *ctx = iothread_ref_and_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_unref_and_put_aio_context(iothread, NULL); } static void test_propagate_mirror(void) { IOThread *iothread = iothread_new(); - AioContext *ctx = iothread_get_aio_context(iothread); + AioContext *ctx = iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx = 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_unref_and_put_aio_context(iothread, NULL); } static void test_attach_second_node(void) { IOThread *iothread = iothread_new(); - AioContext *ctx = iothread_get_aio_context(iothread); + AioContext *ctx = iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx = 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_unref_and_put_aio_context(iothread, NULL); } static void test_attach_preserve_blk_ctx(void) { IOThread *iothread = iothread_new(); - AioContext *ctx = iothread_get_aio_context(iothread); + AioContext *ctx = iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; @@ -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_unref_and_put_aio_context(iothread, NULL); } int main(int argc, char **argv) -- 2.54.0