From nobody Wed Apr 16 08:19:20 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558369642; cv=none; d=zoho.com; s=zohoarc; b=DZbrXAsuOvYHzwNcR81nl6BZ0uQDQqKPD5BLBJv4UautxAnS1kz0gnZU6BdD87WkuMUepPHlZ6f6qzexb4UPx4X2tRmD0+mzhFLgn9fsHXUwkFFBaSCGC1dAJXuIDqNJrPh58LKLUhhuzzbnmUh5uAog9dkrTtA592hGjv0MBKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558369642; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=X2NKChOY0dMyftuEVfvb2MDlzrlspY7bVt/ktIz0D40=; b=ZljsZS7WYp2IrLzPVuySkiOV/t628+xSnmO47MX5N5qWXOCn0O1gSL18IGcuy8eOmG/rvQKh4qzLEvAYVCOKpWGFcbis3CinPu3LOMVKP4L7kIE83F6DN5/hSpQbCN7k05l2cjyqrZcIQUDq1QNsoFrsApyeyGOqFmUt427HQwU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155836964278354.065714567531586; Mon, 20 May 2019 09:27:22 -0700 (PDT) Received: from localhost ([127.0.0.1]:38188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSl8C-0001R5-B0 for importer@patchew.org; Mon, 20 May 2019 12:27:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSkwt-0008Io-Mz for qemu-devel@nongnu.org; Mon, 20 May 2019 12:15:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSkws-0003av-IL for qemu-devel@nongnu.org; Mon, 20 May 2019 12:15:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hSkwp-0003XN-E3; Mon, 20 May 2019 12:15:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4632913A5C; Mon, 20 May 2019 16:15:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57325D1E4; Mon, 20 May 2019 16:15:23 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 20 May 2019 18:14:40 +0200 Message-Id: <20190520161453.30723-12-kwolf@redhat.com> In-Reply-To: <20190520161453.30723-1-kwolf@redhat.com> References: <20190520161453.30723-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 20 May 2019 16:15:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/24] test-block-iothread: Test AioContext propagation through the tree X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf --- tests/test-block-iothread.c | 131 ++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c index 036ed9a3b3..938831c9bd 100644 --- a/tests/test-block-iothread.c +++ b/tests/test-block-iothread.c @@ -27,6 +27,7 @@ #include "block/blockjob_int.h" #include "sysemu/block-backend.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "iothread.h" =20 static int coroutine_fn bdrv_test_co_prwv(BlockDriverState *bs, @@ -459,6 +460,134 @@ static void test_attach_blockjob(void) blk_unref(blk); } =20 +/* + * Test that changing the AioContext for one node in a tree (here through = blk) + * changes all other nodes as well: + * + * blk + * | + * | bs_verify [blkverify] + * | / \ + * | / \ + * bs_a [bdrv_test] bs_b [bdrv_test] + * + */ +static void test_propagate_basic(void) +{ + IOThread *iothread =3D iothread_new(); + AioContext *ctx =3D iothread_get_aio_context(iothread); + BlockBackend *blk; + BlockDriverState *bs_a, *bs_b, *bs_verify; + QDict *options; + + /* Create bs_a and its BlockBackend */ + blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + bs_a =3D bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_= abort); + blk_insert_bs(blk, bs_a, &error_abort); + + /* Create bs_b */ + bs_b =3D bdrv_new_open_driver(&bdrv_test, "bs_b", BDRV_O_RDWR, &error_= abort); + + /* Create blkverify filter that references both bs_a and bs_b */ + options =3D qdict_new(); + qdict_put_str(options, "driver", "blkverify"); + qdict_put_str(options, "test", "bs_a"); + qdict_put_str(options, "raw", "bs_b"); + + bs_verify =3D bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort= ); + + /* Switch the AioContext */ + blk_set_aio_context(blk, ctx); + g_assert(blk_get_aio_context(blk) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_a) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_verify) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_b) =3D=3D ctx); + + /* Switch the AioContext back */ + ctx =3D qemu_get_aio_context(); + blk_set_aio_context(blk, ctx); + g_assert(blk_get_aio_context(blk) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_a) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_verify) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_b) =3D=3D ctx); + + bdrv_unref(bs_verify); + bdrv_unref(bs_b); + bdrv_unref(bs_a); + blk_unref(blk); +} + +/* + * Test that diamonds in the graph don't lead to endless recursion: + * + * blk + * | + * bs_verify [blkverify] + * / \ + * / \ + * bs_b [raw] bs_c[raw] + * \ / + * \ / + * bs_a [bdrv_test] + */ +static void test_propagate_diamond(void) +{ + IOThread *iothread =3D iothread_new(); + AioContext *ctx =3D iothread_get_aio_context(iothread); + BlockBackend *blk; + BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify; + QDict *options; + + /* Create bs_a */ + bs_a =3D bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_= abort); + + /* Create bs_b and bc_c */ + options =3D qdict_new(); + qdict_put_str(options, "driver", "raw"); + qdict_put_str(options, "file", "bs_a"); + qdict_put_str(options, "node-name", "bs_b"); + bs_b =3D bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); + + options =3D qdict_new(); + qdict_put_str(options, "driver", "raw"); + qdict_put_str(options, "file", "bs_a"); + qdict_put_str(options, "node-name", "bs_c"); + bs_c =3D bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); + + /* Create blkverify filter that references both bs_b and bs_c */ + options =3D qdict_new(); + qdict_put_str(options, "driver", "blkverify"); + qdict_put_str(options, "test", "bs_b"); + qdict_put_str(options, "raw", "bs_c"); + + bs_verify =3D bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort= ); + blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + blk_insert_bs(blk, bs_verify, &error_abort); + + /* Switch the AioContext */ + blk_set_aio_context(blk, ctx); + g_assert(blk_get_aio_context(blk) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_verify) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_a) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_b) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_c) =3D=3D ctx); + + /* Switch the AioContext back */ + ctx =3D qemu_get_aio_context(); + blk_set_aio_context(blk, ctx); + g_assert(blk_get_aio_context(blk) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_verify) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_a) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_b) =3D=3D ctx); + g_assert(bdrv_get_aio_context(bs_c) =3D=3D ctx); + + blk_unref(blk); + bdrv_unref(bs_verify); + bdrv_unref(bs_c); + bdrv_unref(bs_b); + bdrv_unref(bs_a); +} + int main(int argc, char **argv) { int i; @@ -474,6 +603,8 @@ int main(int argc, char **argv) } =20 g_test_add_func("/attach/blockjob", test_attach_blockjob); + g_test_add_func("/propagate/basic", test_propagate_basic); + g_test_add_func("/propagate/diamond", test_propagate_diamond); =20 return g_test_run(); } --=20 2.20.1