qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Max Reitz <mreitz@redhat.com>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>
Cc: Kevin Wolf <kwolf@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [PATCH for-5.0 v4 1/5] block: Add bdrv_qapi_perm_to_blk_perm()
Date: Fri, 8 Nov 2019 14:05:54 +0000	[thread overview]
Message-ID: <d77d0a3e-6466-88fa-f169-98293babdf22@virtuozzo.com> (raw)
In-Reply-To: <20191108123455.39445-2-mreitz@redhat.com>

08.11.2019 15:34, Max Reitz wrote:
> We need some way to correlate QAPI BlockPermission values with
> BLK_PERM_* flags.  We could:
> 
> (1) have the same order in the QAPI definition as the the BLK_PERM_*
>      flags are in LSb-first order.  However, then there is no guarantee
>      that they actually match (e.g. when someone modifies the QAPI schema
>      without thinking of the BLK_PERM_* definitions).
>      We could add static assertions, but these would break what’s good
>      about this solution, namely its simplicity.
> 
> (2) define the BLK_PERM_* flags based on the BlockPermission values.
>      But this way whenever someone were to modify the QAPI order
>      (perfectly sensible in theory), the BLK_PERM_* values would change.
>      Because these values are used for file locking, this might break
>      file locking between different qemu versions.
> 
> Therefore, go the slightly more cumbersome way: Add a function to
> translate from the QAPI constants to the BLK_PERM_* flags.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

> ---
>   block.c               | 18 ++++++++++++++++++
>   include/block/block.h |  1 +
>   2 files changed, 19 insertions(+)
> 
> diff --git a/block.c b/block.c
> index 4cffc2bc35..066433f3e2 100644
> --- a/block.c
> +++ b/block.c
> @@ -2227,6 +2227,24 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
>       *nshared = shared;
>   }
>   
> +uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm)
> +{
> +    static const uint64_t permissions[] = {
> +        [BLOCK_PERMISSION_CONSISTENT_READ]  = BLK_PERM_CONSISTENT_READ,
> +        [BLOCK_PERMISSION_WRITE]            = BLK_PERM_WRITE,
> +        [BLOCK_PERMISSION_WRITE_UNCHANGED]  = BLK_PERM_WRITE_UNCHANGED,
> +        [BLOCK_PERMISSION_RESIZE]           = BLK_PERM_RESIZE,
> +        [BLOCK_PERMISSION_GRAPH_MOD]        = BLK_PERM_GRAPH_MOD,
> +    };
> +
> +    QEMU_BUILD_BUG_ON(ARRAY_SIZE(permissions) != BLOCK_PERMISSION__MAX);
> +    QEMU_BUILD_BUG_ON(1UL << ARRAY_SIZE(permissions) != BLK_PERM_ALL + 1);

safe enough)

> +
> +    assert(qapi_perm < BLOCK_PERMISSION__MAX);
> +
> +    return permissions[qapi_perm];
> +}
> +
>   static void bdrv_replace_child_noperm(BdrvChild *child,
>                                         BlockDriverState *new_bs)
>   {
> diff --git a/include/block/block.h b/include/block/block.h
> index 1df9848e74..e9dcfef7fa 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -280,6 +280,7 @@ enum {
>   };
>   
>   char *bdrv_perm_names(uint64_t perm);
> +uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm);
>   
>   /* disk I/O throttling */
>   void bdrv_init(void);
> 


-- 
Best regards,
Vladimir

  reply	other threads:[~2019-11-08 14:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-08 12:34 [PATCH for-5.0 v4 0/5] iotests: Test failing mirror complete Max Reitz
2019-11-08 12:34 ` [PATCH for-5.0 v4 1/5] block: Add bdrv_qapi_perm_to_blk_perm() Max Reitz
2019-11-08 14:05   ` Vladimir Sementsov-Ogievskiy [this message]
2019-11-08 12:34 ` [PATCH for-5.0 v4 2/5] block: Use bdrv_qapi_perm_to_blk_perm() Max Reitz
2019-11-08 14:11   ` Vladimir Sementsov-Ogievskiy
2019-11-08 12:34 ` [PATCH for-5.0 v4 3/5] blkdebug: Allow taking/unsharing permissions Max Reitz
2019-11-08 15:19   ` Vladimir Sementsov-Ogievskiy
2019-11-08 12:34 ` [PATCH for-5.0 v4 4/5] iotests: Add @error to wait_until_completed Max Reitz
2019-11-08 12:34 ` [PATCH for-5.0 v4 5/5] iotests: Add test for failing mirror complete Max Reitz
2019-11-26  8:27 ` [PATCH for-5.0 v4 0/5] iotests: Test " Max Reitz

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=d77d0a3e-6466-88fa-f169-98293babdf22@virtuozzo.com \
    --to=vsementsov@virtuozzo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).