提交 9944b710 编写于 作者: P Peter Krempa

util: storagefile: Always store raw backing name in the metadata

Don't use the backingStoreRaw as a indication of broken chains. Fill it
always and tweak the broken image chain detector to avoid changing the
semantics.

The new semantics to detect a broken chain is the presence of string in
backingStoreRaw but the lack of the backing chain metadata structure in
the chain.

Now that the raw backing store name is always filled there's no need to
pass the raw name variable separately to fill in case the backing is not
a file. Tweak the function so that it can handle a NULL in that case.
上级 00c27242
...@@ -864,8 +864,7 @@ virStorageFileGetMetadataInternal(const char *path, ...@@ -864,8 +864,7 @@ virStorageFileGetMetadataInternal(const char *path,
} }
if (fileTypeInfo[format].getBackingStore != NULL) { if (fileTypeInfo[format].getBackingStore != NULL) {
char *backing = NULL; int store = fileTypeInfo[format].getBackingStore(&meta->backingStoreRaw,
int store = fileTypeInfo[format].getBackingStore(&backing,
backingFormat, backingFormat,
buf, len); buf, len);
if (store == BACKING_STORE_INVALID) if (store == BACKING_STORE_INVALID)
...@@ -874,15 +873,10 @@ virStorageFileGetMetadataInternal(const char *path, ...@@ -874,15 +873,10 @@ virStorageFileGetMetadataInternal(const char *path,
if (store == BACKING_STORE_ERROR) if (store == BACKING_STORE_ERROR)
goto cleanup; goto cleanup;
if (backing != NULL) { if (meta->backingStoreRaw) {
if (VIR_STRDUP(meta->backingStore, backing) < 0) { if (virStorageIsFile(meta->backingStoreRaw)) {
VIR_FREE(backing); if (virFindBackingFile(directory,
goto cleanup; meta->backingStoreRaw,
}
if (virStorageIsFile(backing)) {
meta->backingStoreRaw = meta->backingStore;
meta->backingStore = NULL;
if (virFindBackingFile(directory, backing,
backingDirectory, backingDirectory,
&meta->backingStore) < 0) { &meta->backingStore) < 0) {
/* the backing file is (currently) unavailable, treat this /* the backing file is (currently) unavailable, treat this
...@@ -894,11 +888,15 @@ virStorageFileGetMetadataInternal(const char *path, ...@@ -894,11 +888,15 @@ virStorageFileGetMetadataInternal(const char *path,
} }
} else { } else {
*backingStore = backing; if (VIR_STRDUP(meta->backingStore, meta->backingStoreRaw) < 0)
backing = NULL; goto cleanup;
if (backingStore &&
VIR_STRDUP(*backingStore, meta->backingStoreRaw) < 0)
goto cleanup;
*backingFormat = VIR_STORAGE_FILE_RAW; *backingFormat = VIR_STORAGE_FILE_RAW;
} }
VIR_FREE(backing);
} else { } else {
meta->backingStore = NULL; meta->backingStore = NULL;
*backingFormat = VIR_STORAGE_FILE_NONE; *backingFormat = VIR_STORAGE_FILE_NONE;
...@@ -1085,7 +1083,7 @@ virStorageFileGetMetadataFromFDInternal(const char *path, ...@@ -1085,7 +1083,7 @@ virStorageFileGetMetadataFromFDInternal(const char *path,
ret = virStorageFileGetMetadataInternal(path, canonPath, directory, ret = virStorageFileGetMetadataInternal(path, canonPath, directory,
buf, len, format, meta, buf, len, format, meta,
&meta->backingStoreRaw, NULL,
backingFormat, backingDirectory); backingFormat, backingDirectory);
if (ret == 0) { if (ret == 0) {
...@@ -1296,31 +1294,24 @@ virStorageFileChainGetBroken(virStorageFileMetadataPtr chain, ...@@ -1296,31 +1294,24 @@ virStorageFileChainGetBroken(virStorageFileMetadataPtr chain,
char **brokenFile) char **brokenFile)
{ {
virStorageFileMetadataPtr tmp; virStorageFileMetadataPtr tmp;
int ret = -1;
*brokenFile = NULL; *brokenFile = NULL;
if (!chain) if (!chain)
return 0; return 0;
tmp = chain; for (tmp = chain; tmp; tmp = tmp->backingMeta) {
while (tmp) {
/* Break when we hit end of chain; report error if we detected /* Break when we hit end of chain; report error if we detected
* a missing backing file, infinite loop, or other error */ * a missing backing file, infinite loop, or other error */
if (!tmp->backingStoreRaw) if (!tmp->backingMeta && tmp->backingStoreRaw) {
break; if (VIR_STRDUP(*brokenFile, tmp->backingStoreRaw) < 0)
if (!tmp->backingStore) { return -1;
if (VIR_STRDUP(*brokenFile, tmp->backingStoreRaw) < 0)
goto error;
break;
}
tmp = tmp->backingMeta;
}
ret = 0; return 0;
}
}
error: return 0;
return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册