Merge pull request #1206 from dbungert/partition-alignment

filesystem: add partition alignment table
This commit is contained in:
Dan Bungert 2022-03-10 08:47:30 -07:00 committed by GitHub
commit 510d63d93d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 5 deletions

View File

@ -21,13 +21,12 @@ from subiquity.common.filesystem import boot, gaps
from subiquity.common.types import Bootloader
from subiquity.models.filesystem import (
align_up,
MiB,
Partition,
)
log = logging.getLogger('subiquity.common.filesystem.manipulator')
MiB = 1024 * 1024
BIOS_GRUB_SIZE_BYTES = 1 * MiB
PREP_GRUB_SIZE_BYTES = 8 * MiB

View File

@ -33,9 +33,10 @@ from probert.storage import StorageInfo
from subiquity.common.types import Bootloader, OsProber
log = logging.getLogger('subiquity.models.filesystem')
MiB = 1024 * 1024
def _set_backlinks(obj):
if obj.id is None:
@ -575,6 +576,10 @@ class Disk(_Device):
_info = attr.ib(default=None)
def alignment_data(self):
ptable = self.ptable_for_new_partition()
return self._m._partition_alignment_data[ptable]
def info_for_display(self):
bus = self._info.raw.get('ID_BUS', None)
major = self._info.raw.get('MAJOR', None)
@ -927,12 +932,44 @@ def align_down(size, block_size=1 << 20):
return size & ~(block_size - 1)
@attr.s(auto_attribs=True)
class PartitionAlignmentData:
part_align: int
min_gap_size: int
min_start_offset: int
min_end_offset: int
primary_part_limit: int
ebr_space: int = 0
class FilesystemModel(object):
lower_size_limit = 128 * (1 << 20)
target = None
_partition_alignment_data = {
'gpt': PartitionAlignmentData(
part_align=MiB,
min_gap_size=MiB,
min_start_offset=GPT_OVERHEAD//2,
min_end_offset=GPT_OVERHEAD//2,
primary_part_limit=128),
'msdos': PartitionAlignmentData(
part_align=MiB,
min_gap_size=MiB,
min_start_offset=GPT_OVERHEAD//2,
min_end_offset=0,
ebr_space=MiB,
primary_part_limit=4),
# XXX check this one!!
'vtoc': PartitionAlignmentData(
part_align=MiB,
min_gap_size=MiB,
min_start_offset=GPT_OVERHEAD//2,
min_end_offset=0,
ebr_space=MiB,
primary_part_limit=3),
}
@classmethod
def is_mounted_filesystem(self, fstype):
if fstype in [None, 'swap']:

View File

@ -661,3 +661,20 @@ class TestAutoInstallConfig(unittest.TestCase):
self.assertTrue(disk1p1.id in rendered_ids)
self.assertTrue(disk2.id in rendered_ids)
self.assertTrue(disk2p1.id in rendered_ids)
class TestAlignmentData(unittest.TestCase):
def test_alignment_gaps_coherence(self):
for ptable in 'gpt', 'msdos', 'vtoc':
model = make_model(Bootloader.NONE)
disk1 = make_disk(model, ptable=ptable)
gaps_max = gaps.largest_gap_size(disk1)
align_data = disk1.alignment_data()
align_max = (disk1.size - align_data.min_start_offset
- align_data.min_end_offset)
# The alignment data currently has a better notion of end
# information, so gaps produces numbers that are too small by 1MiB
# for ptable != 'gpt'
self.assertTrue(gaps_max <= align_max, f'ptable={ptable}')