[libvirt] [PATCH 3/3] Shrink volume even with ALLOCATE flag

Ján Tomko jtomko at redhat.com
Mon Sep 25 15:46:10 UTC 2017


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 5df1ea0b8..80a33b1a6 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.13.0




More information about the libvir-list mailing list