[PATCH] Honor kickstart's clearpart --initlabel option.

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

 



---
 storage/devices.py    |   40 +++++++++++++++++++++++++++-------------
 storage/devicetree.py |   14 ++++++++------
 2 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index ae1ad09..a4a1ac5 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -639,7 +639,7 @@ class DiskDevice(StorageDevice):
 
     def __init__(self, device, format=None,
                  size=None, major=None, minor=None, sysfsPath='', \
-                 parents=None, initcb=None):
+                 parents=None, initcb=None, initlabel=None):
         """ Create a DiskDevice instance.
 
             Arguments:
@@ -657,6 +657,7 @@ class DiskDevice(StorageDevice):
                 removable -- whether or not this is a removable device
 
                 initcb -- the call back to be used when initiating disk.
+                initlabel -- whether to start with a fresh disklabel
 
 
             DiskDevices always exist.
@@ -667,20 +668,24 @@ class DiskDevice(StorageDevice):
 
         self.partedDevice = None
         self.partedDisk = None
+
         log.debug("looking up parted Device: %s" % self.path)
         self.partedDevice = parted.Device(path=self.path)
         if not self.partedDevice:
             raise DeviceError("cannot find parted device instance")
+
         log.debug("creating parted Disk: %s" % self.path)
-        try:
-            self.partedDisk = parted.Disk(device=self.partedDevice)
-        except _ped.DiskLabelException:
-            # if we have a cb function use it. else an error.
-            if initcb is not None and initcb():
-                self.partedDisk = parted.freshDisk(device=self.partedDevice, \
-                        ty = platform.getPlatform(None).diskType)
-            else:
-                raise DeviceUserDeniedFormatError("User prefered to not format.")
+        if initlabel:
+            self.partedDisk = self.freshPartedDisk()
+        else:
+            try:
+                self.partedDisk = parted.Disk(device=self.partedDevice)
+            except _ped.DiskLabelException:
+                # if we have a cb function use it. else an error.
+                if initcb is not None and initcb():
+                    self.partedDisk = self.freshPartedDisk()
+                else:
+                    raise DeviceUserDeniedFormatError("User prefered to not format.")
 
         # We save the actual state of the disk here. Before the first
         # modification (addPartition or removePartition) to the partition
@@ -690,6 +695,10 @@ class DiskDevice(StorageDevice):
 
         self.probe()
 
+    def freshPartedDisk(self):
+        labelType = platform.getPlatform(None).diskType
+        return parted.freshDisk(device=self.partedDevice, ty=labelType)
+
     @property
     def size(self):
         """ The disk's size in MB """
@@ -2123,8 +2132,9 @@ class DMRaidArrayDevice(DiskDevice):
     _packages = ["dmraid"]
     devDir = "/dev/mapper"
 
-    def __init__(self, name, raidSet=None, level=None, format=None, size=None,
-                 major=None, minor=None, parents=None, sysfsPath='', initcb=None):
+    def __init__(self, name, raidSet=None, level=None, format=None,
+                 size=None, major=None, minor=None, parents=None,
+                 sysfsPath='', initcb=None, initlabel=None):
         """ Create a DMRaidArrayDevice instance.
 
             Arguments:
@@ -2139,6 +2149,9 @@ class DMRaidArrayDevice(DiskDevice):
                 sysfsPath -- sysfs device path
                 size -- the device's size
                 format -- a DeviceFormat instance
+
+                initcb -- the call back to be used when initiating disk.
+                initlabel -- whether to start with a fresh disklabel
         """
         if isinstance(parents, list):
             for parent in parents:
@@ -2146,7 +2159,8 @@ class DMRaidArrayDevice(DiskDevice):
                     raise ValueError("parent devices must contain dmraidmember format")
         DiskDevice.__init__(self, name, format=format, size=size,
                             major=major, minor=minor, parents=parents,
-                            sysfsPath=sysfsPath, initcb=initcb)
+                            sysfsPath=sysfsPath, initcb=initcb,
+                            initlabel=initlabel)
 
         self.formatClass = get_device_format_class("dmraidmember")
         if not self.formatClass:
diff --git a/storage/devicetree.py b/storage/devicetree.py
index 49f551c..8f6e0d9 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -981,7 +981,8 @@ class DeviceTree(object):
                                     major=udev_device_get_major(info),
                                     minor=udev_device_get_minor(info),
                                     sysfsPath=sysfs_path,
-                                    initcb=cb)
+                                    initcb=cb,
+                                    initlabel=self.reinitializeDisks)
                     self._addDevice(device)
                 except DeviceUserDeniedFormatError: #drive not initialized?
                     self.ignoredDisks.append(name)
@@ -1159,11 +1160,12 @@ class DeviceTree(object):
                                 cb = lambda: questionInitializeDisk(self.intf,
                                                                     rs.name)
                             dm_array = DMRaidArrayDevice(rs.name,
-                                                         major=major, minor=minor,
-                                                         raidSet=rs,
-                                                         level=rs.level,
-                                                         parents=[device],
-                                                         initcb=cb)
+                                             major=major, minor=minor,
+                                             raidSet=rs,
+                                             level=rs.level,
+                                             parents=[device],
+                                             initcb=cb,
+                                             initlabel=self.reinitializeDisks)
 
                             self._addDevice(dm_array)
                             # Use the rs's object on the device.
-- 
1.6.0.6

_______________________________________________
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