From nobody Sun Oct 5 21:00:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530218754151866.4283773540849; Thu, 28 Jun 2018 13:45:54 -0700 (PDT) Received: from localhost ([::1]:38503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdnd-00087p-Co for importer@patchew.org; Thu, 28 Jun 2018 16:45:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdKN-0007yv-7E for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:15:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdKK-0007dz-0v for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:15:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49686 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYdKG-0007WJ-J2; Thu, 28 Jun 2018 16:15:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3493A81A8EB3; Thu, 28 Jun 2018 20:15:32 +0000 (UTC) Received: from red.redhat.com (ovpn-125-113.rdu2.redhat.com [10.10.125.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AAAD2142F20; Thu, 28 Jun 2018 20:15:31 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 15:15:21 -0500 Message-Id: <20180628201525.281787-5-eblake@redhat.com> In-Reply-To: <20180628201525.281787-1-eblake@redhat.com> References: <20180628201525.281787-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 28 Jun 2018 20:15:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 28 Jun 2018 20:15:32 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 4/8] qcow: Switch qcow_co_writev to byte-based calls 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, famz@redhat.com, qemu-block@nongnu.org, jcody@redhat.com, mreitz@redhat.com, stefanha@redhat.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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the internals of the qcow driver write function, by iterating over offset/bytes instead of sector_num/nb_sectors, and with a rename of index_in_cluster and repurposing of n to track bytes instead of sectors. A later patch will then switch the qcow driver as a whole over to byte-based operation. Signed-off-by: Eric Blake Reviewed-by: Jeff Cody --- v2: prefer 64-bit * over 23-bit <<, rename variable for legibility [Kevin] --- block/qcow.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 175f1c8f848..d2af7b8e025 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -724,13 +724,15 @@ static coroutine_fn int qcow_co_writev(BlockDriverSta= te *bs, int64_t sector_num, int flags) { BDRVQcowState *s =3D bs->opaque; - int index_in_cluster; + int offset_in_cluster; uint64_t cluster_offset; int ret =3D 0, n; struct iovec hd_iov; QEMUIOVector hd_qiov; uint8_t *buf; void *orig_buf; + int64_t offset =3D sector_num * BDRV_SECTOR_SIZE; + int64_t bytes =3D nb_sectors * BDRV_SECTOR_SIZE; assert(!flags); s->cluster_cache_offset =3D -1; /* disable compressed cache */ @@ -750,16 +752,14 @@ static coroutine_fn int qcow_co_writev(BlockDriverSta= te *bs, int64_t sector_num, qemu_co_mutex_lock(&s->lock); - while (nb_sectors !=3D 0) { - - index_in_cluster =3D sector_num & (s->cluster_sectors - 1); - n =3D s->cluster_sectors - index_in_cluster; - if (n > nb_sectors) { - n =3D nb_sectors; + while (bytes !=3D 0) { + offset_in_cluster =3D offset & (s->cluster_size - 1); + n =3D s->cluster_size - offset_in_cluster; + if (n > bytes) { + n =3D bytes; } - ret =3D get_cluster_offset(bs, sector_num << 9, 1, 0, - index_in_cluster << 9, - (index_in_cluster + n) << 9, &cluster_off= set); + ret =3D get_cluster_offset(bs, offset, 1, 0, offset_in_cluster, + offset_in_cluster + n, &cluster_offset); if (ret < 0) { break; } @@ -769,30 +769,28 @@ static coroutine_fn int qcow_co_writev(BlockDriverSta= te *bs, int64_t sector_num, } if (bs->encrypted) { assert(s->crypto); - if (qcrypto_block_encrypt(s->crypto, sector_num * BDRV_SECTOR_= SIZE, - buf, n * BDRV_SECTOR_SIZE, NULL) < 0= ) { + if (qcrypto_block_encrypt(s->crypto, offset, buf, n, NULL) < 0= ) { ret =3D -EIO; break; } } hd_iov.iov_base =3D (void *)buf; - hd_iov.iov_len =3D n * 512; + hd_iov.iov_len =3D n; qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); - ret =3D bdrv_co_writev(bs->file, - (cluster_offset >> 9) + index_in_cluster, - n, &hd_qiov); + ret =3D bdrv_co_pwritev(bs->file, cluster_offset + offset_in_clust= er, + n, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; } ret =3D 0; - nb_sectors -=3D n; - sector_num +=3D n; - buf +=3D n * 512; + bytes -=3D n; + offset +=3D n; + buf +=3D n; } qemu_co_mutex_unlock(&s->lock); --=20 2.14.4