From nobody Sun Oct 5 19:25:08 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515193268604722.7136240393804; Fri, 5 Jan 2018 15:01:08 -0800 (PST) Received: from localhost ([::1]:34595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXaz5-0005Gq-Ir for importer@patchew.org; Fri, 05 Jan 2018 18:01:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXawU-000337-IG for qemu-devel@nongnu.org; Fri, 05 Jan 2018 17:58:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXawQ-0000AZ-4y for qemu-devel@nongnu.org; Fri, 05 Jan 2018 17:58:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60156) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eXawM-000074-HP; Fri, 05 Jan 2018 17:58:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E1717CB8B; Fri, 5 Jan 2018 22:58:17 +0000 (UTC) Received: from red.redhat.com (ovpn-124-124.rdu2.redhat.com [10.10.124.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75F0760BE7; Fri, 5 Jan 2018 22:58:13 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 5 Jan 2018 16:57:40 -0600 Message-Id: <20180105225753.30509-8-eblake@redhat.com> In-Reply-To: <20180105225753.30509-1-eblake@redhat.com> References: <20180105225753.30509-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 05 Jan 2018 22:58:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 07/20] iscsi: Switch to .bdrv_co_block_status() 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, famz@redhat.com, qemu-block@nongnu.org, jcody@redhat.com, Peter Lieven , Max Reitz , Ronnie Sahlberg , Paolo Bonzini 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. Update the iscsi driver accordingly. In this case, it is handy to teach iscsi_co_block_status() to handle a NULL map and file parameter, even though the block layer passes non-NULL values, because we also call the function directly. For now, there are no optimizations done based on the want_zero flag. We can also make the simplification of asserting that the block layer passed in aligned values. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng --- v7: rebase to master v6: no change v5: assert rather than check for alignment v4: rebase to interface tweaks v3: no change v2: rebase to mapping parameter --- block/iscsi.c | 67 ++++++++++++++++++++++++++++---------------------------= ---- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index a823cdcb0b..ea4cc08b0c 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -651,34 +651,34 @@ out_unlock: -static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnu= m, - BlockDriverState **file) +static int coroutine_fn iscsi_co_block_status(BlockDriverState *bs, + bool want_zero, int64_t offs= et, + int64_t bytes, int64_t *pnum, + int64_t *map, + BlockDriverState **file) { IscsiLun *iscsilun =3D bs->opaque; struct scsi_get_lba_status *lbas =3D NULL; struct scsi_lba_status_descriptor *lbasd =3D NULL; struct IscsiTask iTask; uint64_t lba; - int64_t ret; + int ret; - if (!is_sector_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { - ret =3D -EINVAL; - goto out; - } + assert(QEMU_IS_ALIGNED(offset | bytes, iscsilun->block_size)); /* default to all sectors allocated */ - ret =3D BDRV_BLOCK_DATA; - ret |=3D (sector_num << BDRV_SECTOR_BITS) | BDRV_BLOCK_OFFSET_VALID; - *pnum =3D nb_sectors; + ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; + if (map) { + *map =3D offset; + } + *pnum =3D bytes; /* LUN does not support logical block provisioning */ if (!iscsilun->lbpme) { goto out; } - lba =3D sector_qemu2lun(sector_num, iscsilun); + lba =3D offset / iscsilun->block_size; iscsi_co_init_iscsitask(iscsilun, &iTask); qemu_mutex_lock(&iscsilun->mutex); @@ -724,12 +724,12 @@ retry: lbasd =3D &lbas->descriptors[0]; - if (sector_qemu2lun(sector_num, iscsilun) !=3D lbasd->lba) { + if (lba !=3D lbasd->lba) { ret =3D -EIO; goto out_unlock; } - *pnum =3D sector_lun2qemu(lbasd->num_blocks, iscsilun); + *pnum =3D lbasd->num_blocks * iscsilun->block_size; if (lbasd->provisioning =3D=3D SCSI_PROVISIONING_TYPE_DEALLOCATED || lbasd->provisioning =3D=3D SCSI_PROVISIONING_TYPE_ANCHORED) { @@ -740,15 +740,13 @@ retry: } if (ret & BDRV_BLOCK_ZERO) { - iscsi_allocmap_set_unallocated(iscsilun, sector_num * BDRV_SECTOR_= SIZE, - *pnum * BDRV_SECTOR_SIZE); + iscsi_allocmap_set_unallocated(iscsilun, offset, *pnum); } else { - iscsi_allocmap_set_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, - *pnum * BDRV_SECTOR_SIZE); + iscsi_allocmap_set_allocated(iscsilun, offset, *pnum); } - if (*pnum > nb_sectors) { - *pnum =3D nb_sectors; + if (*pnum > bytes) { + *pnum =3D bytes; } out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -757,7 +755,7 @@ out: if (iTask.task !=3D NULL) { scsi_free_scsi_task(iTask.task); } - if (ret > 0 && ret & BDRV_BLOCK_OFFSET_VALID) { + if (ret > 0 && ret & BDRV_BLOCK_OFFSET_VALID && file) { *file =3D bs; } return ret; @@ -797,25 +795,24 @@ static int coroutine_fn iscsi_co_readv(BlockDriverSta= te *bs, nb_sectors * BDRV_SECTOR_SIZE) && !iscsi_allocmap_is_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, nb_sectors * BDRV_SECTOR_SIZE)) { - int pnum; - BlockDriverState *file; + int64_t pnum; /* check the block status from the beginning of the cluster * containing the start sector */ - int cluster_sectors =3D iscsilun->cluster_size >> BDRV_SECTOR_BITS; - int head; - int64_t ret; + int64_t head; + int ret; - assert(cluster_sectors); - head =3D sector_num % cluster_sectors; - ret =3D iscsi_co_get_block_status(bs, sector_num - head, - BDRV_REQUEST_MAX_SECTORS, &pnum, - &file); + assert(iscsilun->cluster_size); + head =3D (sector_num * BDRV_SECTOR_SIZE) % iscsilun->cluster_size; + ret =3D iscsi_co_block_status(bs, false, + sector_num * BDRV_SECTOR_SIZE - head, + BDRV_REQUEST_MAX_BYTES, &pnum, NULL, N= ULL); if (ret < 0) { return ret; } /* if the whole request falls into an unallocated area we can avoid * reading and directly return zeroes instead */ - if (ret & BDRV_BLOCK_ZERO && pnum >=3D nb_sectors + head) { + if (ret & BDRV_BLOCK_ZERO && + pnum >=3D nb_sectors * BDRV_SECTOR_SIZE + head) { qemu_iovec_memset(iov, 0, 0x00, iov->size); return 0; } @@ -2213,7 +2210,7 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_truncate =3D iscsi_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, - .bdrv_co_get_block_status =3D iscsi_co_get_block_status, + .bdrv_co_block_status =3D iscsi_co_block_status, .bdrv_co_pdiscard =3D iscsi_co_pdiscard, .bdrv_co_pwrite_zeroes =3D iscsi_co_pwrite_zeroes, .bdrv_co_readv =3D iscsi_co_readv, @@ -2248,7 +2245,7 @@ static BlockDriver bdrv_iser =3D { .bdrv_truncate =3D iscsi_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, - .bdrv_co_get_block_status =3D iscsi_co_get_block_status, + .bdrv_co_block_status =3D iscsi_co_block_status, .bdrv_co_pdiscard =3D iscsi_co_pdiscard, .bdrv_co_pwrite_zeroes =3D iscsi_co_pwrite_zeroes, .bdrv_co_readv =3D iscsi_co_readv, --=20 2.14.3