[libvirt] [PATCH v2 09/12] esx: split datastorePathToStorageVol helper

Pino Toscano posted 12 patches 6 years, 2 months ago
There is a newer version of this series
[libvirt] [PATCH v2 09/12] esx: split datastorePathToStorageVol helper
Posted by Pino Toscano 6 years, 2 months ago
Move the creation of a virStorageVolPtr object by lookup out of
esxStorageVolLookupByPath in an own helper. This way it can be used
also in other functions.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
---
 src/esx/esx_storage_backend_vmfs.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index 1270c21e00..ab47a4c272 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -695,32 +695,40 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
 
 
 
+static virStorageVolPtr
+datastorePathToStorageVol(virConnectPtr conn, const char *pool,
+                          const char *path)
+{
+    esxPrivate *priv = conn->privateData;
+    g_autofree char *key = NULL;
+
+    if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary, path,
+                                                    &key) < 0) {
+        return NULL;
+    }
+
+    return virGetStorageVol(conn, pool, path, key,
+                            &esxStorageBackendVMFS, NULL);
+}
+
+
 static virStorageVolPtr
 esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
 {
     virStorageVolPtr volume = NULL;
-    esxPrivate *priv = conn->privateData;
     char *datastoreName = NULL;
     char *directoryAndFileName = NULL;
-    char *key = NULL;
 
     if (esxUtil_ParseDatastorePath(path, &datastoreName, NULL,
                                    &directoryAndFileName) < 0) {
         goto cleanup;
     }
 
-    if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary, path,
-                                                    &key) < 0) {
-        goto cleanup;
-    }
-
-    volume = virGetStorageVol(conn, datastoreName, directoryAndFileName, key,
-                              &esxStorageBackendVMFS, NULL);
+    volume = datastorePathToStorageVol(conn, datastoreName, directoryAndFileName);
 
  cleanup:
     VIR_FREE(datastoreName);
     VIR_FREE(directoryAndFileName);
-    VIR_FREE(key);
 
     return volume;
 }
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 09/12] esx: split datastorePathToStorageVol helper
Posted by Cole Robinson 6 years, 1 month ago
On 11/15/19 7:40 AM, Pino Toscano wrote:
> Move the creation of a virStorageVolPtr object by lookup out of
> esxStorageVolLookupByPath in an own helper. This way it can be used
> also in other functions.
> 
> Signed-off-by: Pino Toscano <ptoscano@redhat.com>
> ---
>  src/esx/esx_storage_backend_vmfs.c | 28 ++++++++++++++++++----------
>  1 file changed, 18 insertions(+), 10 deletions(-)
> 
> diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
> index 1270c21e00..ab47a4c272 100644
> --- a/src/esx/esx_storage_backend_vmfs.c
> +++ b/src/esx/esx_storage_backend_vmfs.c
> @@ -695,32 +695,40 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
>  
>  
>  
> +static virStorageVolPtr
> +datastorePathToStorageVol(virConnectPtr conn, const char *pool,
> +                          const char *path)
> +{
> +    esxPrivate *priv = conn->privateData;
> +    g_autofree char *key = NULL;
> +
> +    if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary, path,
> +                                                    &key) < 0) {
> +        return NULL;
> +    }
> +
> +    return virGetStorageVol(conn, pool, path, key,
> +                            &esxStorageBackendVMFS, NULL);
> +}
> +
> +

Add an extra newline here, since this file uses triple line spacing

Reviewed-by: Cole Robinson <crobinso@redhat.com>

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list