From nobody Sun Feb 8 14:22:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576853937; cv=none; d=zohomail.com; s=zohoarc; b=BuVsq9Ix6xl3hDiG+Nj+N08ittuPssBEHSaWK7QAgM4+ioJhaH6OMzHETPwHFh1+LVuNhPR5mNladT3hkZI1LLzvlnDi4DZhV1v67/U89lA/aBnCbq7y28wjm3AnY3IIcOYbCrZWNFHR4ZexqY/zobx/z5jVF91puKUGB7WQL2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576853937; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iIBrBK7nVfBcZ0VRlOgH3eDVjM2Cchxw0efc4+VfwDM=; b=H05zzoTQC2fFCgymRze9VfF2igsqq+RRpkD6jCaq7YGDDOb2PvTuzvvi0Cj45TeuFJIszge4f9rSuQkSb5D/6aGuRp/uucC66tqXG6S8ydx6XcJsiarEFgRN9+OgRYee7eey0D9RBNBCw44OwQFSOVnnK98/zDgv3HrlEPodiSQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1576853937962579.2974828862563; Fri, 20 Dec 2019 06:58:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-67-6mACUkpOP_62iNqLmUIMGA-1; Fri, 20 Dec 2019 09:58:55 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C603801F77; Fri, 20 Dec 2019 14:58:49 +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 599195C28F; Fri, 20 Dec 2019 14:58:49 +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 12423252F3; Fri, 20 Dec 2019 14:58:49 +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 xBKEwOfw032524 for ; Fri, 20 Dec 2019 09:58:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id B3D596E41E; Fri, 20 Dec 2019 14:58:24 +0000 (UTC) Received: from lindworm.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D2BC6FEEA for ; Fri, 20 Dec 2019 14:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576853936; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iIBrBK7nVfBcZ0VRlOgH3eDVjM2Cchxw0efc4+VfwDM=; b=VKTFplSNeAv6MoRVb91NPy+aXmeOUNlo7FtUmQLzNPHz+za7NKP85sSUNT14dU5C0uq4I8 TImTH2gT7hTUxaiuCKLa/MptGAcMklk2Wrs3RfXweai7oGzSSK57JMnZPvNsa7zK4eh9LK G1g4EHCEe4Fi/np77hP8TJCtBxr2DXM= From: Pino Toscano To: libvir-list@redhat.com Date: Fri, 20 Dec 2019 15:58:07 +0100 Message-Id: <20191220145813.756206-6-ptoscano@redhat.com> In-Reply-To: <20191220145813.756206-1-ptoscano@redhat.com> References: <20191220145813.756206-1-ptoscano@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 05/11] esx: implement storagePoolListAllVolumes 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: , 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-MC-Unique: 6mACUkpOP_62iNqLmUIMGA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Implement the .storagePoolListAllVolumes storage API in the esx storage driver, and in all its subdrivers. Signed-off-by: Pino Toscano --- src/esx/esx_storage_backend_iscsi.c | 68 +++++++++++++++++++++++ src/esx/esx_storage_backend_vmfs.c | 83 +++++++++++++++++++++++++++++ src/esx/esx_storage_driver.c | 19 +++++++ 3 files changed, 170 insertions(+) diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_back= end_iscsi.c index 50de7d88ac..cd83a0fbfd 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -850,6 +850,73 @@ esxConnectListAllStoragePools(virConnectPtr conn, =20 =20 =20 +static int +esxStoragePoolListAllVolumes(virStoragePoolPtr pool, + virStorageVolPtr **vols, + unsigned int flags) +{ + int ret =3D -1; + size_t count =3D 0; + esxPrivate *priv =3D pool->conn->privateData; + esxVI_HostScsiTopologyLun *hostScsiTopologyLunList =3D NULL; + esxVI_HostScsiTopologyLun *hostScsiTopologyLun; + esxVI_ScsiLun *scsiLunList =3D NULL; + esxVI_ScsiLun *scsiLun =3D NULL; + size_t i; + + virCheckFlags(0, -1); + + if (esxVI_LookupHostScsiTopologyLunListByTargetName + (priv->primary, pool->name, &hostScsiTopologyLunList) < 0) { + goto cleanup; + } + + if (!hostScsiTopologyLunList) { + /* iSCSI adapter may not be enabled on ESX host */ + return 0; + } + + if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) + goto cleanup; + + for (scsiLun =3D scsiLunList; scsiLun; + scsiLun =3D scsiLun->_next) { + for (hostScsiTopologyLun =3D hostScsiTopologyLunList; + hostScsiTopologyLun; + hostScsiTopologyLun =3D hostScsiTopologyLun->_next) { + if (STREQ(hostScsiTopologyLun->scsiLun, scsiLun->key)) { + virStorageVolPtr volume; + + volume =3D scsiLunToStorageVol(pool->conn, scsiLun, pool->= name); + if (!volume) + goto cleanup; + + if (VIR_APPEND_ELEMENT(*vols, count, volume) < 0) + goto cleanup; + } + + } + } + + ret =3D count; + + cleanup: + if (ret < 0) { + if (*vols) { + for (i =3D 0; i < count; ++i) + VIR_FREE((*vols)[i]); + VIR_FREE(*vols); + } + } + + esxVI_HostScsiTopologyLun_Free(&hostScsiTopologyLunList); + esxVI_ScsiLun_Free(&scsiLunList); + + return ret; +} + + + virStorageDriver esxStorageBackendISCSI =3D { .connectNumOfStoragePools =3D esxConnectNumOfStoragePools, /* 1.0.1 */ .connectListStoragePools =3D esxConnectListStoragePools, /* 1.0.1 */ @@ -871,4 +938,5 @@ virStorageDriver esxStorageBackendISCSI =3D { .storageVolWipe =3D esxStorageVolWipe, /* 1.0.1 */ .storageVolGetPath =3D esxStorageVolGetPath, /* 1.0.1 */ .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 6.0.= 0 */ + .storagePoolListAllVolumes =3D esxStoragePoolListAllVolumes, /* 6.0.0 = */ }; diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index 1d7f9afda1..70005717cb 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -1565,6 +1565,88 @@ esxConnectListAllStoragePools(virConnectPtr conn, =20 =20 =20 +static int +esxStoragePoolListAllVolumes(virStoragePoolPtr pool, + virStorageVolPtr **vols, + unsigned int flags) +{ + int ret =3D -1; + esxPrivate *priv =3D pool->conn->privateData; + esxVI_HostDatastoreBrowserSearchResults *searchResultsList =3D NULL; + esxVI_HostDatastoreBrowserSearchResults *searchResults =3D NULL; + esxVI_FileInfo *fileInfo =3D NULL; + char *directoryAndFileName =3D NULL; + size_t length; + size_t count =3D 0; + size_t i; + + virCheckFlags(0, -1); + + if (esxVI_LookupDatastoreContentByDatastoreName(priv->primary, pool->n= ame, + &searchResultsList) < = 0) { + goto cleanup; + } + + /* Interpret search result */ + for (searchResults =3D searchResultsList; searchResults; + searchResults =3D searchResults->_next) { + VIR_FREE(directoryAndFileName); + + if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL, NU= LL, + &directoryAndFileName) < 0) { + goto cleanup; + } + + /* Strip trailing separators */ + length =3D strlen(directoryAndFileName); + + while (length > 0 && directoryAndFileName[length - 1] =3D=3D '/') { + directoryAndFileName[length - 1] =3D '\0'; + --length; + } + + /* Build volume names */ + for (fileInfo =3D searchResults->file; fileInfo; + fileInfo =3D fileInfo->_next) { + g_autofree char *datastorePath =3D NULL; + virStorageVolPtr volume; + + if (length < 1) { + datastorePath =3D g_strdup(fileInfo->path); + } else { + datastorePath =3D g_strdup_printf("%s/%s", + directoryAndFileName, + fileInfo->path); + } + + volume =3D datastorePathToStorageVol(pool->conn, pool->name, d= atastorePath); + if (!volume) + goto cleanup; + + if (VIR_APPEND_ELEMENT(*vols, count, volume) < 0) + goto cleanup; + } + } + + ret =3D count; + + cleanup: + if (ret < 0) { + if (*vols) { + for (i =3D 0; i < count; ++i) + VIR_FREE((*vols)[i]); + VIR_FREE(*vols); + } + } + + esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList); + VIR_FREE(directoryAndFileName); + + return ret; +} + + + virStorageDriver esxStorageBackendVMFS =3D { .connectNumOfStoragePools =3D esxConnectNumOfStoragePools, /* 0.8.2 */ .connectListStoragePools =3D esxConnectListStoragePools, /* 0.8.2 */ @@ -1586,4 +1668,5 @@ virStorageDriver esxStorageBackendVMFS =3D { .storageVolGetXMLDesc =3D esxStorageVolGetXMLDesc, /* 0.8.4 */ .storageVolGetPath =3D esxStorageVolGetPath, /* 0.8.4 */ .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 6.0.= 0 */ + .storagePoolListAllVolumes =3D esxStoragePoolListAllVolumes, /* 6.0.0 = */ }; diff --git a/src/esx/esx_storage_driver.c b/src/esx/esx_storage_driver.c index 9e14b8b0ac..8470a31c68 100644 --- a/src/esx/esx_storage_driver.c +++ b/src/esx/esx_storage_driver.c @@ -581,6 +581,24 @@ esxConnectListAllStoragePools(virConnectPtr conn, =20 =20 =20 +static int +esxStoragePoolListAllVolumes(virStoragePoolPtr pool, + virStorageVolPtr **vols, + unsigned int flags) +{ + esxPrivate *priv =3D pool->conn->privateData; + virStorageDriverPtr backend =3D pool->privateData; + + virCheckNonNullArgReturn(pool->privateData, -1); + + if (esxVI_EnsureSession(priv->primary) < 0) + return -1; + + return backend->storagePoolListAllVolumes(pool, vols, flags); +} + + + virStorageDriver esxStorageDriver =3D { .connectNumOfStoragePools =3D esxConnectNumOfStoragePools, /* 0.8.2 */ .connectListStoragePools =3D esxConnectListStoragePools, /* 0.8.2 */ @@ -609,4 +627,5 @@ virStorageDriver esxStorageDriver =3D { .storagePoolIsActive =3D esxStoragePoolIsActive, /* 0.8.2 */ .storagePoolIsPersistent =3D esxStoragePoolIsPersistent, /* 0.8.2 */ .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 6.0.= 0 */ + .storagePoolListAllVolumes =3D esxStoragePoolListAllVolumes, /* 6.0.0 = */ }; --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list