From ba9d9f3dc7d37884d63812f1c6bc27f8448066ee Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Tue, 17 Sep 2013 15:58:05 -0500
Subject: [PATCH 3/6] Move getActiveMounts from Blivet into DeviceTree.

---
 blivet/__init__.py   | 54 +---------------------------------------------------
 blivet/devicetree.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/blivet/__init__.py b/blivet/__init__.py
index bdd1200..b4a32e9 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -71,7 +71,6 @@ from deviceaction import *
 from formats import getFormat
 from formats import get_device_format_class
 from formats import get_default_filesystem_type
-from formats.fs import nodev_filesystems
 import devicefactory
 from devicelibs.dm import name_from_dm_node
 from devicelibs.crypto import generateBackupPassphrase
@@ -435,7 +434,7 @@ class Blivet(object):
             self.dumpState("initial")
 
         if not flags.installer_mode:
-            self.getActiveMounts()
+            self.devicetree.getActiveMounts()
 
         self.updateBootLoaderDiskList()
 
@@ -1788,57 +1787,6 @@ class Blivet(object):
         log.debug("finished Blivet copy")
         return new
 
-    def getActiveMounts(self):
-        """ Reflect active mounts in the appropriate devices' formats. """
-        log.info("collecting information about active mounts")
-        for line in open("/proc/mounts").readlines():
-            try:
-                (devspec, mountpoint, fstype, options, rest) = line.split(None,
-                                                                          4)
-            except IndexError:
-                log.error("failed to parse /proc/mounts line: %s" % line)
-                continue
-
-            if fstype == "btrfs":
-                # get the subvol name from /proc/self/mountinfo
-                for line in open("/proc/self/mountinfo").readlines():
-                    fields = line.split()
-                    _subvol = fields[3]
-                    _mountpoint = fields[4]
-                    _devspec = fields[9]
-                    if _mountpoint == mountpoint and _devspec == devspec:
-                        log.debug("subvol %s" % _subvol)
-                        options += ",subvol=%s" % _subvol[1:]
-
-            if fstype in nodev_filesystems:
-                if not flags.include_nodev:
-                    continue
-
-                log.info("found nodev %s filesystem mounted at %s"
-                            % (fstype, mountpoint))
-                # nodev filesystems require some special handling.
-                # For now, a lot of this is based on the idea that it's a losing
-                # battle to require the presence of an FS class for every type
-                # of nodev filesystem. Based on that idea, we just instantiate
-                # NoDevFS directly and then hack in the fstype as the device
-                # attribute.
-                fmt = getFormat("nodev")
-                fmt.device = fstype
-
-                # NoDevice also needs some special works since they don't have
-                # per-instance names in the kernel.
-                device = NoDevice(format=fmt)
-                n = len([d for d in self.devices if d.format.type == fstype])
-                device._name += ".%d" % n
-                self.devicetree._addDevice(device)
-                devspec = device.name
-
-            device = self.devicetree.resolveDevice(devspec, options=options)
-            if device is not None:
-                device.format.mountpoint = mountpoint   # for future mounts
-                device.format._mountpoint = mountpoint  # active mountpoint
-                device.format.mountopts = options
-
     def updateKSData(self):
         """ Update ksdata to reflect the settings of this Blivet instance. """
         if not self.ksdata or not self.mountpoints:
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 39e756c..0770840 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -33,6 +33,7 @@ from devices import *
 from deviceaction import *
 from pykickstart.constants import *
 import formats
+from formats.fs import nodev_filesystems
 import devicelibs.mdraid
 import devicelibs.dm
 import devicelibs.lvm
@@ -2327,3 +2328,54 @@ class DeviceTree(object):
         else:
             log.debug("failed to resolve '%s'" % devspec)
         return device
+
+    def getActiveMounts(self):
+        """ Reflect active mounts in the appropriate devices' formats. """
+        log.info("collecting information about active mounts")
+        for line in open("/proc/mounts").readlines():
+            try:
+                (devspec, mountpoint, fstype, options, rest) = line.split(None,
+                                                                          4)
+            except IndexError:
+                log.error("failed to parse /proc/mounts line: %s" % line)
+                continue
+
+            if fstype == "btrfs":
+                # get the subvol name from /proc/self/mountinfo
+                for line in open("/proc/self/mountinfo").readlines():
+                    fields = line.split()
+                    _subvol = fields[3]
+                    _mountpoint = fields[4]
+                    _devspec = fields[9]
+                    if _mountpoint == mountpoint and _devspec == devspec:
+                        log.debug("subvol %s" % _subvol)
+                        options += ",subvol=%s" % _subvol[1:]
+
+            if fstype in nodev_filesystems:
+                if not flags.include_nodev:
+                    continue
+
+                log.info("found nodev %s filesystem mounted at %s"
+                            % (fstype, mountpoint))
+                # nodev filesystems require some special handling.
+                # For now, a lot of this is based on the idea that it's a losing
+                # battle to require the presence of an FS class for every type
+                # of nodev filesystem. Based on that idea, we just instantiate
+                # NoDevFS directly and then hack in the fstype as the device
+                # attribute.
+                fmt = getFormat("nodev")
+                fmt.device = fstype
+
+                # NoDevice also needs some special works since they don't have
+                # per-instance names in the kernel.
+                device = NoDevice(format=fmt)
+                n = len([d for d in self.devices if d.format.type == fstype])
+                device._name += ".%d" % n
+                self._addDevice(device)
+                devspec = device.name
+
+            device = self.resolveDevice(devspec, options=options)
+            if device is not None:
+                device.format.mountpoint = mountpoint   # for future mounts
+                device.format._mountpoint = mountpoint  # active mountpoint
+                device.format.mountopts = options
-- 
1.8.1.4

