Use virStorageFileGetMetadataFromFD instead in
virStorageBackendProbeTarget as it now returns all required data and the
storage file is already open in a filedescriptor.
Also fix improper error code being returned when virFileReadHeaderFD
would fail as virStorageBackendUpdateVolTargetInfoFD would set the
return code to 0.
---
src/storage/storage_backend_fs.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 33551e7..003c6df 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -71,8 +71,6 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
int ret = -1;
virStorageSourcePtr meta = NULL;
struct stat sb;
- char *header = NULL;
- ssize_t len = VIR_STORAGE_MAX_HEADER;
*backingStore = NULL;
*backingStoreFormat = VIR_STORAGE_FILE_AUTO;
@@ -89,22 +87,19 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
goto error;
}
+ ret = -1;
+
if (S_ISDIR(sb.st_mode)) {
target->format = VIR_STORAGE_FILE_DIR;
} else {
- if ((len = virFileReadHeaderFD(fd, len, &header)) < 0) {
- virReportSystemError(errno, _("cannot read header '%s'"),
- target->path);
+ if (!(meta = virStorageFileGetMetadataFromFD(target->path,
+ fd,
+ VIR_STORAGE_FILE_AUTO,
+ backingStoreFormat)))
goto error;
- }
- if (!(meta = virStorageFileGetMetadataFromBuf(target->path,
- header, len,
- backingStore,
- backingStoreFormat))) {
- ret = -1;
+ if (VIR_STRDUP(*backingStore, meta->backingStoreRaw) < 0)
goto error;
- }
}
VIR_FORCE_CLOSE(fd);
@@ -170,7 +165,6 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
cleanup:
virStorageSourceFree(meta);
- VIR_FREE(header);
return ret;
}
--
1.9.3