From: Ján Tomko Date: Tue, 16 Aug 2016 10:29:05 +0000 (+0200) Subject: Shrink volume even with ALLOCATE flag X-Git-Tag: v3.8.0-rc1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=959fe7de1f0f6fadb86e853edead6d32c3cb3559;p=thirdparty%2Flibvirt.git Shrink volume even with ALLOCATE flag Calling fallocate on the new (smaller) capacity ensures that the whole file is allocated, but it does not reduce the file size. Also call ftruncate after fallocate. https://bugzilla.redhat.com/show_bug.cgi?id=1366446 --- diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 5df1ea0b8d..80a33b1a6e 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1338,12 +1338,12 @@ virStorageFileResize(const char *path, } goto cleanup; } - } else { - if (ftruncate(fd, capacity) < 0) { - virReportSystemError(errno, - _("Failed to truncate file '%s'"), path); - goto cleanup; - } + } + + if (ftruncate(fd, capacity) < 0) { + virReportSystemError(errno, + _("Failed to truncate file '%s'"), path); + goto cleanup; } if (VIR_CLOSE(fd) < 0) {