mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
storage: fs: Drop-in replace use of virStorageFileGetMetadataFromBuf
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.
This commit is contained in:
parent
5a1cf6bd16
commit
34d86185ec
@ -71,8 +71,6 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
virStorageSourcePtr meta = NULL;
|
virStorageSourcePtr meta = NULL;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *header = NULL;
|
|
||||||
ssize_t len = VIR_STORAGE_MAX_HEADER;
|
|
||||||
|
|
||||||
*backingStore = NULL;
|
*backingStore = NULL;
|
||||||
*backingStoreFormat = VIR_STORAGE_FILE_AUTO;
|
*backingStoreFormat = VIR_STORAGE_FILE_AUTO;
|
||||||
@ -89,23 +87,20 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
target->format = VIR_STORAGE_FILE_DIR;
|
target->format = VIR_STORAGE_FILE_DIR;
|
||||||
} else {
|
} else {
|
||||||
if ((len = virFileReadHeaderFD(fd, len, &header)) < 0) {
|
if (!(meta = virStorageFileGetMetadataFromFD(target->path,
|
||||||
virReportSystemError(errno, _("cannot read header '%s'"),
|
fd,
|
||||||
target->path);
|
VIR_STORAGE_FILE_AUTO,
|
||||||
|
backingStoreFormat)))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(meta = virStorageFileGetMetadataFromBuf(target->path,
|
if (VIR_STRDUP(*backingStore, meta->backingStoreRaw) < 0)
|
||||||
header, len,
|
|
||||||
backingStore,
|
|
||||||
backingStoreFormat))) {
|
|
||||||
ret = -1;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
|
||||||
@ -170,7 +165,6 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virStorageSourceFree(meta);
|
virStorageSourceFree(meta);
|
||||||
VIR_FREE(header);
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user