[PATCH] storage: only fallocate when allocation matches capacity

Christian Ehrhardt christian.ehrhardt at canonical.com
Wed Sep 2 13:58:14 UTC 2020


In c9ec7088 "storage: extend preallocation flags support for qemu-img"
the option to fallocate was added and meant to be active when (quote):
"the XML described storage <allocation> matches its <capacity>"

Up until recently 81a3042a12 "storage_util: fix qemu-img sparse allocation"
the compared allocation size was an order of magnitude too small, but still
it does use fallocate too often unless capacity>allocation.

This change fixes the comparison to match the intended description
of the feature.

Fixes: c9ec7088c7a3f4cd26bb471f1f243931fff6f4f9
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1759454
Fixes: https://bugs.launchpad.net/ubuntu/focal/+source/libvirt/+bug/1847105

Signed-off-by: Christian Ehrhardt <christian.ehrhardt at canonical.com>
---
 src/storage/storage_util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index cf82ea0a87..85bed76863 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -710,10 +710,10 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr encinfo,
         virQEMUBuildQemuImgKeySecretOpts(&buf, encinfo, info->secretAlias);
 
     if (info->preallocate) {
-        if (info->size_arg > info->allocation)
-            virBufferAddLit(&buf, "preallocation=metadata,");
-        else
+        if (info->size_arg == info->allocation)
             virBufferAddLit(&buf, "preallocation=falloc,");
+        else
+            virBufferAddLit(&buf, "preallocation=metadata,");
     }
 
     if (info->nocow)
-- 
2.28.0




More information about the libvir-list mailing list