diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 326c939c85c0fa405f51ebf7619a20f68123c368..542e20c5e4a08e5363cbe5c27e762e38f0f3072d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7514,19 +7514,24 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, /* skip to the end of the chain if there is any */ while (virStorageSourceHasBacking(src)) { - if (report_broken && - virStorageFileSupportsAccess(src)) { + if (report_broken) { + int rv = virStorageFileSupportsAccess(src); - if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0) + if (rv < 0) goto cleanup; - if (virStorageFileAccess(src, F_OK) < 0) { - virStorageFileReportBrokenChain(errno, src, disk->src); + if (rv > 0) { + 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); - goto cleanup; } - - virStorageFileDeinit(src); } src = src->backingStore; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f136ee265ff6208937dec01412b9697a38e1565b..ef11e3cc449d4b2bdaa2ffc3838d2538c3cdff5a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -308,9 +308,11 @@ qemuSecurityChownCallback(const virStorageSource *src, struct stat sb; int save_errno = 0; int ret = -1; + int rv; - if (!virStorageFileSupportsSecurityDriver(src)) - return 0; + rv = virStorageFileSupportsSecurityDriver(src); + if (rv <= 0) + return rv; if (virStorageSourceIsLocalStorage(src)) { /* use direct chmod for local files so that the file doesn't diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index f09035cd4a5d027ffed4c1bdd8bf109e197955c5..9e9b5f916892ae5a41b28c9ce7eacb4ea72d5589 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4098,34 +4098,46 @@ virStorageFileIsInitialized(const virStorageSource *src) } -static virStorageFileBackendPtr -virStorageFileGetBackendForSupportCheck(const virStorageSource *src) +static int +virStorageFileGetBackendForSupportCheck(const virStorageSource *src, + virStorageFileBackendPtr *backend) { int actualType; - if (!src) - return NULL; - if (src->drv) - return src->drv->backend; + if (!src) { + *backend = NULL; + return 0; + } + + if (src->drv) { + *backend = src->drv->backend; + return 0; + } actualType = virStorageSourceGetActualType(src); - return virStorageFileBackendForTypeInternal(actualType, src->protocol, false); + *backend = virStorageFileBackendForTypeInternal(actualType, src->protocol, false); + return 0; } -static bool +static int virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src) { virStorageFileBackendPtr backend; + int rv; - if (!(backend = virStorageFileGetBackendForSupportCheck(src))) - return false; + rv = virStorageFileGetBackendForSupportCheck(src, &backend); + if (rv < 0) + return -1; + + if (!backend) + return 0; return backend->storageFileGetUniqueIdentifier && backend->storageFileRead && - backend->storageFileAccess; + backend->storageFileAccess ? 1 : 0; } @@ -4137,15 +4149,19 @@ virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src) * Check if a storage file supports operations needed by the security * driver to perform labelling */ -bool +int virStorageFileSupportsSecurityDriver(const virStorageSource *src) { virStorageFileBackendPtr backend; + int rv; - if (!(backend = virStorageFileGetBackendForSupportCheck(src))) - return false; + rv = virStorageFileGetBackendForSupportCheck(src, &backend); + 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) * Check if a storage file supports checking if the storage source is accessible * for the given vm. */ -bool +int virStorageFileSupportsAccess(const virStorageSource *src) { virStorageFileBackendPtr backend; + int ret; - if (!(backend = virStorageFileGetBackendForSupportCheck(src))) - return false; + ret = virStorageFileGetBackendForSupportCheck(src, &backend); + 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, ssize_t headerLen; virStorageSourcePtr backingStore = NULL; int backingFormat; + int rv; VIR_DEBUG("path=%s format=%d uid=%u gid=%u probe=%d", src->path, src->format, (unsigned int)uid, (unsigned int)gid, allow_probe); /* exit if we can't load information about the current image */ - if (!virStorageFileSupportsBackingChainTraversal(src)) - return 0; + rv = virStorageFileSupportsBackingChainTraversal(src); + if (rv <= 0) + return rv; if (virStorageFileInitAs(src, uid, gid) < 0) return -1; diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index b92c1c47ddb7182303f32aebba6f5957f7d2459b..0909fe212c521547ec22cc549643997f79f38f48 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -465,8 +465,8 @@ const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src); int virStorageFileAccess(virStorageSourcePtr src, int mode); int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid); -bool virStorageFileSupportsSecurityDriver(const virStorageSource *src); -bool virStorageFileSupportsAccess(const virStorageSource *src); +int virStorageFileSupportsSecurityDriver(const virStorageSource *src); +int virStorageFileSupportsAccess(const virStorageSource *src); int virStorageFileGetMetadata(virStorageSourcePtr src, uid_t uid, gid_t gid,