From: "Denis V. Lunev" <den@openvz.org>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
"Denis V . Lunev" <den@openvz.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 5/5] block/parallels: add backing support to readv/writev
Date: Mon, 18 Dec 2017 14:09:11 +0300 [thread overview]
Message-ID: <1513595351-5899-6-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1513595351-5899-1-git-send-email-den@openvz.org>
From: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
Since parallels format supports backing files, refine
readv/writev (allocate_clusters) to redirect read/write requests
to a backing file (if cluster is not available in the current bs).
Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Stefan Hajnoczi <stefanha@redhat.com>
---
block/parallels.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 44 insertions(+), 6 deletions(-)
diff --git a/block/parallels.c b/block/parallels.c
index 7a8e8b0..d380208 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -142,6 +142,7 @@ static int64_t block_status(BDRVParallelsState *s, int64_t sector_num,
static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum)
{
+ int ret;
BDRVParallelsState *s = bs->opaque;
int64_t pos, space, idx, to_allocate, i, len;
@@ -170,7 +171,6 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
return len;
}
if (s->data_end + space > (len >> BDRV_SECTOR_BITS)) {
- int ret;
space += s->prealloc_size;
if (s->prealloc_mode == PRL_PREALLOC_MODE_FALLOCATE) {
ret = bdrv_pwrite_zeroes(bs->file,
@@ -186,6 +186,37 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
}
}
+ /* Try to read from backing to fill empty clusters
+ * FIXME: 1. previous write_zeroes may be redundant
+ * 2. most of data we read from backing will be rewritten by
+ * parallels_co_writev. On aligned-to-cluster write we do not need
+ * this read at all.
+ * 3. it would be good to combine write of data from backing and new
+ * data into one write call */
+ if (bs->backing) {
+ int64_t nb_cow_sectors = to_allocate * s->tracks;
+ int64_t nb_cow_bytes = nb_cow_sectors << BDRV_SECTOR_BITS;
+ QEMUIOVector qiov;
+ struct iovec iov = {
+ .iov_len = nb_cow_bytes,
+ .iov_base = qemu_blockalign(bs, nb_cow_bytes)
+ };
+ qemu_iovec_init_external(&qiov, &iov, 1);
+
+ ret = bdrv_co_readv(bs->backing, idx * s->tracks, nb_cow_sectors,
+ &qiov);
+ if (ret < 0) {
+ qemu_vfree(iov.iov_base);
+ return ret;
+ }
+
+ ret = bdrv_co_writev(bs->file, s->data_end, nb_cow_sectors, &qiov);
+ qemu_vfree(iov.iov_base);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
for (i = 0; i < to_allocate; i++) {
s->bat_bitmap[idx + i] = cpu_to_le32(s->data_end / s->off_multiplier);
s->data_end += s->tracks;
@@ -309,12 +340,19 @@ static coroutine_fn int parallels_co_readv(BlockDriverState *bs,
nbytes = n << BDRV_SECTOR_BITS;
+ qemu_iovec_reset(&hd_qiov);
+ qemu_iovec_concat(&hd_qiov, qiov, bytes_done, nbytes);
+
if (position < 0) {
- qemu_iovec_memset(qiov, bytes_done, 0, nbytes);
+ if (bs->backing) {
+ ret = bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov);
+ if (ret < 0) {
+ break;
+ }
+ } else {
+ qemu_iovec_memset(&hd_qiov, 0, 0, nbytes);
+ }
} else {
- qemu_iovec_reset(&hd_qiov);
- qemu_iovec_concat(&hd_qiov, qiov, bytes_done, nbytes);
-
ret = bdrv_co_readv(bs->file, position, n, &hd_qiov);
if (ret < 0) {
break;
@@ -748,7 +786,7 @@ static BlockDriver bdrv_parallels = {
.bdrv_co_flush_to_os = parallels_co_flush_to_os,
.bdrv_co_readv = parallels_co_readv,
.bdrv_co_writev = parallels_co_writev,
-
+ .supports_backing = true,
.bdrv_create = parallels_create,
.bdrv_check = parallels_check,
.create_opts = ¶llels_create_opts,
--
2.7.4
next prev parent reply other threads:[~2017-12-18 11:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-18 11:09 [Qemu-devel] [PATCH 0/5] preparation for Parallels Disk xml driver Denis V. Lunev
2017-12-18 11:09 ` [Qemu-devel] [PATCH 1/5] docs/interop/prl-xml: description of Parallels Disk format Denis V. Lunev
2018-01-04 11:34 ` Stefan Hajnoczi
2018-01-10 16:23 ` klim
2018-01-11 15:33 ` Stefan Hajnoczi
2017-12-18 11:09 ` [Qemu-devel] [PATCH 2/5] configure: add dependency Denis V. Lunev
2017-12-22 12:38 ` [Qemu-devel] [Qemu-block] " Roman Kagan
2018-01-10 15:37 ` klim
2018-01-10 15:49 ` Daniel P. Berrange
2017-12-18 11:09 ` [Qemu-devel] [PATCH 3/5] block/parallels: move some structures into header Denis V. Lunev
2018-01-04 13:18 ` Stefan Hajnoczi
2017-12-18 11:09 ` [Qemu-devel] [PATCH 4/5] block/parallels: replace some magic numbers Denis V. Lunev
2018-01-04 13:20 ` Stefan Hajnoczi
2017-12-18 11:09 ` Denis V. Lunev [this message]
2018-01-04 13:29 ` [Qemu-devel] [PATCH 5/5] block/parallels: add backing support to readv/writev Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2018-01-10 17:36 [Qemu-devel] [PATCH 0/5 v2] preparation for Parallels Disk xml driver Klim Kireev
2018-01-10 17:36 ` [Qemu-devel] [PATCH 5/5] block/parallels: add backing support to readv/writev Klim Kireev
2018-01-12 9:01 [Qemu-devel] [PATCH 0/5 v3] preparation for Parallels Disk xml driver Klim Kireev
2018-01-12 9:01 ` [Qemu-devel] [PATCH 5/5] block/parallels: add backing support to readv/writev Klim Kireev
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=1513595351-5899-6-git-send-email-den@openvz.org \
--to=den@openvz.org \
--cc=edgar.kaziakhmedov@virtuozzo.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.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).