]> Git Repo - qemu.git/commitdiff
block/vdi.c: Fix several bugs
authorStefan Weil <[email protected]>
Fri, 14 Aug 2009 19:50:02 +0000 (21:50 +0200)
committerAnthony Liguori <[email protected]>
Fri, 28 Aug 2009 00:33:15 +0000 (19:33 -0500)
* The code for option '-static' was wrong, so image creation
  always created static images.

* Static images created with qemu-img did not set header entry
  blocks_allocated.

* The size of the block map must be rounded to the next multiple
  of SECTOR_SIZE, otherwise the block map is only read partially
  for block map sizes which are not a multiple of SECTOR_SIZE.

Signed-off-by: Stefan Weil <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
block/vdi.c

index 4ca8dcb7dc6466cb3ced426ff4cc2c569d0cb58c..c9c8890f59b6384c5314e3d1e42eff2e243db4eb 100644 (file)
@@ -437,9 +437,9 @@ static int vdi_open(BlockDriverState *bs, const char *filename, int flags)
     s->header = header;
 
     bmap_size = header.blocks_in_image * sizeof(uint32_t);
-    s->bmap = qemu_malloc(bmap_size);
-    if (bdrv_read(s->hd, s->bmap_sector,
-                  (uint8_t *)s->bmap, bmap_size / SECTOR_SIZE) < 0) {
+    bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE;
+    s->bmap = qemu_malloc(bmap_size * SECTOR_SIZE);
+    if (bdrv_read(s->hd, s->bmap_sector, (uint8_t *)s->bmap, bmap_size) < 0) {
         goto fail_free_bmap;
     }
 
@@ -817,7 +817,9 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
 #endif
 #if defined(CONFIG_VDI_STATIC_IMAGE)
         } else if (!strcmp(options->name, BLOCK_OPT_STATIC)) {
-            image_type = VDI_TYPE_STATIC;
+            if (options->value.n) {
+                image_type = VDI_TYPE_STATIC;
+            }
 #endif
         }
         options++;
@@ -845,6 +847,9 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
     header.disk_size = bytes;
     header.block_size = block_size;
     header.blocks_in_image = blocks;
+    if (image_type == VDI_TYPE_STATIC) {
+        header.blocks_allocated = blocks;
+    }
     uuid_generate(header.uuid_image);
     uuid_generate(header.uuid_last_snap);
     /* There is no need to set header.uuid_link or header.uuid_parent here. */
This page took 0.02396 seconds and 4 git commands to generate.