From nobody Fri Mar 29 00:26:33 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 1533908153960326.73953498936953; Fri, 10 Aug 2018 06:35:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B61833C22; Fri, 10 Aug 2018 13:35:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CA121001F4E; Fri, 10 Aug 2018 13:35:48 +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 8CAA61841C4B; Fri, 10 Aug 2018 13:35:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7ADYHZ5005839 for ; Fri, 10 Aug 2018 09:34:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7BC151799F; Fri, 10 Aug 2018 13:34:17 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 707C367641 for ; Fri, 10 Aug 2018 13:34:12 +0000 (UTC) Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) (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 42F4C81DF3 for ; Fri, 10 Aug 2018 13:34:11 +0000 (UTC) Received: by mail-wm0-f44.google.com with SMTP id n11-v6so1937675wmc.2 for ; Fri, 10 Aug 2018 06:34:11 -0700 (PDT) Received: from clem.localdomain ([37.173.181.240]) by smtp.gmail.com with ESMTPSA id y11-v6sm10380792wrt.4.2018.08.10.06.34.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 06:34:08 -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=3JP11DUyEd/KzXWRYqfOLe+mtuXuitli1xXGOIBBkPk=; b=AVpCahTiNMhwDNK/x1xXVbFBE7WYLCU2pbKgQdYkRbsqgb9Hys+Unp+wQ9qmMVsmU1 6VGkG2X9tQ29guzrgKA08rMdc4wHd9gPnmKZZIDG0lOgKJMTt/fKF4SxyBY2+zr+VzJn fnBrrMfMHFv6mvVh57XzevznaINKEgLiOo9KXtmK0g1TP0q8WZuAen6LyYCaKFoZzh2s H1l6RSspkNTQHtgICIAxI5yqiyo9YL7npIHdHExI6R8Ivam3Hpvle9uJhH94YX5+PWAZ bFX3jwfiHhZvpUQBWIk968CueqviwvSqzYTgHR2FBcUCcwtLbeyZR4LcofzYCGyXz13Y tsEg== X-Gm-Message-State: AOUpUlFl4iwyHPLbs5fByyDRXHPST0sm9ZmZEKRTBkg+Y/+5hffa+OhS WIeo+o+XmRF0cddGy+idgBSerIgZ X-Google-Smtp-Source: AA+uWPwIbcPO8fHBvd38D+lf3ipxKhUySylNGV5bFsgN6JEoWoeteS2ggxnKaS6YeUacOf7AEaQ+iQ== X-Received: by 2002:a1c:6f06:: with SMTP id k6-v6mr1509521wmc.1.1533908049095; Fri, 10 Aug 2018 06:34:09 -0700 (PDT) From: clem@lse.epita.fr To: libvir-list@redhat.com Date: Fri, 10 Aug 2018 15:33:59 +0200 Message-Id: <20180810133359.27698-1-clem@lse.epita.fr> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 10 Aug 2018 13:34:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 10 Aug 2018 13:34:11 +0000 (UTC) for IP:'74.125.82.44' DOMAIN:'mail-wm0-f44.google.com' HELO:'mail-wm0-f44.google.com' FROM:'clementinehayat@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.008 (FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 74.125.82.44 mail-wm0-f44.google.com 74.125.82.44 mail-wm0-f44.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Clementine Hayat Subject: [libvirt] [PATCH v2] 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 10 Aug 2018 13:35:51 +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 and put the connection and helpers in one function to avoid code duplicates. 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 | 173 ++++++++++++++++++--- 1 file changed, 152 insertions(+), 21 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 0764356b62..958f5937f9 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -41,6 +41,8 @@ =20 #define ISCSI_DEFAULT_TARGET_PORT 3260 #define VIR_ISCSI_TEST_UNIT_TIMEOUT 30 * 1000 +#define BLOCK_PER_PACKET 128 +#define VOL_NAME_PREFIX "unit:0:0:" =20 VIR_LOG_INIT("storage.storage_backend_iscsi_direct"); =20 @@ -225,7 +227,7 @@ virISCSIDirectSetVolumeAttributes(virStoragePoolObjPtr = pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); =20 - if (virAsprintf(&vol->name, "unit:0:0:%u", lun) < 0) + if (virAsprintf(&vol->name, "%s%u", VOL_NAME_PREFIX, lun) < 0) return -1; if (virAsprintf(&vol->key, "ip-%s-iscsi-%s-lun-%u", portal, def->source.devices[0].path, lun) < 0) @@ -237,13 +239,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 +284,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 +303,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 +316,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 @@ -553,24 +558,33 @@ virStorageBackendISCSIDirectFindPoolSources(const cha= r *srcSpec, virStoragePoolSourceFree(source); return ret; } +static int +virStorageBackendISCSIDirectSetConnection(virStoragePoolObjPtr pool, + struct iscsi_context **iscsi, + char **portal) +{ + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + + if (!(*iscsi =3D virISCSIDirectCreateContext(def->source.initiator.iqn= ))) + return -1; + if (!(*portal =3D virStorageBackendISCSIDirectPortal(&def->source))) + return -1; + if (virStorageBackendISCSIDirectSetAuth(*iscsi, &def->source) < 0) + return -1; + if (virISCSIDirectSetContext(*iscsi, def->source.devices[0].path, ISCS= I_SESSION_NORMAL) < 0) + return -1; + if (virISCSIDirectConnect(*iscsi, *portal) < 0) + return -1; + return 0; +} =20 static int virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool) { - virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); struct iscsi_context *iscsi =3D NULL; char *portal =3D NULL; int ret =3D -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) + if (virStorageBackendISCSIDirectSetConnection(pool, &iscsi, &portal) <= 0) goto cleanup; if (virISCSIDirectReportLuns(pool, iscsi, portal) < 0) goto disconect; @@ -584,12 +598,129 @@ virStorageBackendISCSIDirectRefreshPool(virStoragePo= olObjPtr pool) return ret; } =20 +static int +virStorageBackendISCSIDirectGetLun(virStorageVolDefPtr vol, + int *lun) +{ + const char *name =3D vol->name; + int ret =3D -1; + + if (!STRPREFIX(name, VOL_NAME_PREFIX)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid volume name %s"), name); + goto cleanup; + } + + name +=3D strlen(VOL_NAME_PREFIX); + if (virStrToLong_i(name, NULL, 10, lun) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + 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) +{ + struct iscsi_context *iscsi =3D NULL; + char *portal =3D NULL; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (virStorageBackendISCSIDirectSetConnection(pool, &iscsi, &portal) <= 0) + goto cleanup; + + switch ((virStorageVolWipeAlgorithm) algorithm) { + case VIR_STORAGE_VOL_WIPE_ALG_ZERO: + if (virStorageBackendISCSIDirectVolWipeZero(vol, iscsi) < 0) { + virReportError(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