From nobody Sun Oct 5 17:23:30 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 1524681606144870.2742791699725; Wed, 25 Apr 2018 11:40:06 -0700 (PDT) Received: from localhost ([::1]:38494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPKj-0003Ld-Fy for importer@patchew.org; Wed, 25 Apr 2018 14:40:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDa-0005xU-QL 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-0004QX-Fv for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34004 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 1fBPDV-0004Ip-0U; Wed, 25 Apr 2018 14:32:33 -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 98EFC81A8071; Wed, 25 Apr 2018 18:32:32 +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 52043111CB8E; Wed, 25 Apr 2018 18:32:29 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:16 -0500 Message-Id: <20180425183223.580566-2-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.8]); Wed, 25 Apr 2018 18:32:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 25 Apr 2018 18:32:32 +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 1/8] parallels: Switch 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 , "Denis V. Lunev" , "open list:parallels" , Stefan Hajnoczi , 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 last few sector-based calls into the block layer from the parallels driver. Ideally, the parallels driver should switch to doing everything byte-based, but that's a more invasive change that requires a bit more auditing. Signed-off-by: Eric Blake Reviewed-by: Denis V. Lunev Reviewed-by: Stefan Hajnoczi --- block/parallels.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 3f74fcb877a..c071c7f759f 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -226,14 +226,15 @@ static int64_t allocate_clusters(BlockDriverState *bs= , int64_t sector_num, }; qemu_iovec_init_external(&qiov, &iov, 1); - ret =3D bdrv_co_readv(bs->backing, idx * s->tracks, nb_cow_sectors, - &qiov); + ret =3D bdrv_co_preadv(bs->backing, idx * s->tracks * BDRV_SECTOR_= SIZE, + nb_cow_bytes, &qiov, 0); 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); + ret =3D bdrv_co_pwritev(bs->file, s->data_end * BDRV_SECTOR_SIZE, + nb_cow_bytes, &qiov, 0); qemu_vfree(iov.iov_base); if (ret < 0) { return ret; @@ -339,7 +340,8 @@ static coroutine_fn int parallels_co_writev(BlockDriver= State *bs, qemu_iovec_reset(&hd_qiov); qemu_iovec_concat(&hd_qiov, qiov, bytes_done, nbytes); - ret =3D bdrv_co_writev(bs->file, position, n, &hd_qiov); + ret =3D bdrv_co_pwritev(bs->file, position * BDRV_SECTOR_SIZE, nby= tes, + &hd_qiov, 0); if (ret < 0) { break; } @@ -378,7 +380,8 @@ static coroutine_fn int parallels_co_readv(BlockDriverS= tate *bs, if (position < 0) { if (bs->backing) { - ret =3D bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov= ); + ret =3D bdrv_co_preadv(bs->backing, sector_num * BDRV_SECT= OR_SIZE, + nbytes, &hd_qiov, 0); if (ret < 0) { break; } @@ -386,7 +389,8 @@ static coroutine_fn int parallels_co_readv(BlockDriverS= tate *bs, qemu_iovec_memset(&hd_qiov, 0, 0, nbytes); } } else { - ret =3D bdrv_co_readv(bs->file, position, n, &hd_qiov); + ret =3D bdrv_co_preadv(bs->file, position * BDRV_SECTOR_SIZE, = nbytes, + &hd_qiov, 0); if (ret < 0) { break; } --=20 2.14.3 From nobody Sun Oct 5 17:23:30 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 152468146551954.101821764598185; Wed, 25 Apr 2018 11:37:45 -0700 (PDT) Received: from localhost ([::1]:38484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPIS-0001Rn-M0 for importer@patchew.org; Wed, 25 Apr 2018 14:37:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDa-0005xI-Lp 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-0004QV-FY for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39278 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 1fBPDV-0004Jc-Jv; Wed, 25 Apr 2018 14:32:33 -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 31B22406C741; Wed, 25 Apr 2018 18:32:33 +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 BDBD1111DD13; Wed, 25 Apr 2018 18:32:32 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:17 -0500 Message-Id: <20180425183223.580566-3-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.5]); Wed, 25 Apr 2018 18:32:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 25 Apr 2018 18:32:33 +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 2/8] qcow: Switch get_cluster_offset to be byte-based 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 internal helper function get_cluster_offset(), by changing n_start and n_end to by byte offsets rather than sector indices within the cluster being allocated. 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 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index dd042b8ddbe..32730a8dd91 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -345,8 +345,8 @@ static int qcow_reopen_prepare(BDRVReopenState *state, * * 0 to not allocate. * - * 1 to allocate a normal cluster (for sector indexes 'n_start' to - * 'n_end') + * 1 to allocate a normal cluster (for byte offsets 'n_start' to + * 'n_end' within the cluster) * * 2 to allocate a compressed cluster of size * 'compressed_size'. 'compressed_size' must be > 0 and < @@ -442,7 +442,7 @@ static int get_cluster_offset(BlockDriverState *bs, BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC); /* allocate a new cluster */ if ((cluster_offset & QCOW_OFLAG_COMPRESSED) && - (n_end - n_start) < s->cluster_sectors) { + (n_end - n_start) < s->cluster_size) { /* if the cluster is already compressed, we must decompress it in the case it is not completely overwritten */ @@ -480,16 +480,15 @@ static int get_cluster_offset(BlockDriverState *bs, /* if encrypted, we must initialize the cluster content which won't be written */ if (bs->encrypted && - (n_end - n_start) < s->cluster_sectors) { - uint64_t start_sect; + (n_end - n_start) < s->cluster_size) { + uint64_t start_offset; assert(s->crypto); - start_sect =3D (offset & ~(s->cluster_size - 1)) >> 9; - for(i =3D 0; i < s->cluster_sectors; i++) { + start_offset =3D offset & ~(s->cluster_size - 1); + for (i =3D 0; i < s->cluster_size; i +=3D BDRV_SECTOR_= SIZE) { if (i < n_start || i >=3D n_end) { - memset(s->cluster_data, 0x00, 512); + memset(s->cluster_data, 0x00, BDRV_SECTOR_SIZE= ); if (qcrypto_block_encrypt(s->crypto, - (start_sect + i) * - BDRV_SECTOR_SIZE, + start_offset + i, s->cluster_data, BDRV_SECTOR_SIZE, NULL) < 0) { @@ -497,8 +496,9 @@ static int get_cluster_offset(BlockDriverState *bs, } BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); ret =3D bdrv_pwrite(bs->file, - cluster_offset + i * 512, - s->cluster_data, 512); + cluster_offset + i, + s->cluster_data, + BDRV_SECTOR_SIZE); if (ret < 0) { return ret; } @@ -758,8 +758,8 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, n =3D nb_sectors; } ret =3D get_cluster_offset(bs, sector_num << 9, 1, 0, - index_in_cluster, - index_in_cluster + n, &cluster_offset); + index_in_cluster << 9, + (index_in_cluster + n) << 9, &cluster_off= set); if (ret < 0) { break; } --=20 2.14.3 From nobody Sun Oct 5 17:23:30 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 1524681466281318.91797447494434; Wed, 25 Apr 2018 11:37:46 -0700 (PDT) Received: from localhost ([::1]:38485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPIX-0001VO-GP for importer@patchew.org; Wed, 25 Apr 2018 14:37:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDa-0005xF-Js 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-0004Qf-GD for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50118 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-0004KS-66; 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 BFBCC7CBBA; Wed, 25 Apr 2018 18:32:33 +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 567921101E88; Wed, 25 Apr 2018 18:32:33 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:18 -0500 Message-Id: <20180425183223.580566-4-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:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 25 Apr 2018 18:32:33 +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 3/8] qcow: Switch qcow_co_readv 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 read 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 | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 32730a8dd91..bf9d80fd227 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -623,6 +623,8 @@ static coroutine_fn int qcow_co_readv(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; if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); @@ -636,36 +638,36 @@ static coroutine_fn int qcow_co_readv(BlockDriverStat= e *bs, int64_t sector_num, qemu_co_mutex_lock(&s->lock); - while (nb_sectors !=3D 0) { + while (bytes !=3D 0) { /* prepare next request */ - ret =3D get_cluster_offset(bs, sector_num << 9, + ret =3D get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset); if (ret < 0) { break; } - 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; + index_in_cluster =3D offset & (s->cluster_size - 1); + n =3D s->cluster_size - index_in_cluster; + if (n > bytes) { + n =3D bytes; } if (!cluster_offset) { if (bs->backing) { /* read from the base image */ 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); /* qcow2 emits this on bs->file instead of bs->backing */ BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); - ret =3D bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov= ); + ret =3D bdrv_co_preadv(bs->backing, offset, n, &hd_qiov, 0= ); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; } } else { /* Note: in this case, no need to wait */ - memset(buf, 0, 512 * n); + memset(buf, 0, n); } } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { /* add AIO support for compressed blocks ? */ @@ -673,21 +675,19 @@ static coroutine_fn int qcow_co_readv(BlockDriverStat= e *bs, int64_t sector_num, ret =3D -EIO; break; } - memcpy(buf, - s->cluster_cache + index_in_cluster * 512, 512 * n); + memcpy(buf, s->cluster_cache + index_in_cluster, n); } else { if ((cluster_offset & 511) !=3D 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_READ_AIO); - ret =3D bdrv_co_readv(bs->file, - (cluster_offset >> 9) + index_in_cluster, - n, &hd_qiov); + ret =3D bdrv_co_preadv(bs->file, cluster_offset + index_in_clu= ster, + n, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; @@ -695,8 +695,7 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, if (bs->encrypted) { assert(s->crypto); if (qcrypto_block_decrypt(s->crypto, - sector_num * BDRV_SECTOR_SIZE, b= uf, - n * BDRV_SECTOR_SIZE, NULL) < 0)= { + offset, buf, n, NULL) < 0) { ret =3D -EIO; break; } @@ -704,9 +703,9 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, } 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 From nobody Sun Oct 5 17:23:30 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 From nobody Sun Oct 5 17:23:30 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 152468146845128.490977675834642; Wed, 25 Apr 2018 11:37:48 -0700 (PDT) Received: from localhost ([::1]:38486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPIZ-0001Xi-NT for importer@patchew.org; Wed, 25 Apr 2018 14:37:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDb-0005xu-3d for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBPDZ-0004RN-Sy for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58116 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 1fBPDX-0004ME-BP; Wed, 25 Apr 2018 14:32:35 -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 E6AA3EB6E5; 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 7E65110F1C05; Wed, 25 Apr 2018 18:32:34 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:20 -0500 Message-Id: <20180425183223.580566-6-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.1]); Wed, 25 Apr 2018 18:32:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); 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 5/8] qcow: Switch to a byte-based driver 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. The qcow driver is now ready to fully utilize the byte-based callback interface, as long as we override the default alignment to still be 512 (needed at least for encryption, but easier to do everywhere than to audit which sub-sector requests are handled correctly). Signed-off-by: Eric Blake --- block/qcow.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index ea81a3bf87d..75fd75cf976 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -69,7 +69,6 @@ typedef struct QCowHeader { typedef struct BDRVQcowState { int cluster_bits; int cluster_size; - int cluster_sectors; int l2_bits; int l2_size; unsigned int l1_size; @@ -235,7 +234,6 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, } s->cluster_bits =3D header.cluster_bits; s->cluster_size =3D 1 << s->cluster_bits; - s->cluster_sectors =3D 1 << (s->cluster_bits - 9); s->l2_bits =3D header.l2_bits; s->l2_size =3D 1 << s->l2_bits; bs->total_sectors =3D header.size / 512; @@ -612,8 +610,18 @@ static int decompress_cluster(BlockDriverState *bs, ui= nt64_t cluster_offset) return 0; } -static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector= _num, - int nb_sectors, QEMUIOVector *qiov) +static void qcow_refresh_limits(BlockDriverState *bs, Error **errp) +{ + /* At least encrypted images require 512-byte alignment. Apply the + * limit universally, rather than just on encrypted images, as + * it's easier to let the block layer handle rounding than to + * audit this code further. */ + bs->bl.request_alignment =3D BDRV_SECTOR_SIZE; +} + +static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, uint64_t offs= et, + uint64_t bytes, QEMUIOVector *qiov, + int flags) { BDRVQcowState *s =3D bs->opaque; int index_in_cluster; @@ -623,9 +631,8 @@ static coroutine_fn int qcow_co_readv(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); if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); if (buf =3D=3D NULL) { @@ -718,9 +725,9 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, return ret; } -static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t secto= r_num, - int nb_sectors, QEMUIOVector *qiov, - int flags) +static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, uint64_t off= set, + uint64_t bytes, QEMUIOVector *qiov, + int flags) { BDRVQcowState *s =3D bs->opaque; int index_in_cluster; @@ -730,8 +737,6 @@ 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 */ @@ -1108,8 +1113,7 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, uint= 64_t offset, if (ret !=3D Z_STREAM_END || out_len >=3D s->cluster_size) { /* could not compress: write normal cluster */ - ret =3D qcow_co_writev(bs, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS, qiov, 0); + ret =3D qcow_co_pwritev(bs, offset, bytes, qiov, 0); if (ret < 0) { goto fail; } @@ -1194,9 +1198,10 @@ static BlockDriver bdrv_qcow =3D { .bdrv_co_create_opts =3D qcow_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .supports_backing =3D true, + .bdrv_refresh_limits =3D qcow_refresh_limits, - .bdrv_co_readv =3D qcow_co_readv, - .bdrv_co_writev =3D qcow_co_writev, + .bdrv_co_preadv =3D qcow_co_preadv, + .bdrv_co_pwritev =3D qcow_co_pwritev, .bdrv_co_block_status =3D qcow_co_block_status, .bdrv_make_empty =3D qcow_make_empty, --=20 2.14.3 From nobody Sun Oct 5 17:23:30 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 1524681321456866.0813142534957; Wed, 25 Apr 2018 11:35:21 -0700 (PDT) Received: from localhost ([::1]:38462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPGC-0007iO-Kw for importer@patchew.org; Wed, 25 Apr 2018 14:35:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDa-0005xZ-T3 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 1fBPDa-0004Rh-1U for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34016 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 1fBPDY-0004Nk-12; Wed, 25 Apr 2018 14:32:36 -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 A1ED181A8720; Wed, 25 Apr 2018 18:32:35 +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 192B210F1C05; Wed, 25 Apr 2018 18:32:35 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:21 -0500 Message-Id: <20180425183223.580566-7-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.8]); Wed, 25 Apr 2018 18:32:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 25 Apr 2018 18:32:35 +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 6/8] replication: Switch 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 , Wen Congyang , Xie Changlong , "open list:Block layer core" , 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 last few sector-based calls into the block layer from the replication driver. Ideally, the replication driver should switch to doing everything byte-based, but that's a more invasive change that requires a bit more auditing. Signed-off-by: Eric Blake --- block/replication.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block/replication.c b/block/replication.c index 48148b884a5..131639d0714 100644 --- a/block/replication.c +++ b/block/replication.c @@ -246,13 +246,14 @@ static coroutine_fn int replication_co_readv(BlockDri= verState *bs, backup_cow_request_begin(&req, child->bs->job, sector_num * BDRV_SECTOR_SIZE, remaining_bytes); - ret =3D bdrv_co_readv(bs->file, sector_num, remaining_sectors, - qiov); + ret =3D bdrv_co_preadv(bs->file, sector_num * BDRV_SECTOR_SIZE, + remaining_bytes, qiov, 0); backup_cow_request_end(&req); goto out; } - ret =3D bdrv_co_readv(bs->file, sector_num, remaining_sectors, qiov); + ret =3D bdrv_co_preadv(bs->file, sector_num * BDRV_SECTOR_SIZE, + remaining_sectors * BDRV_SECTOR_SIZE, qiov, 0); out: return replication_return_value(s, ret); } @@ -279,8 +280,8 @@ static coroutine_fn int replication_co_writev(BlockDriv= erState *bs, } if (ret =3D=3D 0) { - ret =3D bdrv_co_writev(top, sector_num, - remaining_sectors, qiov); + ret =3D bdrv_co_pwritev(top, sector_num * BDRV_SECTOR_SIZE, + remaining_sectors * BDRV_SECTOR_SIZE, qiov, = 0); return replication_return_value(s, ret); } @@ -306,7 +307,8 @@ static coroutine_fn int replication_co_writev(BlockDriv= erState *bs, qemu_iovec_concat(&hd_qiov, qiov, bytes_done, count); target =3D ret ? top : base; - ret =3D bdrv_co_writev(target, sector_num, n, &hd_qiov); + ret =3D bdrv_co_pwritev(target, sector_num * BDRV_SECTOR_SIZE, + n * BDRV_SECTOR_SIZE, &hd_qiov, 0); if (ret < 0) { goto out1; } --=20 2.14.3 From nobody Sun Oct 5 17:23:30 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524681605159510.5587362629059; Wed, 25 Apr 2018 11:40:05 -0700 (PDT) Received: from localhost ([::1]:38493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPKc-0003HD-Nu for importer@patchew.org; Wed, 25 Apr 2018 14:39:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDb-0005z7-U6 for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBPDb-0004TN-0R for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34022 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 1fBPDY-0004PE-W7; Wed, 25 Apr 2018 14:32:37 -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 9117E81A88BE; Wed, 25 Apr 2018 18:32:36 +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 161C910F1C00; Wed, 25 Apr 2018 18:32:36 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:22 -0500 Message-Id: <20180425183223.580566-8-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.8]); Wed, 25 Apr 2018 18:32:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 25 Apr 2018 18:32:36 +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 7/8] vhdx: Switch 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 , Jeff Cody , "open list:VHDX" , 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 last few sector-based calls into the block layer from the vhdx driver. Ideally, the vhdx driver should switch to doing everything byte-based, but that's a more invasive change that requires a bit more auditing. Signed-off-by: Eric Blake --- block/vhdx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 0b72d895db4..f1dfda6e3e5 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1126,9 +1126,9 @@ static coroutine_fn int vhdx_co_readv(BlockDriverStat= e *bs, int64_t sector_num, break; case PAYLOAD_BLOCK_FULLY_PRESENT: qemu_co_mutex_unlock(&s->lock); - ret =3D bdrv_co_readv(bs->file, - sinfo.file_offset >> BDRV_SECTOR_BITS, - sinfo.sectors_avail, &hd_qiov); + ret =3D bdrv_co_preadv(bs->file, sinfo.file_offset, + sinfo.sectors_avail * BDRV_SECTOR_SIZ= E, + &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto exit; @@ -1348,9 +1348,9 @@ static coroutine_fn int vhdx_co_writev(BlockDriverSta= te *bs, int64_t sector_num, } /* block exists, so we can just overwrite it */ qemu_co_mutex_unlock(&s->lock); - ret =3D bdrv_co_writev(bs->file, - sinfo.file_offset >> BDRV_SECTOR_BITS, - sectors_to_write, &hd_qiov); + ret =3D bdrv_co_pwritev(bs->file, sinfo.file_offset, + sectors_to_write * BDRV_SECTOR_SIZE, + &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto error_bat_restore; --=20 2.14.3 From nobody Sun Oct 5 17:23:30 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 1524681720665711.6115382541308; Wed, 25 Apr 2018 11:42:00 -0700 (PDT) Received: from localhost ([::1]:38514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPMd-0004yu-VI for importer@patchew.org; Wed, 25 Apr 2018 14:42:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDh-00062q-IX for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBPDg-0004c5-Go for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58124 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 1fBPDb-0004UG-Q2; Wed, 25 Apr 2018 14:32:39 -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 68022EB6E5; Wed, 25 Apr 2018 18:32:39 +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 B72F9111DD13; Wed, 25 Apr 2018 18:32:36 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:23 -0500 Message-Id: <20180425183223.580566-9-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.1]); Wed, 25 Apr 2018 18:32:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 25 Apr 2018 18:32:39 +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 8/8] block: Removed unused sector-based vectored I/O 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 , Fam Zheng , "open list:Block I/O path" , Stefan Hajnoczi , 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. Now that all callers of vectored I/O have been converted to use our preferred byte-based bdrv_co_p{read,write}v(), we can delete the unused bdrv_co_{read,write}v(). Furthermore, this gets rid of the signature difference between the public bdrv_co_writev and the callback .bdrv_co_writev. Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block.h | 4 ---- block/io.c | 36 ------------------------------------ 2 files changed, 40 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index cdec3639a35..8b191c23d97 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -278,10 +278,6 @@ int bdrv_pwrite(BdrvChild *child, int64_t offset, cons= t void *buf, int bytes); int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, const void *buf, int count); -int coroutine_fn bdrv_co_readv(BdrvChild *child, int64_t sector_num, - int nb_sectors, QEMUIOVector *qiov); -int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num, - int nb_sectors, QEMUIOVector *qiov); /* * Efficiently zero a region of the disk image. Note that this is a regul= ar * I/O request like read or write and should have a reasonable size. This diff --git a/block/io.c b/block/io.c index 4fad5ac2fef..7155786eb47 100644 --- a/block/io.c +++ b/block/io.c @@ -1339,24 +1339,6 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, return ret; } -static int coroutine_fn bdrv_co_do_readv(BdrvChild *child, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, - BdrvRequestFlags flags) -{ - if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { - return -EINVAL; - } - - return bdrv_co_preadv(child, sector_num << BDRV_SECTOR_BITS, - nb_sectors << BDRV_SECTOR_BITS, qiov, flags); -} - -int coroutine_fn bdrv_co_readv(BdrvChild *child, int64_t sector_num, - int nb_sectors, QEMUIOVector *qiov) -{ - return bdrv_co_do_readv(child, sector_num, nb_sectors, qiov, 0); -} - static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { @@ -1795,24 +1777,6 @@ out: return ret; } -static int coroutine_fn bdrv_co_do_writev(BdrvChild *child, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, - BdrvRequestFlags flags) -{ - if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { - return -EINVAL; - } - - return bdrv_co_pwritev(child, sector_num << BDRV_SECTOR_BITS, - nb_sectors << BDRV_SECTOR_BITS, qiov, flags); -} - -int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num, - int nb_sectors, QEMUIOVector *qiov) -{ - return bdrv_co_do_writev(child, sector_num, nb_sectors, qiov, 0); -} - int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) { --=20 2.14.3