[libvirt] [PATCH 1/5] esx: split datastoreToStoragePoolPtr helper

Pino Toscano ptoscano at redhat.com
Wed Nov 13 12:46:07 UTC 2019


Move the creation of a virStoragePtr object from the esxVI_ObjectContent
object of a datastore out of esxStoragePoolLookupByName in an own
helper. This way it can be used also in other functions.

Signed-off-by: Pino Toscano <ptoscano at redhat.com>
---
 src/esx/esx_storage_backend_vmfs.c | 45 ++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index 5f25f80072..78fe2b598d 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -195,26 +195,16 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names,
 
 
 static virStoragePoolPtr
-esxStoragePoolLookupByName(virConnectPtr conn,
-                           const char *name)
+datastoreToStoragePoolPtr(virConnectPtr conn,
+                          const char *name,
+                          esxVI_ObjectContent *datastore)
 {
     esxPrivate *priv = conn->privateData;
-    esxVI_ObjectContent *datastore = NULL;
     esxVI_DatastoreHostMount *hostMount = NULL;
     /* VIR_CRYPTO_HASH_SIZE_MD5 = VIR_UUID_BUFLEN = 16 */
     unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5];
     virStoragePoolPtr pool = NULL;
 
-    if (esxVI_LookupDatastoreByName(priv->primary, name, NULL, &datastore,
-                                    esxVI_Occurrence_OptionalItem) < 0) {
-        goto cleanup;
-    }
-
-    if (!datastore) {
-        /* Not found, let the base storage driver handle error reporting */
-        goto cleanup;
-    }
-
     /*
      * Datastores don't have a UUID, but we can use the 'host.mountInfo.path'
      * property as source for a UUID. The mount path is unique per host and
@@ -239,7 +229,6 @@ esxStoragePoolLookupByName(virConnectPtr conn,
     pool = virGetStoragePool(conn, name, md5, &esxStorageBackendVMFS, NULL);
 
  cleanup:
-    esxVI_ObjectContent_Free(&datastore);
     esxVI_DatastoreHostMount_Free(&hostMount);
 
     return pool;
@@ -247,6 +236,34 @@ esxStoragePoolLookupByName(virConnectPtr conn,
 
 
 
+static virStoragePoolPtr
+esxStoragePoolLookupByName(virConnectPtr conn,
+                           const char *name)
+{
+    esxPrivate *priv = conn->privateData;
+    esxVI_ObjectContent *datastore = NULL;
+    virStoragePoolPtr pool = NULL;
+
+    if (esxVI_LookupDatastoreByName(priv->primary, name, NULL, &datastore,
+                                    esxVI_Occurrence_OptionalItem) < 0) {
+        goto cleanup;
+    }
+
+    if (!datastore) {
+        /* Not found, let the base storage driver handle error reporting */
+        goto cleanup;
+    }
+
+    pool = datastoreToStoragePoolPtr(conn, name, datastore);
+
+ cleanup:
+    esxVI_ObjectContent_Free(&datastore);
+
+    return pool;
+}
+
+
+
 static virStoragePoolPtr
 esxStoragePoolLookupByUUID(virConnectPtr conn,
                            const unsigned char *uuid)
-- 
2.21.0




More information about the libvir-list mailing list