[PATCH] [storage] Reinitialize drive if parted.Drive fails

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

 



Hi,

I have a patch which should enable the user to reinitialize new drives, but I have to setup the storage testing environment first, so look at the logic while I'm getting all the pieces needed for testing it together.

Martin
diff --git a/storage/devices.py b/storage/devices.py
index 68bda21..5107559 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -562,7 +562,7 @@ class DiskDevice(StorageDevice):
 
     def __init__(self, device, format=None,
                  size=None, major=None, minor=None,
-                 sysfsPath='', parents=None):
+                 sysfsPath='', parents=None, init = False, labeltype = None):
         """ Create a DiskDevice instance.
 
             Arguments:
@@ -579,6 +579,10 @@ class DiskDevice(StorageDevice):
                 parents -- a list of required Device instances
                 removable -- whether or not this is a removable device
 
+                init -- initialize label on this drive
+                labeltype -- type of the label to use during initialization
+
+
             DiskDevices always exist.
         """
         StorageDevice.__init__(self, device, format=format, size=size,
@@ -593,7 +597,10 @@ class DiskDevice(StorageDevice):
         if not self.partedDevice:
             raise DeviceError("cannot find parted device instance")
         log.debug("creating parted Disk: %s" % self.path)
-        self.partedDisk = parted.Disk(device=self.partedDevice)
+        if init:
+            self.partedDisk = parted.freshDisk(device=self.partedDevice, labeltype)
+        else:
+            self.partedDisk = parted.Disk(device=self.partedDevice)
         if not self.partedDisk:
             raise DeviceError("failed to create parted Disk")
 
diff --git a/storage/devicetree.py b/storage/devicetree.py
index b6fee30..7a91946 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -27,6 +27,7 @@ from devices import *
 from deviceaction import *
 import formats
 from udev import *
+import parted
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
@@ -727,11 +728,33 @@ class DeviceTree(object):
             log.debug("%s is a disk" % name)
             device = self.getDeviceByName(name)
             if device is None:
-                device = DiskDevice(name,
+                try:
+                    device = DiskDevice(name,
                                     major=udev_device_get_major(info),
                                     minor=udev_device_get_minor(info),
                                     sysfsPath=sysfs_path)
-                self._addDevice(device)
+                    self._addDevice(device)
+                except parted._ped.IOException: #drive not initialized?
+                    if not intf:
+                        self.ignoredDisks.append(name)
+                    else:
+                        rc = intf.messageWindow(_("Warning"),
+                                _("Error processing drive %s.\n"
+                                  "Maybe it needs to be reinitialized."
+                                  "YOU WILL LOSE ALL DATA ON THIS DRIVE!"),
+                                type="custom",
+                                custom_buttons = [ _("_Ignore drive"),
+                                                   _("_Re-initialize drive") ],
+                                custom_icon="question")
+                        if rc == 0:
+                            self.ignoredDisks.append(name)
+                        else:
+                            device = DiskDevice(name,
+                                            major=udev_device_get_major(info),
+                                            minor=udev_device_get_minor(info),
+                                            sysfsPath=sysfs_path, init = True,
+                                            labeltype = platform.getPlatform(None).diskType)
+                            self._addDevice(device)
         elif udev_device_is_partition(info):
             log.debug("%s is a partition" % name)
             device = self.getDeviceByName(name)
_______________________________________________
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