[Thincrust-devel] [PATCH 3/4] Add Logical Volume interface to partitionedfs
Yongjun Wei
weiyj.lk at gmail.com
Fri Dec 16 10:01:02 UTC 2011
Kickstart has an option 'logvol' to support create a Logical
Volume. But partitionedfs does not have the interface to apply
this option. We added Logical Volume 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 8b444ad..12ff818 100644
--- a/appcreate/partitionedfs.py
+++ b/appcreate/partitionedfs.py
@@ -43,6 +43,7 @@ class PartitionedMount(Mount):
self.partitions = []
self.groups = []
+ self.volumes = []
self.mapped = False
self.mountOrder = []
self.unmountOrder = []
@@ -63,6 +64,16 @@ class PartitionedMount(Mount):
'pesize': pesize,
'physvols': physvols})
+ def add_logical_volume(self, name, size, vgname, mountpoint, fstype = None):
+ self.volumes.append({'name': name,
+ 'size': size,
+ 'vgname': vgname,
+ 'mountpoint': mountpoint, # Mount relative to chroot
+ 'fstype': fstype,
+ 'device': None,
+ 'devicemapper': None,
+ 'mount': None})
+
def __format_disks(self):
logging.debug("Formatting disks")
for dev in self.disks.keys():
@@ -150,10 +161,21 @@ class PartitionedMount(Mount):
raise MountError("Error create volume group %s using %s" %
(g['name'], g['physvols']))
+ def __create_logical_volumes(self):
+ logging.debug("Create logical volumes")
+ for v in self.volumes:
+ logging.debug("Create logical volume %s in volume group %s" %
+ (v['name'], v['vgname']))
+ rc = subprocess.call(["/sbin/lvm", "lvcreate", "--name", v['name'],
+ "--size", str(v['size']), v['vgname']])
+ if rc != 0:
+ raise MountError("Error create logical volume %s" % v['name'])
+
def __format_volumes(self):
logging.debug("Formatting volumes")
self.__create_physical_volumes()
self.__create_volume_groups()
+ self.__create_logical_volumes()
def __map_partitions(self):
for dev in self.disks.keys():
@@ -225,7 +247,10 @@ class PartitionedMount(Mount):
d['mapped'] = False
def __map_volumes(self):
+ vgnames = []
for g in self.groups:
+ vgnames.append(g['name'])
+
if g['mapped']:
continue
@@ -235,6 +260,32 @@ class PartitionedMount(Mount):
g['mapped'] = True
+ lvs = subprocess.Popen(["/sbin/lvm", "lvs", "--all","--noheadings",
+ "-o", "vg_name,lv_name,lv_path",
+ ' '.join(vgnames)],
+ stdout=subprocess.PIPE)
+
+ lvsOutput = lvs.communicate()[0].split("\n")
+ # Strip trailing blank
+ lvsOutput = lvsOutput[0:len(lvsOutput)-1]
+ if len(lvsOutput) != len(self.volumes):
+ raise MountError("Unexpected number of logical volumes from lvs %d != %d" % (len(lvsOutput), len(self.volumes)))
+
+ for i in range(len(lvsOutput)):
+ lvinfo = lvsOutput[i].strip().split()
+ vgname = lvinfo[0]
+ lvname = lvinfo[1]
+ device = lvinfo[2]
+ mapperdev = "/dev/mapper/%s-%s" %(vgname, lvname)
+
+ for v in self.volumes:
+ if v['name'] == lvname and v['vgname'] == vgname:
+ logging.debug("LogVol %s: %s -> %s -> %s" %
+ (vgname, lvname, device, mapperdev))
+ v['device'] = device
+ v['devicemapper'] = mapperdev
+ break
+
def __unmap_volumes(self):
for g in self.groups:
if not g['mapped']:
@@ -254,6 +305,10 @@ class PartitionedMount(Mount):
self.mountOrder.append(p['mountpoint'])
self.unmountOrder.append(p['mountpoint'])
+ for v in self.volumes:
+ self.mountOrder.append(v['mountpoint'])
+ self.unmountOrder.append(v['mountpoint'])
+
self.mountOrder.sort()
self.unmountOrder.sort()
self.unmountOrder.reverse()
@@ -280,6 +335,11 @@ class PartitionedMount(Mount):
p = p1
break
+ for v in self.volumes:
+ if v['mountpoint'] == mp:
+ p = v
+ break
+
if p['mount'] != None:
try:
p['mount'].cleanup()
@@ -305,6 +365,11 @@ class PartitionedMount(Mount):
p = p1
break
+ for v in self.volumes:
+ if v['mountpoint'] == mp:
+ p = v
+ break
+
if mp == 'biosboot':
subprocess.call(["/sbin/parted", "-s", self.disks[p['disk']]['disk'].device, "set", "1", "bios_grub", "on"])
continue
--
1.7.7.4
More information about the Thincrust-devel
mailing list