提交 d30e0d3a 编写于 作者: P Peter Krempa

util: storage: Refactor logic for using virStorageFileGetBackendForSupportCheck

Modify the return value so that callers don't have to repeat logic.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 77521d27
...@@ -4411,6 +4411,14 @@ virStorageFileIsInitialized(const virStorageSource *src) ...@@ -4411,6 +4411,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 static int
virStorageFileGetBackendForSupportCheck(const virStorageSource *src, virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
virStorageFileBackendPtr *backend) virStorageFileBackendPtr *backend)
...@@ -4425,7 +4433,7 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src, ...@@ -4425,7 +4433,7 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
if (src->drv) { if (src->drv) {
*backend = src->drv->backend; *backend = src->drv->backend;
return 0; return 1;
} }
actualType = virStorageSourceGetActualType(src); actualType = virStorageSourceGetActualType(src);
...@@ -4433,7 +4441,10 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src, ...@@ -4433,7 +4441,10 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
if (virStorageFileBackendForType(actualType, src->protocol, false, backend) < 0) if (virStorageFileBackendForType(actualType, src->protocol, false, backend) < 0)
return -1; return -1;
return 0; if (!*backend)
return 0;
return 1;
} }
...@@ -4443,12 +4454,8 @@ virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src) ...@@ -4443,12 +4454,8 @@ virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src)
virStorageFileBackendPtr backend; virStorageFileBackendPtr backend;
int rv; int rv;
rv = virStorageFileGetBackendForSupportCheck(src, &backend); if ((rv = virStorageFileGetBackendForSupportCheck(src, &backend)) < 1)
if (rv < 0) return rv;
return -1;
if (!backend)
return 0;
return backend->storageFileGetUniqueIdentifier && return backend->storageFileGetUniqueIdentifier &&
backend->storageFileRead && backend->storageFileRead &&
...@@ -4470,11 +4477,8 @@ virStorageFileSupportsSecurityDriver(const virStorageSource *src) ...@@ -4470,11 +4477,8 @@ virStorageFileSupportsSecurityDriver(const virStorageSource *src)
virStorageFileBackendPtr backend; virStorageFileBackendPtr backend;
int rv; int rv;
rv = virStorageFileGetBackendForSupportCheck(src, &backend); if ((rv = virStorageFileGetBackendForSupportCheck(src, &backend)) < 1)
if (rv < 0) return rv;
return -1;
if (backend == NULL)
return 0;
return backend->storageFileChown ? 1 : 0; return backend->storageFileChown ? 1 : 0;
} }
...@@ -4492,13 +4496,10 @@ int ...@@ -4492,13 +4496,10 @@ int
virStorageFileSupportsAccess(const virStorageSource *src) virStorageFileSupportsAccess(const virStorageSource *src)
{ {
virStorageFileBackendPtr backend; virStorageFileBackendPtr backend;
int ret; int rv;
ret = virStorageFileGetBackendForSupportCheck(src, &backend); if ((rv = virStorageFileGetBackendForSupportCheck(src, &backend)) < 1)
if (ret < 0) return rv;
return -1;
if (backend == NULL)
return 0;
return backend->storageFileAccess ? 1 : 0; return backend->storageFileAccess ? 1 : 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册