commit a2d208935d70e5ad3d147cc32828a8a9ea941e89
Author: David Lehman <dlehman@redhat.com>
Date:   Tue Oct 25 14:52:28 2011 -0500

    Move detection of live backing device into Anaconda.protected.
    
    This uses the same code for live and non-live installs. If the
    backing device is a partition, we also protect the disk it is on.

diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 2e06346..c196951 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -161,16 +161,32 @@ class Anaconda(object):
 
     @property
     def protected(self):
-        import stat
-
-        if os.path.exists("/dev/live") and \
-           stat.S_ISBLK(os.stat("/dev/live")[stat.ST_MODE]):
-            return [os.readlink("/dev/live")]
-        elif self.methodstr and self.methodstr.startswith("hd:"):
-            method = self.methodstr[3:]
-            return [method.split(":", 3)[0]]
-        else:
-            return []
+        specs = []
+        root_info = "/run/initramfs/tmp/root.info"
+        if os.path.exists(root_info):
+            prefix = "root='"
+            for line in open(root_info):
+                if not line.startswith(prefix) or \
+                   (line[6:12] != "block:" and line[6:11] != "live:"):
+                    continue
+
+                start_idx = line.index(":") + 1
+                root = line[start_idx:-1]
+                specs.append(root)
+
+                # if the backing device is a partition, also add the disk
+                root_name = os.path.basename(os.path.realpath(root))
+                root_sys_dir = "/sys/class/block/%s" % root_name
+                if not os.path.exists(root_sys_dir + "/partition"):
+                    continue
+
+                disk_name = os.path.realpath(root_sys_dir).split("/")[-2]
+                specs.append("/dev/" + disk_name)
+
+        if self.methodstr and self.methodstr.startswith("hd:"):
+            specs.append(self.methodstr[3:].split(":", 3)[0])
+
+        return specs
 
     @property
     def users(self):
diff --git a/pyanaconda/storage/devicetree.py b/pyanaconda/storage/devicetree.py
index 27827f2..4296d2a 100644
--- a/pyanaconda/storage/devicetree.py
+++ b/pyanaconda/storage/devicetree.py
@@ -1016,47 +1016,11 @@ class DeviceTree(object):
             log.error("Unknown block device type for: %s" % name)
             return
 
-        def get_live_backing_device_path():
-            """ Return a path to the live block device or an empty string.
-
-                The line we're looking for will be of the form
-
-                    root='block:/dev/disk/by-uuid/<UUID>'
-
-            """
-            root_info = "/run/initramfs/tmp/root.info"
-            dev_live = "/dev/live"
-            root_path = ""
-            if os.path.exists(dev_live):
-                root_path = os.readlink(dev_live)
-            elif os.path.exists(root_info):
-                prefix = "root='block:"
-                for line in open(root_info):
-                    if not line.startswith(prefix):
-                        continue
-
-                    start_idx = len(prefix) - 1
-                    root_path = os.path.realpath(line[start_idx:-1])
-                    root_name = devicePathToName(root_path)
-                    if root_name.startswith("dm-"):
-                        root_name = dm.name_from_dm_node(root_name)
-                        root_path = "/dev/mapper/%s" % root_name
-
-                    break
-
-            return root_path
-
         # 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 and device.name in self.protectedDevNames:
             device.protected = True
-            # if this is the live backing device we want to mark its parents
-            # as protected also
-            live_path = get_live_backing_device_path()
-            if live_path and device.path == live_path:
-                for parent in device.parents:
-                    parent.protected = True
 
         # Don't try to do format handling on drives without media or
         # if we didn't end up with a device somehow.
@@ -1856,16 +1820,6 @@ class DeviceTree(object):
             if name:
                 self.protectedDevNames.append(name)
 
-        # FIXME: the backing dev for the live image can't be used as an
-        # install target.  note that this is a little bit of a hack
-        # since we're assuming that /dev/live will exist
-        if os.path.exists("/dev/live") and \
-           stat.S_ISBLK(os.stat("/dev/live")[stat.ST_MODE]):
-            livetarget = devicePathToName(os.path.realpath("/dev/live"))
-            log.info("%s looks to be the live device; marking as protected"
-                     % (livetarget,))
-            self.protectedDevNames.append(livetarget)
-
         cfg = self.__multipathConfigWriter.write(self.mpathFriendlyNames)
         with open("/etc/multipath.conf", "w+") as mpath_cfg:
             mpath_cfg.write(cfg)
