storage: Switch metadata crawler to use storage driver to read headers

Use virStorageFileReadHeader() to read headers of storage files possibly
on remote storage to retrieve the image metadata.

The backend information is now parsed by
virStorageFileGetMetadataInternal which is now exported from the util
source and virStorageFileGetMetadataFromFDInternal now doesn't need to
be exported.
This commit is contained in:
Peter Krempa 2014-04-25 21:38:40 +02:00
parent 395171f87f
commit 2bdb8b965b
4 changed files with 17 additions and 27 deletions

View File

@ -1865,7 +1865,7 @@ virStorageFileFormatTypeToString;
virStorageFileGetLVMKey; virStorageFileGetLVMKey;
virStorageFileGetMetadataFromBuf; virStorageFileGetMetadataFromBuf;
virStorageFileGetMetadataFromFD; virStorageFileGetMetadataFromFD;
virStorageFileGetMetadataFromFDInternal; virStorageFileGetMetadataInternal;
virStorageFileGetSCSIKey; virStorageFileGetSCSIKey;
virStorageFileIsClusterFS; virStorageFileIsClusterFS;
virStorageFileParseChainIndex; virStorageFileParseChainIndex;

View File

@ -3132,10 +3132,11 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
bool allow_probe, bool allow_probe,
virHashTablePtr cycle) virHashTablePtr cycle)
{ {
int fd;
int ret = -1; int ret = -1;
struct stat st; struct stat st;
const char *uniqueName; const char *uniqueName;
char *buf = NULL;
ssize_t headerLen;
virStorageSourcePtr backingStore = NULL; virStorageSourcePtr backingStore = NULL;
int backingFormat; int backingFormat;
@ -3163,26 +3164,13 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
if (virHashAddEntry(cycle, uniqueName, (void *)1) < 0) if (virHashAddEntry(cycle, uniqueName, (void *)1) < 0)
goto cleanup; goto cleanup;
if (virStorageSourceGetActualType(src) != VIR_STORAGE_TYPE_NETWORK) { if ((headerLen = virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADER,
if ((fd = virFileOpenAs(src->path, O_RDONLY, 0, uid, gid, 0)) < 0) { &buf)) < 0)
virReportSystemError(-fd, _("Failed to open file '%s'"), goto cleanup;
src->path);
goto cleanup; if (virStorageFileGetMetadataInternal(src, buf, headerLen,
} &backingFormat) < 0)
if (virStorageFileGetMetadataFromFDInternal(src, fd,
&backingFormat) < 0) {
VIR_FORCE_CLOSE(fd);
goto cleanup;
}
if (VIR_CLOSE(fd) < 0)
VIR_WARN("could not close file %s", src->path);
} else {
/* TODO: currently we call this only for local storage */
ret = 0;
goto cleanup; goto cleanup;
}
/* check whether we need to go deeper */ /* check whether we need to go deeper */
if (!src->backingStoreRaw) { if (!src->backingStoreRaw) {

View File

@ -740,8 +740,7 @@ qcow2GetFeatures(virBitmapPtr *features,
* with information about the file and its backing store. Return format * with information about the file and its backing store. Return format
* of the backing store as BACKING_FORMAT. PATH and FORMAT have to be * of the backing store as BACKING_FORMAT. PATH and FORMAT have to be
* pre-populated in META */ * pre-populated in META */
static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) int
ATTRIBUTE_NONNULL(4)
virStorageFileGetMetadataInternal(virStorageSourcePtr meta, virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
char *buf, char *buf,
size_t len, size_t len,
@ -955,7 +954,7 @@ virStorageFileGetMetadataFromBuf(const char *path,
/* Internal version that also supports a containing directory name. */ /* Internal version that also supports a containing directory name. */
int static int
virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta, virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta,
int fd, int fd,
int *backingFormat) int *backingFormat)

View File

@ -265,9 +265,12 @@ struct _virStorageSource {
int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid); int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
int virStorageFileGetMetadataFromFDInternal(virStorageSourcePtr meta, int virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
int fd, char *buf,
int *backingFormat); size_t len,
int *backingFormat)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
virStorageSourcePtr virStorageFileGetMetadataFromFD(const char *path, virStorageSourcePtr virStorageFileGetMetadataFromFD(const char *path,
int fd, int fd,
int format, int format,