|
|
99cbc7 |
From e308683f879155b6912f979f3e2cd17f93d35c87 Mon Sep 17 00:00:00 2001
|
|
|
99cbc7 |
Message-Id: <e308683f879155b6912f979f3e2cd17f93d35c87@dist-git>
|
|
|
99cbc7 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
99cbc7 |
Date: Fri, 16 Aug 2019 14:36:51 +0200
|
|
|
99cbc7 |
Subject: [PATCH] util: storage: Refactor logic for using
|
|
|
99cbc7 |
virStorageFileGetBackendForSupportCheck
|
|
|
99cbc7 |
MIME-Version: 1.0
|
|
|
99cbc7 |
Content-Type: text/plain; charset=UTF-8
|
|
|
99cbc7 |
Content-Transfer-Encoding: 8bit
|
|
|
99cbc7 |
|
|
|
99cbc7 |
Modify the return value so that callers don't have to repeat logic.
|
|
|
99cbc7 |
|
|
|
99cbc7 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
99cbc7 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
99cbc7 |
(cherry picked from commit d30e0d3abc0cb082d8d97c53dcff2b978e3eb372)
|
|
|
99cbc7 |
https: //bugzilla.redhat.com/show_bug.cgi?id=1724808
|
|
|
99cbc7 |
Message-Id: <73fad4d39daf47dc1c7ebd6da52a021670d113d6.1565958905.git.pkrempa@redhat.com>
|
|
|
99cbc7 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
99cbc7 |
---
|
|
|
99cbc7 |
src/util/virstoragefile.c | 39 ++++++++++++++++++++-------------------
|
|
|
99cbc7 |
1 file changed, 20 insertions(+), 19 deletions(-)
|
|
|
99cbc7 |
|
|
|
99cbc7 |
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
|
|
|
99cbc7 |
index 0187c8d2c9..f320bc1928 100644
|
|
|
99cbc7 |
--- a/src/util/virstoragefile.c
|
|
|
99cbc7 |
+++ b/src/util/virstoragefile.c
|
|
|
99cbc7 |
@@ -4352,6 +4352,14 @@ virStorageFileIsInitialized(const virStorageSource *src)
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
|
|
|
99cbc7 |
+/**
|
|
|
99cbc7 |
+ * virStorageFileGetBackendForSupportCheck:
|
|
|
99cbc7 |
+ * @src: storage source to check support for
|
|
|
99cbc7 |
+ * @backend: pointer to the storage backend for @src if it's supported
|
|
|
99cbc7 |
+ *
|
|
|
99cbc7 |
+ * Returns 0 if @src is not supported by any storage backend currently linked
|
|
|
99cbc7 |
+ * 1 if it is supported and -1 on error with an error reported.
|
|
|
99cbc7 |
+ */
|
|
|
99cbc7 |
static int
|
|
|
99cbc7 |
virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
|
|
|
99cbc7 |
virStorageFileBackendPtr *backend)
|
|
|
99cbc7 |
@@ -4366,7 +4374,7 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (src->drv) {
|
|
|
99cbc7 |
*backend = src->drv->backend;
|
|
|
99cbc7 |
- return 0;
|
|
|
99cbc7 |
+ return 1;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
actualType = virStorageSourceGetActualType(src);
|
|
|
99cbc7 |
@@ -4374,7 +4382,10 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
|
|
|
99cbc7 |
if (virStorageFileBackendForType(actualType, src->protocol, false, backend) < 0)
|
|
|
99cbc7 |
return -1;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- return 0;
|
|
|
99cbc7 |
+ if (!*backend)
|
|
|
99cbc7 |
+ return 0;
|
|
|
99cbc7 |
+
|
|
|
99cbc7 |
+ return 1;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
|
|
|
99cbc7 |
@@ -4384,12 +4395,8 @@ virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src)
|
|
|
99cbc7 |
virStorageFileBackendPtr backend;
|
|
|
99cbc7 |
int rv;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- rv = virStorageFileGetBackendForSupportCheck(src, &backend);
|
|
|
99cbc7 |
- if (rv < 0)
|
|
|
99cbc7 |
- return -1;
|
|
|
99cbc7 |
-
|
|
|
99cbc7 |
- if (!backend)
|
|
|
99cbc7 |
- return 0;
|
|
|
99cbc7 |
+ if ((rv = virStorageFileGetBackendForSupportCheck(src, &backend)) < 1)
|
|
|
99cbc7 |
+ return rv;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
return backend->storageFileGetUniqueIdentifier &&
|
|
|
99cbc7 |
backend->storageFileRead &&
|
|
|
99cbc7 |
@@ -4411,11 +4418,8 @@ virStorageFileSupportsSecurityDriver(const virStorageSource *src)
|
|
|
99cbc7 |
virStorageFileBackendPtr backend;
|
|
|
99cbc7 |
int rv;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- rv = virStorageFileGetBackendForSupportCheck(src, &backend);
|
|
|
99cbc7 |
- if (rv < 0)
|
|
|
99cbc7 |
- return -1;
|
|
|
99cbc7 |
- if (backend == NULL)
|
|
|
99cbc7 |
- return 0;
|
|
|
99cbc7 |
+ if ((rv = virStorageFileGetBackendForSupportCheck(src, &backend)) < 1)
|
|
|
99cbc7 |
+ return rv;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
return backend->storageFileChown ? 1 : 0;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
@@ -4433,13 +4437,10 @@ int
|
|
|
99cbc7 |
virStorageFileSupportsAccess(const virStorageSource *src)
|
|
|
99cbc7 |
{
|
|
|
99cbc7 |
virStorageFileBackendPtr backend;
|
|
|
99cbc7 |
- int ret;
|
|
|
99cbc7 |
+ int rv;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- ret = virStorageFileGetBackendForSupportCheck(src, &backend);
|
|
|
99cbc7 |
- if (ret < 0)
|
|
|
99cbc7 |
- return -1;
|
|
|
99cbc7 |
- if (backend == NULL)
|
|
|
99cbc7 |
- return 0;
|
|
|
99cbc7 |
+ if ((rv = virStorageFileGetBackendForSupportCheck(src, &backend)) < 1)
|
|
|
99cbc7 |
+ return rv;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
return backend->storageFileAccess ? 1 : 0;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
--
|
|
|
99cbc7 |
2.22.1
|
|
|
99cbc7 |
|