mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 01:43:23 +00:00
Probe for capacity in virStorageBackendUpdateVolTargetInfo
Instead of just looking at the output of fstat, call virStorageFileGetMetadata to get the full capacity from image headers. Note that the capacity is probed unconditionally. The updateCapacity bool parameter is ignored and will be removed in the following commit.
This commit is contained in:
parent
e3f1d2a820
commit
a760ba3a7f
@ -1514,6 +1514,9 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
|
||||
{
|
||||
int ret, fd = -1;
|
||||
struct stat sb;
|
||||
virStorageSourcePtr meta = NULL;
|
||||
char *buf = NULL;
|
||||
ssize_t len = VIR_STORAGE_MAX_HEADER;
|
||||
|
||||
if ((ret = virStorageBackendVolOpen(target->path, &sb, openflags)) < 0)
|
||||
goto cleanup;
|
||||
@ -1523,14 +1526,41 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
|
||||
updateCapacity)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (target->type == VIR_STORAGE_VOL_FILE &&
|
||||
target->format != VIR_STORAGE_FILE_NONE) {
|
||||
if (S_ISDIR(sb.st_mode)) {
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
|
||||
virReportSystemError(errno, _("cannot seek to start of '%s'"), target->path);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((len = virFileReadHeaderFD(fd, len, &buf)) < 0) {
|
||||
virReportSystemError(errno, _("cannot read header '%s'"), target->path);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(meta = virStorageFileGetMetadataFromBuf(target->path, buf, len, target->format,
|
||||
NULL))) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (meta->capacity)
|
||||
target->capacity = meta->capacity;
|
||||
}
|
||||
|
||||
if (withBlockVolFormat) {
|
||||
if ((ret = virStorageBackendDetectBlockVolFormatFD(target, fd)) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virStorageSourceFree(meta);
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
|
||||
VIR_FREE(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user