From d69bc0dd770c3deefe062e62756963bbf4034a62 Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Wed, 10 May 2023 17:24:59 -0600 Subject: [PATCH] filesystem: select gap by offset Given disk layout like so [p1 g1 p2 p3 g2] The code attempting to create p4 used the largest_gap() method to attempt to select g2. If the disk was small enough, below 28GiB with current numbers, g1 would actually be larger, but the sizing math was done with the offset that was correct for g2, so p4 would be created a very incorrect size (-800MiB or so). Just select gap by offset - we have the info needed. --- subiquity/server/controllers/filesystem.py | 4 ++-- subiquity/server/controllers/tests/test_filesystem.py | 9 ++++++++- subiquity/tests/api/test_api.py | 11 +++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index 0b0c844e..a0b35d98 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -648,8 +648,8 @@ class FilesystemController(SubiquityController, FilesystemManipulator): else: if structure.role == snapdapi.Role.SYSTEM_DATA and \ structure == self._on_volume.structure[-1]: - gap = gaps.largest_gap(disk) - size = gap.size - (offset - gap.offset) + gap = gaps.at_offset(disk, offset) + size = gap.size part = self.model.add_partition( disk, offset=offset, size=size, check_alignment=False) diff --git a/subiquity/server/controllers/tests/test_filesystem.py b/subiquity/server/controllers/tests/test_filesystem.py index 51e4b10f..13d1f581 100644 --- a/subiquity/server/controllers/tests/test_filesystem.py +++ b/subiquity/server/controllers/tests/test_filesystem.py @@ -919,6 +919,13 @@ class TestCoreBootInstallMethods(IsolatedAsyncioTestCase): async def test_guided_core_boot_system_data(self): disk = make_disk(self.fsc.model) self._add_details_for_structures([ + snapdapi.VolumeStructure( + type="21686148-6449-6E6F-744E-656564454649", + offset=1 << 20, + name='BIOS Boot', + size=1 << 20, + role='', + filesystem=''), snapdapi.VolumeStructure( type="0FC63DAF-8483-4772-8E79-3D69D8477DE4", offset=2 << 20, @@ -928,7 +935,7 @@ class TestCoreBootInstallMethods(IsolatedAsyncioTestCase): filesystem='ext4'), ]) await self.fsc.guided_core_boot(disk) - [part] = disk.partitions() + [bios_part, part] = disk.partitions() self.assertEqual(part.offset, 2 << 20) self.assertEqual(part.partition_name, 'ptname') self.assertEqual(part.flag, 'linux') diff --git a/subiquity/tests/api/test_api.py b/subiquity/tests/api/test_api.py index 643195b3..4ad2014d 100644 --- a/subiquity/tests/api/test_api.py +++ b/subiquity/tests/api/test_api.py @@ -590,7 +590,10 @@ class TestGuided(TestAPI): class TestCore(TestAPI): @timeout() async def test_basic_core_boot(self): - cfg = 'examples/simple.json' + cfg = self.machineConfig('examples/simple.json') + with cfg.edit() as data: + attrs = data['storage']['blockdev']['/dev/sda']['attrs'] + attrs['size'] = str(25 << 30) kw = dict( bootloader='uefi', extra_args=[ @@ -609,7 +612,11 @@ class TestCore(TestAPI): await inst.post('/storage/v2/guided', data) v2resp = await inst.get('/storage/v2') [d] = v2resp['disks'] - [p1, p2, p3, p4] = d['partitions'] + pgs = d['partitions'] + [p4] = match(pgs, number=4) + # FIXME The current model has a ~13GiB gap between p1 and p2. + # Presumably this will be removed later. + [p1, g1, p2, p3, p4] = d['partitions'] e1 = dict(offset=1 << 20, mount='/boot/efi') self.assertDictSubset(e1, p1) self.assertDictSubset(dict(mount='/boot'), p2)