[master 22/30] Use mkfs task to make filesystem.

mulkieran installerbot-noreply at redhat.com
Wed Mar 25 22:48:00 UTC 2015


From: mulhern <amulhern at redhat.com>

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/fs.py | 93 +++++++++++++---------------------------------------
 1 file changed, 23 insertions(+), 70 deletions(-)

diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 3615e11..2ac8885 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -29,10 +29,12 @@
 from ..tasks import fsck
 from ..tasks import fsinfo
 from ..tasks import fslabeling
+from ..tasks import fsmkfs
 from ..tasks import fsreadlabel
 from ..tasks import fssync
 from ..tasks import fswritelabel
-from ..errors import FormatCreateError, FSError, FSReadLabelError, FSResizeError
+from ..errors import FormatCreateError, FSError, FSReadLabelError
+from ..errors import FSWriteLabelError, FSResizeError
 from . import DeviceFormat, register_device_format
 from .. import util
 from .. import platform
@@ -56,20 +58,18 @@ class FS(DeviceFormat):
     _type = "Abstract Filesystem Class"  # fs type name
     _mountType = None                    # like _type but for passing to mount
     _name = None
-    _mkfs = ""                           # mkfs utility
     _modules = []                        # kernel modules required for support
     _resizefs = ""                       # resize utility
     _labelfs = None                      # labeling functionality
     _fsckClass = None                    # fsck
     _infoClass = None
+    _mkfsClass = None                    # mkfs
     _readlabelClass = None               # read label
     _syncClass = None                    # sync the filesystem
     _writelabelClass = None              # write label after creation
-    _defaultFormatOptions = []           # default options passed to mkfs
     _defaultMountOptions = ["defaults"]  # default options passed to mount
     _existingSizeFields = []
     _resizefsUnit = None
-    _fsProfileSpecifier = None           # mkfs option specifying fsprofile
 
     def __init__(self, **kwargs):
         """
@@ -105,6 +105,7 @@ def getTaskObject(klass):
         # Create task objects
         self._info = getTaskObject(self._infoClass)
         self._fsck = getTaskObject(self._fsckClass)
+        self._mkfs = getTaskObject(self._mkfsClass)
         self._readlabel = getTaskObject(self._readlabelClass)
         self._sync = getTaskObject(self._syncClass)
         self._writelabel = getTaskObject(self._writelabelClass)
@@ -373,30 +374,6 @@ def free(self):
         """
         return max(Size(0), self.currentSize - self.minSize)
 
-    def _getFormatOptions(self, options=None, do_labeling=False):
-        """Get a list of format options to be used when creating the
-           filesystem.
-
-           :param options: any special options
-           :type options: list of str or None
-           :param bool do_labeling: True if labeling during filesystem creation,
-             otherwise False
-        """
-        argv = []
-        if options and isinstance(options, list):
-            argv.extend(options)
-        argv.extend(self.defaultFormatOptions)
-        if self._fsProfileSpecifier and self.fsprofile:
-            argv.extend([self._fsProfileSpecifier, self.fsprofile])
-
-        if do_labeling and self.label is not None:
-            if self.labelFormatOK(self.label):
-                argv.extend(self._labelfs.labelingArgs(self.label))
-            else:
-                log.warning("Choosing not to apply label (%s) during creation of filesystem %s. Label format is unacceptable for this filesystem.", self.label, self.type)
-
-        argv.append(self.device)
-        return argv
 
     def doFormat(self, options=None):
         """ Create the filesystem.
@@ -408,29 +385,16 @@ def doFormat(self, options=None):
         log_method_call(self, type=self.mountType, device=self.device,
                         mountpoint=self.mountpoint)
 
-        if self.exists:
-            raise FormatCreateError("filesystem already exists", self.device)
-
-        if not self.formattable:
-            return
-
-        if not self.mkfsProg:
+        if not self._mkfs:
             return
 
-        if not os.path.exists(self.device):
-            raise FormatCreateError("device does not exist", self.device)
-
-        argv = self._getFormatOptions(options=options,
-           do_labeling=not self.relabels())
-
         try:
-            ret = util.run_program([self.mkfsProg] + argv)
-        except OSError as e:
+            self._mkfs.doTask(options=options, label=not self.relabels())
+        except FSWriteLabelError as e:
+            log.warning("Choosing not to apply label (%s) during creation of filesystem %s. Label format is unacceptable for this filesystem.", self.label, self.type)
+        except FSError as e:
             raise FormatCreateError(e, self.device)
 
-        if ret:
-            raise FormatCreateError("format failed: %s" % ret, self.device)
-
         self.exists = True
         self.notifyKernel()
 
@@ -712,7 +676,7 @@ def writeLabel(self):
     @property
     def mkfsProg(self):
         """ Program used to create filesystems of this type. """
-        return self._mkfs
+        return self._mkfs.app_name if self._mkfs else None
 
     @property
     def resizefsProg(self):
@@ -777,12 +741,6 @@ def resizable(self):
         return super(FS, self).resizable and self.utilsAvailable
 
     @property
-    def defaultFormatOptions(self):
-        """ Default options passed to mkfs for this filesystem type. """
-        # return a copy to prevent modification
-        return self._defaultFormatOptions[:]
-
-    @property
     def defaultMountOptions(self):
         """ Default options passed to mount for this filesystem type. """
         # return a copy to prevent modification
@@ -882,7 +840,6 @@ def populateKSData(self, data):
 class Ext2FS(FS):
     """ ext2 filesystem. """
     _type = "ext2"
-    _mkfs = "mke2fs"
     _modules = ["ext2"]
     _resizefs = "resize2fs"
     _labelfs = fslabeling.Ext2FSLabeling()
@@ -896,11 +853,11 @@ class Ext2FS(FS):
     _check = True
     _fsckClass = fsck.Ext2FSCK
     _infoClass = fsinfo.Ext2FSInfo
+    _mkfsClass = fsmkfs.Ext2FSMkfs
     _readlabelClass = fsreadlabel.Ext2FSReadLabel
     _writelabelClass = fswritelabel.Ext2FSWriteLabel
     _existingSizeFields = ["Block count:", "Block size:"]
     _resizefsUnit = MiB
-    _fsProfileSpecifier = "-T"
     partedSystem = fileSystemType["ext2"]
 
     def _getMinSize(self, info=None):
@@ -981,9 +938,9 @@ def resizeArgs(self):
 class Ext3FS(Ext2FS):
     """ ext3 filesystem. """
     _type = "ext3"
-    _defaultFormatOptions = ["-t", "ext3"]
     _modules = ["ext3"]
     partedSystem = fileSystemType["ext3"]
+    _mkfsClass = fsmkfs.Ext3FSMkfs
 
     # It is possible for a user to specify an fsprofile that defines a blocksize
     # smaller than the default of 4096 bytes and therefore to make liars of us
@@ -997,8 +954,8 @@ class Ext3FS(Ext2FS):
 class Ext4FS(Ext3FS):
     """ ext4 filesystem. """
     _type = "ext4"
-    _defaultFormatOptions = ["-t", "ext4"]
     _modules = ["ext4"]
+    _mkfsClass = fsmkfs.Ext4FSMkfs
     partedSystem = fileSystemType["ext4"]
 
 register_device_format(Ext4FS)
@@ -1007,7 +964,6 @@ class Ext4FS(Ext3FS):
 class FATFS(FS):
     """ FAT filesystem. """
     _type = "vfat"
-    _mkfs = "mkdosfs"
     _modules = ["vfat"]
     _labelfs = fslabeling.FATFSLabeling()
     _supported = True
@@ -1015,6 +971,7 @@ class FATFS(FS):
     _maxSize = Size("1 TiB")
     _packages = [ "dosfstools" ]
     _fsckClass = fsck.DosFSCK
+    _mkfsClass = fsmkfs.FATFSMkfs
     _readlabelClass = fsreadlabel.DosFSReadLabel
     _writelabelClass = fswritelabel.DosFSWriteLabel
     _defaultMountOptions = ["umask=0077", "shortname=winnt"]
@@ -1041,7 +998,6 @@ def supported(self):
 class BTRFS(FS):
     """ btrfs filesystem """
     _type = "btrfs"
-    _mkfs = "mkfs.btrfs"
     _modules = ["btrfs"]
     _formattable = True
     _linuxNative = True
@@ -1049,6 +1005,7 @@ class BTRFS(FS):
     _packages = ["btrfs-progs"]
     _minSize = Size("256 MiB")
     _maxSize = Size("16 EiB")
+    _mkfsClass = fsmkfs.BTRFSMkfs
     # FIXME parted needs to be taught about btrfs so that we can set the
     # partition table type correctly for btrfs partitions
     # partedSystem = fileSystemType["btrfs"]
@@ -1099,14 +1056,13 @@ def setup(self, **kwargs):
 class GFS2(FS):
     """ gfs2 filesystem. """
     _type = "gfs2"
-    _mkfs = "mkfs.gfs2"
     _modules = ["dlm", "gfs2"]
     _formattable = True
-    _defaultFormatOptions = ["-j", "1", "-p", "lock_nolock", "-O"]
     _linuxNative = True
     _dump = True
     _check = True
     _packages = ["gfs2-utils"]
+    _mkfsClass = fsmkfs.GFS2Mkfs
     # FIXME parted needs to be thaught about btrfs so that we can set the
     # partition table type correctly for btrfs partitions
     # partedSystem = fileSystemType["gfs2"]
@@ -1122,16 +1078,15 @@ def supported(self):
 class JFS(FS):
     """ JFS filesystem """
     _type = "jfs"
-    _mkfs = "mkfs.jfs"
     _modules = ["jfs"]
     _labelfs = fslabeling.JFSLabeling()
-    _defaultFormatOptions = ["-q"]
     _maxSize = Size("8 TiB")
     _formattable = True
     _linuxNative = True
     _dump = True
     _check = True
     _infoClass = fsinfo.JFSInfo
+    _mkfsClass = fsmkfs.JFSMkfs
     _writelabelClass = fswritelabel.JFSWriteLabel
     _existingSizeFields = ["Physical block size:", "Aggregate size:"]
     partedSystem = fileSystemType["jfs"]
@@ -1147,10 +1102,8 @@ def supported(self):
 class ReiserFS(FS):
     """ reiserfs filesystem """
     _type = "reiserfs"
-    _mkfs = "mkreiserfs"
     _labelfs = fslabeling.ReiserFSLabeling()
     _modules = ["reiserfs"]
-    _defaultFormatOptions = ["-f", "-f"]
     _maxSize = Size("16 TiB")
     _formattable = True
     _linuxNative = True
@@ -1158,6 +1111,7 @@ class ReiserFS(FS):
     _check = True
     _packages = ["reiserfs-utils"]
     _infoClass = fsinfo.ReiserFSInfo
+    _mkfsClass = fsmkfs.ReiserFSMkfs
     _writelabelClass = fswritelabel.ReiserFSWriteLabel
     _existingSizeFields = ["Count of blocks on the device:", "Blocksize:"]
     partedSystem = fileSystemType["reiserfs"]
@@ -1173,16 +1127,15 @@ def supported(self):
 class XFS(FS):
     """ XFS filesystem """
     _type = "xfs"
-    _mkfs = "mkfs.xfs"
     _modules = ["xfs"]
     _labelfs = fslabeling.XFSLabeling()
-    _defaultFormatOptions = ["-f"]
     _maxSize = Size("16 EiB")
     _formattable = True
     _linuxNative = True
     _supported = True
     _packages = ["xfsprogs"]
     _infoClass = fsinfo.XFSInfo
+    _mkfsClass = fsmkfs.XFSMkfs
     _readlabelClass = fsreadlabel.XFSReadLabel
     _syncClass = fssync.XFSSync
     _writelabelClass = fswritelabel.XFSWriteLabel
@@ -1193,10 +1146,10 @@ class XFS(FS):
 
 class HFS(FS):
     _type = "hfs"
-    _mkfs = "hformat"
     _modules = ["hfs"]
     _labelfs = fslabeling.HFSLabeling()
     _formattable = True
+    _mkfsClass = fsmkfs.HFSMkfs
     partedSystem = fileSystemType["hfs"]
 
 register_device_format(HFS)
@@ -1221,7 +1174,6 @@ class HFSPlus(FS):
     _type = "hfs+"
     _modules = ["hfsplus"]
     _udevTypes = ["hfsplus"]
-    _mkfs = "mkfs.hfsplus"
     _packages = ["hfsplus-tools"]
     _labelfs = fslabeling.HFSPlusLabeling()
     _formattable = True
@@ -1231,6 +1183,7 @@ class HFSPlus(FS):
     _check = True
     partedSystem = fileSystemType["hfs+"]
     _fsckClass = fsck.HFSPlusFSCK
+    _mkfsClass = fsmkfs.HFSPlusMkfs
 
 register_device_format(HFSPlus)
 
@@ -1257,7 +1210,6 @@ def __init__(self, **kwargs):
 class NTFS(FS):
     """ ntfs filesystem. """
     _type = "ntfs"
-    _mkfs = "mkntfs"
     _resizefs = "ntfsresize"
     _labelfs = fslabeling.NTFSLabeling()
     _resizable = True
@@ -1267,6 +1219,7 @@ class NTFS(FS):
     _packages = ["ntfsprogs"]
     _fsckClass = fsck.NTFSFSCK
     _infoClass = fsinfo.NTFSInfo
+    _mkfsClass = fsmkfs.NTFSMkfs
     _readlabelClass = fsreadlabel.NTFSReadLabel
     _writelabelClass = fswritelabel.NTFSWriteLabel
     _existingSizeFields = ["Cluster Size:", "Volume Size in Clusters:"]


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


More information about the anaconda-patches mailing list