提交 1421e716 编写于 作者: D Daniel P. Berrangé

util: refactor storage file checks to allow error reporting

The virStorageFileSupportsSecurityDriver and
virStorageFileSupportsAccess currently just return a boolean
value. This is ok because they don't have any failure scenarios
but a subsequent patch is going to introduce potential failure
scenario. This changes their return type from a boolean to an
int with values -1, 0, 1.
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 c444505c
...@@ -7514,19 +7514,24 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, ...@@ -7514,19 +7514,24 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
/* skip to the end of the chain if there is any */ /* skip to the end of the chain if there is any */
while (virStorageSourceHasBacking(src)) { while (virStorageSourceHasBacking(src)) {
if (report_broken && if (report_broken) {
virStorageFileSupportsAccess(src)) { int rv = virStorageFileSupportsAccess(src);
if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0) if (rv < 0)
goto cleanup; goto cleanup;
if (virStorageFileAccess(src, F_OK) < 0) { if (rv > 0) {
virStorageFileReportBrokenChain(errno, src, disk->src); if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0)
goto cleanup;
if (virStorageFileAccess(src, F_OK) < 0) {
virStorageFileReportBrokenChain(errno, src, disk->src);
virStorageFileDeinit(src);
goto cleanup;
}
virStorageFileDeinit(src); virStorageFileDeinit(src);
goto cleanup;
} }
virStorageFileDeinit(src);
} }
src = src->backingStore; src = src->backingStore;
} }
......
...@@ -308,9 +308,11 @@ qemuSecurityChownCallback(const virStorageSource *src, ...@@ -308,9 +308,11 @@ qemuSecurityChownCallback(const virStorageSource *src,
struct stat sb; struct stat sb;
int save_errno = 0; int save_errno = 0;
int ret = -1; int ret = -1;
int rv;
if (!virStorageFileSupportsSecurityDriver(src)) rv = virStorageFileSupportsSecurityDriver(src);
return 0; if (rv <= 0)
return rv;
if (virStorageSourceIsLocalStorage(src)) { if (virStorageSourceIsLocalStorage(src)) {
/* use direct chmod for local files so that the file doesn't /* use direct chmod for local files so that the file doesn't
......
...@@ -4098,34 +4098,46 @@ virStorageFileIsInitialized(const virStorageSource *src) ...@@ -4098,34 +4098,46 @@ virStorageFileIsInitialized(const virStorageSource *src)
} }
static virStorageFileBackendPtr static int
virStorageFileGetBackendForSupportCheck(const virStorageSource *src) virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
virStorageFileBackendPtr *backend)
{ {
int actualType; int actualType;
if (!src)
return NULL;
if (src->drv) if (!src) {
return src->drv->backend; *backend = NULL;
return 0;
}
if (src->drv) {
*backend = src->drv->backend;
return 0;
}
actualType = virStorageSourceGetActualType(src); actualType = virStorageSourceGetActualType(src);
return virStorageFileBackendForTypeInternal(actualType, src->protocol, false); *backend = virStorageFileBackendForTypeInternal(actualType, src->protocol, false);
return 0;
} }
static bool static int
virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src) virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src)
{ {
virStorageFileBackendPtr backend; virStorageFileBackendPtr backend;
int rv;
if (!(backend = virStorageFileGetBackendForSupportCheck(src))) rv = virStorageFileGetBackendForSupportCheck(src, &backend);
return false; if (rv < 0)
return -1;
if (!backend)
return 0;
return backend->storageFileGetUniqueIdentifier && return backend->storageFileGetUniqueIdentifier &&
backend->storageFileRead && backend->storageFileRead &&
backend->storageFileAccess; backend->storageFileAccess ? 1 : 0;
} }
...@@ -4137,15 +4149,19 @@ virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src) ...@@ -4137,15 +4149,19 @@ virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src)
* Check if a storage file supports operations needed by the security * Check if a storage file supports operations needed by the security
* driver to perform labelling * driver to perform labelling
*/ */
bool int
virStorageFileSupportsSecurityDriver(const virStorageSource *src) virStorageFileSupportsSecurityDriver(const virStorageSource *src)
{ {
virStorageFileBackendPtr backend; virStorageFileBackendPtr backend;
int rv;
if (!(backend = virStorageFileGetBackendForSupportCheck(src))) rv = virStorageFileGetBackendForSupportCheck(src, &backend);
return false; if (rv < 0)
return -1;
if (backend == NULL)
return 0;
return !!backend->storageFileChown; return backend->storageFileChown ? 1 : 0;
} }
...@@ -4157,15 +4173,19 @@ virStorageFileSupportsSecurityDriver(const virStorageSource *src) ...@@ -4157,15 +4173,19 @@ virStorageFileSupportsSecurityDriver(const virStorageSource *src)
* Check if a storage file supports checking if the storage source is accessible * Check if a storage file supports checking if the storage source is accessible
* for the given vm. * for the given vm.
*/ */
bool int
virStorageFileSupportsAccess(const virStorageSource *src) virStorageFileSupportsAccess(const virStorageSource *src)
{ {
virStorageFileBackendPtr backend; virStorageFileBackendPtr backend;
int ret;
if (!(backend = virStorageFileGetBackendForSupportCheck(src))) ret = virStorageFileGetBackendForSupportCheck(src, &backend);
return false; if (ret < 0)
return -1;
if (backend == NULL)
return 0;
return !!backend->storageFileAccess; return backend->storageFileAccess ? 1 : 0;
} }
...@@ -4514,14 +4534,16 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src, ...@@ -4514,14 +4534,16 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
ssize_t headerLen; ssize_t headerLen;
virStorageSourcePtr backingStore = NULL; virStorageSourcePtr backingStore = NULL;
int backingFormat; int backingFormat;
int rv;
VIR_DEBUG("path=%s format=%d uid=%u gid=%u probe=%d", VIR_DEBUG("path=%s format=%d uid=%u gid=%u probe=%d",
src->path, src->format, src->path, src->format,
(unsigned int)uid, (unsigned int)gid, allow_probe); (unsigned int)uid, (unsigned int)gid, allow_probe);
/* exit if we can't load information about the current image */ /* exit if we can't load information about the current image */
if (!virStorageFileSupportsBackingChainTraversal(src)) rv = virStorageFileSupportsBackingChainTraversal(src);
return 0; if (rv <= 0)
return rv;
if (virStorageFileInitAs(src, uid, gid) < 0) if (virStorageFileInitAs(src, uid, gid) < 0)
return -1; return -1;
......
...@@ -465,8 +465,8 @@ const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src); ...@@ -465,8 +465,8 @@ const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src);
int virStorageFileAccess(virStorageSourcePtr src, int mode); int virStorageFileAccess(virStorageSourcePtr src, int mode);
int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid); int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid);
bool virStorageFileSupportsSecurityDriver(const virStorageSource *src); int virStorageFileSupportsSecurityDriver(const virStorageSource *src);
bool virStorageFileSupportsAccess(const virStorageSource *src); int virStorageFileSupportsAccess(const virStorageSource *src);
int virStorageFileGetMetadata(virStorageSourcePtr src, int virStorageFileGetMetadata(virStorageSourcePtr src,
uid_t uid, gid_t gid, uid_t uid, gid_t gid,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册