From nobody Wed Nov 27 22:45:05 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 1533198831578688.0332756589304; Thu, 2 Aug 2018 01:33:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 026FD3082136; Thu, 2 Aug 2018 08:33: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 4C344765DF; Thu, 2 Aug 2018 08:33: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 104BF18037ED; Thu, 2 Aug 2018 08:33:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w728XiOe029829 for ; Thu, 2 Aug 2018 04:33:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id F06DF26E67; Thu, 2 Aug 2018 08:33:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8E9226E64; Thu, 2 Aug 2018 08:33:40 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) (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 D68B6935AE; Thu, 2 Aug 2018 08:33:38 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id c14-v6so1501105wmb.4; Thu, 02 Aug 2018 01:33:38 -0700 (PDT) Received: from clem.home ([2a01:cb15:173:6f00:f2d5:bfff:fe6e:3278]) by smtp.gmail.com with ESMTPSA id 71-v6sm2008008wmq.17.2018.08.02.01.33.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Aug 2018 01:33:36 -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=sirw3ZMiUO7SASJ1BV6YtdwCC3OJuSmj9G/9lueqbe4=; b=Wsp1iBq3wT6ff3vaySEjcrbgG8q8xWAXSzfNrdpmTzje5iQntyIwXt0sGN+D/hxtPU O+zRh8hRcqk5h8eHTKgUWQBnRsyE6zfQ9idwpP1g8O+nTHxwmkW1facH+MIcWdTWjaYH Msf9hVS/h1cySwh3Tcxt5W1LCLJO2CsLT5spY707O6iHadFFGSJ/h2UgTZ9BkJcDDDAn 4iC+Or6I4RWtlj4jeEsz3C5rwRxcB20TLm1JUjI5nzdAeBQyVbkTbqoEQEkC899QYnQy qNA1NzDpObRwXT7bQsBgg9nw51tCZ1p2TrSkqolzodNRthOmrAc5Sq9CRADSoOQDL887 FepA== X-Gm-Message-State: AOUpUlHEl1jI8zhfRJI33S97AiX4h66au83uJkPBAq7wFDz91q+dzTxB WfujJH5icVv9ALbkDMRPg69NoOu1 X-Google-Smtp-Source: AAOMgpcblp6+yMWOYAcK086dwAqXJF9ovEzsgw9tYQbkmUnn38Y9aiQbWA1jMQrjhNPHBC64beSyhA== X-Received: by 2002:a1c:20cb:: with SMTP id g194-v6mr1386002wmg.102.1533198817044; Thu, 02 Aug 2018 01:33:37 -0700 (PDT) From: clem@lse.epita.fr To: mprivozn@redhat.com, phrdina@redhat.com, libvir-list@redhat.com Date: Thu, 2 Aug 2018 10:33:27 +0200 Message-Id: <20180802083327.30666-1-clem@lse.epita.fr> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 02 Aug 2018 08:33:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 02 Aug 2018 08:33:39 +0000 (UTC) for IP:'74.125.82.68' DOMAIN:'mail-wm0-f68.google.com' HELO:'mail-wm0-f68.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.68 mail-wm0-f68.google.com 74.125.82.68 mail-wm0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Clementine Hayat Subject: [libvirt] [PATCH] storage: add findPoolSources to iscsi_direct pool 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 02 Aug 2018 08:33:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Clementine Hayat Change the SetContext function to be able to take the session type in argument. Took the function findPoolSources of iscsi backend and wired it to my function since the formatting is essentially the same. Signed-off-by: Clementine Hayat --- src/storage/storage_backend_iscsi_direct.c | 179 ++++++++++++++++++++- 1 file changed, 171 insertions(+), 8 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index ab192730fb..fc30f2dfac 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -131,7 +131,8 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_contex= t *iscsi, =20 static int virISCSIDirectSetContext(struct iscsi_context *iscsi, - const char *target_name) + const char *target_name, + enum iscsi_session_type session) { if (iscsi_init_transport(iscsi, TCP_TRANSPORT) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -139,13 +140,15 @@ virISCSIDirectSetContext(struct iscsi_context *iscsi, iscsi_get_error(iscsi)); return -1; } - if (iscsi_set_targetname(iscsi, target_name) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to set target name: %s"), - iscsi_get_error(iscsi)); - return -1; + if (session =3D=3D ISCSI_SESSION_NORMAL) { + if (iscsi_set_targetname(iscsi, target_name) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to set target name: %s"), + iscsi_get_error(iscsi)); + return -1; + } } - if (iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL) < 0) { + if (iscsi_set_session_type(iscsi, session) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to set session type: %s"), iscsi_get_error(iscsi)); @@ -400,6 +403,92 @@ virISCSIDirectDisconnect(struct iscsi_context *iscsi) return 0; } =20 +static void +virFreeTargets(char **targets, size_t ntargets, char *target) +{ + size_t i; + + VIR_FREE(target); + for (i =3D 0; i < ntargets; i++) + VIR_FREE(targets[i]); + VIR_FREE(targets); +} + +static int +virISCSIDirectUpdateTargets(struct iscsi_context *iscsi, + size_t *ntargets, + char ***targets) +{ + int ret =3D -1; + struct iscsi_discovery_address *addr; + struct iscsi_discovery_address *tmp_addr; + size_t tmp_ntargets =3D 0; + char **tmp_targets =3D NULL; + + if (!(addr =3D iscsi_discovery_sync(iscsi))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to discover session: %s"), + iscsi_get_error(iscsi)); + return ret; + } + *ntargets =3D 0; + for (tmp_addr =3D addr; tmp_addr; tmp_addr =3D tmp_addr->next) { + char *target =3D NULL; + if (VIR_STRDUP(target, tmp_addr->target_name) < 0) { + virFreeTargets(tmp_targets, tmp_ntargets, NULL); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to allocate memory for: %s"), + tmp_addr->target_name); + goto cleanup; + } + + if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) { + virFreeTargets(tmp_targets, tmp_ntargets, target); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to append to the list element: %s"), + tmp_addr->target_name); + goto cleanup; + } + + } + + if (tmp_ntargets) { + *targets =3D tmp_targets; + *ntargets =3D tmp_ntargets; + } + + ret =3D 0; + cleanup: + iscsi_free_discovery_data(iscsi, addr); + return ret; +} + +static int +virISCSIDirectScanTargets(char *initiator_iqn, + char *portal, + size_t *ntargets, + char ***targets) +{ + struct iscsi_context *iscsi =3D NULL; + int ret =3D -1; + + if (!(iscsi =3D virISCSIDirectCreateContext(initiator_iqn))) + goto cleanup; + if (virISCSIDirectSetContext(iscsi, NULL, ISCSI_SESSION_DISCOVERY) < 0) + goto cleanup; + if (virISCSIDirectConnect(iscsi, portal) < 0) + goto cleanup; + if (virISCSIDirectUpdateTargets(iscsi, ntargets, targets) < 0) + goto disconnect; + + ret =3D 0; + disconnect: + virISCSIDirectDisconnect(iscsi); + cleanup: + iscsi_destroy_context(iscsi); + return ret; +} + static int virStorageBackendISCSIDirectCheckPool(virStoragePoolObjPtr pool, bool *isActive) @@ -408,6 +497,79 @@ virStorageBackendISCSIDirectCheckPool(virStoragePoolOb= jPtr pool, return 0; } =20 +static char * +virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec, + unsigned int flags) +{ + virStoragePoolSourcePtr source =3D NULL; + size_t ntargets =3D 0; + char **targets =3D NULL; + char *ret =3D NULL; + size_t i; + virStoragePoolSourceList list =3D { + .type =3D VIR_STORAGE_POOL_ISCSI_DIRECT, + .nsources =3D 0, + .sources =3D NULL + }; + char *portal =3D NULL; + + virCheckFlags(0, NULL); + + if (!srcSpec) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("hostname must be specified for iscsi sources")); + return NULL; + } + + if (!(source =3D virStoragePoolDefParseSourceString(srcSpec, list.type= ))) + return NULL; + + if (source->nhost !=3D 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Expected exactly 1 host for the storage pool")); + goto cleanup; + } + + if (!(portal =3D virStorageBackendISCSIDirectPortal(source))) + goto cleanup; + + if (virISCSIDirectScanTargets(source->initiator.iqn, portal, &ntargets= , &targets) < 0) + goto cleanup; + + if (VIR_ALLOC_N(list.sources, ntargets) < 0) + goto cleanup; + + for (i =3D 0; i < ntargets; i++) { + if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0 || + VIR_ALLOC_N(list.sources[i].hosts, 1) < 0) + goto cleanup; + list.sources[i].nhost =3D 1; + list.sources[i].hosts[0] =3D source->hosts[0]; + list.sources[i].initiator =3D source->initiator; + list.sources[i].ndevice =3D 1; + list.sources[i].devices[0].path =3D targets[i]; + list.nsources++; + } + + if (!(ret =3D virStoragePoolSourceListFormat(&list))) + goto cleanup; + + cleanup: + if (list.sources) { + for (i =3D 0; i < ntargets; i++) { + VIR_FREE(list.sources[i].hosts); + VIR_FREE(list.sources[i].devices); + } + VIR_FREE(list.sources); + } + for (i =3D 0; i < ntargets; i++) + VIR_FREE(targets[i]); + VIR_FREE(targets); + VIR_FREE(portal); + virStoragePoolSourceFree(source); + return ret; +} + static int virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool) { @@ -422,7 +584,7 @@ virStorageBackendISCSIDirectRefreshPool(virStoragePoolO= bjPtr pool) goto cleanup; if (virStorageBackendISCSIDirectSetAuth(iscsi, &def->source) < 0) goto cleanup; - if (virISCSIDirectSetContext(iscsi, def->source.devices[0].path) < 0) + if (virISCSIDirectSetContext(iscsi, def->source.devices[0].path, ISCSI= _SESSION_NORMAL) < 0) goto cleanup; if (virISCSIDirectConnect(iscsi, portal) < 0) goto cleanup; @@ -442,6 +604,7 @@ virStorageBackend virStorageBackendISCSIDirect =3D { .type =3D VIR_STORAGE_POOL_ISCSI_DIRECT, =20 .checkPool =3D virStorageBackendISCSIDirectCheckPool, + .findPoolSources =3D virStorageBackendISCSIDirectFindPoolSources, .refreshPool =3D virStorageBackendISCSIDirectRefreshPool, }; =20 --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list