On 11/15/19 7:40 AM, Pino Toscano wrote: > Implement the .storagePoolListAllVolumes storage API in the esx storage > driver, and in all its subdrivers. > > Signed-off-by: Pino Toscano <ptoscano@xxxxxxxxxx> > --- > 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_backend_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, > > > > +static int > +esxStoragePoolListAllVolumes(virStoragePoolPtr pool, > + virStorageVolPtr **vols, > + unsigned int flags) > +{ > + bool success = false; > + size_t count = 0; > + esxPrivate *priv = pool->conn->privateData; > + esxVI_HostScsiTopologyLun *hostScsiTopologyLunList = NULL; > + esxVI_HostScsiTopologyLun *hostScsiTopologyLun; > + esxVI_ScsiLun *scsiLunList = NULL; > + esxVI_ScsiLun *scsiLun = 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 = scsiLunList; scsiLun; > + scsiLun = scsiLun->_next) { > + for (hostScsiTopologyLun = hostScsiTopologyLunList; > + hostScsiTopologyLun; > + hostScsiTopologyLun = hostScsiTopologyLun->_next) { > + if (STREQ(hostScsiTopologyLun->scsiLun, scsiLun->key)) { > + virStorageVolPtr volume; > + > + volume = scsilunToStorageVol(pool->conn, scsiLun, pool->name); > + if (!volume) > + goto cleanup; > + > + if (VIR_APPEND_ELEMENT(*vols, count, volume) < 0) > + goto cleanup; > + } > + > + } > + } > + > + success = true; > + > + cleanup: > + if (! success) { > + if (*vols) { > + for (i = 0; i < count; ++i) > + VIR_FREE((*vols)[i]); > + VIR_FREE(*vols); > + } > + > + count = -1; > + } > + > + esxVI_HostScsiTopologyLun_Free(&hostScsiTopologyLunList); > + esxVI_ScsiLun_Free(&scsiLunList); > + > + return count; > +} > + > + > + > virStorageDriver esxStorageBackendISCSI = { > .connectNumOfStoragePools = esxConnectNumOfStoragePools, /* 1.0.1 */ > .connectListStoragePools = esxConnectListStoragePools, /* 1.0.1 */ > @@ -873,4 +942,5 @@ virStorageDriver esxStorageBackendISCSI = { > .storageVolWipe = esxStorageVolWipe, /* 1.0.1 */ > .storageVolGetPath = esxStorageVolGetPath, /* 1.0.1 */ > .connectListAllStoragePools = esxConnectListAllStoragePools, /* 5.10.0 */ > + .storagePoolListAllVolumes = esxStoragePoolListAllVolumes, /* 5.10.0 */ > }; > diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_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, > > > > +static int > +esxStoragePoolListAllVolumes(virStoragePoolPtr pool, > + virStorageVolPtr **vols, > + unsigned int flags) > +{ > + bool success = false; > + esxPrivate *priv = pool->conn->privateData; > + esxVI_HostDatastoreBrowserSearchResults *searchResultsList = NULL; > + esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL; > + esxVI_FileInfo *fileInfo = NULL; > + char *directoryAndFileName = NULL; > + size_t length; > + size_t count = 0; > + size_t i; > + > + virCheckFlags(0, -1); > + > + if (esxVI_LookupDatastoreContentByDatastoreName(priv->primary, pool->name, > + &searchResultsList) < 0) { > + goto cleanup; > + } > + > + /* Interpret search result */ > + for (searchResults = searchResultsList; searchResults; > + searchResults = searchResults->_next) { > + VIR_FREE(directoryAndFileName); > + > + if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL, NULL, > + &directoryAndFileName) < 0) { > + goto cleanup; > + } > + > + /* Strip trailing separators */ > + length = strlen(directoryAndFileName); > + > + while (length > 0 && directoryAndFileName[length - 1] == '/') { > + directoryAndFileName[length - 1] = '\0'; > + --length; > + } > + > + /* Build volume names */ > + for (fileInfo = searchResults->file; fileInfo; > + fileInfo = fileInfo->_next) { > + g_autofree char *datastorePath = NULL; > + virStorageVolPtr volume; > + > + if (length < 1) { > + datastorePath = g_strdup(fileInfo->path); > + } else { > + datastorePath = g_strdup_printf("%s/%s", > + directoryAndFileName, > + fileInfo->path); > + } > + All this black magic shouldn't be duplicated IMO. I think it should be factored out first from esxStoragePoolListVolumes and then used here. All of Jano's previous comments apply to this one as well too - Cole -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list