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