Skip to content

Commit

Permalink
Make mountsCache store subvolspec as a str if not None.
Browse files Browse the repository at this point in the history
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@redhat.com>
  • Loading branch information
mulkieran committed May 6, 2015
1 parent 0e3263d commit e9f2984
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions blivet/mounts.py
Expand Up @@ -21,6 +21,7 @@
#
from collections import defaultdict
from . import util
from .devicelibs import btrfs

import logging
log = logging.getLogger("blivet")
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit e9f2984

Please sign in to comment.