Skip to content

Commit

Permalink
Do filesystem label writing with a task.
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Mar 25, 2015
1 parent a902be1 commit 89a3e4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
39 changes: 15 additions & 24 deletions blivet/formats/fs.py
Expand Up @@ -31,6 +31,7 @@
from ..tasks import fslabeling
from ..tasks import fsreadlabel
from ..tasks import fssync
from ..tasks import fswritelabel
from ..errors import FormatCreateError, FSError, FSReadLabelError, FSResizeError
from . import DeviceFormat, register_device_format
from .. import util
Expand Down Expand Up @@ -63,6 +64,7 @@ class FS(DeviceFormat):
_infoClass = None
_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 = []
Expand Down Expand Up @@ -105,6 +107,7 @@ def getTaskObject(klass):
self._fsck = getTaskObject(self._fsckClass)
self._readlabel = getTaskObject(self._readlabelClass)
self._sync = getTaskObject(self._syncClass)
self._writelabel = getTaskObject(self._writelabelClass)

self.mountpoint = kwargs.get("mountpoint")
self.mountopts = kwargs.get("mountopts")
Expand Down Expand Up @@ -169,7 +172,7 @@ def relabels(self):
:rtype: bool
"""
return self._labelfs is not None and self._labelfs.label_app is not None
return self._writelabel is not None and not self._writelabel.unavailable

def labelFormatOK(self, label):
"""Return True if the label has an acceptable format for this
Expand Down Expand Up @@ -700,25 +703,10 @@ def writeLabel(self):
Raises a FSError if the label can not be set.
"""
if self.label is None:
raise FSError("makes no sense to write a label when accepting default label")

if not self.exists:
raise FSError("filesystem has not been created")

if not self.relabels():
raise FSError("no application to set label for filesystem %s" % self.type)

if not self.labelFormatOK(self.label):
raise FSError("bad label format for labelling application %s" % self._labelfs.label_app.name)

if not os.path.exists(self.device):
raise FSError("device does not exist")

rc = util.run_program(self._labelfs.label_app.setLabelCommand(self))
if rc:
raise FSError("label failed")

if self._writelabel:
self._writelabel.doTask()
else:
raise FSError("label writing not implemented for filesystem %s" % self.type)
self.notifyKernel()

@property
Expand All @@ -737,10 +725,7 @@ def labelfsProg(self):
May be None if no such program exists.
"""
if self._labelfs and self._labelfs.label_app:
return self._labelfs.label_app.name
else:
return None
return self._writelabel.app_name if self._writelabel else None

@property
def infofsProg(self):
Expand Down Expand Up @@ -912,6 +897,7 @@ class Ext2FS(FS):
_fsckClass = fsck.Ext2FSCK
_infoClass = fsinfo.Ext2FSInfo
_readlabelClass = fsreadlabel.Ext2FSReadLabel
_writelabelClass = fswritelabel.Ext2FSWriteLabel
_existingSizeFields = ["Block count:", "Block size:"]
_resizefsUnit = MiB
_fsProfileSpecifier = "-T"
Expand Down Expand Up @@ -1030,6 +1016,7 @@ class FATFS(FS):
_packages = [ "dosfstools" ]
_fsckClass = fsck.DosFSCK
_readlabelClass = fsreadlabel.DosFSReadLabel
_writelabelClass = fswritelabel.DosFSWriteLabel
_defaultMountOptions = ["umask=0077", "shortname=winnt"]
# FIXME this should be fat32 in some cases
partedSystem = fileSystemType["fat16"]
Expand Down Expand Up @@ -1145,6 +1132,7 @@ class JFS(FS):
_dump = True
_check = True
_infoClass = fsinfo.JFSInfo
_writelabelClass = fswritelabel.JFSWriteLabel
_existingSizeFields = ["Physical block size:", "Aggregate size:"]
partedSystem = fileSystemType["jfs"]

Expand All @@ -1170,6 +1158,7 @@ class ReiserFS(FS):
_check = True
_packages = ["reiserfs-utils"]
_infoClass = fsinfo.ReiserFSInfo
_writelabelClass = fswritelabel.ReiserFSWriteLabel
_existingSizeFields = ["Count of blocks on the device:", "Blocksize:"]
partedSystem = fileSystemType["reiserfs"]

Expand All @@ -1196,6 +1185,7 @@ class XFS(FS):
_infoClass = fsinfo.XFSInfo
_readlabelClass = fsreadlabel.XFSReadLabel
_syncClass = fssync.XFSSync
_writelabelClass = fswritelabel.XFSWriteLabel
_existingSizeFields = ["dblocks =", "blocksize ="]
partedSystem = fileSystemType["xfs"]

Expand Down Expand Up @@ -1278,6 +1268,7 @@ class NTFS(FS):
_fsckClass = fsck.NTFSFSCK
_infoClass = fsinfo.NTFSInfo
_readlabelClass = fsreadlabel.NTFSReadLabel
_writelabelClass = fswritelabel.NTFSWriteLabel
_existingSizeFields = ["Cluster Size:", "Volume Size in Clusters:"]
_resizefsUnit = B
partedSystem = fileSystemType["ntfs"]
Expand Down
2 changes: 1 addition & 1 deletion tests/tasks_test/fslabeling.py
Expand Up @@ -44,7 +44,7 @@ def testLabeling(self):
an_fs.readLabel()

an_fs.label = "an fs"
with self.assertRaisesRegexp(FSError, "no application to set label for filesystem"):
with self.assertRaises(FSError):
an_fs.writeLabel()

def testCreating(self):
Expand Down

0 comments on commit 89a3e4f

Please sign in to comment.