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

conf: drop extra storage probe

All callers of virStorageFileGetMetadataFromBuf were first calling
virStorageFileProbeFormatFromBuf, to learn what format to pass in.
But this function is already wired to do the exact same probe if
the incoming format is VIR_STORAGE_FILE_AUTO, so it's simpler to
just refactor the probing into the central function.

* src/util/virstoragefile.h (virStorageFileGetMetadataFromBuf):
Drop parameter.
(virStorageFileProbeFormatFromBuf): Drop declaration.
* src/util/virstoragefile.c (virStorageFileGetMetadataFromBuf):
Do probe here instead of in callers.
(virStorageFileProbeFormatFromBuf): Make static.
* src/libvirt_private.syms (virstoragefile.h): Drop function.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Update caller.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 0541727c
...@@ -1854,7 +1854,6 @@ virStorageFileGetSCSIKey; ...@@ -1854,7 +1854,6 @@ virStorageFileGetSCSIKey;
virStorageFileIsClusterFS; virStorageFileIsClusterFS;
virStorageFileParseChainIndex; virStorageFileParseChainIndex;
virStorageFileProbeFormat; virStorageFileProbeFormat;
virStorageFileProbeFormatFromBuf;
virStorageFileResize; virStorageFileResize;
virStorageIsFile; virStorageIsFile;
virStorageNetHostDefClear; virStorageNetHostDefClear;
......
...@@ -98,16 +98,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, ...@@ -98,16 +98,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
goto error; goto error;
} }
target->format = virStorageFileProbeFormatFromBuf(target->path,
header, len);
if (target->format < 0) {
ret = -1;
goto error;
}
if (!(meta = virStorageFileGetMetadataFromBuf(target->path, if (!(meta = virStorageFileGetMetadataFromBuf(target->path,
header, len, header, len,
target->format,
backingStore, backingStore,
backingStoreFormat))) { backingStoreFormat))) {
ret = -1; ret = -1;
......
...@@ -293,12 +293,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state, ...@@ -293,12 +293,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
if ((len = virStorageBackendGlusterReadHeader(fd, name, len, &header)) < 0) if ((len = virStorageBackendGlusterReadHeader(fd, name, len, &header)) < 0)
goto cleanup; goto cleanup;
if ((vol->target.format = virStorageFileProbeFormatFromBuf(name,
header,
len)) < 0)
goto cleanup;
if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len, if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len,
vol->target.format,
&vol->backingStore.path, &vol->backingStore.path,
&vol->backingStore.format))) &vol->backingStore.format)))
goto cleanup; goto cleanup;
......
...@@ -713,7 +713,8 @@ virStorageIsFile(const char *backing) ...@@ -713,7 +713,8 @@ virStorageIsFile(const char *backing)
return true; return true;
} }
int
static int
virStorageFileProbeFormatFromBuf(const char *path, virStorageFileProbeFormatFromBuf(const char *path,
char *buf, char *buf,
size_t buflen) size_t buflen)
...@@ -971,16 +972,13 @@ virStorageFileMetadataNew(const char *path, ...@@ -971,16 +972,13 @@ virStorageFileMetadataNew(const char *path,
* @path: name of file, for error messages * @path: name of file, for error messages
* @buf: header bytes from @path * @buf: header bytes from @path
* @len: length of @buf * @len: length of @buf
* @format: expected image format
* @backing: output malloc'd name of backing image, if any * @backing: output malloc'd name of backing image, if any
* @backingFormat: format of @backing * @backingFormat: format of @backing
* *
* Extract metadata about the storage volume with the specified * Extract metadata about the storage volume, including probing its
* image format. If image format is VIR_STORAGE_FILE_AUTO, it * format. Does not recurse. Callers are advised not to trust the
* will probe to automatically identify the format. Does not recurse. * learned format if a guest has ever used the volume when it was
* * raw, since a malicious guest can turn a raw file into any
* Callers are advised never to use VIR_STORAGE_FILE_AUTO as a
* 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 @backingFormat is VIR_STORAGE_FILE_AUTO * If the returned @backingFormat is VIR_STORAGE_FILE_AUTO
...@@ -994,14 +992,13 @@ virStorageSourcePtr ...@@ -994,14 +992,13 @@ virStorageSourcePtr
virStorageFileGetMetadataFromBuf(const char *path, virStorageFileGetMetadataFromBuf(const char *path,
char *buf, char *buf,
size_t len, size_t len,
int format,
char **backing, char **backing,
int *backingFormat) int *backingFormat)
{ {
virStorageSourcePtr ret = NULL; virStorageSourcePtr ret = NULL;
virStorageSourcePtr meta = NULL; virStorageSourcePtr meta = NULL;
if (!(meta = virStorageFileMetadataNew(path, format))) if (!(meta = virStorageFileMetadataNew(path, VIR_STORAGE_FILE_AUTO)))
return NULL; return NULL;
if (virStorageFileGetMetadataInternal(meta, buf, len, if (virStorageFileGetMetadataInternal(meta, buf, len,
......
...@@ -260,8 +260,6 @@ struct _virStorageSource { ...@@ -260,8 +260,6 @@ struct _virStorageSource {
# endif # endif
int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid); int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
int virStorageFileProbeFormatFromBuf(const char *path, char *buf,
size_t buflen);
int virStorageFileGetMetadata(virStorageSourcePtr src, int virStorageFileGetMetadata(virStorageSourcePtr src,
uid_t uid, gid_t gid, uid_t uid, gid_t gid,
...@@ -273,11 +271,10 @@ virStorageSourcePtr virStorageFileGetMetadataFromFD(const char *path, ...@@ -273,11 +271,10 @@ virStorageSourcePtr virStorageFileGetMetadataFromFD(const char *path,
virStorageSourcePtr virStorageFileGetMetadataFromBuf(const char *path, virStorageSourcePtr virStorageFileGetMetadataFromBuf(const char *path,
char *buf, char *buf,
size_t len, size_t len,
int format,
char **backing, char **backing,
int *backingFormat) int *backingFormat)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4)
ATTRIBUTE_NONNULL(6); ATTRIBUTE_NONNULL(5);
int virStorageFileChainGetBroken(virStorageSourcePtr chain, int virStorageFileChainGetBroken(virStorageSourcePtr chain,
char **broken_file); char **broken_file);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册