From nobody Sun Oct 5 19:22:57 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 1507835086196759.1193833064618; Thu, 12 Oct 2017 12:04:46 -0700 (PDT) Received: from localhost ([::1]:46849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ima-0006EV-2u for importer@patchew.org; Thu, 12 Oct 2017 15:04:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2iku-0005H2-8b for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:02:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2iks-0000Y6-US for qemu-devel@nongnu.org; Thu, 12 Oct 2017 15:02:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2ikn-0000Ri-OC; Thu, 12 Oct 2017 15:02:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0BB5780C1; Thu, 12 Oct 2017 19:02:44 +0000 (UTC) Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 158EB614E7; Thu, 12 Oct 2017 19:02:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B0BB5780C1 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 13:59:02 -0500 Message-Id: <20171012185916.22776-7-eblake@redhat.com> In-Reply-To: <20171012185916.22776-1-eblake@redhat.com> References: <20171012185916.22776-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 12 Oct 2017 19:02:44 +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 v4 06/20] iscsi: Switch iscsi_allocmap_update() to 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: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, Peter Lieven , Max Reitz , Ronnie Sahlberg , Paolo Bonzini , jsnow@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 converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert all uses of the allocmap (no semantic change). Callers that already had bytes available are simpler, and callers that now scale to bytes will be easier to switch to byte-based in the future. Signed-off-by: Eric Blake Acked-by: Paolo Bonzini --- v2: rebase to count/bytes rename --- block/iscsi.c | 90 +++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 8f903d8370..4896d50d6e 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -455,24 +455,22 @@ static int iscsi_allocmap_init(IscsiLun *iscsilun, in= t open_flags) } static void -iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num, - int nb_sectors, bool allocated, bool valid) +iscsi_allocmap_update(IscsiLun *iscsilun, int64_t offset, + int64_t bytes, bool allocated, bool valid) { int64_t cl_num_expanded, nb_cls_expanded, cl_num_shrunk, nb_cls_shrunk; - int cluster_sectors =3D iscsilun->cluster_size >> BDRV_SECTOR_BITS; if (iscsilun->allocmap =3D=3D NULL) { return; } /* expand to entirely contain all affected clusters */ - assert(cluster_sectors); - cl_num_expanded =3D sector_num / cluster_sectors; - nb_cls_expanded =3D DIV_ROUND_UP(sector_num + nb_sectors, - cluster_sectors) - cl_num_expanded; + assert(iscsilun->cluster_size); + cl_num_expanded =3D offset / iscsilun->cluster_size; + nb_cls_expanded =3D DIV_ROUND_UP(offset + bytes, iscsilun->cluster_siz= e) + - cl_num_expanded; /* shrink to touch only completely contained clusters */ - cl_num_shrunk =3D DIV_ROUND_UP(sector_num, cluster_sectors); - nb_cls_shrunk =3D (sector_num + nb_sectors) / cluster_sectors - - cl_num_shrunk; + cl_num_shrunk =3D DIV_ROUND_UP(offset, iscsilun->cluster_size); + nb_cls_shrunk =3D (offset + bytes) / iscsilun->cluster_size - cl_num_s= hrunk; if (allocated) { bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded); } else { @@ -495,26 +493,26 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sec= tor_num, } static void -iscsi_allocmap_set_allocated(IscsiLun *iscsilun, int64_t sector_num, - int nb_sectors) +iscsi_allocmap_set_allocated(IscsiLun *iscsilun, int64_t offset, + int64_t bytes) { - iscsi_allocmap_update(iscsilun, sector_num, nb_sectors, true, true); + iscsi_allocmap_update(iscsilun, offset, bytes, true, true); } static void -iscsi_allocmap_set_unallocated(IscsiLun *iscsilun, int64_t sector_num, - int nb_sectors) +iscsi_allocmap_set_unallocated(IscsiLun *iscsilun, int64_t offset, + int64_t bytes) { /* Note: if cache.direct=3Don the fifth argument to iscsi_allocmap_upd= ate * is ignored, so this will in effect be an iscsi_allocmap_set_invalid. */ - iscsi_allocmap_update(iscsilun, sector_num, nb_sectors, false, true); + iscsi_allocmap_update(iscsilun, offset, bytes, false, true); } -static void iscsi_allocmap_set_invalid(IscsiLun *iscsilun, int64_t sector_= num, - int nb_sectors) +static void iscsi_allocmap_set_invalid(IscsiLun *iscsilun, int64_t offset, + int64_t bytes) { - iscsi_allocmap_update(iscsilun, sector_num, nb_sectors, false, false); + iscsi_allocmap_update(iscsilun, offset, bytes, false, false); } static void iscsi_allocmap_invalidate(IscsiLun *iscsilun) @@ -528,34 +526,30 @@ static void iscsi_allocmap_invalidate(IscsiLun *iscsi= lun) } static inline bool -iscsi_allocmap_is_allocated(IscsiLun *iscsilun, int64_t sector_num, - int nb_sectors) +iscsi_allocmap_is_allocated(IscsiLun *iscsilun, int64_t offset, + int64_t bytes) { unsigned long size; if (iscsilun->allocmap =3D=3D NULL) { return true; } assert(iscsilun->cluster_size); - size =3D DIV_ROUND_UP(sector_num + nb_sectors, - iscsilun->cluster_size >> BDRV_SECTOR_BITS); + size =3D DIV_ROUND_UP(offset + bytes, iscsilun->cluster_size); return !(find_next_bit(iscsilun->allocmap, size, - sector_num * BDRV_SECTOR_SIZE / - iscsilun->cluster_size) =3D=3D size); + offset / iscsilun->cluster_size) =3D=3D size); } static inline bool iscsi_allocmap_is_valid(IscsiLun *iscsilun, - int64_t sector_num, int nb_sect= ors) + int64_t offset, int64_t bytes) { unsigned long size; if (iscsilun->allocmap_valid =3D=3D NULL) { return false; } assert(iscsilun->cluster_size); - size =3D DIV_ROUND_UP(sector_num + nb_sectors, - iscsilun->cluster_size >> BDRV_SECTOR_BITS); + size =3D DIV_ROUND_UP(offset + bytes, iscsilun->cluster_size); return (find_next_zero_bit(iscsilun->allocmap_valid, size, - sector_num * BDRV_SECTOR_SIZE / - iscsilun->cluster_size) =3D=3D size); + offset / iscsilun->cluster_size) =3D=3D siz= e); } static int coroutine_fn @@ -637,12 +631,14 @@ retry: } if (iTask.status !=3D SCSI_STATUS_GOOD) { - iscsi_allocmap_set_invalid(iscsilun, sector_num, nb_sectors); + iscsi_allocmap_set_invalid(iscsilun, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE); r =3D iTask.err_code; goto out_unlock; } - iscsi_allocmap_set_allocated(iscsilun, sector_num, nb_sectors); + iscsi_allocmap_set_allocated(iscsilun, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE); out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -737,9 +733,11 @@ retry: } if (ret & BDRV_BLOCK_ZERO) { - iscsi_allocmap_set_unallocated(iscsilun, sector_num, *pnum); + iscsi_allocmap_set_unallocated(iscsilun, sector_num * BDRV_SECTOR_= SIZE, + *pnum * BDRV_SECTOR_SIZE); } else { - iscsi_allocmap_set_allocated(iscsilun, sector_num, *pnum); + iscsi_allocmap_set_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, + *pnum * BDRV_SECTOR_SIZE); } if (*pnum > nb_sectors) { @@ -777,15 +775,19 @@ static int coroutine_fn iscsi_co_readv(BlockDriverSta= te *bs, /* if cache.direct is off and we have a valid entry in our allocation = map * we can skip checking the block status and directly return zeroes if * the request falls within an unallocated area */ - if (iscsi_allocmap_is_valid(iscsilun, sector_num, nb_sectors) && - !iscsi_allocmap_is_allocated(iscsilun, sector_num, nb_sectors)) { + if (iscsi_allocmap_is_valid(iscsilun, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE) && + !iscsi_allocmap_is_allocated(iscsilun, sector_num * BDRV_SECTOR_SI= ZE, + nb_sectors * BDRV_SECTOR_SIZE)) { qemu_iovec_memset(iov, 0, 0x00, iov->size); return 0; } if (nb_sectors >=3D ISCSI_CHECKALLOC_THRES && - !iscsi_allocmap_is_valid(iscsilun, sector_num, nb_sectors) && - !iscsi_allocmap_is_allocated(iscsilun, sector_num, nb_sectors)) { + !iscsi_allocmap_is_valid(iscsilun, sector_num * BDRV_SECTOR_SIZE, + 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; /* check the block status from the beginning of the cluster @@ -1154,8 +1156,7 @@ retry: goto out_unlock; } - iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, bytes); out_unlock: qemu_mutex_unlock(&iscsilun->mutex); @@ -1253,18 +1254,15 @@ retry: } if (iTask.status !=3D SCSI_STATUS_GOOD) { - iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, bytes); r =3D iTask.err_code; goto out_unlock; } if (flags & BDRV_REQ_MAY_UNMAP) { - iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_invalid(iscsilun, offset, bytes); } else { - iscsi_allocmap_set_allocated(iscsilun, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS); + iscsi_allocmap_set_allocated(iscsilun, offset, bytes); } out_unlock: --=20 2.13.6