Skip to content

Commit

Permalink
Add support for setting label when creating GFS2 format
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtrefny committed Jan 24, 2024
1 parent 38f4b48 commit 55fca35
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions blivet/formats/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ class GFS2(FS):
_check = True
_packages = ["gfs2-utils"]
_mkfs_class = fsmkfs.GFS2Mkfs
_labelfs = fslabeling.GFS2Labeling()
# FIXME parted needs to be thaught about btrfs so that we can set the
# partition table type correctly for btrfs partitions
# parted_system = fileSystemType["gfs2"]
Expand Down
17 changes: 17 additions & 0 deletions blivet/tasks/fslabeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Red Hat Author(s): Anne Mulhern <amulhern@redhat.com>

import abc
import string

from six import add_metaclass

Expand Down Expand Up @@ -95,3 +96,19 @@ class F2FSLabeling(FSLabeling):
@classmethod
def label_format_ok(cls, label):
return cls._blockdev_check_label("f2fs", label)


class GFS2Labeling(FSLabeling):

@classmethod
def label_format_ok(cls, label):
try:
clustername, lockspace = label.split(":")
except ValueError:
return False

if len(clustername) > 32 or len(lockspace) > 30:
return False

allowed = string.ascii_letters + string.digits + "-_"
return all(c in allowed for c in clustername) and all(c in allowed for c in lockspace)
2 changes: 1 addition & 1 deletion blivet/tasks/fsmkfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def do_task(self, options=None, label=False, set_uuid=False, nodiscard=False):

class GFS2Mkfs(FSMkfs):
ext = availability.MKFS_GFS2_APP
label_option = None
label_option = "-t"
nodiscard_option = None
get_uuid_args = None

Expand Down
14 changes: 13 additions & 1 deletion tests/storage_tests/formats_test/fs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,21 @@ class BTRFSTestCase(fstesting.FSAsRoot):
_fs_class = fs.BTRFS


@unittest.skip("Unable to create GFS2 filesystem.")
class GFS2TestCase(fstesting.FSAsRoot):
_fs_class = fs.GFS2
_valid_label = "label:label"

@classmethod
def setUpClass(cls):
# allow creating gfs2
flags.gfs2 = True
super(GFS2TestCase, cls).setUpClass()

@classmethod
def tearDownClass(cls):
# reset flag back to default
flags.gfs2 = False
super(GFS2TestCase, cls).tearDownClass()


class XFSTestCase(fstesting.FSAsRoot):
Expand Down
11 changes: 6 additions & 5 deletions tests/storage_tests/formats_test/fstesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FSAsRoot(loopbackedtestcase.LoopBackedTestCase):
doc="The class of the filesystem being tested on.")

_DEVICE_SIZE = Size("100 MiB")
_valid_label = "label"

def __init__(self, methodName='run_test'):
super(FSAsRoot, self).__init__(methodName=methodName, device_spec=[self._DEVICE_SIZE])
Expand Down Expand Up @@ -127,15 +128,15 @@ def test_labeling(self):
if not an_fs.formattable or not an_fs.labeling():
self.skipTest("can not label filesystem %s" % an_fs.name)
an_fs.device = self.loop_devices[0]
an_fs.label = "label"
self.assertTrue(an_fs.label_format_ok("label"))
an_fs.label = self._valid_label
self.assertTrue(an_fs.label_format_ok(self._valid_label))
self.assertIsNone(an_fs.create())
try:
label = an_fs.read_label()
if an_fs.type in ("vfat", "efi"):
self.assertEqual(label, "LABEL")
self.assertEqual(label, self._valid_label.upper())
else:
self.assertEqual(label, "label")
self.assertEqual(label, self._valid_label)
except FSError:
pass

Expand All @@ -146,7 +147,7 @@ def test_relabeling(self):
an_fs.device = self.loop_devices[0]
self.assertIsNone(an_fs.create())
an_fs.label = "label"
self.assertTrue(an_fs.label_format_ok("label"))
self.assertTrue(an_fs.label_format_ok(self._valid_label))
if an_fs.relabels():
self.assertIsNone(an_fs.write_label())
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/storage_tests/formats_test/labeling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def test_labels(self):
self.assertFalse(fs.NTFS().label_format_ok("n" * 129))
self.assertTrue(fs.NTFS().label_format_ok("n" * 128))

# GFS2 has special format: two parts, limited lengths and characters
self.assertFalse(fs.GFS2().label_format_ok("label"))
self.assertFalse(fs.GFS2().label_format_ok("label:label:label"))
self.assertFalse(fs.GFS2().label_format_ok("n" * 33 + ":label"))
self.assertFalse(fs.GFS2().label_format_ok("label:" + "n" * 31))
self.assertFalse(fs.GFS2().label_format_ok("label:label*"))
self.assertTrue(fs.GFS2().label_format_ok("label:label"))

# all devices are permitted to be passed a label argument of None
# some will ignore it completely
for _k, v in device_formats.items():
Expand Down Expand Up @@ -76,6 +84,12 @@ class NTFSTestCase(fslabeling.CompleteLabelingAsRoot):
_default_label = ""


class GFS2TestCase(fslabeling.CompleteLabelingAsRoot):
_fs_class = fs.GFS2
_invalid_label = "label:label*"
_default_label = ""


class LabelingSwapSpaceTestCase(loopbackedtestcase.LoopBackedTestCase):

def test_labeling(self):
Expand Down

0 comments on commit 55fca35

Please sign in to comment.