From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, carnold@suse.com
Subject: [Qemu-devel] [PATCH] vpc: Round up image size during fixed image creation
Date: Tue, 7 Feb 2012 10:22:22 +0100 [thread overview]
Message-ID: <1328606542-3230-1-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <4F30045B0200009100079F6E@novprvoes0310.provo.novell.com>
The geometry calculation algorithm from the VHD spec rounds the image
size down if it doesn't exactly match a geometry. During image
conversion, this causes the image to be truncated. For dynamic images,
we already have code in place to round up instead, let's do the same for
fixed images.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/vpc.c | 23 ++++++++++-------------
1 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index db6b14b..6b4816f 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -685,24 +685,21 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options)
return -EIO;
}
+ /*
+ * Calculate matching total_size and geometry. Increase the number of
+ * sectors requested until we get enough (or fail). This ensures that
+ * qemu-img convert doesn't truncate images, but rather rounds up.
+ */
total_sectors = total_size / BDRV_SECTOR_SIZE;
- if (disk_type == VHD_DYNAMIC) {
- /* Calculate matching total_size and geometry. Increase the number of
- sectors requested until we get enough (or fail). */
- for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl;
- i++) {
- if (calculate_geometry(total_sectors + i,
- &cyls, &heads, &secs_per_cyl)) {
- ret = -EFBIG;
- goto fail;
- }
- }
- } else {
- if (calculate_geometry(total_sectors, &cyls, &heads, &secs_per_cyl)) {
+ for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; i++) {
+ if (calculate_geometry(total_sectors + i, &cyls, &heads,
+ &secs_per_cyl))
+ {
ret = -EFBIG;
goto fail;
}
}
+
total_sectors = (int64_t) cyls * heads * secs_per_cyl;
/* Prepare the Hard Disk Footer */
--
1.7.6.5
prev parent reply other threads:[~2012-02-07 9:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-31 19:03 [Qemu-devel] [PATCH] block: Add support for vpc Fixed Disk type Charles Arnold
2012-01-31 22:08 ` Andreas Färber
2012-01-31 23:04 ` Charles Arnold
2012-01-31 23:15 ` Andreas Färber
2012-02-01 12:15 ` Kevin Wolf
2012-02-01 16:51 ` Charles Arnold
2012-02-01 17:09 ` Stefan Weil
2012-02-02 8:58 ` Kevin Wolf
2012-02-03 0:16 ` Charles Arnold
2012-02-06 15:46 ` Kevin Wolf
2012-02-06 16:22 ` Charles Arnold
2012-02-06 16:51 ` Kevin Wolf
2012-02-06 23:48 ` Charles Arnold
2012-02-07 9:22 ` Kevin Wolf [this message]
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=1328606542-3230-1-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=carnold@suse.com \
--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).