From 3f702f5ab1d8cfcfa41a49aa7f6e3881242d5f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Mon, 25 Sep 2017 16:35:42 +0200 Subject: [PATCH] virStorageFileResize: fallocate the whole capacity We have been trying to implement the ALLOCATE flag to mean "the volume should be fully allocated after the resize". Since commit b0579ed9 we do not allocate from the existing capacity, but from the existing allocation value. However this value is a total of all the allocated bytes, not an offset. For a sparsely allocated file: $ perl -e 'print "x"x8192;' > vol1 $ fallocate -p -o 0 -l 4096 vol1 $ virsh vol-info vol1 default Capacity: 8.00 KiB Allocation: 4.00 KiB Treating allocation as an offset would result in an incompletely allocated file: $ virsh vol-resize vol1 --pool default 16384 --allocate Capacity: 16.00 KiB Allocation: 12.00 KiB Call fallocate from zero on the whole requested capacity to fully allocate the file. After that, the volume is fully allocated after the resize: $ virsh vol-resize vol1 --pool default 16384 --allocate $ virsh vol-info vol1 default Capacity: 16.00 KiB Allocation: 16.00 KiB --- src/storage/storage_util.c | 3 +-- src/util/virstoragefile.c | 8 +------- src/util/virstoragefile.h | 1 - 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 07dba22220..b94b3f397c 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2329,8 +2329,7 @@ virStorageBackendVolResizeLocal(virConnectPtr conn ATTRIBUTE_UNUSED, bool pre_allocate = flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE; if (vol->target.format == VIR_STORAGE_FILE_RAW) { - return virStorageFileResize(vol->target.path, capacity, - vol->target.allocation, pre_allocate); + return virStorageFileResize(vol->target.path, capacity, pre_allocate); } else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) { return storagePloopResize(vol, capacity); } else { diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b3da0a4528..5df1ea0b8d 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1315,17 +1315,11 @@ virStorageFileChainGetBroken(virStorageSourcePtr chain, int virStorageFileResize(const char *path, unsigned long long capacity, - unsigned long long orig_capacity, bool pre_allocate) { int fd = -1; int ret = -1; int rc; - off_t offset ATTRIBUTE_UNUSED; - off_t len ATTRIBUTE_UNUSED; - - offset = orig_capacity; - len = capacity - orig_capacity; if ((fd = open(path, O_RDWR)) < 0) { virReportSystemError(errno, _("Unable to open '%s'"), path); @@ -1333,7 +1327,7 @@ virStorageFileResize(const char *path, } if (pre_allocate) { - if ((rc = virFileAllocate(fd, offset, len)) != 0) { + if ((rc = virFileAllocate(fd, 0, capacity)) != 0) { if (rc == -2) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("preallocate is not supported on this platform")); diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index f7e897f25e..1eb1c6471c 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -328,7 +328,6 @@ virStorageSourcePtr virStorageFileChainLookup(virStorageSourcePtr chain, int virStorageFileResize(const char *path, unsigned long long capacity, - unsigned long long orig_capacity, bool pre_allocate); int virStorageFileIsClusterFS(const char *path);