From nobody Wed Oct 29 08:39:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513595448719690.9769815694868; Mon, 18 Dec 2017 03:10:48 -0800 (PST) Received: from localhost ([::1]:57924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtJi-0003pb-Mr for importer@patchew.org; Mon, 18 Dec 2017 06:10:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtIO-000375-9F for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQtIL-0007Yl-Fc for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:20 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:32542 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQtIL-0007XK-4Y; Mon, 18 Dec 2017 06:09:17 -0500 Received: from iris.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBHC7I70013555; Sun, 17 Dec 2017 15:07:19 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 14:09:11 +0300 Message-Id: <1513595351-5899-6-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513595351-5899-1-git-send-email-den@openvz.org> References: <1513595351-5899-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 5/5] block/parallels: add backing support to readv/writev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Denis V . Lunev" , Vladimir Sementsov-Ogievskiy , Edgar Kaziakhmedov , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Edgar Kaziakhmedov 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 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Stefan Hajnoczi Reviewed-by: Stefan Hajnoczi --- 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, int6= 4_t sector_num, static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { + int ret; BDRVParallelsState *s =3D bs->opaque; int64_t pos, space, idx, to_allocate, i, len; =20 @@ -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 +=3D s->prealloc_size; if (s->prealloc_mode =3D=3D PRL_PREALLOC_MODE_FALLOCATE) { ret =3D bdrv_pwrite_zeroes(bs->file, @@ -186,6 +186,37 @@ static int64_t allocate_clusters(BlockDriverState *bs,= int64_t sector_num, } } =20 + /* 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 no= t need + * this read at all. + * 3. it would be good to combine write of data from backing an= d new + * data into one write call */ + if (bs->backing) { + int64_t nb_cow_sectors =3D to_allocate * s->tracks; + int64_t nb_cow_bytes =3D nb_cow_sectors << BDRV_SECTOR_BITS; + QEMUIOVector qiov; + struct iovec iov =3D { + .iov_len =3D nb_cow_bytes, + .iov_base =3D qemu_blockalign(bs, nb_cow_bytes) + }; + qemu_iovec_init_external(&qiov, &iov, 1); + + ret =3D bdrv_co_readv(bs->backing, idx * s->tracks, nb_cow_sectors, + &qiov); + if (ret < 0) { + qemu_vfree(iov.iov_base); + return ret; + } + + ret =3D bdrv_co_writev(bs->file, s->data_end, nb_cow_sectors, &qio= v); + qemu_vfree(iov.iov_base); + if (ret < 0) { + return ret; + } + } + for (i =3D 0; i < to_allocate; i++) { s->bat_bitmap[idx + i] =3D cpu_to_le32(s->data_end / s->off_multip= lier); s->data_end +=3D s->tracks; @@ -309,12 +340,19 @@ static coroutine_fn int parallels_co_readv(BlockDrive= rState *bs, =20 nbytes =3D n << BDRV_SECTOR_BITS; =20 + 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 =3D 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 =3D bdrv_co_readv(bs->file, position, n, &hd_qiov); if (ret < 0) { break; @@ -748,7 +786,7 @@ static BlockDriver bdrv_parallels =3D { .bdrv_co_flush_to_os =3D parallels_co_flush_to_os, .bdrv_co_readv =3D parallels_co_readv, .bdrv_co_writev =3D parallels_co_writev, - + .supports_backing =3D true, .bdrv_create =3D parallels_create, .bdrv_check =3D parallels_check, .create_opts =3D ¶llels_create_opts, --=20 2.7.4