Skip to content

Commit

Permalink
disk: test relayout() function fix
Browse files Browse the repository at this point in the history
Add two new test cases, dos and gpt with LVM, that force the VG
partition and partition table to grow to fit the LVs.  The partition
size calculation can be a bit hard to follow with metadata and rounding,
but the comments should help.
  • Loading branch information
achilleas-k authored and supakeen committed Jul 25, 2024
1 parent 344fc96 commit 4ef7f0d
Showing 1 changed file with 110 additions and 1 deletion.
111 changes: 110 additions & 1 deletion pkg/disk/partition_table_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ func TestRelayout(t *testing.T) {
Payload: &Filesystem{
Mountpoint: "/",
},
// TODO: fix bug where the VG partition is not resized to fit the sum of LVs
Size: 10 * MiB,
},
},
Expand Down Expand Up @@ -691,6 +690,116 @@ func TestRelayout(t *testing.T) {
},
},
},
"lvm-dos-grow-rootvg": {
pt: &PartitionTable{
Type: "dos",
Size: 10 * MiB, // PT is smaller than the sum of Partitions
Partitions: []Partition{
{
Size: 200 * MiB,
},
{
Size: 10 * MiB, // VG partition is smaller than sum of LVs
Payload: &LVMVolumeGroup{
LogicalVolumes: []LVMLogicalVolume{
{
Size: 20 * MiB,
},
{
Payload: &Filesystem{
Mountpoint: "/",
},
Size: 100 * MiB,
},
},
},
},
},
},
size: 99 * MiB,
expected: &PartitionTable{
Type: "dos",
Size: 325 * MiB,
Partitions: []Partition{
{
Start: 1 * MiB, // 1 sector header aligned up to the default grain (1 MiB)
Size: 200 * MiB,
},
{
Start: 201 * MiB,
Size: 124 * MiB, // grows to fit logical volumes + 1 MiB metadata, rounded up to default extent size (4 MiB)
Payload: &LVMVolumeGroup{
LogicalVolumes: []LVMLogicalVolume{
{
Size: 20 * MiB,
},
{
Payload: &Filesystem{
Mountpoint: "/",
},
Size: 100 * MiB,
},
},
},
},
},
},
},
"lvm-gpt-grow-rootvg": {
pt: &PartitionTable{
Type: "gpt",
Size: 10 * MiB,
Partitions: []Partition{
{
Size: 200 * MiB,
},
{
Size: 10 * MiB,
Payload: &LVMVolumeGroup{
LogicalVolumes: []LVMLogicalVolume{
{
Size: 20 * MiB,
},
{
Payload: &Filesystem{
Mountpoint: "/",
},
Size: 100 * MiB,
},
},
},
},
},
},
size: 99 * MiB,
expected: &PartitionTable{
Type: "gpt",
Size: 326 * MiB,
Partitions: []Partition{
{
Start: 1 * MiB, // 1 sector header aligned up to the default grain (1 MiB)
Size: 200 * MiB,
},
{
Start: 201 * MiB,
Size: 125*MiB - (DefaultSectorSize + (128 * 128)), // grows to fit logical volumes and metadata, rounded up to default extent size + (1 MiB - footer) so that the no partitions shrink below the desired sizes
Payload: &LVMVolumeGroup{
LogicalVolumes: []LVMLogicalVolume{
{
Size: 20 * MiB,
},
{
Payload: &Filesystem{
Mountpoint: "/",
},
Size: 100 * MiB,
},
},
},
},
},
},
},
}

for name := range testCases {
Expand Down

0 comments on commit 4ef7f0d

Please sign in to comment.