diff options
| author | Dan Bungert <[email protected]> | 2023-09-12 19:12:32 -0600 |
|---|---|---|
| committer | Dan Bungert <[email protected]> | 2023-09-13 20:19:53 -0600 |
| commit | 2004e046b97a73d697938ff7ed23b0987b233cb5 (patch) | |
| tree | 5c6bb6907838bcf999ebd4d03f63921250923b18 | |
| parent | 9e3cb714ea2160d1e3650185cde7142898050956 (diff) | |
storage_config: handle partitions on 4k disk
In LP: #2035034, a user reported that the layout of existing
partitions was showing as 1/8th the correct size. Update storage_config
to no longer hard-code a 512 byte sector and read the value instead.
| -rw-r--r-- | curtin/storage_config.py | 12 | ||||
| -rw-r--r-- | tests/unittests/test_storage_config.py | 8 |
2 files changed, 16 insertions, 4 deletions
diff --git a/curtin/storage_config.py b/curtin/storage_config.py index d5092dd5..af7b6f3a 100644 --- a/curtin/storage_config.py +++ b/curtin/storage_config.py @@ -792,15 +792,19 @@ class BlockdevParser(ProbertParser): else: part = attrs - # sectors 512B sector units in both attrs and ptable - offset_val = int(part['start']) * 512 + # sector units are used in both attrs and ptable + parent_attrs = parent_blockdev.get('attrs', {}) + logical_sector_size = int( + parent_attrs.get('queue/logical_block_size', 512) + ) + + offset_val = int(part['start']) * logical_sector_size if offset_val > 0: entry['offset'] = offset_val - # ptable size field is in sectors entry['size'] = int(part['size']) if ptable: - entry['size'] *= 512 + entry['size'] *= logical_sector_size if blockdev_data.get('ID_PART_TABLE_TYPE') == 'gpt': part_uuid = blockdev_data.get('ID_PART_ENTRY_UUID') diff --git a/tests/unittests/test_storage_config.py b/tests/unittests/test_storage_config.py index b032bf4e..caaac29b 100644 --- a/tests/unittests/test_storage_config.py +++ b/tests/unittests/test_storage_config.py @@ -603,6 +603,14 @@ class TestBlockdevParser(CiTestCase): 'type': 'disk'} self.assertDictEqual(expected_dict, self.bdevp.asdict(blockdev)) + def test_blockdev_asdict_4k_sector_size(self): + """ existing part on 4k logical sector size disk with size 5000 MiB """ + self.probe_data = _get_data('probert_storage_4ksectors.json') + self.bdevp = BlockdevParser(self.probe_data) + blockdev = self.bdevp.blockdev_data['/dev/sda1'] + actual = self.bdevp.asdict(blockdev) + self.assertEqual(5000 << 20, actual['size']) + class TestFilesystemParser(CiTestCase): |
