From nobody Fri May 3 13:48:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551366615513379.8881259682257; Thu, 28 Feb 2019 07:10:15 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7646913B224; Thu, 28 Feb 2019 15:10:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 026571973C; Thu, 28 Feb 2019 15:10:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 045B03FB11; Thu, 28 Feb 2019 15:10:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1SFA8TF029775 for ; Thu, 28 Feb 2019 10:10:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id EC44D17AFD; Thu, 28 Feb 2019 15:10:08 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF1C55DD74 for ; Thu, 28 Feb 2019 15:10:08 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 6EA3D1011B8; Thu, 28 Feb 2019 16:10:07 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Thu, 28 Feb 2019 16:10:05 +0100 Message-Id: <5de5432e34e097fde32b2b1ad96b8b8b1186dec1.1551366577.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] storage: Fix iscsi-direct volume size for volumes > 4GiB X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 28 Feb 2019 15:10:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Both block_size and nb_block are unit32_t and multiplying them overflows at 4GiB. Moreover, the iscsi_*10_* APIs use 32bit number of blocks and thus they can only address images up to 2TiB with 512B blocks. Let's use 64b iscsi_*16_* APIs instead. Signed-off-by: Jiri Denemark --- Notes: Version 2: - also fix volumes > 2TiB src/storage/storage_backend_iscsi_direct.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 32ceb592d9..786663534d 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -245,7 +245,7 @@ static int virISCSIDirectGetVolumeCapacity(struct iscsi_context *iscsi, int lun, uint32_t *block_size, - uint32_t *nb_block) + uint64_t *nb_block) { struct scsi_task *task =3D NULL; struct scsi_inquiry_standard *inq =3D NULL; @@ -267,12 +267,12 @@ virISCSIDirectGetVolumeCapacity(struct iscsi_context = *iscsi, } =20 if (inq->device_type =3D=3D SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT= _ACCESS) { - struct scsi_readcapacity10 *rc10 =3D NULL; + struct scsi_readcapacity16 *rc16 =3D NULL; =20 scsi_free_scsi_task(task); task =3D NULL; =20 - if (!(task =3D iscsi_readcapacity10_sync(iscsi, lun, 0, 0)) || + if (!(task =3D iscsi_readcapacity16_sync(iscsi, lun)) || task->status !=3D SCSI_STATUS_GOOD) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to get capacity of lun: %s"), @@ -280,15 +280,15 @@ virISCSIDirectGetVolumeCapacity(struct iscsi_context = *iscsi, goto cleanup; } =20 - if (!(rc10 =3D scsi_datain_unmarshall(task))) { + if (!(rc16 =3D scsi_datain_unmarshall(task))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to unmarshall reply: %s"), iscsi_get_error(iscsi)); goto cleanup; } =20 - *block_size =3D rc10->block_size; - *nb_block =3D rc10->lba; + *block_size =3D rc16->block_length; + *nb_block =3D rc16->returned_lba; =20 } =20 @@ -306,7 +306,7 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); uint32_t block_size; - uint32_t nb_block; + uint64_t nb_block; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (virISCSIDirectTestUnitReady(iscsi, lun) < 0) @@ -627,9 +627,9 @@ static int virStorageBackendISCSIDirectVolWipeZero(virStorageVolDefPtr vol, struct iscsi_context *iscsi) { - uint32_t lba =3D 0; + uint64_t lba =3D 0; uint32_t block_size; - uint32_t nb_block; + uint64_t nb_block; struct scsi_task *task =3D NULL; int lun =3D 0; int ret =3D -1; @@ -647,14 +647,14 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVol= DefPtr vol, while (lba < nb_block) { if (nb_block - lba > block_size * BLOCK_PER_PACKET) { =20 - if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, + if (!(task =3D iscsi_write16_sync(iscsi, lun, lba, data, block_size * BLOCK_PER_PACKET, block_size, 0, 0, 0, 0, 0))) return -1; scsi_free_scsi_task(task); lba +=3D BLOCK_PER_PACKET; } else { - if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, block= _size, + if (!(task =3D iscsi_write16_sync(iscsi, lun, lba, data, block= _size, block_size, 0, 0, 0, 0, 0))) return -1; scsi_free_scsi_task(task); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list