summaryrefslogtreecommitdiffstats
path: root/lvm.py
diff options
context:
space:
mode:
Diffstat (limited to 'lvm.py')
-rw-r--r--lvm.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/lvm.py b/lvm.py
index 3c0a7bd3a..cc4b804cc 100644
--- a/lvm.py
+++ b/lvm.py
@@ -152,6 +152,13 @@ def vgremove(vgname):
if flags.test or lvmDevicePresent == 0:
return
+ # find the Physical Volumes which make up this Volume Group, so we
+ # can prune and recreate them.
+ pvs = []
+ for pv in pvlist():
+ if pv[1] == vgname:
+ pvs.append(pv[0])
+
# we'll try to deactivate... if it fails, we'll probably fail on
# the removal too... but it's worth a shot
try:
@@ -161,6 +168,7 @@ def vgremove(vgname):
args = ["lvm", "vgremove", vgname]
+ log(string.join(args, ' '))
rc = iutil.execWithRedirect(args[0], args,
stdout = output,
stderr = output,
@@ -168,6 +176,31 @@ def vgremove(vgname):
if rc:
raise SystemError, "vgremove failed"
+ # now iterate all the PVs we've just freed up, so we reclaim the metadata
+ # space. This is an LVM bug, AFAICS.
+ for pvname in pvs:
+ args = ["lvm", "pvremove", pvname]
+
+ log(string.join(args, ' '))
+ rc = iutil.execWithRedirect(args[0], args,
+ stdout = output,
+ stderr = output,
+ searchPath = 1)
+
+ if rc:
+ raise SystemError, "pvremove failed"
+
+ args = ["lvm", "pvcreate", "-ff", "-y", "-v", pvname]
+
+ log(string.join(args, ' '))
+ rc = iutil.execWithRedirect(args[0], args,
+ stdout = output,
+ stderr = output,
+ searchPath = 1)
+
+ if rc:
+ raise SystemError, "pvcreate failed for %s" % (pvname,)
+
def lvlist():
global lvmDevicePresent
if lvmDevicePresent == 0:
@@ -388,5 +421,8 @@ def getVGUsedSpace(vgreq, requests, diskset):
def getVGFreeSpace(vgreq, requests, diskset):
used = getVGUsedSpace(vgreq, requests, diskset)
+ log("used space is %s" % (used,))
- return vgreq.getActualSize(requests, diskset) - used
+ total = vgreq.getActualSize(requests, diskset)
+ log("actual space is %s" % (total,))
+ return total - used