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

util: fix virStorageFileGetBackingStoreStr error handling

The virStorageFileGetBackingStoreStr method has overloaded the NULL
return value to indicate both no backing available and a fatal
error dealing with it.

The caller is thus not able to correctly propagate the error
messages.
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 dbf28572
...@@ -11582,8 +11582,16 @@ qemuDomainBlockPeek(virDomainPtr dom, ...@@ -11582,8 +11582,16 @@ qemuDomainBlockPeek(virDomainPtr dom,
if (qemuDomainStorageFileInit(driver, vm, disk->src, NULL) < 0) if (qemuDomainStorageFileInit(driver, vm, disk->src, NULL) < 0)
goto cleanup; goto cleanup;
if ((nread = virStorageFileRead(disk->src, offset, size, &tmpbuf)) < 0) if ((nread = virStorageFileRead(disk->src, offset, size, &tmpbuf)) < 0) {
if (nread == -2) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("storage file reading is not supported for "
"storage type %s (protocol: %s)"),
virStorageTypeToString(disk->src->type),
virStorageNetProtocolTypeToString(disk->src->protocol));
}
goto cleanup; goto cleanup;
}
if (nread < size) { if (nread < size) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
...@@ -14608,12 +14616,15 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver, ...@@ -14608,12 +14616,15 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
/* relative backing store paths need to be updated so that relative /* relative backing store paths need to be updated so that relative
* block commit still works */ * block commit still works */
if (reuse && if (reuse) {
(backingStoreStr = virStorageFileGetBackingStoreStr(dd->src))) { if (virStorageFileGetBackingStoreStr(dd->src, &backingStoreStr) < 0)
if (virStorageIsRelative(backingStoreStr)) goto error;
VIR_STEAL_PTR(dd->relPath, backingStoreStr); if (backingStoreStr != NULL) {
else if (virStorageIsRelative(backingStoreStr))
VIR_FREE(backingStoreStr); VIR_STEAL_PTR(dd->relPath, backingStoreStr);
else
VIR_FREE(backingStoreStr);
}
} }
/* Note that it's unsafe to assume that the disks in the persistent /* Note that it's unsafe to assume that the disks in the persistent
......
...@@ -4357,14 +4357,8 @@ virStorageFileRead(virStorageSourcePtr src, ...@@ -4357,14 +4357,8 @@ virStorageFileRead(virStorageSourcePtr src,
return -1; return -1;
} }
if (!src->drv->backend->storageFileRead) { if (!src->drv->backend->storageFileRead)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("storage file reading is not supported for "
"storage type %s (protocol: %s)"),
virStorageTypeToString(src->type),
virStorageNetProtocolTypeToString(src->protocol));
return -2; return -2;
}
ret = src->drv->backend->storageFileRead(src, offset, len, buf); ret = src->drv->backend->storageFileRead(src, offset, len, buf);
...@@ -4551,8 +4545,15 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src, ...@@ -4551,8 +4545,15 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
goto cleanup; goto cleanup;
if ((headerLen = virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, if ((headerLen = virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER,
&buf)) < 0) &buf)) < 0) {
if (headerLen == -2)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("storage file reading is not supported for "
"storage type %s (protocol: %s)"),
virStorageTypeToString(src->type),
virStorageNetProtocolTypeToString(src->protocol));
goto cleanup; goto cleanup;
}
if (virStorageFileGetMetadataInternal(src, buf, headerLen, if (virStorageFileGetMetadataInternal(src, buf, headerLen,
&backingFormat) < 0) &backingFormat) < 0)
...@@ -4664,24 +4665,36 @@ virStorageFileGetMetadata(virStorageSourcePtr src, ...@@ -4664,24 +4665,36 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
* In case when the string can't be retrieved or does not exist NULL is * In case when the string can't be retrieved or does not exist NULL is
* returned. * returned.
*/ */
char * int
virStorageFileGetBackingStoreStr(virStorageSourcePtr src) virStorageFileGetBackingStoreStr(virStorageSourcePtr src,
char **backing)
{ {
virStorageSourcePtr tmp = NULL; virStorageSourcePtr tmp = NULL;
char *buf = NULL; char *buf = NULL;
ssize_t headerLen; ssize_t headerLen;
char *ret = NULL; int ret = -1;
int rv;
*backing = NULL;
/* 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)) if (!virStorageFileSupportsBackingChainTraversal(src))
return NULL; return 0;
if (virStorageFileAccess(src, F_OK) < 0) rv = virStorageFileAccess(src, F_OK);
return NULL; if (rv == -2)
return 0;
if (rv < 0) {
virStorageFileReportBrokenChain(errno, src, src);
return -1;
}
if ((headerLen = virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, if ((headerLen = virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER,
&buf)) < 0) &buf)) < 0) {
return NULL; if (headerLen == -2)
return 0;
return -1;
}
if (!(tmp = virStorageSourceCopy(src, false))) if (!(tmp = virStorageSourceCopy(src, false)))
goto cleanup; goto cleanup;
...@@ -4689,7 +4702,9 @@ virStorageFileGetBackingStoreStr(virStorageSourcePtr src) ...@@ -4689,7 +4702,9 @@ virStorageFileGetBackingStoreStr(virStorageSourcePtr src)
if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0) if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0)
goto cleanup; goto cleanup;
VIR_STEAL_PTR(ret, tmp->backingStoreRaw); VIR_STEAL_PTR(*backing, tmp->backingStoreRaw);
ret = 0;
cleanup: cleanup:
VIR_FREE(buf); VIR_FREE(buf);
......
...@@ -474,8 +474,9 @@ int virStorageFileGetMetadata(virStorageSourcePtr src, ...@@ -474,8 +474,9 @@ int virStorageFileGetMetadata(virStorageSourcePtr src,
bool report_broken) bool report_broken)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
char *virStorageFileGetBackingStoreStr(virStorageSourcePtr src) int virStorageFileGetBackingStoreStr(virStorageSourcePtr src,
ATTRIBUTE_NONNULL(1); char **backing)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void virStorageFileReportBrokenChain(int errcode, void virStorageFileReportBrokenChain(int errcode,
virStorageSourcePtr src, virStorageSourcePtr src,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册