[master 1/6] Make mountsCache store subvolspec as a str if not None.

mulkieran installerbot-noreply at redhat.com
Wed May 6 15:03:51 UTC 2015


From: mulhern <amulhern at redhat.com>

Externally to the mountsCache it seems that sometimes the subvolspec is
a str, sometimes an int. Make mountsCache store and retrieve treating
subvolspec always as a str.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/mounts.py | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/blivet/mounts.py b/blivet/mounts.py
index 617ca21..af45c7e 100644
--- a/blivet/mounts.py
+++ b/blivet/mounts.py
@@ -21,6 +21,7 @@
 #
 from collections import defaultdict
 from . import util
+from .devicelibs import btrfs
 
 import logging
 log = logging.getLogger("blivet")
@@ -40,7 +41,7 @@ def getMountpoints(self, devspec, subvolspec=None):
             :param devscpec: device specification, eg. "/dev/vda1"
             :type devspec: str
             :param subvolspec: btrfs subvolume specification, eg. ID or name
-            :type subvolspec: str
+            :type subvolspec: object (may be NoneType)
             :returns: list of mountpoints (path)
             :rtype: list of str or empty list
 
@@ -50,6 +51,9 @@ def getMountpoints(self, devspec, subvolspec=None):
         """
         self._cacheCheck()
 
+        if subvolspec is not None:
+            subvolspec = str(subvolspec)
+
         return self.mountpoints[(devspec, subvolspec)]
 
     def isMountpoint(self, path):
@@ -61,6 +65,23 @@ def isMountpoint(self, path):
 
         return any(path in p for p in self.mountpoints.values())
 
+    def _getSubvolSpec(self, devspec, mountpoint):
+        """ Get the subvolume specification for this btrfs volume.
+
+            :param str devspec: the device specification
+            :param str mountpoint: the mountpoint
+
+            :returns: the subvolume specification, 5 for a top-level volume
+            :rtype: str or NoneType
+        """
+        for line in open("/proc/self/mountinfo").readlines():
+            fields = line.split()
+            if fields[4] == mountpoint and fields[9] == devspec:
+                # empty _subvol[1:] means it is a top-level volume
+                subvolspec = fields[3]
+                return subvolspec[1:] or str(btrfs.MAIN_VOLUME_ID)
+        return None
+
     def _getActiveMounts(self):
         """ Get information about mounted devices from /proc/mounts and
             /proc/self/mountinfo
@@ -76,18 +97,11 @@ def _getActiveMounts(self):
                 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:
-                        # empty _subvol[1:] means it is a top-level volume
-                        subvolspec = _subvol[1:] or 5
-
-                        self.mountpoints[(devspec, subvolspec)].append(mountpoint)
-
+                subvolspec = self._getSubvolSpec(devspec, mountpoint)
+                if subvolspec is not None:
+                    self.mountpoints[(devspec, subvolspec)].append(mountpoint)
+                else:
+                    log.error("failed to obtain subvolspec for btrfs device %s", devspec)
             else:
                 self.mountpoints[(devspec, None)].append(mountpoint)
 


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/e9f298428f0bd6b3c87d7e00bc79a631ec573e90


More information about the anaconda-patches mailing list