diff mbox

block: Round up total_sectors

Message ID 1383738486-21045-1-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Nov. 6, 2013, 11:48 a.m. UTC
Since b94a2610, bdrv_getlength() is omitted when probing image. VMDK
monolithicFlat is broken by that because a file < 512 bytes can't be
read with its total_sectors truncated to 0. This patch round up the size
to BDRV_SECTOR_SIZE, when a image size is not sector aligned.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Benoît Canet Nov. 6, 2013, 1:08 p.m. UTC | #1
Le Wednesday 06 Nov 2013 à 19:48:06 (+0800), Fam Zheng a écrit :
> Since b94a2610, bdrv_getlength() is omitted when probing image. VMDK
> monolithicFlat is broken by that because a file < 512 bytes can't be
> read with its total_sectors truncated to 0. This patch round up the size
> to BDRV_SECTOR_SIZE, when a image size is not sector aligned.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block.c b/block.c
> index 58efb5b..f706634 100644
> --- a/block.c
> +++ b/block.c
> @@ -640,7 +640,7 @@ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint)
>          if (length < 0) {
>              return length;
>          }
> -        hint = length >> BDRV_SECTOR_BITS;
> +        hint = DIV_ROUND_UP(length, BDRV_SECTOR_SIZE);
>      }
>  
>      bs->total_sectors = hint;
> -- 
> 1.8.3.1
> 
> 

Reviewed-by: Benoit Canet <benoit@irqsave.net>
diff mbox

Patch

diff --git a/block.c b/block.c
index 58efb5b..f706634 100644
--- a/block.c
+++ b/block.c
@@ -640,7 +640,7 @@  static int refresh_total_sectors(BlockDriverState *bs, int64_t hint)
         if (length < 0) {
             return length;
         }
-        hint = length >> BDRV_SECTOR_BITS;
+        hint = DIV_ROUND_UP(length, BDRV_SECTOR_SIZE);
     }
 
     bs->total_sectors = hint;