[PATCH 2/2] Create and use unique ids for Device instances. (#500808)

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

 



The use of a unique id frees us from having to worry about parted renaming
partitions whenever we remove one. It will also provide a mechanism with
which we can more reliably track protected partitions, currently
problematic for the same reason.
---
 iw/partition_dialog_gui.py |    2 +-
 storage/devices.py         |   14 ++++++++++++--
 storage/devicetree.py      |   37 +++++++++++++++++++++----------------
 3 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/iw/partition_dialog_gui.py b/iw/partition_dialog_gui.py
index 45748c2..8e0161e 100644
--- a/iw/partition_dialog_gui.py
+++ b/iw/partition_dialog_gui.py
@@ -271,7 +271,7 @@ class PartitionEditor:
                     elif not self.fsoptionsDict["formatcb"].get_active():
                         creates = devicetree.findActions(type="create",
                                                          object="format",
-                                                         path=usedev.path)
+                                                         devid=usedev.id)
                         for action in creates:
                             devicetree.cancelAction(action)
 
diff --git a/storage/devices.py b/storage/devices.py
index 7d0e36e..b5e32af 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -176,6 +176,10 @@ class Device(object):
         before destroying the device itself.
 
     """
+
+    # This is a counter for generating unique ids for Devices.
+    _id = 0
+
     _type = "generic device"
     _packages = []
 
@@ -201,6 +205,10 @@ class Device(object):
         self.kids = 0
         self.description = description
 
+        # Set this instance's id and increment the counter.
+        self.id = Device._id
+        Device._id += 1
+
         for parent in self.parents:
             parent.addChild()
 
@@ -227,10 +235,12 @@ class Device(object):
         s = ("%(type)s instance (%(id)s) --\n"
              "  description = %(descr)s  name = %(name)s  status = %(status)s"
              "  parents = %(parents)s\n"
-             "  kids = %(kids)s\n" %
+             "  kids = %(kids)s\n"
+             "  id = %(dev_id)s\n" %
              {"type": self.__class__.__name__, "id": "%#x" % id(self),
               "name": self.name, "parents": self.parents, "kids": self.kids,
-              "descr": self.description, "status": self.status})
+              "descr": self.description, "status": self.status,
+              "dev_id": self.id})
         return s
 
     def writeKS(self, f, preexisting=False, noformat=False, s=None):
diff --git a/storage/devicetree.py b/storage/devicetree.py
index 63fc18b..f026348 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -226,11 +226,11 @@ class DeviceTree(object):
                 continue
 
             log.debug("action '%s' (%s)" % (a, id(a)))
-            destroys = self.findActions(path=a.device.path,
+            destroys = self.findActions(devid=a.device.id,
                                         type="destroy",
                                         object="device")
 
-            creates = self.findActions(path=a.device.path,
+            creates = self.findActions(devid=a.device.id,
                                        type="create",
                                        object="device")
 
@@ -282,11 +282,11 @@ class DeviceTree(object):
                 continue
 
             log.debug("action '%s' (%s)" % (a, id(a)))
-            creates = self.findActions(path=a.device.path,
+            creates = self.findActions(devid=a.device.id,
                                        type="create",
                                        object="device")
 
-            destroys = self.findActions(path=a.device.path,
+            destroys = self.findActions(devid=a.device.id,
                                         type="destroy",
                                         object="device")
 
@@ -318,7 +318,7 @@ class DeviceTree(object):
 
             # remove all actions on this from after the first destroy up
             # to the last create
-            dev_actions = self.findActions(path=a.device.path)
+            dev_actions = self.findActions(devid=a.device.id)
             for rem in dev_actions:
                 if rem == stop_action:
                     break
@@ -337,7 +337,7 @@ class DeviceTree(object):
                 continue
 
             log.debug("action '%s' (%s)" % (a, id(a)))
-            loops = self.findActions(path=a.device.path,
+            loops = self.findActions(devid=a.device.id,
                                      type="resize",
                                      object="device")
 
@@ -359,11 +359,11 @@ class DeviceTree(object):
                 continue
 
             log.debug("action '%s' (%s)" % (a, id(a)))
-            destroys = self.findActions(path=a.device.path,
+            destroys = self.findActions(devid=a.device.id,
                                         type="destroy",
                                         object="format")
 
-            creates = self.findActions(path=a.device.path,
+            creates = self.findActions(devid=a.device.id,
                                        type="create",
                                        object="format")
 
@@ -396,7 +396,7 @@ class DeviceTree(object):
 
             # now we remove all actions on this device's format between
             # the start index (into self._actions) and stop_action.
-            dev_actions = self.findActions(path=a.device.path,
+            dev_actions = self.findActions(devid=a.device.id,
                                            object="format")
             for rem in dev_actions:
                 end = self._actions.index(stop_action)
@@ -417,11 +417,11 @@ class DeviceTree(object):
                 continue
 
             log.debug("action '%s' (%s)" % (a, id(a)))
-            creates = self.findActions(path=a.device.path,
+            creates = self.findActions(devid=a.device.id,
                                        type="create",
                                        object="format")
 
-            destroys = self.findActions(path=a.device.path,
+            destroys = self.findActions(devid=a.device.id,
                                         type="destroy",
                                         object="format")
 
@@ -453,7 +453,7 @@ class DeviceTree(object):
 
             # remove all actions on this from after the first destroy up
             # to the last create
-            dev_actions = self.findActions(path=a.device.path,
+            dev_actions = self.findActions(devid=a.device.id,
                                            object="format")
             for rem in dev_actions:
                 if rem == stop_action:
@@ -473,7 +473,7 @@ class DeviceTree(object):
                 continue
 
             log.debug("action '%s' (%s)" % (a, id(a)))
-            loops = self.findActions(path=a.device.path,
+            loops = self.findActions(devid=a.device.id,
                                      type="resize",
                                      object="format")
 
@@ -495,7 +495,7 @@ class DeviceTree(object):
                 continue
 
             log.debug("action '%s' (%s)" % (a, id(a)))
-            loops = self.findActions(path=a.device.path,
+            loops = self.findActions(devid=a.device.id,
                                      type="migrate",
                                      object="format")
 
@@ -783,7 +783,8 @@ class DeviceTree(object):
 
         self._actions.remove(action)
 
-    def findActions(self, device=None, type=None, object=None, path=None):
+    def findActions(self, device=None, type=None, object=None, path=None,
+                    devid=None):
         """ Find all actions that match all specified parameters.
 
             Keyword arguments:
@@ -794,7 +795,8 @@ class DeviceTree(object):
                 path -- device path to match (string, or None to match any)
 
         """
-        if device is None and type is None and object is None and path is None:
+        if device is None and type is None and object is None and \
+           path is None and devid is None:
             return self._actions[:]
 
         # convert the string arguments to the types used in actions
@@ -814,6 +816,9 @@ class DeviceTree(object):
 
             if path is not None and action.device.path != path:
                 continue
+
+            if devid is not None and action.device.id != devid:
+                continue
                 
             actions.append(action)
 
-- 
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