From nobody Fri Dec 19 20:33:57 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=openvz.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1648682596485988.6589719542251; Wed, 30 Mar 2022 16:23:16 -0700 (PDT) Received: from localhost ([::1]:58950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZhel-00063C-Cx for importer@patchew.org; Wed, 30 Mar 2022 19:23:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZfso-0007t2-Gy for qemu-devel@nongnu.org; Wed, 30 Mar 2022 17:29:38 -0400 Received: from [2a00:1450:4864:20::133] (port=34615 helo=mail-lf1-x133.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nZfsl-00039Z-Ha for qemu-devel@nongnu.org; Wed, 30 Mar 2022 17:29:38 -0400 Received: by mail-lf1-x133.google.com with SMTP id 5so38079656lfp.1 for ; Wed, 30 Mar 2022 14:29:35 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id y3-20020a056512044300b0044a9bda3242sm1057573lfk.90.2022.03.30.14.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 14:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OyOe9IHk32wXpt1lyEECx4DZ0roDPHO4SQyPjhiHFIk=; b=AkXoLHWE3LmdEq51WNmjw9pPqtK0kWxw2ilWD6OIOxzCguLOuo2nnyNdiZpHxQRiUs 6D6tkecY6dPm1yVti+yEG7a0K2lgyDRRq+3Xob4PK9+SxdxAosKhfOF/zOGGGMPYeRW7 WQ5KAqUiCD05/RAX9MhK5ZZuGMiNjLseANw6D49JrIMWpJxgWgfts1ugCJ6gbVFJOQeV K62W/OjvFfRmKXVaX1GD2L6/+hDmnNnrZHgYHbzsxHuu5RPV2oUd3pbSjr8G+ST4DrGe N/YJj5gLZ/Sw70xUYkKO5gWMkS3QKN2xpwdIII7BLLvNV3VqRPTjUUo+k9a3eRRPFnKv IJQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OyOe9IHk32wXpt1lyEECx4DZ0roDPHO4SQyPjhiHFIk=; b=7Kh4xSvO0yH/cH/Nr04oZ6sHrybu2/iDVJ7KuYJMKK06kMDRQk6CYrMElVjp5GX2/k h5vZVgN+FCmdGubNk292K9lYQHXXEGBQO8MYKEA6lQRbgTnkeZsU1rWtXw2NxV/ihbNI ogDvo5R5fulRRwOm2H6XbDT712QSLgunSmMzZ1xkrdQw4BBAwoD2H6LVKXwyvPpz4tf2 9nIVbDOQYkLyUZKBotiBCQhm2jySIS07ZYls0P6mAHmYmqkWUlyMMsbmMeh/gpzXb04f pKI0NHxphkfw/zZnDYqHKJ+U7v0VtPu9grWY18wYJgtRcWpmsKeSb7qtZGN/Ib5sMkBB 6R8Q== X-Gm-Message-State: AOAM530S7JD5JrRkATUMI0J//LvkVLkHkcfvAi1S/Khhux93c6lpZxuX nWsj16EeKG+w4xtBAskxlr2Pzw== X-Google-Smtp-Source: ABdhPJxlwTD3RJO/wQjgXwk9ycK8UeC9U+Al0EF4KEd+I+aG5OFA6djtmM8IuHqM+ni77FnlnPkK6g== X-Received: by 2002:a05:6512:2214:b0:44a:348a:d72 with SMTP id h20-20020a056512221400b0044a348a0d72mr8585285lfu.416.1648675773887; Wed, 30 Mar 2022 14:29:33 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v5 04/45] test-bdrv-graph-mod: update test_parallel_perm_update test case Date: Thu, 31 Mar 2022 00:28:21 +0300 Message-Id: <20220330212902.590099-5-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220330212902.590099-1-vsementsov@openvz.org> References: <20220330212902.590099-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::133 (failed) 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lf1-x133.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 30 Mar 2022 19:17:15 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, hreitz@redhat.com, vsementsov@openvz.org, v.sementsov-og@mail.ru, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1648682597022100001 test_parallel_perm_update() does two things that we are going to restrict in the near future: 1. It updates bs->file field by hand. bs->file will be managed automatically by generic code (together with bs->children list). Let's better refactor our "tricky" bds to have own state where one of children is linked as "selected". This also looks less "tricky", so avoid using this word. 2. It create FILTERED children that are not PRIMARY. Except for tests all FILTERED children in the Qemu block layer are always PRIMARY as well. We are going to formalize this rule, so let's better use DATA children here. While being here, update the picture to better correspond to the test code. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/unit/test-bdrv-graph-mod.c | 70 ++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-= mod.c index a6e3bb79be..40795d3c04 100644 --- a/tests/unit/test-bdrv-graph-mod.c +++ b/tests/unit/test-bdrv-graph-mod.c @@ -241,13 +241,26 @@ static void test_parallel_exclusive_write(void) bdrv_unref(top); } =20 -static void write_to_file_perms(BlockDriverState *bs, BdrvChild *c, - BdrvChildRole role, - BlockReopenQueue *reopen_queue, - uint64_t perm, uint64_t shared, - uint64_t *nperm, uint64_t *nshared) +/* + * write-to-selected node may have several DATA children, one of them may = be + * "selected". Exclusive write permission is taken on selected child. + * + * We don't realize write handler itself, as we need only to test how perm= ission + * update works. + */ +typedef struct BDRVWriteToSelectedState { + BdrvChild *selected; +} BDRVWriteToSelectedState; + +static void write_to_selected_perms(BlockDriverState *bs, BdrvChild *c, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) { - if (bs->file && c =3D=3D bs->file) { + BDRVWriteToSelectedState *s =3D bs->opaque; + + if (s->selected && c =3D=3D s->selected) { *nperm =3D BLK_PERM_WRITE; *nshared =3D BLK_PERM_ALL & ~BLK_PERM_WRITE; } else { @@ -256,9 +269,10 @@ static void write_to_file_perms(BlockDriverState *bs, = BdrvChild *c, } } =20 -static BlockDriver bdrv_write_to_file =3D { - .format_name =3D "tricky-perm", - .bdrv_child_perm =3D write_to_file_perms, +static BlockDriver bdrv_write_to_selected =3D { + .format_name =3D "write-to-selected", + .instance_size =3D sizeof(BDRVWriteToSelectedState), + .bdrv_child_perm =3D write_to_selected_perms, }; =20 =20 @@ -266,15 +280,18 @@ static BlockDriver bdrv_write_to_file =3D { * The following test shows that topological-sort order is required for * permission update, simple DFS is not enough. * - * Consider the block driver which has two filter children: one active - * with exclusive write access and one inactive with no specific - * permissions. + * Consider the block driver (write-to-selected) which has two children: o= ne is + * selected so we have exclusive write access to it and for the other one = we + * don't need any specific permissions. * * And, these two children has a common base child, like this: + * (additional "top" on top is used in test just because the only public + * function to update permission should get a specific child to update. + * Making bdrv_refresh_perms() public just for this test doesn't worth = it) * - * =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2= =94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 - * =E2=94=82 fl2 =E2=94=82 =E2=97=80=E2=94=80=E2=94=80 =E2=94=82 top =E2= =94=82 - * =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2= =94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 + * =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2= =94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=90 =E2=94=8C=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=90 + * =E2=94=82 fl2 =E2=94=82 =E2=97=80=E2=94=80=E2=94=80 =E2=94=82 write-to-= selected =E2=94=82 =E2=97=80=E2=94=80=E2=94=80 =E2=94=82 top =E2=94=82 + * =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2= =94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=98 =E2=94=94=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=98 * =E2=94=82 =E2=94=82 * =E2=94=82 =E2=94=82 w * =E2=94=82 =E2=96=BC @@ -290,7 +307,7 @@ static BlockDriver bdrv_write_to_file =3D { * * So, exclusive write is propagated. * - * Assume, we want to make fl2 active instead of fl1. + * Assume, we want to select fl2 instead of fl1. * So, we set some option for top driver and do permission update. * * With simple DFS, if permission update goes first through @@ -306,9 +323,10 @@ static BlockDriver bdrv_write_to_file =3D { static void test_parallel_perm_update(void) { BlockDriverState *top =3D no_perm_node("top"); - BlockDriverState *tricky =3D - bdrv_new_open_driver(&bdrv_write_to_file, "tricky", BDRV_O_RDW= R, + BlockDriverState *ws =3D + bdrv_new_open_driver(&bdrv_write_to_selected, "ws", BDRV_O_RDW= R, &error_abort); + BDRVWriteToSelectedState *s =3D ws->opaque; BlockDriverState *base =3D no_perm_node("base"); BlockDriverState *fl1 =3D pass_through_node("fl1"); BlockDriverState *fl2 =3D pass_through_node("fl2"); @@ -320,33 +338,33 @@ static void test_parallel_perm_update(void) */ bdrv_ref(base); =20 - bdrv_attach_child(top, tricky, "file", &child_of_bds, BDRV_CHILD_DATA, + bdrv_attach_child(top, ws, "file", &child_of_bds, BDRV_CHILD_DATA, &error_abort); - c_fl1 =3D bdrv_attach_child(tricky, fl1, "first", &child_of_bds, - BDRV_CHILD_FILTERED, &error_abort); - c_fl2 =3D bdrv_attach_child(tricky, fl2, "second", &child_of_bds, - BDRV_CHILD_FILTERED, &error_abort); + c_fl1 =3D bdrv_attach_child(ws, fl1, "first", &child_of_bds, + BDRV_CHILD_DATA, &error_abort); + c_fl2 =3D bdrv_attach_child(ws, fl2, "second", &child_of_bds, + BDRV_CHILD_DATA, &error_abort); bdrv_attach_child(fl1, base, "backing", &child_of_bds, BDRV_CHILD_FILT= ERED, &error_abort); bdrv_attach_child(fl2, base, "backing", &child_of_bds, BDRV_CHILD_FILT= ERED, &error_abort); =20 /* Select fl1 as first child to be active */ - tricky->file =3D c_fl1; + s->selected =3D c_fl1; bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); =20 assert(c_fl1->perm & BLK_PERM_WRITE); assert(!(c_fl2->perm & BLK_PERM_WRITE)); =20 /* Now, try to switch active child and update permissions */ - tricky->file =3D c_fl2; + s->selected =3D c_fl2; bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); =20 assert(c_fl2->perm & BLK_PERM_WRITE); assert(!(c_fl1->perm & BLK_PERM_WRITE)); =20 /* Switch once more, to not care about real child order in the list */ - tricky->file =3D c_fl1; + s->selected =3D c_fl1; bdrv_child_refresh_perms(top, top->children.lh_first, &error_abort); =20 assert(c_fl1->perm & BLK_PERM_WRITE); --=20 2.35.1