From nobody Thu May 2 02:42:31 2024 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513096444943134.64548757186606; Tue, 12 Dec 2017 08:34:04 -0800 (PST) Received: from localhost ([::1]:59279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOnVG-0001G8-Hb for importer@patchew.org; Tue, 12 Dec 2017 11:33:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOmE5-0001aA-53 for qemu-devel@nongnu.org; Tue, 12 Dec 2017 10:12:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOmE2-00061A-Im for qemu-devel@nongnu.org; Tue, 12 Dec 2017 10:12:09 -0500 Received: from [195.214.232.23] (port=25690 helo=US-EXCH2.sw.swsoft.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eOmDt-0005vN-D2; Tue, 12 Dec 2017 10:11:57 -0500 Received: from darkstar.sw.ru (172.16.25.219) by US-EXCH2.sw.swsoft.com (172.16.10.60) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 12 Dec 2017 06:41:01 -0800 From: Edgar Kaziakhmedov To: , Date: Tue, 12 Dec 2017 17:40:54 +0300 Message-ID: <20171212144054.16955-1-edgar.kaziakhmedov@virtuozzo.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-ClientProxiedBy: US-EXCH2.sw.swsoft.com (172.16.10.60) To US-EXCH2.sw.swsoft.com (172.16.10.60) X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 195.214.232.23 X-Mailman-Approved-At: Tue, 12 Dec 2017 11:32:28 -0500 Subject: [Qemu-devel] [PATCH] qcow2: get rid of qcow2_backing_read1 routine 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: kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com, klim.kireev@virtuozzo.com, den@openvz.org, edgar.kaziakhmedov@virtuozzo.com 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 Content-Type: text/plain; charset="utf-8" Since bdrv_co_preadv does all neccessary checks including reading after the end of the backing file, avoid duplication of verification before bdrv_co_preadv call. Signed-off-by: Edgar Kaziakhmedov Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/qcow2.c | 51 ++++++++------------------------------------------- block/qcow2.h | 3 --- 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 1914a940e5..4348b2c0c5 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1672,34 +1672,12 @@ static int64_t coroutine_fn qcow2_co_get_block_stat= us(BlockDriverState *bs, return status; } =20 -/* handle reading after the end of the backing file */ -int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, - int64_t offset, int bytes) -{ - uint64_t bs_size =3D bs->total_sectors * BDRV_SECTOR_SIZE; - int n1; - - if ((offset + bytes) <=3D bs_size) { - return bytes; - } - - if (offset >=3D bs_size) { - n1 =3D 0; - } else { - n1 =3D bs_size - offset; - } - - qemu_iovec_memset(qiov, n1, 0, bytes - n1); - - return n1; -} - static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t off= set, uint64_t bytes, QEMUIOVector *qiov, int flags) { BDRVQcow2State *s =3D bs->opaque; - int offset_in_cluster, n1; + int offset_in_cluster; int ret; unsigned int cur_bytes; /* number of bytes in current iteration */ uint64_t cluster_offset =3D 0; @@ -1734,26 +1712,13 @@ static coroutine_fn int qcow2_co_preadv(BlockDriver= State *bs, uint64_t offset, case QCOW2_CLUSTER_UNALLOCATED: =20 if (bs->backing) { - /* read from the base image */ - n1 =3D qcow2_backing_read1(bs->backing->bs, &hd_qiov, - offset, cur_bytes); - if (n1 > 0) { - QEMUIOVector local_qiov; - - qemu_iovec_init(&local_qiov, hd_qiov.niov); - qemu_iovec_concat(&local_qiov, &hd_qiov, 0, n1); - - BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); - qemu_co_mutex_unlock(&s->lock); - ret =3D bdrv_co_preadv(bs->backing, offset, n1, - &local_qiov, 0); - qemu_co_mutex_lock(&s->lock); - - qemu_iovec_destroy(&local_qiov); - - if (ret < 0) { - goto fail; - } + BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); + qemu_co_mutex_unlock(&s->lock); + ret =3D bdrv_co_preadv(bs->backing, offset, cur_bytes, + &hd_qiov, 0); + qemu_co_mutex_lock(&s->lock); + if (ret < 0) { + goto fail; } } else { /* Note: in this case, no need to wait */ diff --git a/block/qcow2.h b/block/qcow2.h index 6f0ff15dd0..46c8cf44ec 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -528,9 +528,6 @@ uint32_t offset_to_reftable_index(BDRVQcow2State *s, ui= nt64_t offset) } =20 /* qcow2.c functions */ -int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, - int64_t sector_num, int nb_sectors); - int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size, int refcount_order, bool generous_inc= rease, uint64_t *refblock_count); --=20 2.11.0