[PATCH] Allow user-specified values for data alignment of new lvm pvs. (#1178705)
David Lehman
dlehman at redhat.com
Fri Jan 16 18:09:43 UTC 2015
---
blivet/devicelibs/lvm.py | 7 +++++--
blivet/formats/lvmpv.py | 11 +++++++----
tests/devicelibs_test/lvm_test.py | 29 +++++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
index efca4c8..269b9c3 100644
--- a/blivet/devicelibs/lvm.py
+++ b/blivet/devicelibs/lvm.py
@@ -233,8 +233,11 @@ def lvm(args, capture=False, ignore_errors=False):
if capture:
return strip_lvm_warnings(out)
-def pvcreate(device):
- args = ["pvcreate", device]
+def pvcreate(device, data_alignment=None):
+ args = ["pvcreate"]
+ if data_alignment is not None:
+ args.extend(["--dataalignment", "%dk" % data_alignment.convertTo(KiB)])
+ args.append(device)
try:
lvm(args)
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
index a9d2801..efda438 100644
--- a/blivet/formats/lvmpv.py
+++ b/blivet/formats/lvmpv.py
@@ -56,6 +56,8 @@ class LVMPhysicalVolume(DeviceFormat):
:keyword vgUuid: the UUID of the VG this PV belongs to
:keyword peStart: offset of first physical extent
:type peStart: :class:`~.size.Size`
+ :keyword dataAlignment: data alignment (for non-existent PVs)
+ :type dataAlignment: :class:`~.size.Size`
.. note::
@@ -72,22 +74,23 @@ class LVMPhysicalVolume(DeviceFormat):
# liblvm may be able to tell us this at some point, even
# for not-yet-created devices
self.peStart = kwargs.get("peStart", lvm.LVM_PE_START)
+ self.dataAlignment = kwargs.get("dataAlignment")
self.inconsistentVG = False
def __repr__(self):
s = DeviceFormat.__repr__(self)
s += (" vgName = %(vgName)s vgUUID = %(vgUUID)s"
- " peStart = %(peStart)s" %
+ " peStart = %(peStart)s dataAlignment = %(dataAlignment)s" %
{"vgName": self.vgName, "vgUUID": self.vgUuid,
- "peStart": self.peStart})
+ "peStart": self.peStart, "dataAlignment": self.dataAlignment})
return s
@property
def dict(self):
d = super(LVMPhysicalVolume, self).dict
d.update({"vgName": self.vgName, "vgUUID": self.vgUuid,
- "peStart": self.peStart})
+ "peStart": self.peStart, "dataAlignment": self.dataAlignment})
return d
def create(self, **kwargs):
@@ -115,7 +118,7 @@ class LVMPhysicalVolume(DeviceFormat):
# hammer...
DeviceFormat.destroy(self, **kwargs)
lvm.pvscan(self.device)
- lvm.pvcreate(self.device)
+ lvm.pvcreate(self.device, data_alignment=self.dataAlignment)
except Exception:
raise
finally:
diff --git a/tests/devicelibs_test/lvm_test.py b/tests/devicelibs_test/lvm_test.py
index 6fc81fd..1c3d9f7 100755
--- a/tests/devicelibs_test/lvm_test.py
+++ b/tests/devicelibs_test/lvm_test.py
@@ -306,5 +306,34 @@ class LVMAsRootTestCase(LVMAsRootTestCaseBase):
# pv already removed
self.assertEqual(lvm.pvremove(_LOOP_DEV0), None)
+def lvm_passthrough_argv(args, *other_args, **kwargs):
+ """ Just return args as passed so tests can validate them. """
+ return args
+
+class LVMAsNonRootTestCase(object):
+ def setUp(self):
+ self.orig_lvm_func = lvm.lvm
+ lvm.lvm = lvm_passthrough_args
+
+ def tearDown(self):
+ lvm.lvm = self.orig_lvm_func
+
+ def testLVM(self):
+ #
+ # verify we pass appropriate args for various data alignment values
+ #
+
+ # default => do not specify a data alignment
+ argv = lvm.pvcreate('/dev/placeholder')
+ self.assertEqual(any(a.startswith('--dataalignment') for a in argv),
+ False)
+
+ # sizes get specified in KiB
+ argv = lvm.pvcreate('/dev/placeholder', data_alignment=Size('1 MiB'))
+ self.assertEqual("--dataalignment 1024k" in "".join(argv), True)
+
+ argv = lvm.pvcreate('/dev/placeholder', data_alignment=Size(1023))
+ self.assertEqual("--dataalignment 0k" in "".join(argv), True)
+
if __name__ == "__main__":
unittest.main()
--
1.9.3
More information about the anaconda-patches
mailing list