Skip to content

Commit

Permalink
Merge pull request #1171 from vojtechtrefny/3.9-devel_fsoptions-fix
Browse files Browse the repository at this point in the history
Fix passing extra mkfs arguments to libblockdev
  • Loading branch information
vojtechtrefny authored Nov 16, 2023
2 parents 0dad8f8 + 6c282c2 commit 238c2c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion blivet/tasks/fsmkfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,18 @@ def do_task(self, options=None, label=False, set_uuid=False, nodiscard=False):
" is unacceptable for this filesystem."
% (self.fs.label, self.fs.type))

if self.fs.create_options:
create_options = shlex.split(self.fs.create_options)
else:
create_options = []
if options:
create_options += options

try:
bd_options = BlockDev.FSMkfsOptions(label=self.fs.label if label else None,
uuid=self.fs.uuid if set_uuid else None,
no_discard=self.fs._mkfs_nodiscard if nodiscard else False)
BlockDev.fs.mkfs(self.fs.device, self.fstype, bd_options, extra=options or [])
BlockDev.fs.mkfs(self.fs.device, self.fstype, bd_options, extra={k: '' for k in create_options})
except BlockDev.FSError as e:
raise FSError(str(e))

Expand Down
20 changes: 20 additions & 0 deletions tests/storage_tests/formats_test/fs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from blivet.formats import get_format
from blivet.devices import PartitionDevice, DiskDevice
from blivet.flags import flags
from blivet.util import capture_output

from .loopbackedtestcase import LoopBackedTestCase

Expand Down Expand Up @@ -67,6 +68,25 @@ def test_online_resize(self):

an_fs.unmount()

def test_create_options(self):
label = "root-test-label"
uuid = "c1b9d5a2-f162-11cf-9ece-0020afc76f16"

an_fs = self._fs_class()
if not an_fs.formattable:
self.skipTest("can not create filesystem %s" % an_fs.name)
an_fs.device = self.loop_devices[0]

# custom fs create options -- -L <label> and -U <uuid> for mke2fs
an_fs.create_options = "-L %s -U %s" % (label, uuid)
an_fs.create()

sys_label = an_fs.read_label()
self.assertEqual(sys_label, label)

out = capture_output(["blkid", "-sUUID", "-ovalue", self.loop_devices[0]])
self.assertEqual(out.strip(), uuid)


class FATFSTestCase(fstesting.FSAsRoot):
_fs_class = fs.FATFS
Expand Down

0 comments on commit 238c2c9

Please sign in to comment.