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.
This commit is contained in:
Dan Bungert 2023-05-10 17:24:59 -06:00
parent e2d55f50a2
commit d69bc0dd77
3 changed files with 19 additions and 5 deletions

View File

@ -648,8 +648,8 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
else: else:
if structure.role == snapdapi.Role.SYSTEM_DATA and \ if structure.role == snapdapi.Role.SYSTEM_DATA and \
structure == self._on_volume.structure[-1]: structure == self._on_volume.structure[-1]:
gap = gaps.largest_gap(disk) gap = gaps.at_offset(disk, offset)
size = gap.size - (offset - gap.offset) size = gap.size
part = self.model.add_partition( part = self.model.add_partition(
disk, offset=offset, size=size, check_alignment=False) disk, offset=offset, size=size, check_alignment=False)

View File

@ -919,6 +919,13 @@ class TestCoreBootInstallMethods(IsolatedAsyncioTestCase):
async def test_guided_core_boot_system_data(self): async def test_guided_core_boot_system_data(self):
disk = make_disk(self.fsc.model) disk = make_disk(self.fsc.model)
self._add_details_for_structures([ 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( snapdapi.VolumeStructure(
type="0FC63DAF-8483-4772-8E79-3D69D8477DE4", type="0FC63DAF-8483-4772-8E79-3D69D8477DE4",
offset=2 << 20, offset=2 << 20,
@ -928,7 +935,7 @@ class TestCoreBootInstallMethods(IsolatedAsyncioTestCase):
filesystem='ext4'), filesystem='ext4'),
]) ])
await self.fsc.guided_core_boot(disk) await self.fsc.guided_core_boot(disk)
[part] = disk.partitions() [bios_part, part] = disk.partitions()
self.assertEqual(part.offset, 2 << 20) self.assertEqual(part.offset, 2 << 20)
self.assertEqual(part.partition_name, 'ptname') self.assertEqual(part.partition_name, 'ptname')
self.assertEqual(part.flag, 'linux') self.assertEqual(part.flag, 'linux')

View File

@ -590,7 +590,10 @@ class TestGuided(TestAPI):
class TestCore(TestAPI): class TestCore(TestAPI):
@timeout() @timeout()
async def test_basic_core_boot(self): 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( kw = dict(
bootloader='uefi', bootloader='uefi',
extra_args=[ extra_args=[
@ -609,7 +612,11 @@ class TestCore(TestAPI):
await inst.post('/storage/v2/guided', data) await inst.post('/storage/v2/guided', data)
v2resp = await inst.get('/storage/v2') v2resp = await inst.get('/storage/v2')
[d] = v2resp['disks'] [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') e1 = dict(offset=1 << 20, mount='/boot/efi')
self.assertDictSubset(e1, p1) self.assertDictSubset(e1, p1)
self.assertDictSubset(dict(mount='/boot'), p2) self.assertDictSubset(dict(mount='/boot'), p2)