]> xenbits.xensource.com Git - libvirt.git/commitdiff
Shrink volume even with ALLOCATE flag
authorJán Tomko <jtomko@redhat.com>
Tue, 16 Aug 2016 10:29:05 +0000 (12:29 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 27 Sep 2017 12:40:44 +0000 (14:40 +0200)
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

index 5df1ea0b8d679cf09777a165fe1e6ae3e296f07e..80a33b1a6e9ae8bbd75d5ac724bd9f557f2eda40 100644 (file)
@@ -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) {