提交 a4dfc8d3 编写于 作者: E Eric Blake

conf: return backing information separately from metadata

A couple pieces of virStorageFileMetadata are used only while
collecting information about the chain, and don't need to
live permanently in the struct.  This patch refactors external
callers to collect the information separately, so that the
next patch can remove the fields.

* src/util/virstoragefile.h (virStorageFileGetMetadataFromBuf):
Alter signature.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal):
Likewise.
(virStorageFileGetMetadataFromFDInternal): Adjust callers.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 c919ed7e
...@@ -106,7 +106,9 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, ...@@ -106,7 +106,9 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
if (!(meta = virStorageFileGetMetadataFromBuf(target->path, if (!(meta = virStorageFileGetMetadataFromBuf(target->path,
header, len, header, len,
target->format))) { target->format,
backingStore,
backingStoreFormat))) {
ret = -1; ret = -1;
goto error; goto error;
} }
...@@ -114,25 +116,19 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, ...@@ -114,25 +116,19 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
if (meta && meta->backingStore) { if (meta && *backingStore &&
*backingStore = meta->backingStore; *backingStoreFormat == VIR_STORAGE_FILE_AUTO &&
meta->backingStore = NULL; virStorageIsFile(*backingStore)) {
if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO && if ((ret = virStorageFileProbeFormat(*backingStore, -1, -1)) < 0) {
virStorageIsFile(*backingStore)) { /* If the backing file is currently unavailable, only log an error,
if ((ret = virStorageFileProbeFormat(*backingStore, -1, -1)) < 0) { * but continue. Returning -1 here would disable the whole storage
/* If the backing file is currently unavailable, only log an error, * pool, making it unavailable for even maintenance. */
* but continue. Returning -1 here would disable the whole storage virReportError(VIR_ERR_INTERNAL_ERROR,
* pool, making it unavailable for even maintenance. */ _("cannot probe backing volume format: %s"),
virReportError(VIR_ERR_INTERNAL_ERROR, *backingStore);
_("cannot probe backing volume format: %s"), ret = -3;
*backingStore);
ret = -3;
} else {
*backingStoreFormat = ret;
ret = 0;
}
} else { } else {
*backingStoreFormat = meta->backingStoreFormat; *backingStoreFormat = ret;
ret = 0; ret = 0;
} }
} else { } else {
......
...@@ -298,16 +298,14 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state, ...@@ -298,16 +298,14 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
len)) < 0) len)) < 0)
goto cleanup; goto cleanup;
if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len, if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len,
vol->target.format))) vol->target.format,
&vol->backingStore.path,
&vol->backingStore.format)))
goto cleanup; goto cleanup;
if (meta->backingStore) { if (vol->backingStore.path &&
vol->backingStore.path = meta->backingStore; vol->backingStore.format < 0)
meta->backingStore = NULL; vol->backingStore.format = VIR_STORAGE_FILE_RAW;
vol->backingStore.format = meta->backingStoreFormat;
if (vol->backingStore.format < 0)
vol->backingStore.format = VIR_STORAGE_FILE_RAW;
}
if (meta->capacity) if (meta->capacity)
vol->target.capacity = meta->capacity; vol->target.capacity = meta->capacity;
if (meta->encryption) { if (meta->encryption) {
......
...@@ -790,13 +790,16 @@ qcow2GetFeatures(virBitmapPtr *features, ...@@ -790,13 +790,16 @@ qcow2GetFeatures(virBitmapPtr *features,
* information about the file and its backing store. */ * information about the file and its backing store. */
static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(7) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(7)
ATTRIBUTE_NONNULL(8) ATTRIBUTE_NONNULL(9)
virStorageFileGetMetadataInternal(const char *path, virStorageFileGetMetadataInternal(const char *path,
const char *canonPath, const char *canonPath,
const char *directory, const char *directory,
char *buf, char *buf,
size_t len, size_t len,
int format, int format,
virStorageFileMetadataPtr meta) virStorageFileMetadataPtr meta,
char **backingStore,
int *backingFormat)
{ {
int ret = -1; int ret = -1;
...@@ -855,10 +858,9 @@ virStorageFileGetMetadataInternal(const char *path, ...@@ -855,10 +858,9 @@ virStorageFileGetMetadataInternal(const char *path,
} }
if (fileTypeInfo[format].getBackingStore != NULL) { if (fileTypeInfo[format].getBackingStore != NULL) {
char *backing; char *backing = NULL;
int backingFormat;
int store = fileTypeInfo[format].getBackingStore(&backing, int store = fileTypeInfo[format].getBackingStore(&backing,
&backingFormat, backingFormat,
buf, len); buf, len);
if (store == BACKING_STORE_INVALID) if (store == BACKING_STORE_INVALID)
goto done; goto done;
...@@ -880,23 +882,20 @@ virStorageFileGetMetadataInternal(const char *path, ...@@ -880,23 +882,20 @@ virStorageFileGetMetadataInternal(const char *path,
/* the backing file is (currently) unavailable, treat this /* the backing file is (currently) unavailable, treat this
* file as standalone: * file as standalone:
* backingStoreRaw is kept to mark broken image chains */ * backingStoreRaw is kept to mark broken image chains */
backingFormat = VIR_STORAGE_FILE_NONE; *backingFormat = VIR_STORAGE_FILE_NONE;
VIR_WARN("Backing file '%s' of image '%s' is missing.", VIR_WARN("Backing file '%s' of image '%s' is missing.",
meta->backingStoreRaw, path); meta->backingStoreRaw, path);
} }
} else { } else {
if (VIR_STRDUP(meta->backingStoreRaw, backing) < 0) { *backingStore = backing;
VIR_FREE(backing); backing = NULL;
goto cleanup; *backingFormat = VIR_STORAGE_FILE_RAW;
}
backingFormat = VIR_STORAGE_FILE_RAW;
} }
VIR_FREE(backing); VIR_FREE(backing);
meta->backingStoreFormat = backingFormat;
} else { } else {
meta->backingStore = NULL; meta->backingStore = NULL;
meta->backingStoreFormat = VIR_STORAGE_FILE_NONE; *backingFormat = VIR_STORAGE_FILE_NONE;
} }
} }
...@@ -980,6 +979,8 @@ virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid) ...@@ -980,6 +979,8 @@ virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid)
* @buf: header bytes from @path * @buf: header bytes from @path
* @len: length of @buf * @len: length of @buf
* @format: expected image format * @format: expected image format
* @backing: output malloc'd name of backing image, if any
* @backingFormat: format of @backing
* *
* Extract metadata about the storage volume with the specified * Extract metadata about the storage volume with the specified
* image format. If image format is VIR_STORAGE_FILE_AUTO, it * image format. If image format is VIR_STORAGE_FILE_AUTO, it
...@@ -989,7 +990,7 @@ virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid) ...@@ -989,7 +990,7 @@ virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid)
* format, since a malicious guest can turn a raw file into any * format, since a malicious guest can turn a raw file into any
* other non-raw format at will. * other non-raw format at will.
* *
* If the returned meta.backingStoreFormat is VIR_STORAGE_FILE_AUTO * If the returned @backingFormat is VIR_STORAGE_FILE_AUTO
* it indicates the image didn't specify an explicit format for its * it indicates the image didn't specify an explicit format for its
* backing store. Callers are advised against probing for the * backing store. Callers are advised against probing for the
* backing store format in this case. * backing store format in this case.
...@@ -1000,7 +1001,9 @@ virStorageFileMetadataPtr ...@@ -1000,7 +1001,9 @@ virStorageFileMetadataPtr
virStorageFileGetMetadataFromBuf(const char *path, virStorageFileGetMetadataFromBuf(const char *path,
char *buf, char *buf,
size_t len, size_t len,
int format) int format,
char **backing,
int *backingFormat)
{ {
virStorageFileMetadataPtr ret = NULL; virStorageFileMetadataPtr ret = NULL;
char *canonPath; char *canonPath;
...@@ -1013,7 +1016,8 @@ virStorageFileGetMetadataFromBuf(const char *path, ...@@ -1013,7 +1016,8 @@ virStorageFileGetMetadataFromBuf(const char *path,
goto cleanup; goto cleanup;
if (virStorageFileGetMetadataInternal(path, canonPath, ".", buf, len, if (virStorageFileGetMetadataInternal(path, canonPath, ".", buf, len,
format, ret) < 0) { format, ret, backing,
backingFormat) < 0) {
virStorageFileFreeMetadata(ret); virStorageFileFreeMetadata(ret);
ret = NULL; ret = NULL;
} }
...@@ -1068,7 +1072,9 @@ virStorageFileGetMetadataFromFDInternal(const char *path, ...@@ -1068,7 +1072,9 @@ virStorageFileGetMetadataFromFDInternal(const char *path,
} }
ret = virStorageFileGetMetadataInternal(path, canonPath, directory, ret = virStorageFileGetMetadataInternal(path, canonPath, directory,
buf, len, format, meta); buf, len, format, meta,
&meta->backingStoreRaw,
&meta->backingStoreFormat);
if (ret == 0) { if (ret == 0) {
if (S_ISREG(sb.st_mode)) if (S_ISREG(sb.st_mode))
......
...@@ -295,7 +295,11 @@ virStorageFileMetadataPtr virStorageFileGetMetadataFromFD(const char *path, ...@@ -295,7 +295,11 @@ virStorageFileMetadataPtr virStorageFileGetMetadataFromFD(const char *path,
virStorageFileMetadataPtr virStorageFileGetMetadataFromBuf(const char *path, virStorageFileMetadataPtr virStorageFileGetMetadataFromBuf(const char *path,
char *buf, char *buf,
size_t len, size_t len,
int format); int format,
char **backing,
int *backingFormat)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5)
ATTRIBUTE_NONNULL(6);
int virStorageFileChainGetBroken(virStorageFileMetadataPtr chain, int virStorageFileChainGetBroken(virStorageFileMetadataPtr chain,
char **broken_file); char **broken_file);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册