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); + } + + volume = datastorePathToStorageVol(pool->conn, pool->name, datastorePath); + 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_HostDatastoreBrowserSearchResults_Free(&searchResultsList); + VIR_FREE(directoryAndFileName); + + return count; +} + + + virStorageDriver esxStorageBackendVMFS = { .connectNumOfStoragePools = esxConnectNumOfStoragePools, /* 0.8.2 */ .connectListStoragePools = esxConnectListStoragePools, /* 0.8.2 */ @@ -1587,4 +1671,5 @@ virStorageDriver esxStorageBackendVMFS = { .storageVolGetXMLDesc = esxStorageVolGetXMLDesc, /* 0.8.4 */ .storageVolGetPath = esxStorageVolGetPath, /* 0.8.4 */ .connectListAllStoragePools = esxConnectListAllStoragePools, /* 5.10.0 */ + .storagePoolListAllVolumes = 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, +static int +esxStoragePoolListAllVolumes(virStoragePoolPtr pool, + virStorageVolPtr **vols, + unsigned int flags) +{ + esxPrivate *priv = pool->conn->privateData; + virStorageDriverPtr backend = pool->privateData; + + virCheckNonNullArgReturn(pool->privateData, -1); + + if (esxVI_EnsureSession(priv->primary) < 0) + return -1; + + return backend->storagePoolListAllVolumes(pool, vols, flags); +} + + + virStorageDriver esxStorageDriver = { .connectNumOfStoragePools = esxConnectNumOfStoragePools, /* 0.8.2 */ .connectListStoragePools = esxConnectListStoragePools, /* 0.8.2 */ @@ -612,4 +630,5 @@ virStorageDriver esxStorageDriver = { .storagePoolIsActive = esxStoragePoolIsActive, /* 0.8.2 */ .storagePoolIsPersistent = esxStoragePoolIsPersistent, /* 0.8.2 */ .connectListAllStoragePools = esxConnectListAllStoragePools, /* 5.10.0 */ + .storagePoolListAllVolumes = esxStoragePoolListAllVolumes, /* 5.10.0 */ }; -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list