Skip to content

Commit

Permalink
filesystem: add basic guided zfs
Browse files Browse the repository at this point in the history
  • Loading branch information
dbungert committed Jul 17, 2023
1 parent 0022025 commit 13890db
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions subiquity/common/filesystem/manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ def delete_logical_volume(self, lv):
self.model.remove_logical_volume(lv)
delete_lvm_partition = delete_logical_volume

def create_zpool(self, device, pool, mountpoint):
self.model.add_zpool(device, pool, mountpoint)

def delete(self, obj):
if obj is None:
return
Expand Down
19 changes: 19 additions & 0 deletions subiquity/models/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1854,3 +1854,22 @@ def should_add_swapfile(self):
if swap.mount():
return False
return True

def add_zpool(self, device, pool, mountpoint):
fs_properties = dict(
acltype='posixacl',
relatime='on',
canmount='on',
compression='gzip',
devices='off',
xattr='sa',
)
zpool = ZPool(
m=self,
vdevs=[device],
pool=pool,
mountpoint=mountpoint,
pool_properties=dict(ashift=12),
fs_properties=fs_properties)
self._actions.append(zpool)
return zpool
14 changes: 14 additions & 0 deletions subiquity/server/controllers/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,18 @@ def guided_lvm(self, gap, choice: GuidedChoiceV2):
mount="/",
))

def guided_zfs(self, gap, choice: GuidedChoiceV2):
device = gap.device
part_align = device.alignment_data().part_align
bootfs_size = align_up(sizes.get_bootfs_size(gap.size), part_align)
gap_boot, gap_rest = gap.split(bootfs_size)

bpool_part = self.create_partition(device, gap_boot, dict(fstype=None))
rpool_part = self.create_partition(device, gap_rest, dict(fstype=None))

self.create_zpool(rpool_part, 'rpool', '/')
self.create_zpool(bpool_part, 'bpool', '/boot')

@functools.singledispatchmethod
def start_guided(self, target: GuidedStorageTarget,
disk: ModelDisk) -> gaps.Gap:
Expand Down Expand Up @@ -590,6 +602,8 @@ async def guided(

if choice.capability.is_lvm():
self.guided_lvm(gap, choice)
elif choice.capability.is_zfs():
self.guided_zfs(gap, choice)
elif choice.capability == GuidedCapability.DIRECT:
self.guided_direct(gap)
else:
Expand Down
35 changes: 35 additions & 0 deletions subiquity/server/controllers/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,41 @@ async def test_guided_lvm_BIOS_MSDOS(self):
self.assertFalse(d1p2.preserve)
self.assertIsNone(gaps.largest_gap(self.d1))

@parameterized.expand(boot_expectations)
async def test_guided_zfs(self, bootloader, ptable, p1mnt):
await self._guided_setup(bootloader, ptable)
target = GuidedStorageTargetReformat(
disk_id=self.d1.id, allowed=default_capabilities)
await self.controller.guided(GuidedChoiceV2(
target=target, capability=GuidedCapability.ZFS))
[d1p1, d1p2, d1p3] = self.d1.partitions()
self.assertEqual(p1mnt, d1p1.mount)
self.assertEqual(None, d1p2.mount)
self.assertEqual(None, d1p3.mount)
self.assertFalse(d1p1.preserve)
self.assertFalse(d1p2.preserve)
self.assertFalse(d1p3.preserve)
[rpool] = self.model._all(type='zpool', pool='rpool')
self.assertEqual('/', rpool.mount)
[bpool] = self.model._all(type='zpool', pool='bpool')
self.assertEqual('/boot', bpool.mount)

async def test_guided_zfs_BIOS_MSDOS(self):
await self._guided_setup(Bootloader.BIOS, 'msdos')
target = GuidedStorageTargetReformat(
disk_id=self.d1.id, allowed=default_capabilities)
await self.controller.guided(GuidedChoiceV2(
target=target, capability=GuidedCapability.ZFS))
[d1p1, d1p2] = self.d1.partitions()
self.assertEqual(None, d1p1.mount)
self.assertEqual(None, d1p2.mount)
self.assertFalse(d1p1.preserve)
self.assertFalse(d1p2.preserve)
[rpool] = self.model._all(type='zpool', pool='rpool')
self.assertEqual('/', rpool.mount)
[bpool] = self.model._all(type='zpool', pool='bpool')
self.assertEqual('/boot', bpool.mount)

async def _guided_side_by_side(self, bl, ptable):
await self._guided_setup(bl, ptable, storage_version=2)
self.controller.add_boot_disk(self.d1)
Expand Down

0 comments on commit 13890db

Please sign in to comment.