Re: TAKE II of [PATCH] Add clearpart --scrublvm option (#462615)

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

 



Radek Vykydal wrote:

please disregard the first version, here is a new one which is cleaned-up a bit

>From 82d733049cd5d5b5b182cba8bdc5bee57afbd857 Mon Sep 17 00:00:00 2001
From: Radek Vykydal <rvykydal@xxxxxxxxxx>
Date: Tue, 12 May 2009 10:23:43 +0200
Subject: [PATCH] Add clearpart --scrublvm option (#462615)

The option ensures that lvm metadata are removed from from all cleared
partitions. lvm pvremove is used.  The removal is not part of clearpart but
takes place at a very early stage (added step) which allows to scrub the
metadata also in cases when --initlabel is used.  One consequence is that
unlike clearpart it can't be taken back in UI, but considering the intended
use I think it is ok.
---
 autopart.py     |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dispatch.py     |    3 +-
 installclass.py |    1 +
 kickstart.py    |    2 +
 lvm.py          |   21 ++++++++++++++++++++
 5 files changed, 82 insertions(+), 1 deletions(-)

diff --git a/autopart.py b/autopart.py
index 0f30f6e..352aaa4 100644
--- a/autopart.py
+++ b/autopart.py
@@ -1061,6 +1061,62 @@ def doPartitioning(diskset, requests, doRefresh = 1):
                                        "allocated logical volumes in "
                                        "%s." % (request.volumeGroupName))
 
+def doScrubLVM(anaconda):
+    """clear lvm metadata from partitions, ks only"""
+
+    if anaconda is None or \
+       not anaconda.isKickstart or \
+       not anaconda.id.ksdata.clearpart["scrublvm"]:
+        return
+    scrubdrives = anaconda.id.ksdata.clearpart["drives"]  
+
+    disks = {}
+    diskset = anaconda.id.diskset
+    diskset.stopDmRaid()
+    diskset.stopMPath()
+    diskset.startMPath()
+    diskset.startDmRaid()
+
+
+    for drive in diskset.driveList():
+        if (diskset.exclusiveDisks != [] and drive not in diskset.exclusiveDisks) or drive in diskset.skippedDisks:
+            continue
+        deviceFile = isys.makeDevInode(drive, "/dev/" + drive)
+        if not isys.mediaPresent(drive):
+            continue
+
+        try:
+            dev = parted.PedDevice.get(deviceFile)
+            disk = parted.PedDisk.new(dev)
+        except parted.error, msg:
+            log.debug("scrublvm, parted error: %s" % (msg,))
+            continue
+
+        disks[drive] = disk
+
+        partedUtils.filter_partitions(disk, partedUtils.validateFsType)
+
+    drives = disks.keys()
+    drives.sort()
+
+    for drive in drives:
+        if (scrubdrives and not drive in scrubdrives) or \
+           drive in diskset.skippedDisks:
+            continue
+        disk = disks[drive]
+        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
+            # XXX filter by partition type?
+            device = fsset.PartedPartitionDevice(part).getDevice()
+            log.debug("scrubbing lvm metadata from /dev/%s" % (device,))
+            lvm.scrublvm("/dev/%s" % (device,))
+            part = disk.next_partition(part)
+
+
 # given clearpart specification execute it
 # probably want to reset diskset and partition request lists before calling
 # this the first time
diff --git a/dispatch.py b/dispatch.py
index ddf7885..9293e68 100644
--- a/dispatch.py
+++ b/dispatch.py
@@ -21,7 +21,7 @@ from packages import writeKSConfiguration, turnOnFilesystems
 from packages import doMigrateFilesystems
 from packages import doPostAction
 from packages import copyAnacondaLogs
-from autopart import doAutoPartition
+from autopart import doAutoPartition, doScrubLVM
 from packages import firstbootConfiguration
 from packages import betaNagScreen
 from packages import setupTimezone
@@ -65,6 +65,7 @@ installSteps = [
     ("language", ),
     ("keyboard", ),
     ("regkey", regKeyScreen, ),
+    ("scrublvm", doScrubLVM, ),
     ("findrootparts", findRootParts, ),
     ("findinstall", ),
     ("partitionobjinit", partitionObjectsInitialize, ),
diff --git a/installclass.py b/installclass.py
index c286a81..f8ba4cb 100644
--- a/installclass.py
+++ b/installclass.py
@@ -130,6 +130,7 @@ class BaseInstallClass:
 		 "language",
 		 "keyboard",
 		 "welcome",
+		 "scrublvm",
                  "findrootparts",
 		 "betanag",
 		 "installtype",
diff --git a/kickstart.py b/kickstart.py
index 403fe41..286355d 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -169,6 +169,8 @@ class AnacondaKSHandlers(KickstartHandlers):
 
         self.id.instClass.setClearParts(self.id, dict["type"], drives=dict["drives"],
                                         initAll=dict["initAll"])
+        if not dict["scrublvm"]:
+	    self.skipSteps.append("scrublvm")
 
     def doFirewall(self, args):
         KickstartHandlers.doFirewall(self, args)
diff --git a/lvm.py b/lvm.py
index b45069c..44c2007 100644
--- a/lvm.py
+++ b/lvm.py
@@ -195,6 +195,27 @@ def vgremove(vgname):
         if rc:
             raise SystemError, "pvcreate failed for %s" % (pvname,)
 
+def scrublvm(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:
-- 
1.5.4.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux