[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] Fix sparse volume allocation reporting

I have a sparse volume with a capacity of 1000M, and an allocation of a
little over 750M. 'du' prints the correct sizes, but 'virsh vol-dumpxml'


This is because we were calculating the allocation size using the
requested fs block size, instead of what stat actually uses as a block
size (DEV_BSIZE in sys/params.h). sys/params.h looks to be present in
mingw32-runtime, so I didn't add a configure check for it.

The attached patch fixes allocation listing for me.

diff --git a/src/storage_backend.c b/src/storage_backend.c
index 787630c..54e9289 100644
--- a/src/storage_backend.c
+++ b/src/storage_backend.c
@@ -36,6 +36,7 @@
 #include <fcntl.h>
 #include <stdint.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <dirent.h>
@@ -204,8 +205,15 @@ virStorageBackendUpdateVolTargetInfoFD(virConnectPtr conn,
     if (allocation) {
         if (S_ISREG(sb.st_mode)) {
 #ifndef __MINGW32__
-            *allocation = (unsigned long long)sb.st_blocks *
-                (unsigned long long)sb.st_blksize;
+            unsigned long long blksize;
+#ifdef DEV_BSIZE
+            blksize = (unsigned long long) DEV_BSIZE;
+            blksize = (unsigned long long)sb.st_blksize;
+            *allocation = (unsigned long long)sb.st_blocks * blksize;
             *allocation = sb.st_size;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]