From nobody Wed Apr 24 13:57:41 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 1534112838584327.57061258217936; Sun, 12 Aug 2018 15:27:18 -0700 (PDT) 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 30E19C04F4D1; Sun, 12 Aug 2018 22:27:16 +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 EC81419482; Sun, 12 Aug 2018 22:27:15 +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 A65A04A460; Sun, 12 Aug 2018 22:27:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7CMRF59008514 for ; Sun, 12 Aug 2018 18:27:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 116BC2010CBF; Sun, 12 Aug 2018 22:27:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 09D9D2010CA0 for ; Sun, 12 Aug 2018 22:27:13 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) (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 4B84830E6847 for ; Sun, 12 Aug 2018 22:27:12 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id l2-v6so6117058wme.1 for ; Sun, 12 Aug 2018 15:27:12 -0700 (PDT) Received: from clem.localdomain ([2a01:e34:ec25:e330:f2d5:bfff:fe6e:3278]) by smtp.gmail.com with ESMTPSA id l5-v6sm5120340wmh.0.2018.08.12.15.27.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Aug 2018 15:27:10 -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:in-reply-to :references; bh=QUDaH7vydckDt4r66BX9vkKKvWh7mjuYNnrnHgsVJiI=; b=RUqKMk9VFIbBGi6QquMnHS/MdcCuSMBjiTSfupNFXuE9+MsUeHUq0ORBBE8A95/4pE kk+sOZUBucaBiEpUZjMTgTjwANImdPWZHBFw8GjkSD2bqidVOk2k1Q6FSHkc5jF87rwc 9sTrfSWvM+8s8QImof+JDk4RqtCzK8n8J3Yhn7QN3+YbMoEJaUvWbGtOZXRBuwKv7Rt1 MIqzUGNg+wr/NLICcZwf+swtUz6kx/+6IODFU/Rpybl2AcjiNtizgsGocendJmkzZnFp KoqpmL0+YS2WLs5oiMipNr6LyjcoMps0IuPnspqh0kjSN7co5tCO0wIu8p2hbUKRMDaL hHwQ== X-Gm-Message-State: AOUpUlEOqsJqpqxW28jaYtIjTsJgjXncaGs77TnZA2DL8N9zdMs/qID8 qF+SPiZ0heiYTkyeYpLJ1H4i0A4j X-Google-Smtp-Source: AA+uWPyUVrNfQoQ43prz8SQoTTW7m4M45uB+vKO3kC6aD+h/3PEP7SW336UCyZhaOT9HQDgM6Jn+Lg== X-Received: by 2002:a1c:c289:: with SMTP id s131-v6mr7259365wmf.65.1534112830570; Sun, 12 Aug 2018 15:27:10 -0700 (PDT) From: clem@lse.epita.fr To: libvir-list@redhat.com Date: Mon, 13 Aug 2018 00:26:16 +0200 Message-Id: <20180812222618.13625-2-clem@lse.epita.fr> In-Reply-To: <20180812222618.13625-1-clem@lse.epita.fr> References: <20180812222618.13625-1-clem@lse.epita.fr> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sun, 12 Aug 2018 22:27:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sun, 12 Aug 2018 22:27:12 +0000 (UTC) for IP:'74.125.82.66' DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.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.66 mail-wm0-f66.google.com 74.125.82.66 mail-wm0-f66.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Cc: Clementine Hayat Subject: [libvirt] [PATCH v3 1/3] storage: refactor volume capacity in iscsi-direct 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 12 Aug 2018 22:27:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Clementine Hayat The size of blocks inside a volume and the number of blocks are needed later. Having a function that return thoses information will avoid code duplication. Signed-off-by: Clementine Hayat --- src/storage/storage_backend_iscsi_direct.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 0764356b62..62b7e0d8bc 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -237,13 +237,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 +282,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 +301,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 +314,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 --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Apr 24 13:57:41 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 1534112847584124.79211484699329; Sun, 12 Aug 2018 15:27:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62DD681DE9; Sun, 12 Aug 2018 22:27:25 +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 33066A0B43; Sun, 12 Aug 2018 22:27:25 +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 D5DD218052EA; Sun, 12 Aug 2018 22:27:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7CMRNuG008541 for ; Sun, 12 Aug 2018 18:27:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 84C1D765C4; Sun, 12 Aug 2018 22:27:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7CD06765C3 for ; Sun, 12 Aug 2018 22:27:18 +0000 (UTC) Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 37EA5C015C24 for ; Sun, 12 Aug 2018 22:27:17 +0000 (UTC) Received: by mail-wr1-f51.google.com with SMTP id h15-v6so12672630wrs.7 for ; Sun, 12 Aug 2018 15:27:17 -0700 (PDT) Received: from clem.localdomain ([2a01:e34:ec25:e330:f2d5:bfff:fe6e:3278]) by smtp.gmail.com with ESMTPSA id l5-v6sm5120340wmh.0.2018.08.12.15.27.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Aug 2018 15:27:14 -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:in-reply-to :references; bh=PaZStQDo06mO1iHnkybMt6lFBp0g5IUyUf3ERxq4QrY=; b=TpumbNde1u3d4rbzK5mt8ZcMq1QssSCrSKHKXFC/nS+dX9VAewzYe2VvsDa0+xedF7 PoD7F03euAaGMJfi71DiVr8Z2a+ECaT1DWCdJO98sHdZlYq73vL2GIwNtuuJu22YkhDh wZwiPCGdbUzlblAO5JFOf8UfXwTZITuEssLwtTNWkVC23YplAd72VVoOHPrd/p0bsWgm UMRgDMOIwu6hSCx3ElCTMioiOX4J4kSldkgnEEHbGuNzil+ULZKj/UcpxLyiggXUzS1S vEbPw8Fsgr+NSDed/OK0746jSLA5TGZiZ8Q7P98X9NtQcYvxn63Zwf6IhKvCAmP7x1fh /0aQ== X-Gm-Message-State: AOUpUlEEwBTTzLdO87QCvU2VWZ8HyNMpBMaWxbX+cLCqiYi04gZzqXbI tGvePVuRiCCnwedVTwBm6+Oijhbh X-Google-Smtp-Source: AA+uWPyOXNrvgAEypO43LCJyowGvIvClWJZIdbODScGg8t1Yv+Ec3HoeboG7dbEIXENWi09rX8K92A== X-Received: by 2002:adf:d1cf:: with SMTP id m15-v6mr9962446wri.138.1534112835525; Sun, 12 Aug 2018 15:27:15 -0700 (PDT) From: clem@lse.epita.fr To: libvir-list@redhat.com Date: Mon, 13 Aug 2018 00:26:17 +0200 Message-Id: <20180812222618.13625-3-clem@lse.epita.fr> In-Reply-To: <20180812222618.13625-1-clem@lse.epita.fr> References: <20180812222618.13625-1-clem@lse.epita.fr> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 12 Aug 2018 22:27:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 12 Aug 2018 22:27:17 +0000 (UTC) for IP:'209.85.221.51' DOMAIN:'mail-wr1-f51.google.com' HELO:'mail-wr1-f51.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) 209.85.221.51 mail-wr1-f51.google.com 209.85.221.51 mail-wr1-f51.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Clementine Hayat Subject: [libvirt] [PATCH v3 2/3] storage: add SetConnection to iscsi-direct 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 12 Aug 2018 22:27:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Clementine Hayat The code to set the connection and connect using libiscsi will always be the same. Add function to avoid code duplication. Signed-off-by: Clementine Hayat --- src/storage/storage_backend_iscsi_direct.c | 38 +++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 62b7e0d8bc..7bdd39582b 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -557,23 +557,37 @@ virStorageBackendISCSIDirectFindPoolSources(const cha= r *srcSpec, return ret; } =20 +struct iscsi_context * +virStorageBackendISCSIDirectSetConnection(virStoragePoolObjPtr pool, + char **portal) +{ + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + struct iscsi_context *iscsi =3D NULL; + + if (!(*iscsi =3D virISCSIDirectCreateContext(def->source.initiator.iqn= ))) + return iscsi; + if (!(*portal =3D virStorageBackendISCSIDirectPortal(&def->source))) + goto error ; + if (virStorageBackendISCSIDirectSetAuth(*iscsi, &def->source) < 0) + goto error ; + if (virISCSIDirectSetContext(*iscsi, def->source.devices[0].path, ISCS= I_SESSION_NORMAL) < 0) + goto error ; + if (virISCSIDirectConnect(*iscsi, *portal) < 0) + goto error ; + return iscsi; + + error: + iscsi_destroy_context(iscsi); + return iscsi; +} + 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 (!(iscsi =3D virStorageBackendISCSIDirectSetConnection(pool, &porta= l))) goto cleanup; if (virISCSIDirectReportLuns(pool, iscsi, portal) < 0) goto disconect; @@ -581,9 +595,9 @@ virStorageBackendISCSIDirectRefreshPool(virStoragePoolO= bjPtr pool) ret =3D 0; disconect: virISCSIDirectDisconnect(iscsi); + iscsi_destroy_context(iscsi); cleanup: VIR_FREE(portal); - iscsi_destroy_context(iscsi); return ret; } =20 --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Apr 24 13:57:41 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 1534112848725276.2069999927454; Sun, 12 Aug 2018 15:27:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58C1430820CB; Sun, 12 Aug 2018 22:27:26 +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 12FED3001A51; Sun, 12 Aug 2018 22:27:26 +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 C13AF18037ED; Sun, 12 Aug 2018 22:27:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7CMROaD008546 for ; Sun, 12 Aug 2018 18:27:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 212535D750; Sun, 12 Aug 2018 22:27:24 +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 19BDF5D6A9 for ; Sun, 12 Aug 2018 22:27:21 +0000 (UTC) Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 5D45D307D857 for ; Sun, 12 Aug 2018 22:27:20 +0000 (UTC) Received: by mail-wr1-f45.google.com with SMTP id v14-v6so12671852wro.5 for ; Sun, 12 Aug 2018 15:27:20 -0700 (PDT) Received: from clem.localdomain ([2a01:e34:ec25:e330:f2d5:bfff:fe6e:3278]) by smtp.gmail.com with ESMTPSA id l5-v6sm5120340wmh.0.2018.08.12.15.27.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Aug 2018 15:27:18 -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:in-reply-to :references; bh=KO+RBtajhhvjtTzGmLx3+opOveXBwxO5tBjsDGg0jog=; b=JwiJfVh6K0LOUlnO4kwLGeczeqqUj73MjkzGgltAIMJKsmpP/+Zy0V08Zjmk2Iv8MA I9DVg5Th6jItMaFfab4GA/K1Z5P/p8OuMCuZ2aIGLkNa5/J+U2FGmt5uM+i31b/93cXO klLpOCTzHHxN9v2AQaZgPI3498cIp4KLHSFPvoW/TSuN5GU1ZBQzLDl4ZTtYQiCRbT7e +PBB1qnSTjGMwQ/6yMsNNFpZJ7I7n5+Coz+RdguNkqEjqhRQ/9iUH6RiySqvb9/wyD3d WCXHcueVPyFZ4eU/kPltCJws6rOKA8Fz/AeE3XXfzXZZrSgIBYvoXMnfnTCnG38b9YHh CTsQ== X-Gm-Message-State: AOUpUlGExOvhESyNH1bxKLkfzd5O6K83D4pwTfK/Az/SLgQuHI5twtdV 997TdWjBm9C5txXDQxsbV7b37ajh X-Google-Smtp-Source: AA+uWPwOc2G2hrFE9q1JLg5tLdmSRqPpW5m9UwriMaiSh76+6X2pLLD8TipTD8DYHxhEl6B9qdQa2w== X-Received: by 2002:adf:d142:: with SMTP id b2-v6mr9478004wri.17.1534112838655; Sun, 12 Aug 2018 15:27:18 -0700 (PDT) From: clem@lse.epita.fr To: libvir-list@redhat.com Date: Mon, 13 Aug 2018 00:26:18 +0200 Message-Id: <20180812222618.13625-4-clem@lse.epita.fr> In-Reply-To: <20180812222618.13625-1-clem@lse.epita.fr> References: <20180812222618.13625-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]); Sun, 12 Aug 2018 22:27:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sun, 12 Aug 2018 22:27:20 +0000 (UTC) for IP:'209.85.221.45' DOMAIN:'mail-wr1-f45.google.com' HELO:'mail-wr1-f45.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) 209.85.221.45 mail-wr1-f45.google.com 209.85.221.45 mail-wr1-f45.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Clementine Hayat Subject: [libvirt] [PATCH v3 3/3] 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sun, 12 Aug 2018 22:27:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Clementine Hayat Signed-off-by: Clementine Hayat --- src/storage/storage_backend_iscsi_direct.c | 121 ++++++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 7bdd39582b..5a7d70f24d 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) @@ -601,12 +603,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 (!(iscsi =3D virStorageBackendISCSIDirectSetConnection(pool, &porta= l))) + 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); + iscsi_destroy_context(iscsi); + cleanup: + VIR_FREE(portal); + 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