From: Anton Nefedov <anton.nefedov@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, kwolf@redhat.com, mreitz@redhat.com,
eblake@redhat.com, stefanha@redhat.com, famz@redhat.com,
den@virtuozzo.com, Pavel Butsykin <pbutsykin@virtuozzo.com>,
Anton Nefedov <anton.nefedov@virtuozzo.com>
Subject: [Qemu-devel] [PATCH v2 1/4] qcow2: multiple clusters write compressed
Date: Thu, 16 Nov 2017 19:54:55 +0300 [thread overview]
Message-ID: <1510851298-59922-2-git-send-email-anton.nefedov@virtuozzo.com> (raw)
In-Reply-To: <1510851298-59922-1-git-send-email-anton.nefedov@virtuozzo.com>
From: Pavel Butsykin <pbutsykin@virtuozzo.com>
At the moment, qcow2_co_pwritev_compressed can process the requests size
less than or equal to one cluster. This patch added possibility to write
compressed data in the QCOW2 more than one cluster. The implementation
is simple, we just split large requests into separate clusters and write
using existing functionality.
Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
---
block/qcow2.c | 73 ++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 52 insertions(+), 21 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index c276b24..f1e2759 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3332,11 +3332,9 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset,
return 0;
}
-/* XXX: put compressed sectors first, then all the cluster aligned
- tables to avoid losing bytes in alignment */
static coroutine_fn int
-qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
- uint64_t bytes, QEMUIOVector *qiov)
+qcow2_co_pwritev_cluster_compressed(BlockDriverState *bs, uint64_t offset,
+ uint64_t bytes, QEMUIOVector *qiov)
{
BDRVQcow2State *s = bs->opaque;
QEMUIOVector hd_qiov;
@@ -3346,25 +3344,12 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
uint8_t *buf, *out_buf;
int64_t cluster_offset;
- if (bytes == 0) {
- /* align end of file to a sector boundary to ease reading with
- sector based I/Os */
- cluster_offset = bdrv_getlength(bs->file->bs);
- if (cluster_offset < 0) {
- return cluster_offset;
- }
- return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, NULL);
- }
-
- if (offset_into_cluster(s, offset)) {
- return -EINVAL;
- }
+ assert(bytes <= s->cluster_size);
+ assert(!offset_into_cluster(s, offset));
buf = qemu_blockalign(bs, s->cluster_size);
- if (bytes != s->cluster_size) {
- if (bytes > s->cluster_size ||
- offset + bytes != bs->total_sectors << BDRV_SECTOR_BITS)
- {
+ if (bytes < s->cluster_size) {
+ if (offset + bytes != bs->total_sectors << BDRV_SECTOR_BITS) {
qemu_vfree(buf);
return -EINVAL;
}
@@ -3444,6 +3429,52 @@ fail:
return ret;
}
+/* XXX: put compressed sectors first, then all the cluster aligned
+ tables to avoid losing bytes in alignment */
+static coroutine_fn int
+qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
+ uint64_t bytes, QEMUIOVector *qiov)
+{
+ BDRVQcow2State *s = bs->opaque;
+ QEMUIOVector hd_qiov;
+ uint64_t curr_off = 0;
+ int ret;
+
+ if (bytes == 0) {
+ /* align end of file to a sector boundary to ease reading with
+ sector based I/Os */
+ int64_t cluster_offset = bdrv_getlength(bs->file->bs);
+ if (cluster_offset < 0) {
+ return cluster_offset;
+ }
+ return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, NULL);
+ }
+
+ if (offset_into_cluster(s, offset)) {
+ return -EINVAL;
+ }
+
+ qemu_iovec_init(&hd_qiov, qiov->niov);
+ do {
+ uint32_t chunk_size;
+
+ qemu_iovec_reset(&hd_qiov);
+ chunk_size = MIN(bytes, s->cluster_size);
+ qemu_iovec_concat(&hd_qiov, qiov, curr_off, chunk_size);
+
+ ret = qcow2_co_pwritev_cluster_compressed(bs, offset + curr_off,
+ chunk_size, &hd_qiov);
+ if (ret < 0) {
+ break;
+ }
+ curr_off += chunk_size;
+ bytes -= chunk_size;
+ } while (bytes);
+ qemu_iovec_destroy(&hd_qiov);
+
+ return ret;
+}
+
static int make_completely_empty(BlockDriverState *bs)
{
BDRVQcow2State *s = bs->opaque;
--
2.7.4
next prev parent reply other threads:[~2017-11-16 16:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-16 16:54 [Qemu-devel] [PATCH v2 0/4] compressed block-stream Anton Nefedov
2017-11-16 16:54 ` Anton Nefedov [this message]
2017-11-20 14:53 ` [Qemu-devel] [PATCH v2 1/4] qcow2: multiple clusters write compressed Stefan Hajnoczi
2017-11-20 15:03 ` Denis V. Lunev
2017-11-21 11:07 ` Stefan Hajnoczi
2017-11-16 16:54 ` [Qemu-devel] [PATCH v2 2/4] block: support compressed write for copy-on-read Anton Nefedov
2017-11-20 14:53 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-11-16 16:54 ` [Qemu-devel] [PATCH v2 3/4] block-stream: add compress option Anton Nefedov
2017-11-20 14:53 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-11-16 16:54 ` [Qemu-devel] [PATCH v2 4/4] iotests: 030: add compressed block-stream test Anton Nefedov
2017-11-20 14:38 ` Stefan Hajnoczi
2017-11-20 15:39 ` Anton Nefedov
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=1510851298-59922-2-git-send-email-anton.nefedov@virtuozzo.com \
--to=anton.nefedov@virtuozzo.com \
--cc=den@virtuozzo.com \
--cc=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbutsykin@virtuozzo.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).