[master 30/30] Use fsmount tasks for mounting.
mulkieran
installerbot-noreply at redhat.com
Fri Apr 10 19:49:58 UTC 2015
From: mulhern <amulhern at redhat.com>
Related: #12
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/formats/fs.py | 84 +++++++++--------------------------------
tests/formats_test/fstesting.py | 2 +-
2 files changed, 18 insertions(+), 68 deletions(-)
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 777e746..cea686d 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -30,6 +30,7 @@
from ..tasks import fsinfo
from ..tasks import fslabeling
from ..tasks import fsmkfs
+from ..tasks import fsmount
from ..tasks import fsreadlabel
from ..tasks import fssize
from ..tasks import fssync
@@ -65,11 +66,11 @@ class FS(DeviceFormat):
_fsckClass = None # fsck
_infoClass = None
_mkfsClass = None # mkfs
+ _mountClass = fsmount.FSMount # default class for most filesystems
_readlabelClass = None # read label
_sizeinfoClass = None # get current size
_syncClass = None # sync the filesystem
_writelabelClass = None # write label after creation
- _defaultMountOptions = ["defaults"] # default options passed to mount
_resizefsUnit = None
def __init__(self, **kwargs):
@@ -107,6 +108,7 @@ def getTaskObject(klass):
self._info = getTaskObject(self._infoClass)
self._fsck = getTaskObject(self._fsckClass)
self._mkfs = getTaskObject(self._mkfsClass)
+ self._mount = getTaskObject(self._mountClass)
self._readlabel = getTaskObject(self._readlabelClass)
self._sizeinfo = getTaskObject(self._sizeinfoClass)
self._sync = getTaskObject(self._syncClass)
@@ -511,8 +513,8 @@ def mount(self, options="", chroot="/", mountpoint=None):
:keyword mountpoint: mountpoint (overrides self.mountpoint)
:raises: FSError
"""
- if not self.exists:
- raise FSError("filesystem has not been created")
+ if self.status:
+ return
if not mountpoint:
mountpoint = self.mountpoint
@@ -520,12 +522,6 @@ def mount(self, options="", chroot="/", mountpoint=None):
if not mountpoint:
raise FSError("no mountpoint given")
- if self.status:
- return
-
- if not isinstance(self, NoDevFS) and not os.path.exists(self.device):
- raise FSError("device %s does not exist" % self.device)
-
# XXX os.path.join is FUBAR:
#
# os.path.join("/mnt/foo", "/") -> "/"
@@ -533,22 +529,7 @@ def mount(self, options="", chroot="/", mountpoint=None):
#mountpoint = os.path.join(chroot, mountpoint)
chrootedMountpoint = os.path.normpath("%s/%s" % (chroot, mountpoint))
- # passed in options override default options
- if not options or not isinstance(options, str):
- options = self.options
-
- if isinstance(self, BindFS):
- options = "bind," + options
-
- try:
- rc = util.mount(self.device, chrootedMountpoint,
- fstype=self.mountType,
- options=options)
- except Exception as e:
- raise FSError("mount failed: %s" % e)
-
- if rc:
- raise FSError("mount failed: %s" % rc)
+ options = self._mount.doTask(chrootedMountpoint, options=options)
if flags.selinux and "ro" not in options.split(",") and flags.installer_mode:
ret = util.reset_file_context(mountpoint, chroot)
@@ -655,34 +636,15 @@ def supported(self):
@property
def mountable(self):
- canmount = (self.mountType in kernel_filesystems) or \
- (os.access("/sbin/mount.%s" % (self.mountType,), os.X_OK))
-
- # Still consider the filesystem type mountable if there exists
- # an appropriate filesystem driver in the kernel modules directory.
- if not canmount:
- modpath = os.path.realpath(os.path.join("/lib/modules", os.uname()[2]))
- if os.path.isdir(modpath):
- modname = "%s.ko" % self.mountType
- for _root, _dirs, files in os.walk(modpath):
- if any(x.startswith(modname) for x in files):
- return True
-
- return canmount
+ return not self._mount.unavailable
@property
def resizable(self):
""" Can formats of this filesystem type be resized? """
return super(FS, self).resizable and self.utilsAvailable
- @property
- def defaultMountOptions(self):
- """ Default options passed to mount for this filesystem type. """
- # return a copy to prevent modification
- return self._defaultMountOptions[:]
-
def _getOptions(self):
- return self.mountopts or ",".join(self.defaultMountOptions)
+ return self.mountopts or ",".join(self._mount.options)
def _setOptions(self, options):
self.mountopts = options
@@ -903,9 +865,9 @@ class FATFS(FS):
_packages = [ "dosfstools" ]
_fsckClass = fsck.DosFSCK
_mkfsClass = fsmkfs.FATFSMkfs
+ _mountClass = fsmount.FATFSMount
_readlabelClass = fsreadlabel.DosFSReadLabel
_writelabelClass = fswritelabel.DosFSWriteLabel
- _defaultMountOptions = ["umask=0077", "shortname=winnt"]
# FIXME this should be fat32 in some cases
partedSystem = fileSystemType["fat16"]
@@ -1146,11 +1108,11 @@ class NTFS(FS):
_resizable = True
_minSize = Size("1 MiB")
_maxSize = Size("16 TiB")
- _defaultMountOptions = ["defaults", "ro"]
_packages = ["ntfsprogs"]
_fsckClass = fsck.NTFSFSCK
_infoClass = fsinfo.NTFSInfo
_mkfsClass = fsmkfs.NTFSMkfs
+ _mountClass = fsmount.NTFSMount
_readlabelClass = fsreadlabel.NTFSReadLabel
_sizeinfoClass = fssize.NTFSSize
_writelabelClass = fswritelabel.NTFSWriteLabel
@@ -1220,16 +1182,13 @@ class NFS(FS):
""" NFS filesystem. """
_type = "nfs"
_modules = ["nfs"]
+ _mountClass = fsmount.NFSMount
def _deviceCheck(self, devspec):
if devspec is not None and ":" not in devspec:
return "device must be of the form <host>:<path>"
return None
- @property
- def mountable(self):
- return False
-
register_device_format(NFS)
@@ -1245,7 +1204,7 @@ class Iso9660FS(FS):
""" ISO9660 filesystem. """
_type = "iso9660"
_supported = True
- _defaultMountOptions = ["ro"]
+ _mountClass = fsmount.Iso9660FSMount
register_device_format(Iso9660FS)
@@ -1253,6 +1212,7 @@ class Iso9660FS(FS):
class NoDevFS(FS):
""" nodev filesystem base class """
_type = "nodev"
+ _mountClass = fsmount.NoDevFSMount
def __init__(self, **kwargs):
FS.__init__(self, **kwargs)
@@ -1280,7 +1240,7 @@ def notifyKernel(self):
class DevPtsFS(NoDevFS):
""" devpts filesystem. """
_type = "devpts"
- _defaultMountOptions = ["gid=5", "mode=620"]
+ _mountClass = fsmount.DevPtsFSMount
register_device_format(DevPtsFS)
@@ -1313,6 +1273,7 @@ class TmpFS(NoDevFS):
# once mounted
_formattable = True
_sizeinfoClass = fssize.TmpFSSize
+ _mountClass = fsmount.TmpFSMount
def __init__(self, **kwargs):
NoDevFS.__init__(self, **kwargs)
@@ -1345,10 +1306,6 @@ def destroy(self, *args, **kwargs):
"""
pass
- @property
- def mountable(self):
- return True
-
def _sizeOption(self, size):
""" Returns a size option string appropriate for mounting tmpfs.
@@ -1426,20 +1383,14 @@ def doResize(self):
class BindFS(FS):
_type = "bind"
-
- @property
- def mountable(self):
- return True
+ _mountClass = fsmount.BindFSMount
register_device_format(BindFS)
class SELinuxFS(NoDevFS):
_type = "selinuxfs"
-
- @property
- def mountable(self):
- return flags.selinux and super(SELinuxFS, self).mountable
+ _mountClass = fsmount.SELinuxFSMount
register_device_format(SELinuxFS)
@@ -1448,4 +1399,3 @@ class USBFS(NoDevFS):
_type = "usbfs"
register_device_format(USBFS)
-
diff --git a/tests/formats_test/fstesting.py b/tests/formats_test/fstesting.py
index 600726e..6239c54 100644
--- a/tests/formats_test/fstesting.py
+++ b/tests/formats_test/fstesting.py
@@ -82,7 +82,7 @@ def testInstantiation(self):
self.assertFalse(an_fs.exists)
self.assertIsNone(an_fs.device)
self.assertIsNone(an_fs.uuid)
- self.assertEqual(an_fs.options, ",".join(an_fs.defaultMountOptions))
+ self.assertEqual(an_fs.options, ",".join(an_fs._mount.options))
self.assertEqual(an_fs.resizable, False)
# sizes
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/dc28fb95723f8ebcd40988a9c6dd96586d7ba5ae
More information about the anaconda-patches
mailing list