[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/20] qcow: allow sub-cluster compressed write to l
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 02/20] qcow: allow sub-cluster compressed write to last cluster |
Date: |
Mon, 22 Apr 2013 13:31:16 +0200 |
From: Stefan Hajnoczi <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
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
- [Qemu-devel] [PULL 00/20] Block patches, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 03/20] qemu-img: do not zero-pad the compressed write buffer, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 01/20] qcow2: allow sub-cluster compressed write to last cluster, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 04/20] qemu-iotests: Fix _filter_qemu, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 02/20] qcow: allow sub-cluster compressed write to last cluster,
Kevin Wolf <=
- [Qemu-devel] [PATCH 06/20] block: Add driver-specific options for backing files, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 07/20] block: Enable filename option, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 05/20] block: Fail gracefully when using a format driver on protocol level, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 08/20] raw-posix: Use bdrv_open options instead of filename, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 10/20] blkdebug: Use bdrv_open options instead of filename, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 09/20] raw-win32: Use bdrv_open options instead of filename, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 11/20] blkverify: Use bdrv_open options instead of filename, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 13/20] gluster: Use bdrv_open options instead of filename, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 15/20] rbd: Use bdrv_open options instead of filename, Kevin Wolf, 2013/04/22
- [Qemu-devel] [PATCH 12/20] curl: Use bdrv_open options instead of filename, Kevin Wolf, 2013/04/22