From nobody Sun Feb 8 19:39:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.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=1573821700; cv=none; d=zoho.com; s=zohoarc; b=Vs8uy4pBlbBbDVHB5OKeyCleP5rW1FnT38MqboDmL4kXpgzAcPQsIDiVhwNRaVqCsmM1OAaySsk+zIm2Je4g4oac9gzIAXMOW3y/mxRTZzr1K84opb7/wC6BID8Dz8WuwT76iAFT3WYwnwFnrzqS9n/U/RYRpzpaFjiDZ5OJLIs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573821700; 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=M2IzGUBbdGfToULQAZbqdU+pDo6oEb0K8RLUeUI/NoY=; b=X7gNZ7OQ6Me8A1HoYweQl4My9RbJoB5yiH9EaF8WcWKbxdAASZ7GrIiV9W4O8Kui62z5F5uEhJZ1fyuF/fFOof5K6fHc3gn4daQstaO1ctU3Ad6VOB6HBalv/9vO6+ZN8VHTZdvjZ4s7UntQ7wqxkI/SRux8VS46JpVxcJo82fk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573821700025242.09977692399752; Fri, 15 Nov 2019 04:41:40 -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-218-dH6Z0g0RMQaZDr77Sh90sg-1; Fri, 15 Nov 2019 07:41:36 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 958B4802687; Fri, 15 Nov 2019 12:41:30 +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 6D0D328DDD; Fri, 15 Nov 2019 12:41:30 +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 2A8494E570; Fri, 15 Nov 2019 12:41:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAFCfIXg027062 for ; Fri, 15 Nov 2019 07:41:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id A4E5F5ED35; Fri, 15 Nov 2019 12:41:18 +0000 (UTC) Received: from lindworm.usersys.redhat.com (unknown [10.43.2.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F5115E263 for ; Fri, 15 Nov 2019 12:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573821697; 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=M2IzGUBbdGfToULQAZbqdU+pDo6oEb0K8RLUeUI/NoY=; b=gOUOTf/w5uJikC5c7FWfUGpMYLkszGBxgg6518SnLp/yWgBQiTtWrYG6eHQkZRrKRQngbt VD+virPMt9FagjfV2jBfmAzKe7nAPyCI0XM1DMUd5JduwTcIydgP1JCQvBScPyg99nx3KF aI5D89uSK/N9VBluW6dgNA/GlEy8jZ0= From: Pino Toscano To: libvir-list@redhat.com Date: Fri, 15 Nov 2019 13:40:50 +0100 Message-Id: <20191115124051.989-12-ptoscano@redhat.com> In-Reply-To: <20191115124051.989-1-ptoscano@redhat.com> References: <20191115124051.989-1-ptoscano@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 11/12] 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.84 on 10.5.11.23 X-MC-Unique: dH6Z0g0RMQaZDr77Sh90sg-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 | 70 ++++++++++++++++++++++++ src/esx/esx_storage_backend_vmfs.c | 85 +++++++++++++++++++++++++++++ src/esx/esx_storage_driver.c | 19 +++++++ 3 files changed, 174 insertions(+) diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_back= end_iscsi.c index 34760a837e..2f189a92cf 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -852,6 +852,75 @@ esxConnectListAllStoragePools(virConnectPtr conn, =20 =20 =20 +static int +esxStoragePoolListAllVolumes(virStoragePoolPtr pool, + virStorageVolPtr **vols, + unsigned int flags) +{ + bool success =3D false; + 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; + } + + } + } + + success =3D true; + + cleanup: + if (! success) { + if (*vols) { + for (i =3D 0; i < count; ++i) + VIR_FREE((*vols)[i]); + VIR_FREE(*vols); + } + + count =3D -1; + } + + esxVI_HostScsiTopologyLun_Free(&hostScsiTopologyLunList); + esxVI_ScsiLun_Free(&scsiLunList); + + return count; +} + + + virStorageDriver esxStorageBackendISCSI =3D { .connectNumOfStoragePools =3D esxConnectNumOfStoragePools, /* 1.0.1 */ .connectListStoragePools =3D esxConnectListStoragePools, /* 1.0.1 */ @@ -873,4 +942,5 @@ virStorageDriver esxStorageBackendISCSI =3D { .storageVolWipe =3D esxStorageVolWipe, /* 1.0.1 */ .storageVolGetPath =3D esxStorageVolGetPath, /* 1.0.1 */ .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 5.10= .0 */ + .storagePoolListAllVolumes =3D esxStoragePoolListAllVolumes, /* 5.10.0= */ }; diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index ab47a4c272..27f8b17e06 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -1566,6 +1566,90 @@ esxConnectListAllStoragePools(virConnectPtr conn, =20 =20 =20 +static int +esxStoragePoolListAllVolumes(virStoragePoolPtr pool, + virStorageVolPtr **vols, + unsigned int flags) +{ + bool success =3D false; + 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; + } + } + + success =3D true; + + cleanup: + if (! success) { + if (*vols) { + for (i =3D 0; i < count; ++i) + VIR_FREE((*vols)[i]); + VIR_FREE(*vols); + } + + count =3D -1; + } + + esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList); + VIR_FREE(directoryAndFileName); + + return count; +} + + + virStorageDriver esxStorageBackendVMFS =3D { .connectNumOfStoragePools =3D esxConnectNumOfStoragePools, /* 0.8.2 */ .connectListStoragePools =3D esxConnectListStoragePools, /* 0.8.2 */ @@ -1587,4 +1671,5 @@ virStorageDriver esxStorageBackendVMFS =3D { .storageVolGetXMLDesc =3D esxStorageVolGetXMLDesc, /* 0.8.4 */ .storageVolGetPath =3D esxStorageVolGetPath, /* 0.8.4 */ .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 5.10= .0 */ + .storagePoolListAllVolumes =3D esxStoragePoolListAllVolumes, /* 5.10.0= */ }; diff --git a/src/esx/esx_storage_driver.c b/src/esx/esx_storage_driver.c index 6d17ac28ea..ba72a0e5b5 100644 --- a/src/esx/esx_storage_driver.c +++ b/src/esx/esx_storage_driver.c @@ -584,6 +584,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 */ @@ -612,4 +630,5 @@ virStorageDriver esxStorageDriver =3D { .storagePoolIsActive =3D esxStoragePoolIsActive, /* 0.8.2 */ .storagePoolIsPersistent =3D esxStoragePoolIsPersistent, /* 0.8.2 */ .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 5.10= .0 */ + .storagePoolListAllVolumes =3D esxStoragePoolListAllVolumes, /* 5.10.0= */ }; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list