Patchwork vdi: Fix image creation

login
register
mail settings
Submitter Kevin Wolf
Date May 6, 2010, 12:55 p.m.
Message ID <1273150559-1587-1-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/51852/
State New
Headers show

Comments

Kevin Wolf - May 6, 2010, 12:55 p.m.
The number of blocks needs to be rounded up to cover all of the virtual hard
disk. Without this fix, we can't even open our own images if their size is not
a multiple of the block size.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/vdi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Stefan Weil - May 6, 2010, 6:05 p.m.
Am 06.05.2010 14:55, schrieb Kevin Wolf:
> The number of blocks needs to be rounded up to cover all of the 
> virtual hard
> disk. Without this fix, we can't even open our own images if their 
> size is not
> a multiple of the block size.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> block/vdi.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/block/vdi.c b/block/vdi.c
> index 2b4d2c2..b990bbc 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -827,7 +827,7 @@ static int vdi_create(const char *filename, 
> QEMUOptionParameter *options)
> return -errno;
> }
>
> - blocks = bytes / block_size;
> + blocks = (bytes + block_size - 1) / block_size;
> bmap_size = blocks * sizeof(uint32_t);
> bmap_size = ((bmap_size + SECTOR_SIZE - 1) & ~(SECTOR_SIZE -1));
>


'bytes' (for header.disk_size) must be fixed, too, and so does vdi_open.
I'll send a patch which hopefully addresses all these points.

Thanks + kind regards,
Stefan

Patch

diff --git a/block/vdi.c b/block/vdi.c
index 2b4d2c2..b990bbc 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -827,7 +827,7 @@  static int vdi_create(const char *filename, QEMUOptionParameter *options)
         return -errno;
     }
 
-    blocks = bytes / block_size;
+    blocks = (bytes + block_size - 1) / block_size;
     bmap_size = blocks * sizeof(uint32_t);
     bmap_size = ((bmap_size + SECTOR_SIZE - 1) & ~(SECTOR_SIZE -1));