提交 d3047061 编写于 作者: P Peter Krempa

util: storage: Inline use of virStorageFileGetMetadataFromFDInternal

There was just one callsite left. Integrate the body to the only calling
function.
上级 c5aaf0b4
......@@ -973,16 +973,31 @@ virStorageFileGetMetadataFromBuf(const char *path,
}
/* Internal version that also supports a containing directory name. */
static int
virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta,
int fd,
int *backingFormat)
/**
* virStorageFileGetMetadataFromFD:
*
* Extract metadata about the storage volume with the specified
* image format. If image format is VIR_STORAGE_FILE_AUTO, it
* will probe to automatically identify the format. Does not recurse.
*
* 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.
*
* Caller MUST free the result after use via virStorageSourceFree.
*/
virStorageSourcePtr
virStorageFileGetMetadataFromFD(const char *path,
int fd,
int format,
int *backingFormat)
{
virStorageSourcePtr ret = NULL;
virStorageSourcePtr meta = NULL;
char *buf = NULL;
ssize_t len = VIR_STORAGE_MAX_HEADER;
struct stat sb;
int ret = -1;
int dummy;
if (!backingFormat)
......@@ -992,17 +1007,20 @@ virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta,
if (fstat(fd, &sb) < 0) {
virReportSystemError(errno,
_("cannot stat file '%s'"),
meta->relPath);
return -1;
_("cannot stat file '%s'"), path);
return NULL;
}
if (!(meta = virStorageFileMetadataNew(path, format)))
return NULL;
if (S_ISDIR(sb.st_mode)) {
/* No header to probe for directories, but also no backing file. Just
* update the metadata.*/
meta->type = VIR_STORAGE_TYPE_DIR;
meta->format = VIR_STORAGE_FILE_DIR;
ret = 0;
ret = meta;
meta = NULL;
goto cleanup;
}
......@@ -1016,51 +1034,20 @@ virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta,
goto cleanup;
}
ret = virStorageFileGetMetadataInternal(meta, buf, len, backingFormat);
if (ret == 0) {
if (S_ISREG(sb.st_mode))
meta->type = VIR_STORAGE_TYPE_FILE;
else if (S_ISBLK(sb.st_mode))
meta->type = VIR_STORAGE_TYPE_BLOCK;
}
cleanup:
VIR_FREE(buf);
return ret;
}
/**
* virStorageFileGetMetadataFromFD:
*
* Extract metadata about the storage volume with the specified
* image format. If image format is VIR_STORAGE_FILE_AUTO, it
* will probe to automatically identify the format. Does not recurse.
*
* 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.
*
* Caller MUST free the result after use via virStorageSourceFree.
*/
virStorageSourcePtr
virStorageFileGetMetadataFromFD(const char *path,
int fd,
int format,
int *backingFormat)
{
virStorageSourcePtr ret;
if (!(ret = virStorageFileMetadataNew(path, format)))
return NULL;
if (virStorageFileGetMetadataInternal(meta, buf, len, backingFormat) < 0)
goto cleanup;
if (S_ISREG(sb.st_mode))
meta->type = VIR_STORAGE_TYPE_FILE;
else if (S_ISBLK(sb.st_mode))
meta->type = VIR_STORAGE_TYPE_BLOCK;
if (virStorageFileGetMetadataFromFDInternal(ret, fd, backingFormat) < 0) {
virStorageSourceFree(ret);
return NULL;
}
ret = meta;
meta = NULL;
cleanup:
virStorageSourceFree(meta);
VIR_FREE(buf);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册