From nobody Sun Apr 28 13:38:07 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533899597938245.25683844333662; Fri, 10 Aug 2018 04:13:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC0D931524F4; Fri, 10 Aug 2018 11:13:14 +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 69E3417DFB; Fri, 10 Aug 2018 11:13:14 +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 1AB5A4A460; Fri, 10 Aug 2018 11:13:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7ABDCbx013729 for ; Fri, 10 Aug 2018 07:13:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 73B161001F58; Fri, 10 Aug 2018 11:13:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AE371001F4F for ; Fri, 10 Aug 2018 11:13:09 +0000 (UTC) Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E227307D86C for ; Fri, 10 Aug 2018 11:13:08 +0000 (UTC) Received: by mail-wm0-f54.google.com with SMTP id t25-v6so1482334wmi.3 for ; Fri, 10 Aug 2018 04:13:08 -0700 (PDT) Received: from clem.localdomain ([37.173.232.224]) by smtp.gmail.com with ESMTPSA id y128-v6sm1639742wmy.26.2018.08.10.04.13.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 04:13:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hm2eC+rzsJbkAGL1r50gVBsjMpldOYYGUMEv0s9YuJw=; b=R6/vfB+VOENJ9T1yHxPRibD1F+Lb3R0vscdt6K8vFa2LgGOgOdReuZhGegtgakDrLF DxVs3idAaMTdId10g1PCfKI6lV4UbID3Z0DkaPy8pEL6r0DUPiy6+ojACg7qXT7s4vkC b2odGd1Yl9m96L/o/IkdnEmzSbltVjOg8AwR+1jLsfAhdnsynEUXMnDTQ3H5+OivP8j1 azGYLJLoZ541ZQaoi8u1zrD0HnDYdokzoFmc0u7UCkXxCQKOXe6B+bVilY9mdflF2n3a x/FQ7Z4eVUn2j86OX9fSTgrW0bula0wtmlKGTGAvOnEPSkgOo1EJl46wtvGAEdiTcyZn Tpcw== X-Gm-Message-State: AOUpUlEVBbHJiHEtMJRm9B+lqlM5MBsjfQP3HiOiPyPeIZmbSkbZ5TVo jPwF2zQ4fOZXPFM7dj7awm+1wpnj X-Google-Smtp-Source: AA+uWPyA/7yRZLpcuCx5t2WyTMGxU1Hen90UZFcqjJKt/Nj8SvJwzjh0LhejScJF4ELQDKsubntXdA== X-Received: by 2002:a1c:4887:: with SMTP id v129-v6mr1136319wma.129.1533899586557; Fri, 10 Aug 2018 04:13:06 -0700 (PDT) From: clem@lse.epita.fr To: libvir-list@redhat.com Date: Fri, 10 Aug 2018 13:12:52 +0200 Message-Id: <20180810111252.13422-1-clem@lse.epita.fr> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 10 Aug 2018 11:13:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 10 Aug 2018 11:13:08 +0000 (UTC) for IP:'74.125.82.54' DOMAIN:'mail-wm0-f54.google.com' HELO:'mail-wm0-f54.google.com' FROM:'clementinehayat@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.028 (FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.54 mail-wm0-f54.google.com 74.125.82.54 mail-wm0-f54.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Clementine Hayat Subject: [libvirt] [PATCH] storage: add wipeVol to iscsi-direct storage backend 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 10 Aug 2018 11:13:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Clementine Hayat Change set volume capacity to get volume capacity to avoid code duplicate. Signed-off-by: Clementine Hayat --- Set BLOCK_PER_PACKET to 128. Not sure about this value. Should be potentially tuned. src/storage/storage_backend_iscsi_direct.c | 152 +++++++++++++++++++-- 1 file changed, 143 insertions(+), 9 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 0764356b62..094425c101 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -41,6 +41,7 @@ =20 #define ISCSI_DEFAULT_TARGET_PORT 3260 #define VIR_ISCSI_TEST_UNIT_TIMEOUT 30 * 1000 +#define BLOCK_PER_PACKET 128 =20 VIR_LOG_INIT("storage.storage_backend_iscsi_direct"); =20 @@ -237,13 +238,13 @@ virISCSIDirectSetVolumeAttributes(virStoragePoolObjPt= r pool, } =20 static int -virISCSIDirectSetVolumeCapacity(struct iscsi_context *iscsi, - virStorageVolDefPtr vol, - int lun) +virISCSIDirectGetVolumeCapacity(struct iscsi_context *iscsi, + int lun, + uint32_t *block_size, + uint32_t *nb_block) { struct scsi_task *task =3D NULL; struct scsi_inquiry_standard *inq =3D NULL; - long long size =3D 0; int ret =3D -1; =20 if (!(task =3D iscsi_inquiry_sync(iscsi, lun, 0, 0, 64)) || @@ -282,10 +283,8 @@ virISCSIDirectSetVolumeCapacity(struct iscsi_context *= iscsi, goto cleanup; } =20 - size =3D rc10->block_size; - size *=3D rc10->lba; - vol->target.capacity =3D size; - vol->target.allocation =3D size; + *block_size =3D rc10->block_size; + *nb_block =3D rc10->lba; =20 } =20 @@ -303,6 +302,8 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virStorageVolDefPtr vol =3D NULL; + uint32_t block_size; + uint32_t nb_block; int ret =3D -1; =20 virStoragePoolObjClearVols(pool); @@ -314,9 +315,12 @@ virISCSIDirectRefreshVol(virStoragePoolObjPtr pool, =20 vol->type =3D VIR_STORAGE_VOL_NETWORK; =20 - if (virISCSIDirectSetVolumeCapacity(iscsi, vol, lun) < 0) + if (virISCSIDirectGetVolumeCapacity(iscsi, lun, + &block_size, &nb_block) < 0) goto cleanup; =20 + vol->target.capacity =3D block_size * nb_block; + vol->target.allocation =3D block_size * nb_block; def->capacity +=3D vol->target.capacity; def->allocation +=3D vol->target.allocation; =20 @@ -584,12 +588,142 @@ virStorageBackendISCSIDirectRefreshPool(virStoragePo= olObjPtr pool) return ret; } =20 +static int +virStorageBackendISCSIDirectGetLun(virStorageVolDefPtr vol, + int *lun) +{ + char *name =3D NULL; + char **name_split =3D NULL; + int ret =3D -1; + + if (VIR_STRDUP(name, vol->name) < 0) + return -1; + if (!(name_split =3D virStringSplit(name, ":", 4))) + goto cleanup; + if (!name_split[3]) + goto cleanup; + if (virStrToLong_i(name_split[3], NULL, 10, lun) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + VIR_FREE(name); + virStringListFree(name_split); + printf("\n"); + return ret; +} + +static int +virStorageBackendISCSIDirectVolWipeZero(virStorageVolDefPtr vol, + struct iscsi_context *iscsi) +{ + uint32_t lba =3D 0; + uint32_t block_size; + uint32_t nb_block; + struct scsi_task *task =3D NULL; + int lun =3D 0; + int ret =3D -1; + unsigned char *data; + + if (virStorageBackendISCSIDirectGetLun(vol, &lun) < 0) + return ret; + if (virISCSIDirectTestUnitReady(iscsi, lun) < 0) + return ret; + if (virISCSIDirectGetVolumeCapacity(iscsi, lun, &block_size, &nb_block= )) + return ret; + if (VIR_ALLOC_N(data, block_size * BLOCK_PER_PACKET)) + return ret; + + while (lba < nb_block) { + if (nb_block - lba > block_size * BLOCK_PER_PACKET) { + if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, + block_size * BLOCK_PER_PACKET, + block_size, 0, 0, 0, 0, 0))) + goto cleanup; + scsi_free_scsi_task(task); + lba +=3D BLOCK_PER_PACKET; + } + else { + if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, block= _size, + block_size, 0, 0, 0, 0, 0))) + goto cleanup; + scsi_free_scsi_task(task); + lba++; + } + } + + ret =3D 0; + cleanup: + VIR_FREE(data); + return ret; +} + +static int +virStorageBackenISCSIDirectWipeVol(virStoragePoolObjPtr pool, + virStorageVolDefPtr vol, + unsigned int algorithm, + unsigned int flags) +{ + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + struct iscsi_context *iscsi =3D NULL; + char *portal =3D NULL; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(iscsi =3D virISCSIDirectCreateContext(def->source.initiator.iqn)= )) + goto cleanup; + if (!(portal =3D virStorageBackendISCSIDirectPortal(&def->source))) + goto cleanup; + if (virStorageBackendISCSIDirectSetAuth(iscsi, &def->source) < 0) + goto cleanup; + if (virISCSIDirectSetContext(iscsi, def->source.devices[0].path, ISCSI= _SESSION_NORMAL) < 0) + goto cleanup; + if (virISCSIDirectConnect(iscsi, portal) < 0) + goto cleanup; + + + switch ((virStorageVolWipeAlgorithm) algorithm) { + case VIR_STORAGE_VOL_WIPE_ALG_ZERO: + if (virStorageBackendISCSIDirectVolWipeZero(vol, iscsi) < 0) { + virReportSystemError(VIR_ERR_INTERNAL_ERROR, + _("failed to wipe volume %s"), + vol->name); + goto disconnect; + } + break; + case VIR_STORAGE_VOL_WIPE_ALG_TRIM: + case VIR_STORAGE_VOL_WIPE_ALG_NNSA: + case VIR_STORAGE_VOL_WIPE_ALG_DOD: + case VIR_STORAGE_VOL_WIPE_ALG_BSI: + case VIR_STORAGE_VOL_WIPE_ALG_GUTMANN: + case VIR_STORAGE_VOL_WIPE_ALG_SCHNEIER: + case VIR_STORAGE_VOL_WIPE_ALG_PFITZNER7: + case VIR_STORAGE_VOL_WIPE_ALG_PFITZNER33: + case VIR_STORAGE_VOL_WIPE_ALG_RANDOM: + case VIR_STORAGE_VOL_WIPE_ALG_LAST: + virReportError(VIR_ERR_INVALID_ARG, _("unsupported algorithm %d"), + algorithm); + goto disconnect; + } + + ret =3D 0; + disconnect: + virISCSIDirectDisconnect(iscsi); + cleanup: + VIR_FREE(portal); + iscsi_destroy_context(iscsi); + return ret; +} + + virStorageBackend virStorageBackendISCSIDirect =3D { .type =3D VIR_STORAGE_POOL_ISCSI_DIRECT, =20 .checkPool =3D virStorageBackendISCSIDirectCheckPool, .findPoolSources =3D virStorageBackendISCSIDirectFindPoolSources, .refreshPool =3D virStorageBackendISCSIDirectRefreshPool, + .wipeVol =3D virStorageBackenISCSIDirectWipeVol, }; =20 int --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list