From 959fe7de1f0f6fadb86e853edead6d32c3cb3559 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Tomko?= Date: Tue, 16 Aug 2016 12:29:05 +0200 Subject: [PATCH] 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 --- src/util/virstoragefile.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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) { -- 2.39.5