Re: [PATCH] storage: Round up capacity for LVM volume creation

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

 



ä 2011å01æ24æ 11:02, Daniel Veillard åé:
On Sat, Jan 22, 2011 at 07:18:00PM +0800, Osier Yang wrote:
If vol->capacity is odd, the capacity will be rounded down
by devision, this patch is to round it up instead of rounding
down, to be safer in case of one writes to the volume with the
size he used to create.

* src/storage/storage_backend_logical.c
---
  src/storage/storage_backend_logical.c |    5 ++++-
  1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 203fe5d..2057692 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -604,7 +604,10 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
          cmdargv = cmdargvsnap;
      }

-    snprintf(size, sizeof(size)-1, "%lluK", vol->capacity/1024);
+    unsigned long long int capacity;
+    capacity = vol->capacity/1024 + (vol->capacity%1024>  0 ? 1 : 0);
+
+    snprintf(size, sizeof(size)-1, "%lluK", capacity);
      size[sizeof(size)-1] = '\0';

      vol->type = VIR_STORAGE_VOL_BLOCK;

   To fix such rounding issues I would usually do
      capacity = (vol->capacity + 1023) /1024;

instead, it's really easier to read :-)

Yeah, it looks much better, will update, thanks. :-)

But the principle of the patch looks right to me !

Daniel


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]