From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
Ilkka Tengvall <ilkka.tengvall@cybercom.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 2/4] qcow: allow sub-cluster compressed write to last cluster
Date: Mon, 15 Apr 2013 17:17:32 +0200 [thread overview]
Message-ID: <1366039054-32536-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1366039054-32536-1-git-send-email-stefanha@redhat.com>
Compression in qcow requires image length to be a multiple of the
cluster size. Lift this requirement by zero-padding the final cluster
when necessary. The virtual disk size is still not cluster-aligned, so
the guest cannot access the zero sectors.
Note that this is almost identical to the qcow2 version of this code.
qcow2's compression code is drawn from qcow.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/qcow.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/block/qcow.c b/block/qcow.c
index 3278e55..e2a64c7 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -787,8 +787,21 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
uint8_t *out_buf;
uint64_t cluster_offset;
- if (nb_sectors != s->cluster_sectors)
- return -EINVAL;
+ if (nb_sectors != s->cluster_sectors) {
+ ret = -EINVAL;
+
+ /* Zero-pad last write if image size is not cluster aligned */
+ if (sector_num + nb_sectors == bs->total_sectors &&
+ nb_sectors < s->cluster_sectors) {
+ uint8_t *pad_buf = qemu_blockalign(bs, s->cluster_size);
+ memset(pad_buf, 0, s->cluster_size);
+ memcpy(pad_buf, buf, nb_sectors * BDRV_SECTOR_SIZE);
+ ret = qcow_write_compressed(bs, sector_num,
+ pad_buf, s->cluster_sectors);
+ qemu_vfree(pad_buf);
+ }
+ return ret;
+ }
out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
--
1.8.1.4
next prev parent reply other threads:[~2013-04-15 15:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-15 15:17 [Qemu-devel] [PATCH 0/4] qemu-img: support compression regardless of cluster size Stefan Hajnoczi
2013-04-15 15:17 ` [Qemu-devel] [PATCH 1/4] qcow2: allow sub-cluster compressed write to last cluster Stefan Hajnoczi
2013-04-15 15:17 ` Stefan Hajnoczi [this message]
2013-04-15 15:17 ` [Qemu-devel] [PATCH 3/4] qemu-img: do not zero-pad the compressed write buffer Stefan Hajnoczi
2013-04-15 15:17 ` [Qemu-devel] [PATCH 4/4] qemu-iotests: add 053 unaligned compressed image size test Stefan Hajnoczi
2013-04-15 15:38 ` Eric Blake
2013-04-16 8:36 ` Stefan Hajnoczi
2013-04-16 8:53 ` Kevin Wolf
2013-04-16 9:00 ` [Qemu-devel] [PATCH 0/4] qemu-img: support compression regardless of cluster size Kevin Wolf
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=1366039054-32536-3-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=famz@redhat.com \
--cc=ilkka.tengvall@cybercom.com \
--cc=kwolf@redhat.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).