From bc3427b73914a5530d08d55dfd78b595a69c33af Mon Sep 17 00:00:00 2001
From: Aaron Knister <aaron.knister@gmail.com>
Date: Mon, 15 Apr 2013 12:26:36 -0400
Subject: [PATCH] Use KB as the unit for LVM PE size

LogicalVolume.Attach in bdev.py is calling "lvs" and specifying a unit of
Megabytes that is then converted to an integer resulting in the value 0 for
small sizes.

This patch makes Ganeti use KB for the unit instead of MB.

Fixes Issue 347.

Signed-off-by: Aaron Knister <aaron.knister@gmail.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
---
 lib/bdev.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/bdev.py b/lib/bdev.py
index 3c453d0f1..84fa49d0f 100644
--- a/lib/bdev.py
+++ b/lib/bdev.py
@@ -836,7 +836,7 @@ class LogicalVolume(BlockDev):
     """
     self.attached = False
     result = utils.RunCmd(["lvs", "--noheadings", "--separator=,",
-                           "--units=m", "--nosuffix",
+                           "--units=k", "--nosuffix",
                            "-olv_attr,lv_kernel_major,lv_kernel_minor,"
                            "vg_extent_size,stripes", self.dev_path])
     if result.failed:
@@ -1029,10 +1029,12 @@ class LogicalVolume(BlockDev):
       if not self.Attach():
         _ThrowError("Can't attach to LV during Grow()")
     full_stripe_size = self.pe_size * self.stripe_count
+    # pe_size is in KB
+    amount *= 1024
     rest = amount % full_stripe_size
     if rest != 0:
       amount += full_stripe_size - rest
-    cmd = ["lvextend", "-L", "+%dm" % amount]
+    cmd = ["lvextend", "-L", "+%dk" % amount]
     if dryrun:
       cmd.append("--test")
     # we try multiple algorithms since the 'best' ones might not have
-- 
GitLab