From nobody Sun Oct 5 19:25:48 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 1524681336780988.4285257628233; Wed, 25 Apr 2018 11:35:36 -0700 (PDT) Received: from localhost ([::1]:38464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPGR-0007yp-SK for importer@patchew.org; Wed, 25 Apr 2018 14:35:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDa-0005xN-Na for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBPDZ-0004Qr-Hi for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50122 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 1fBPDW-0004LA-Of; Wed, 25 Apr 2018 14:32:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57AB68DC4C; Wed, 25 Apr 2018 18:32:34 +0000 (UTC) Received: from red.redhat.com (ovpn-123-175.rdu2.redhat.com [10.10.123.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id E535810F1C05; Wed, 25 Apr 2018 18:32:33 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:19 -0500 Message-Id: <20180425183223.580566-5-eblake@redhat.com> In-Reply-To: <20180425183223.580566-1-eblake@redhat.com> References: <20180425183223.580566-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 25 Apr 2018 18:32:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 25 Apr 2018 18:32:34 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 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: Kevin Wolf , "open list:qcow" , Max Reitz 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 repurposing index_in_cluster and n to be 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 --- block/qcow.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index bf9d80fd227..ea81a3bf87d 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -730,6 +730,8 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, QEMUIOVector hd_qiov; uint8_t *buf; void *orig_buf; + int64_t offset =3D sector_num << BDRV_SECTOR_BITS; + int64_t bytes =3D nb_sectors << BDRV_SECTOR_BITS; assert(!flags); s->cluster_cache_offset =3D -1; /* disable compressed cache */ @@ -749,16 +751,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) { + index_in_cluster =3D offset & (s->cluster_size - 1); + n =3D s->cluster_size - index_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, index_in_cluster, + index_in_cluster + n, &cluster_offset); if (ret < 0) { break; } @@ -768,30 +768,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 + index_in_cluste= r, + 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.3