Looks good to me, Regards, Hans On 07/01/2009 01:13 AM, David Lehman wrote:
In storage.Storage we keep the device specifications as provided to us. In the devicetree, during population, we use udev to resolve the user- provided specs to device names. As we create StorageDevice instances for the devices, we set a new attribute ("protected") as appropriate. Once the DeviceTree is populated, we use the devices' protected attribute to determine whether or not they contain installation media. This way we can track protected devices even when their names change. --- storage/__init__.py | 30 +++++++++++++----------------- storage/devices.py | 2 ++ storage/devicetree.py | 25 +++++++++++++++++++++---- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/storage/__init__.py b/storage/__init__.py index 16de311..c88f310 100644 --- a/storage/__init__.py +++ b/storage/__init__.py @@ -69,26 +69,15 @@ def storageInitialize(anaconda): if os.path.exists("/dev/live") and \ stat.S_ISBLK(os.stat("/dev/live")[stat.ST_MODE]): target = os.readlink("/dev/live") - storage.protectedPartitions = [target] + storage.protectedDevSpecs = [target] storage.reset() elif anaconda.methodstr and anaconda.methodstr.startswith("hd:"): method = anaconda.methodstr[3:] devspec = method.split(":", 3)[0] - - for entry in udev_get_block_devices(): - if devspec.startswith("LABEL=") and udev_device_get_label(entry) == devspec[6:]: - storage.protectedPartitions = [udev_device_get_name(entry)] - break - elif devspec.startswith("UUID=") and udev_device_get_uuid(entry) == devspec[5:]: - storage.protectedPartitions = [udev_device_get_name(entry)] - break - elif udev_device_get_name(entry) == devicePathToName(devspec): - storage.protectedPartitions = [udev_device_get_name(entry)] - break - + storage.protectedDevSpecs.append(devspec) storage.reset() - if not storage.protectedPartitions or not storage.devicetree.getDeviceByName(storage.protectedPartitions[0]): + if not storage.protectedDevices: if anaconda.id.getUpgrade(): return else: @@ -209,7 +198,7 @@ class Storage(object): self.encryptionRetrofit = False self.reinitializeDisks = False self.zeroMbr = None - self.protectedPartitions = [] + self.protectedDevSpecs = [] self.autoPartitionRequests = [] self.__luksDevs = {} @@ -228,7 +217,7 @@ class Storage(object): type=self.clearPartType, clear=self.clearPartDisks, reinitializeDisks=self.reinitializeDisks, - protected=self.protectedPartitions, + protected=self.protectedDevSpecs, zeroMbr=self.zeroMbr, passphrase=self.encryptionPassphrase, luksDict=self.__luksDevs) @@ -292,7 +281,7 @@ class Storage(object): type=clearPartType, clear=self.clearPartDisks, reinitializeDisks=self.reinitializeDisks, - protected=self.protectedPartitions, + protected=self.protectedDevSpecs, zeroMbr=self.zeroMbr, passphrase=self.encryptionPassphrase, luksDict=self.__luksDevs) @@ -449,6 +438,13 @@ class Storage(object): swaps.sort(key=lambda d: d.name) return swaps + @property + def protectedDevices(self): + devices = self.devicetree.devices.values() + protected = [d for d in devices if d.protected] + protected.sort(key=lambda d: d.name) + return protected + def exceptionDisks(self): """ Return a list of removable devices to save exceptions to. diff --git a/storage/devices.py b/storage/devices.py index 59ec7c1..c2d4ec9 100644 --- a/storage/devices.py +++ b/storage/devices.py @@ -429,6 +429,8 @@ class StorageDevice(Device): self.sysfsPath = sysfsPath self.exists = exists + self.protected = False + # this may be handy for disk, dmraid, mpath, mdraid self.diskLabel = None diff --git a/storage/devicetree.py b/storage/devicetree.py index 8668ebd..23504c6 100644 --- a/storage/devicetree.py +++ b/storage/devicetree.py @@ -200,7 +200,13 @@ class DeviceTree(object): self.clearPartDisks = clear self.zeroMbr = zeroMbr self.reinitializeDisks = reinitializeDisks - self.protectedPartitions = protected + + # protected device specs as provided by the user + self.protectedDevSpecs = protected + + # names of protected devices at the time of tree population + self.protectedDevNames = [] + self.__passphrase = passphrase self.__luksDevs = {} if luksDict and isinstance(luksDict, dict): @@ -1157,8 +1163,7 @@ class DeviceTree(object): # was specified if not self.clearPartDisks or name in self.clearPartDisks: initlabel = self.reinitializeDisks - - for protected in self.protectedPartitions: + for protected in self.protectedDevNames: _p = "/sys/%s/%s" % (sysfs_path, protected) if os.path.exists(os.path.normpath(_p)): initlabel = False @@ -1267,6 +1272,12 @@ class DeviceTree(object): if device is None: device = self.addUdevPartitionDevice(info) + # If this device is protected, mark it as such now. Once the tree + # has been populated, devices' protected attribute is how we will + # identify protected devices. + if device.name in self.protectedDevNames: + device.protected = True + # now handle the device's formatting self.handleUdevDeviceFormat(info, device) @@ -1490,7 +1501,7 @@ class DeviceTree(object): # we will not wipe the disklabel even if # clearpart --initlabel was specified initlabel = self.reinitializeDisks - for protected in self.protectedPartitions: + for protected in self.protectedDevNames: disk_name = re.sub(r'p\d+$', '', protected) if disk_name != protected and \ disk_name == rs.name: @@ -1733,6 +1744,12 @@ class DeviceTree(object): def populate(self): """ Locate all storage devices. """ + # resolve the protected device specs to device names + for spec in self.protectedDevSpecs: + name = udev_resolve_devspec(spec) + if name: + self.protectedDevNames.append(name) + # each iteration scans any devices that have appeared since the # previous iteration old_devices = []
_______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list