From: Peter Krempa <[email protected]> Upcoming code will want to modify the call semantics of the function to unlock the domain object around it thus we ought to not modify @src directly.
Rename the function to 'virStorageSourceGetSize' and return the detected size via argument instead of directly modifying it. Signed-off-by: Peter Krempa <[email protected]> --- src/libvirt_private.syms | 2 +- src/qemu/qemu_domain.c | 2 +- src/storage_file/storage_source.c | 22 +++++++++++++++------- src/storage_file/storage_source.h | 8 +++++--- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2391f01bc7..a7ce33b428 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1927,6 +1927,7 @@ virStorageSourceGetMetadata; virStorageSourceGetMetadataFromBuf; virStorageSourceGetMetadataFromFD; virStorageSourceGetRelativeBackingPath; +virStorageSourceGetSize; virStorageSourceInit; virStorageSourceInitAs; virStorageSourceNewFromBacking; @@ -1942,7 +1943,6 @@ virStorageSourceSupportsSecurityDriver; virStorageSourceUnlink; virStorageSourceUpdateBackingSizes; virStorageSourceUpdateCapacity; -virStorageSourceUpdatePhysicalSize; # util/viracpi.c diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 84c8645259..ef79fc72aa 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11651,7 +11651,7 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverConfig *cfg, return -1; } - ret = virStorageSourceUpdatePhysicalSize(src, fd, &sb); + ret = virStorageSourceGetSize(src, fd, &sb, &src->physical); qemuDomainStorageCloseStat(src, &fd); diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_source.c index e886433bb4..cc2d3a3198 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -585,39 +585,47 @@ virStorageSourceNewFromDataFile(virStorageSource *parent) /** + * virStorageSourceGetPhysicalSize: * @src: disk source definition structure * @fd: file descriptor * @sb: stat buffer + * @physical: filled with the physical size of @src * - * Updates src->physical depending on the actual type of storage being used. + * Fetches size information about @src depending on the actual type of storage + * being used. * To be called for domain storage source reporting as the volume code does * not set/use the 'type' field for the voldef->source.target * * Returns 0 on success, -1 on error. No libvirt errors are reported. */ int -virStorageSourceUpdatePhysicalSize(virStorageSource *src, - int fd, - struct stat const *sb) +virStorageSourceGetSize(virStorageSource *src, + int fd, + struct stat const *sb, + unsigned long long *physical) { off_t end; virStorageType actual_type = virStorageSourceGetActualType(src); + unsigned long long dummy; + + if (!physical) + physical = &dummy; switch (actual_type) { case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_NETWORK: - src->physical = sb->st_size; + *physical = sb->st_size; break; case VIR_STORAGE_TYPE_BLOCK: if ((end = lseek(fd, 0, SEEK_END)) == (off_t) -1) return -1; - src->physical = end; + *physical = end; break; case VIR_STORAGE_TYPE_DIR: - src->physical = 0; + *physical = 0; break; /* We shouldn't get VOLUME, but the switch requires all cases */ diff --git a/src/storage_file/storage_source.h b/src/storage_file/storage_source.h index 63fefb6919..fd58509eb3 100644 --- a/src/storage_file/storage_source.h +++ b/src/storage_file/storage_source.h @@ -54,9 +54,11 @@ virStorageSourceChainLookupBySource(virStorageSource *chain, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int -virStorageSourceUpdatePhysicalSize(virStorageSource *src, - int fd, - struct stat const *sb); +virStorageSourceGetSize(virStorageSource *src, + int fd, + struct stat const *sb, + unsigned long long *physical) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); int virStorageSourceUpdateBackingSizes(virStorageSource *src, -- 2.54.0
