[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH] Remove LVM metadata when doing clearpart (#426615)



LVM metadata are removed 1) when labeling a disk (covers clearpart --initlabel
cases) or 2) when deleting a partition upon a delete request if the request was
created in clearpart.  Also we don't create dependent meta delete requests in
this case as they would conflict with metadata removing in partition delete.
If the delete request comes from UI, LVM metadata are removed as before by meta
delete (VG) requests created in UI in previous steps.
---
 autopart.py     |   16 ++++++++++++++--
 lvm.py          |   21 +++++++++++++++++++++
 partRequests.py |    4 +++-
 partedUtils.py  |   17 +++++++++++++++++
 4 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/autopart.py b/autopart.py
index 0f30f6e..0ba8e9a 100644
--- a/autopart.py
+++ b/autopart.py
@@ -881,6 +881,10 @@ def deletePart(diskset, delete):
     part = disk.next_partition()
     while part:
         if part.geom.start == delete.start and part.geom.end == delete.end:
+            device = fsset.PartedPartitionDevice(part).getDevice()
+            if delete.clobber:
+                log.debug("removing lvm metadata from %s" %(device,))
+                lvm.pvremove("/dev/%s" % (device,))
             disk.delete_partition(part)
             return
         part = disk.next_partition(part)
@@ -1118,12 +1122,20 @@ def doClearPartAction(anaconda, partitions, diskset):
                     part = disk.next_partition(part)
                     continue
 
-                partitions.deleteDependentRequests(old)
+                # for PV, set a flag to remove lvm metadata in deletePart
+                # and do not create dependent delete requests (VGs, LVs)
+                # because they would be processed (in doMetaDeletes) after
+                # lvm metadata had been removed and thus fail
+                if not old.fstype.getName() == "physical volume (LVM)": 
+                    partitions.deleteDependentRequests(old)
+                    clobber = False
+                else:
+                    clobber = True
                 partitions.removeRequest(old)
 
                 drive = partedUtils.get_partition_drive(part)
                 delete = partRequests.DeleteSpec(drive, part.geom.start,
-                                                 part.geom.end)
+                                                 part.geom.end, clobber=clobber)
                 partitions.addDelete(delete)
 
             # ia64 autopartitioning is strange as /boot/efi is vfat --
diff --git a/lvm.py b/lvm.py
index b45069c..83e19b4 100644
--- a/lvm.py
+++ b/lvm.py
@@ -195,6 +195,27 @@ def vgremove(vgname):
         if rc:
             raise SystemError, "pvcreate failed for %s" % (pvname,)
 
+def pvremove(pvname):
+
+    # Check that device is PV
+    args = ["pvdisplay", pvname]
+
+    log.info(string.join(args, ' '))
+    rc = iutil.execWithRedirect("lvm", args, stdout = output,
+                                stderr = output, searchPath = 1)
+    if rc:
+        # No LVM metadata found on partition
+        return
+
+    args = ["pvremove", "-ff", "-y", "-v", pvname]
+
+    log.info(string.join(args, ' '))
+    rc = iutil.execWithRedirect("lvm", args, stdout = output,
+                                stderr = output, searchPath = 1)
+
+    if rc:
+        raise SystemError, "pvremove failed for %s" % (pvname,)
+
 def lvlist():
     global lvmDevicePresent
     if lvmDevicePresent == 0:
diff --git a/partRequests.py b/partRequests.py
index bf7a4eb..657e62d 100644
--- a/partRequests.py
+++ b/partRequests.py
@@ -38,17 +38,19 @@ log = logging.getLogger("anaconda")
 class DeleteSpec:
     """Defines a preexisting partition which is intended to be removed."""
     
-    def __init__(self, drive, start, end):
+    def __init__(self, drive, start, end, clobber=False):
         """Initializes a DeleteSpec.
 
         drive is the text form of the drive
         start is the start sector of the deleted partition
         end is the end sector of the deleted partition
+        clobber - remove metadata from partition
         """
         
         self.drive = drive
         self.start = start
         self.end = end
+        self.clobber = clobber
 
     def __str__(self):
         return "drive: %s  start: %s  end: %s" %(self.drive, self.start,
diff --git a/partedUtils.py b/partedUtils.py
index 0be98db..8aee9a1 100644
--- a/partedUtils.py
+++ b/partedUtils.py
@@ -291,6 +291,23 @@ def labelDisk(deviceFile, forceLabelType=None):
                 'gpt' in archLabels[rhpl.getArch()]:
             label = parted.disk_type_get('gpt')
 
+    # remove metadata from partitions
+    try:
+        disk = parted.PedDisk.new(dev)
+    except parted.error, msg:
+        log.debug("parted error: %s" % (msg,))
+    else:    
+        part = disk.next_partition()
+        while part:
+            if (not part.is_active() or (part.type == parted.PARTITION_EXTENDED) or
+               (part.disk.type.name == "mac" and part.num == 1 and part.get_name() == "Apple")):
+                part = disk.next_partition(part)
+                continue
+            device = fsset.PartedPartitionDevice(part).getDevice()
+            log.debug("removing lvm metadata from %s" %(device,))
+            lvm.pvremove("/dev/%s" % (device,))
+            part = disk.next_partition(part)
+
     disk = dev.disk_new_fresh(label)
     disk.commit()
     return disk
-- 
1.5.4.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]