[libvirt] [PATCH 01/12] storage: Extract common code to retrieve driver backend for support check

Peter Krempa posted 12 patches 7 years, 6 months ago
[libvirt] [PATCH 01/12] storage: Extract common code to retrieve driver backend for support check
Posted by Peter Krempa 7 years, 6 months ago
The 'file access' module of the storage driver has few feature checks to
determine whether libvirt supports given storage driver method. The code
to retrieve the driver struct needed for the check is the same so it can
be extracted.
---
 src/storage/storage_source.c | 43 +++++++++++++++++++------------------------
 1 file changed, 19 insertions(+), 24 deletions(-)

diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c
index 419fa3d43..e3c5c3285 100644
--- a/src/storage/storage_source.c
+++ b/src/storage/storage_source.c
@@ -44,24 +44,30 @@ virStorageFileIsInitialized(const virStorageSource *src)
 }


-static bool
-virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src)
+static virStorageFileBackendPtr
+virStorageFileGetBackendForSupportCheck(const virStorageSource *src)
 {
     int actualType;
-    virStorageFileBackendPtr backend;

     if (!src)
-        return false;
+        return NULL;
+
+    if (src->drv)
+        return src->drv->backend;
+
     actualType = virStorageSourceGetActualType(src);

-    if (src->drv) {
-        backend = src->drv->backend;
-    } else {
-        if (!(backend = virStorageFileBackendForTypeInternal(actualType,
-                                                             src->protocol,
-                                                             false)))
-            return false;
-    }
+    return virStorageFileBackendForTypeInternal(actualType, src->protocol, false);
+}
+
+
+static bool
+virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src)
+{
+    virStorageFileBackendPtr backend;
+
+    if (!(backend = virStorageFileGetBackendForSupportCheck(src)))
+        return false;

     return backend->storageFileGetUniqueIdentifier &&
            backend->storageFileRead &&
@@ -80,21 +86,10 @@ virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src)
 bool
 virStorageFileSupportsSecurityDriver(const virStorageSource *src)
 {
-    int actualType;
     virStorageFileBackendPtr backend;

-    if (!src)
+    if (!(backend = virStorageFileGetBackendForSupportCheck(src)))
         return false;
-    actualType = virStorageSourceGetActualType(src);
-
-    if (src->drv) {
-        backend = src->drv->backend;
-    } else {
-        if (!(backend = virStorageFileBackendForTypeInternal(actualType,
-                                                             src->protocol,
-                                                             false)))
-            return false;
-    }

     return !!backend->storageFileChown;
 }
-- 
2.14.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 01/12] storage: Extract common code to retrieve driver backend for support check
Posted by John Ferlan 7 years, 6 months ago

On 10/20/2017 09:47 AM, Peter Krempa wrote:
> The 'file access' module of the storage driver has few feature checks to
> determine whether libvirt supports given storage driver method. The code
> to retrieve the driver struct needed for the check is the same so it can
> be extracted.
> ---
>  src/storage/storage_source.c | 43 +++++++++++++++++++------------------------
>  1 file changed, 19 insertions(+), 24 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

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