[Devel] [PATCH rh7] cbt: fix cbt->block_max calculation

Dmitry Monakhov dmonakhov at openvz.org
Tue May 10 00:53:55 PDT 2016


Maxim Patlasov <mpatlasov at virtuozzo.com> writes:

> When the size of block device is multiple of CBT blocksize, the following:
>
>> cbt->block_max  = (size + blocksize) >> cbt->block_bits;
Pure typo fix. ACK.
>
> is incorrect. This may end up in allocating one extra page in cbt->map and
> also make various checks with cbt->block_max prone to error.
>
> Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
> ---
>  block/blk-cbt.c                   |    2 +-
>  drivers/block/ploop/push_backup.c |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/blk-cbt.c b/block/blk-cbt.c
> index 8c52bd8..8cdf1d6 100644
> --- a/block/blk-cbt.c
> +++ b/block/blk-cbt.c
> @@ -252,7 +252,7 @@ static struct cbt_info* do_cbt_alloc(struct request_queue *q, __u8 *uuid,
>  		return ERR_PTR(-ENOMEM);
>  
>  	cbt->block_bits = ilog2(blocksize);
> -	cbt->block_max  = (size + blocksize) >> cbt->block_bits;
> +	cbt->block_max  = (size + blocksize - 1) >> cbt->block_bits;
>  	spin_lock_init(&cbt->lock);
>  	memcpy(cbt->uuid, uuid, sizeof(cbt->uuid));
>  	cbt->cache = alloc_percpu(struct cbt_extent);
> diff --git a/drivers/block/ploop/push_backup.c b/drivers/block/ploop/push_backup.c
> index 05af67c..4d671a5 100644
> --- a/drivers/block/ploop/push_backup.c
> +++ b/drivers/block/ploop/push_backup.c
> @@ -175,7 +175,7 @@ bool ploop_pb_check_bit(struct ploop_pushbackup_desc *pbd, cluster_t clu)
>  static int convert_map_to_map(struct ploop_pushbackup_desc *pbd)
>  {
>  	struct page **from_map = pbd->cbt_map;
> -	blkcnt_t from_max = pbd->cbt_block_max - 1;
> +	blkcnt_t from_max = pbd->cbt_block_max;
>  	blkcnt_t from_bits = pbd->cbt_block_bits;
>  
>  	struct page **to_map = pbd->ppb_map;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://lists.openvz.org/pipermail/devel/attachments/20160510/423f5b26/attachment.sig>


More information about the Devel mailing list