Skip to content

Commit 238c2c9

Browse files
Merge pull request #1171 from vojtechtrefny/3.9-devel_fsoptions-fix
Fix passing extra mkfs arguments to libblockdev
2 parents 0dad8f8 + 6c282c2 commit 238c2c9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

blivet/tasks/fsmkfs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,18 @@ def do_task(self, options=None, label=False, set_uuid=False, nodiscard=False):
272272
" is unacceptable for this filesystem."
273273
% (self.fs.label, self.fs.type))
274274

275+
if self.fs.create_options:
276+
create_options = shlex.split(self.fs.create_options)
277+
else:
278+
create_options = []
279+
if options:
280+
create_options += options
281+
275282
try:
276283
bd_options = BlockDev.FSMkfsOptions(label=self.fs.label if label else None,
277284
uuid=self.fs.uuid if set_uuid else None,
278285
no_discard=self.fs._mkfs_nodiscard if nodiscard else False)
279-
BlockDev.fs.mkfs(self.fs.device, self.fstype, bd_options, extra=options or [])
286+
BlockDev.fs.mkfs(self.fs.device, self.fstype, bd_options, extra={k: '' for k in create_options})
280287
except BlockDev.FSError as e:
281288
raise FSError(str(e))
282289

tests/storage_tests/formats_test/fs_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from blivet.formats import get_format
1111
from blivet.devices import PartitionDevice, DiskDevice
1212
from blivet.flags import flags
13+
from blivet.util import capture_output
1314

1415
from .loopbackedtestcase import LoopBackedTestCase
1516

@@ -67,6 +68,25 @@ def test_online_resize(self):
6768

6869
an_fs.unmount()
6970

71+
def test_create_options(self):
72+
label = "root-test-label"
73+
uuid = "c1b9d5a2-f162-11cf-9ece-0020afc76f16"
74+
75+
an_fs = self._fs_class()
76+
if not an_fs.formattable:
77+
self.skipTest("can not create filesystem %s" % an_fs.name)
78+
an_fs.device = self.loop_devices[0]
79+
80+
# custom fs create options -- -L <label> and -U <uuid> for mke2fs
81+
an_fs.create_options = "-L %s -U %s" % (label, uuid)
82+
an_fs.create()
83+
84+
sys_label = an_fs.read_label()
85+
self.assertEqual(sys_label, label)
86+
87+
out = capture_output(["blkid", "-sUUID", "-ovalue", self.loop_devices[0]])
88+
self.assertEqual(out.strip(), uuid)
89+
7090

7191
class FATFSTestCase(fstesting.FSAsRoot):
7292
_fs_class = fs.FATFS

0 commit comments

Comments
 (0)