[Thincrust-devel] [PATCH 2/4] Add Logical Volume Management(LVM) group interface to partitionedfs
Yongjun Wei
weiyj.lk at gmail.com
Fri Dec 16 09:59:34 UTC 2011
Kickstart has an option 'volgroup' to support create a Logical
Volume Management (LVM) group. But partitionedfs does not have
an interface to apply this option. We added LVM volume group
interface to partitionedfs in this patch.
Signed-off-by: Wei Yongjun <yongjun_wei at trendmicro.com.cn>
diff --git a/appcreate/partitionedfs.py b/appcreate/partitionedfs.py
index 3c6795f..8b444ad 100644
--- a/appcreate/partitionedfs.py
+++ b/appcreate/partitionedfs.py
@@ -42,6 +42,7 @@ class PartitionedMount(Mount):
'offset': 0 } # Offset of next partition
self.partitions = []
+ self.groups = []
self.mapped = False
self.mountOrder = []
self.unmountOrder = []
@@ -56,6 +57,12 @@ class PartitionedMount(Mount):
'mount': None, # Mount object
'num': None}) # Partition number
+ def add_volume_groups(self, name, pesize, physvols):
+ self.groups.append({'name': name,
+ 'mapped': False, # True if volume group mapping exists
+ 'pesize': pesize,
+ 'physvols': physvols})
+
def __format_disks(self):
logging.debug("Formatting disks")
for dev in self.disks.keys():
@@ -125,9 +132,28 @@ class PartitionedMount(Mount):
if rc != 0:
raise MountError("Error initialize physical volume %s" % p['device'])
+ def __create_volume_groups(self):
+ logging.debug("Create volume groups")
+ for g in self.groups:
+ logging.debug("Create volume group %s using %s" % (g['name'], g['physvols']))
+ parts = []
+ for p in self.partitions:
+ if g['physvols'].count(p['mountpoint']) > 0:
+ parts.append(p['device'])
+
+ if len(parts) == 0:
+ raise MountError("Failed to query Physical Volume %s for volume group %s" % (g['physvols'], g['name']))
+
+ rc = subprocess.call(["/sbin/lvm", "vgcreate", g['name'],
+ ' '.join(parts)])
+ if rc != 0:
+ raise MountError("Error create volume group %s using %s" %
+ (g['name'], g['physvols']))
+
def __format_volumes(self):
logging.debug("Formatting volumes")
self.__create_physical_volumes()
+ self.__create_volume_groups()
def __map_partitions(self):
for dev in self.disks.keys():
@@ -198,6 +224,27 @@ class PartitionedMount(Mount):
d['mapped'] = False
+ def __map_volumes(self):
+ for g in self.groups:
+ if g['mapped']:
+ continue
+
+ rc = subprocess.call(["/sbin/lvm", "vgchange", "-ay", g['name']])
+ if rc != 0:
+ raise MountError("Failed to map volume group %s" % g['name'])
+
+ g['mapped'] = True
+
+ def __unmap_volumes(self):
+ for g in self.groups:
+ if not g['mapped']:
+ continue
+
+ rc = subprocess.call(["/sbin/lvm", "vgchange", "-an", g['name']])
+ if rc != 0:
+ raise MountError("Failed to unmap volume group %s" % g['name'])
+
+ g['mapped'] = False
def __calculate_mountorder(self):
for p in self.partitions:
@@ -214,6 +261,7 @@ class PartitionedMount(Mount):
def cleanup(self):
Mount.cleanup(self)
+ self.__unmap_volumes()
self.__unmap_partitions()
for dev in self.disks.keys():
d = self.disks[dev]
@@ -247,6 +295,7 @@ class PartitionedMount(Mount):
self.__format_disks()
self.__map_partitions()
self.__format_volumes()
+ self.__map_volumes()
self.__calculate_mountorder()
for mp in self.mountOrder:
--
1.7.7.4
More information about the Thincrust-devel
mailing list