From: Peter Krempa <[email protected]> Lift the calculation from 'virStorageSourceUpdateBackingSizes'.
This will be used to have a single place for these values for use in VM drivers where 'type' does reflect reality. Signed-off-by: Peter Krempa <[email protected]> --- src/qemu/qemu_domain.c | 2 +- src/storage_file/storage_source.c | 13 +++++++++++++ src/storage_file/storage_source.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ef79fc72aa..e7afeb3fa0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11651,7 +11651,7 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverConfig *cfg, return -1; } - ret = virStorageSourceGetSize(src, fd, &sb, &src->physical); + ret = virStorageSourceGetSize(src, fd, &sb, NULL, &src->physical); qemuDomainStorageCloseStat(src, &fd); diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_source.c index cc2d3a3198..fb4fc48947 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -589,6 +589,7 @@ virStorageSourceNewFromDataFile(virStorageSource *parent) * @src: disk source definition structure * @fd: file descriptor * @sb: stat buffer + * @allocation: current actual disk usage * @physical: filled with the physical size of @src * * Fetches size information about @src depending on the actual type of storage @@ -602,6 +603,7 @@ int virStorageSourceGetSize(virStorageSource *src, int fd, struct stat const *sb, + unsigned long long *allocation, unsigned long long *physical) { off_t end; @@ -611,9 +613,18 @@ virStorageSourceGetSize(virStorageSource *src, if (!physical) physical = &dummy; + if (!allocation) + allocation = &dummy; + switch (actual_type) { case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_NETWORK: +#ifndef WIN32 + *allocation = (unsigned long long) sb->st_blocks * (unsigned long long) DEV_BSIZE; +#else + *allocation = sb->st_size; +#endif + *physical = sb->st_size; break; @@ -621,10 +632,12 @@ virStorageSourceGetSize(virStorageSource *src, if ((end = lseek(fd, 0, SEEK_END)) == (off_t) -1) return -1; + *allocation = end; *physical = end; break; case VIR_STORAGE_TYPE_DIR: + *allocation = 0; *physical = 0; break; diff --git a/src/storage_file/storage_source.h b/src/storage_file/storage_source.h index fd58509eb3..774dcbffee 100644 --- a/src/storage_file/storage_source.h +++ b/src/storage_file/storage_source.h @@ -57,6 +57,7 @@ int virStorageSourceGetSize(virStorageSource *src, int fd, struct stat const *sb, + unsigned long long *allocation, unsigned long long *physical) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); -- 2.54.0
