From: Stefan Weil <weil@mail.berlios.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] block/vdi.c: Fix several bugs
Date: Fri, 14 Aug 2009 21:50:02 +0200 [thread overview]
Message-ID: <1250279402-7233-1-git-send-email-weil@mail.berlios.de> (raw)
* 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 <weil@mail.berlios.de>
---
block/vdi.c | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index db3fe16..b8198ea 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -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. */
--
1.5.6.5
reply other threads:[~2009-08-14 19:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1250279402-7233-1-git-send-email-weil@mail.berlios.de \
--to=weil@mail.berlios.de \
--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).