From: Jeff Cody <jcody@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, pl@kamp.de, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2 3/4] block/vpc: give option to force the current_size field in .bdrv_create
Date: Wed, 24 Feb 2016 11:21:45 -0500 [thread overview]
Message-ID: <ea37a4915b6d2fa5df56a75d62b068f58fdbe55a.1456330357.git.jcody@redhat.com> (raw)
In-Reply-To: <cover.1456330357.git.jcody@redhat.com>
In-Reply-To: <cover.1456330357.git.jcody@redhat.com>
When QEMU creates a VHD image, it goes by the original spec,
calculating the current_size based on the nearest CHS geometry (with an
exception for disks > 127GB).
Apparently, Azure will only allow images that are sized to the nearest
MB, and the current_size as calculated from CHS cannot guarantee that.
Allow QEMU to create images similar to how Hyper-V creates images, by
setting current_size to the specified virtual disk size. This
introduces an option, force_size, to be passed to the vpc format during
image creation, e.g.:
qemu-img convert -f raw -o force_size -O vpc test.img test.vhd
When using the "force_size" option, the creator app field used by
QEMU will be "qem2" instead of "qemu", to indicate the difference.
In light of this, we also add parsing of the "qem2" field during
vpc_open.
Bug reference: https://bugs.launchpad.net/qemu/+bug/1490611
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
block/vpc.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index 54a38a7..8f84b17 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -49,6 +49,8 @@ enum vhd_type {
#define VHD_MAX_SECTORS (65535LL * 255 * 255)
#define VHD_MAX_GEOMETRY (65535LL * 16 * 255)
+#define VPC_OPT_FORCE_SIZE "force_size"
+
// always big-endian
typedef struct vhd_footer {
char creator[8]; // "conectix"
@@ -288,6 +290,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
* Known creator apps:
* 'vpc ' : CHS Virtual PC (uses disk geometry)
* 'qemu' : CHS QEMU (uses disk geometry)
+ * 'qem2' : current_size QEMU (uses current_size)
* 'win ' : current_size Hyper-V
* 'd2v ' : current_size Disk2vhd
*
@@ -296,6 +299,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
* that have CHS geometry of the maximum size.
*/
use_chs = (!!strncmp(footer->creator_app, "win ", 4) &&
+ !!strncmp(footer->creator_app, "qem2", 4) &&
!!strncmp(footer->creator_app, "d2v ", 4)) || s->force_use_chs;
if (!use_chs || bs->total_sectors == VHD_MAX_GEOMETRY || s->force_use_sz) {
@@ -850,6 +854,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
int64_t total_size;
int disk_type;
int ret = -EIO;
+ bool force_size;
Error *local_err = NULL;
BlockDriverState *bs = NULL;
@@ -870,6 +875,8 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
disk_type = VHD_DYNAMIC;
}
+ force_size = qemu_opt_get_bool_del(opts, VPC_OPT_FORCE_SIZE, false);
+
ret = bdrv_create_file(filename, opts, &local_err);
if (ret < 0) {
error_propagate(errp, local_err);
@@ -896,7 +903,8 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
calculate_geometry(total_sectors + i, &cyls, &heads, &secs_per_cyl);
}
- if ((int64_t)cyls * heads * secs_per_cyl == VHD_MAX_GEOMETRY) {
+ if ((int64_t)cyls * heads * secs_per_cyl == VHD_MAX_GEOMETRY ||
+ force_size) {
total_sectors = total_size / BDRV_SECTOR_SIZE;
/* Allow a maximum disk size of approximately 2 TB */
if (total_sectors > VHD_MAX_SECTORS) {
@@ -912,8 +920,11 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
memset(buf, 0, 1024);
memcpy(footer->creator, "conectix", 8);
- /* TODO Check if "qemu" creator_app is ok for VPC */
- memcpy(footer->creator_app, "qemu", 4);
+ if (force_size) {
+ memcpy(footer->creator_app, "qem2", 4);
+ } else {
+ memcpy(footer->creator_app, "qemu", 4);
+ }
memcpy(footer->creator_os, "Wi2k", 4);
footer->features = cpu_to_be32(0x02);
@@ -994,6 +1005,13 @@ static QemuOptsList vpc_create_opts = {
"Type of virtual hard disk format. Supported formats are "
"{dynamic (default) | fixed} "
},
+ {
+ .name = VPC_OPT_FORCE_SIZE,
+ .type = QEMU_OPT_BOOL,
+ .help = "Force disk size calculation to use the actual size "
+ "specified, rather than using the nearest CHS-based "
+ "calculation"
+ },
{ /* end of list */ }
}
};
--
1.9.3
next prev parent reply other threads:[~2016-02-24 16:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 16:21 [Qemu-devel] [PATCH v2 0/4] VHD/VPC format compatibility Jeff Cody
2016-02-24 16:21 ` [Qemu-devel] [PATCH v2 1/4] block/vpc: choose size calculation method based on creator_app field Jeff Cody
2016-02-24 16:21 ` [Qemu-devel] [PATCH v2 2/4] block/vpc: tests for auto-detecting VPC and Hyper-V VHD images Jeff Cody
2016-02-24 16:21 ` Jeff Cody [this message]
2016-02-24 16:21 ` [Qemu-devel] [PATCH v2 4/4] block/vpc: add tests for image creation force_size parameter Jeff Cody
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=ea37a4915b6d2fa5df56a75d62b068f58fdbe55a.1456330357.git.jcody@redhat.com \
--to=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-block@nongnu.org \
--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).