All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com,
	mreitz@redhat.com, kwolf@redhat.com, den@openvz.org
Subject: Re: [PATCH 04/21] block: bdrv_refresh_perms: check parents compliance
Date: Tue, 24 Nov 2020 12:42:46 +0300	[thread overview]
Message-ID: <97ec2117-470e-aac6-7861-903c97e91b97@virtuozzo.com> (raw)
In-Reply-To: <20201123201233.9534-7-vsementsov@virtuozzo.com>

23.11.2020 23:12, Vladimir Sementsov-Ogievskiy wrote:
> Add additional check that node parents do not interfere with each
> other. This should not hurt existing callers and allows in further
> patch use bdrv_refresh_perms() to update a subtree of changed
> BdrvChild (check that change is correct).
> 
> New check will substitute bdrv_check_update_perm() in following
> permissions refactoring, so keep error messages the same to avoid
> unit test result changes.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>   block.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++---------
>   1 file changed, 53 insertions(+), 9 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 0dd28f0902..0d0f065db4 100644
> --- a/block.c
> +++ b/block.c
> @@ -1945,6 +1945,56 @@ bool bdrv_is_writable(BlockDriverState *bs)
>       return bdrv_is_writable_after_reopen(bs, NULL);
>   }
>   
> +static char *bdrv_child_user_desc(BdrvChild *c)
> +{
> +    if (c->klass->get_parent_desc) {
> +        return c->klass->get_parent_desc(c);
> +    }
> +
> +    return g_strdup("another user");
> +}
> +
> +static bool bdrv_a_allow_b(BdrvChild *a, BdrvChild *b, Error **errp)
> +{
> +    g_autofree char *user = NULL;
> +    g_autofree char *perm_names = NULL;
> +
> +    if ((b->perm & a->shared_perm) == b->perm) {
> +        return true;
> +    }
> +
> +    perm_names = bdrv_perm_names(b->perm & ~a->shared_perm);
> +    user = bdrv_child_user_desc(a);
> +    error_setg(errp, "Conflicts with use by %s as '%s', which does not "
> +               "allow '%s' on %s",
> +               user, a->name, perm_names, bdrv_get_node_name(b->bs));
> +
> +    return false;
> +}
> +
> +static bool bdrv_check_parents_compliance(BlockDriverState *bs, Error **errp)
> +{
> +    BdrvChild *a, *b;
> +
> +    QLIST_FOREACH(a, &bs->parents, next_parent) {
> +        QLIST_FOREACH(b, &bs->parents, next_parent) {
> +            if (a == b) {
> +                continue;
> +            }
> +
> +            if (!bdrv_a_allow_b(a, b, errp)) {
> +                return false;
> +            }
> +
> +            if (!bdrv_a_allow_b(b, a, errp)) {
> +                return false;
> +            }

drop this if. We look at each pair twice anyway.

-- 
Best regards,
Vladimir


  reply	other threads:[~2020-11-24  9:44 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 20:12 [PATCH RFC 00/21] block: update graph permissions update Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 1/2] block: make bdrv_drop_intermediate() less wrong Vladimir Sementsov-Ogievskiy
2020-11-24  9:39   ` Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 01/21] tests/test-bdrv-graph-mod: add test_parallel_exclusive_write Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 2/2] block: assert that permission commit sets same permissions Vladimir Sementsov-Ogievskiy
2020-11-24  9:40   ` Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 02/21] tests/test-bdrv-graph-mod: add test_parallel_perm_update Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 03/21] util: add transactions.c Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 04/21] block: bdrv_refresh_perms: check parents compliance Vladimir Sementsov-Ogievskiy
2020-11-24  9:42   ` Vladimir Sementsov-Ogievskiy [this message]
2020-11-23 20:12 ` [PATCH 05/21] block: refactor bdrv_child* permission functions Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 06/21] block: rewrite bdrv_child_try_set_perm() using bdrv_refresh_perms() Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 07/21] block: inline bdrv_child_*() permission functions calls Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 08/21] block: use topological sort for permission update Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 09/21] block: add bdrv_drv_set_perm transaction action Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 10/21] block: add bdrv_list_* permission update functions Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 11/21] block: add bdrv_replace_child_safe() transaction action Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 12/21] block: return value from bdrv_replace_node() Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 13/21] block: fix bdrv_replace_node_common Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 14/21] block: add bdrv_attach_child_noperm() transaction action Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 15/21] block: split out bdrv_replace_node_noperm() Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 16/21] block: bdrv_append(): don't consume reference Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 17/21] block: bdrv_append(): return status Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 18/21] block: adapt bdrv_append() for inserting filters Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 19/21] block: add bdrv_remove_backing transaction action Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 20/21] block: introduce bdrv_drop_filter() Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 21/21] block/backup-top: drop .active Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=97ec2117-470e-aac6-7861-903c97e91b97@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.