--- storage/devices.py | 27 +++++++----- storage/devicetree.py | 107 +++++++++++++++++++++++++++--------------------- storage/errors.py | 3 + 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/storage/devices.py b/storage/devices.py index dd5a4f1..24153fc 100644 --- a/storage/devices.py +++ b/storage/devices.py @@ -101,6 +101,7 @@ from devicelibs import lvm #import block from devicelibs import dm import parted +import platform from errors import * from iutil import log_method_call, notify_kernel, numeric_type @@ -636,8 +637,8 @@ class DiskDevice(StorageDevice): _type = "disk" def __init__(self, device, format=None, - size=None, major=None, minor=None, - sysfsPath='', parents=None, init = False, labeltype = None): + size=None, major=None, minor=None, sysfsPath='', \ + parents=None, initcb=None): """ Create a DiskDevice instance. Arguments: @@ -654,8 +655,7 @@ 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 + initcb -- the call back to be used when initiating disk. DiskDevices always exist. @@ -671,12 +671,15 @@ class DiskDevice(StorageDevice): if not self.partedDevice: raise DeviceError("cannot find parted device instance") log.debug("creating parted Disk: %s" % self.path) - if init: - self.partedDisk = parted.freshDisk(device=self.partedDevice, ty = labeltype) - else: + try: self.partedDisk = parted.Disk(device=self.partedDevice) - if not self.partedDisk: - raise DeviceError("failed to create parted Disk") + except parted.IOException: + # 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.") self.probe() @@ -2159,7 +2162,7 @@ class DMRaidArrayDevice(DiskDevice): devDir = "/dev/mapper" def __init__(self, name, raidSet=None, level=None, format=None, size=None, - major=None, minor=None, parents=None, sysfsPath=''): + major=None, minor=None, parents=None, sysfsPath='', initcb=None): """ Create a DMRaidArrayDevice instance. Arguments: @@ -2180,8 +2183,8 @@ class DMRaidArrayDevice(DiskDevice): if not parent.format or parent.format.type != "dmraidmember": raise ValueError("parent devices must contain dmraidmember format") DiskDevice.__init__(self, name, format=format, size=size, - major=major, minor=minor, - parents=parents, sysfsPath=sysfsPath) + major=major, minor=minor, parents=parents, + sysfsPath=sysfsPath, initcb=initcb) self.formatClass = get_device_format_class("dmraidmember") if not self.formatClass: diff --git a/storage/devicetree.py b/storage/devicetree.py index a83279d..09a5bf4 100644 --- a/storage/devicetree.py +++ b/storage/devicetree.py @@ -28,8 +28,6 @@ from devices import * from deviceaction import * import formats from udev import * -import parted -import platform import gettext _ = lambda x: gettext.ldgettext("anaconda", x) @@ -117,7 +115,26 @@ def getLUKSPassphrase(intf, device, globalPassphrase): return (passphrase, isglobal) - +# Don't really know where to put this. +def questionInitializeDisk(intf=None, name=None): + retVal = False # The less destructive default + if not intf or not name: + pass + else: + rc = intf.messageWindow(_("Warning"), + _("Error processing drive %s.\n" + "Maybe it needs to be reinitialized." + "YOU WILL LOSE ALL DATA ON THIS DRIVE!") % (name,), + type="custom", + custom_buttons = [ _("_Ignore drive"), + _("_Re-initialize drive") ], + custom_icon="question") + if rc == 0: + pass + else: + retVal = True + return retVal + class DeviceTree(object): """ A quasi-tree that represents the devices in the system. @@ -778,32 +795,15 @@ class DeviceTree(object): device = self.getDeviceByName(name) if device is None: try: + cb=lambda:questionInitializeDisk(self.intf, name) device = DiskDevice(name, major=udev_device_get_major(info), minor=udev_device_get_minor(info), - sysfsPath=sysfs_path) + sysfsPath=sysfs_path, + initcb=cb) self._addDevice(device) - except parted.IOException: #drive not initialized? - if not self.intf: - self.ignoredDisks.append(name) - else: - rc = self.intf.messageWindow(_("Warning"), - _("Error processing drive %s.\n" - "Maybe it needs to be reinitialized." - "YOU WILL LOSE ALL DATA ON THIS DRIVE!") % (name,), - 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) + except DeviceUserDeniedFormatError: #drive not initialized? + self.ignoredDisks.append(name) elif udev_device_is_partition(info): log.debug("%s is a partition" % name) device = self.getDeviceByName(name) @@ -954,29 +954,42 @@ class DeviceTree(object): # FIXME: Should handle not finding a dmriad dev better pass - dm_array = self.getDeviceByName(rs.name) - if dm_array is not None: - # We add the new device. - dm_array._addDevice(device) - else: - # Activate the Raid set. - rs.activate(mknod=True) - - # Create the DMRaidArray - dm_array = DMRaidArrayDevice(rs.name, - major=major, minor=minor, - raidSet=rs, - level=rs.level, - parents=[device]) - - self._addDevice(dm_array) + if rs.name in self.ignoredDisks: + # If the rs is being ignored, we should ignore device too. + self.ignoredDisks.append(device.name) - # Use the rs's object on the device. - # pyblock can return the memebers of a set and the device has - # the attribute to hold it. But ATM we are not really using it. - # Commenting this out until we really need it. - #device.format.raidmem = block.getMemFromRaidSet(dm_array, - # major=major, minor=minor, uuid=uuid, name=name) + else: + dm_array = self.getDeviceByName(rs.name) + if dm_array is not None: + # We add the new device. + dm_array._addDevice(device) + else: + # Activate the Raid set. + rs.activate(mknod=True) + + # Create the DMRaidArray + try: + 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) + + self._addDevice(dm_array) + # Use the rs's object on the device. + # pyblock can return the memebers of a set and the + # device has the attribute to hold it. But ATM we + # are not really using it. Commenting this out until + # we really need it. + #device.format.raidmem = block.getMemFromRaidSet(dm_array, + # major=major, minor=minor, uuid=uuid, name=name) + except DeviceUserDeniedFormatError: + # We should ignore the dmriad and its components + self.ignoredDisks.append(rs.name) + self.ignoredDisks.append(device.name) + rs.deactivate() elif format.type == "lvmpv": # lookup/create the VG and LVs try: diff --git a/storage/errors.py b/storage/errors.py index 692e0ac..8fb57b1 100644 --- a/storage/errors.py +++ b/storage/errors.py @@ -21,6 +21,9 @@ class DeviceTeardownError(DeviceError): class DeviceResizeError(DeviceError): pass +class DeviceUserDeniedFormatError(DeviceError): + pass + # DeviceFormat class DeviceFormatError(Exception): pass -- 1.6.0.6 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list