Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disk: tweak ensure{Btrfs,LVM}() to be more linear #1073

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,35 +731,35 @@ func (pt *PartitionTable) ensureLVM() error {

if _, ok := parent.(*LVMLogicalVolume); ok {
return nil
} else if part, ok := parent.(*Partition); ok {
filesystem := part.Payload

vg := &LVMVolumeGroup{
Name: "rootvg",
Description: "created via lvm2 and osbuild",
}
}
part, ok := parent.(*Partition)
if !ok {
return fmt.Errorf("Unsupported parent for LVM")
}
filesystem := part.Payload

// create root logical volume on the new volume group with the same
// size and filesystem as the previous root partition
_, err := vg.CreateLogicalVolume("rootlv", part.Size, filesystem)
if err != nil {
panic(fmt.Sprintf("Could not create LV: %v", err))
}
vg := &LVMVolumeGroup{
Name: "rootvg",
Description: "created via lvm2 and osbuild",
}

// replace the top-level partition payload with the new volume group
part.Payload = vg
// create root logical volume on the new volume group with the same
// size and filesystem as the previous root partition
_, err := vg.CreateLogicalVolume("rootlv", part.Size, filesystem)
if err != nil {
panic(fmt.Sprintf("Could not create LV: %v", err))
}

// reset the vg partition size - it will be grown later
part.Size = 0
// replace the top-level partition payload with the new volume group
part.Payload = vg

if pt.Type == PT_GPT {
part.Type = LVMPartitionGUID
} else {
part.Type = LVMPartitionDOSID
}
// reset the vg partition size - it will be grown later
part.Size = 0

if pt.Type == PT_GPT {
part.Type = LVMPartitionGUID
} else {
return fmt.Errorf("Unsupported parent for LVM")
part.Type = LVMPartitionDOSID
}

return nil
Expand Down Expand Up @@ -789,43 +789,43 @@ func (pt *PartitionTable) ensureBtrfs() error {

if _, ok := parent.(*Btrfs); ok {
return nil
} else if part, ok := parent.(*Partition); ok {
rootMountable, ok := rootPath[0].(Mountable)
if !ok {
return fmt.Errorf("root entity is not mountable: %T, this is a violation of entityPath() contract", rootPath[0])
}
}
part, ok := parent.(*Partition)
if !ok {
return fmt.Errorf("unsupported parent for btrfs: %T", parent)
}
rootMountable, ok := rootPath[0].(Mountable)
if !ok {
return fmt.Errorf("root entity is not mountable: %T, this is a violation of entityPath() contract", rootPath[0])
}

opts, err := rootMountable.GetFSTabOptions()
if err != nil {
return err
}
opts, err := rootMountable.GetFSTabOptions()
if err != nil {
return err
}

btrfs := &Btrfs{
Label: "root",
Subvolumes: []BtrfsSubvolume{
{
Name: "root",
Mountpoint: "/",
Compress: DefaultBtrfsCompression,
ReadOnly: opts.ReadOnly(),
Size: part.Size,
},
btrfs := &Btrfs{
Label: "root",
Subvolumes: []BtrfsSubvolume{
{
Name: "root",
Mountpoint: "/",
Compress: DefaultBtrfsCompression,
ReadOnly: opts.ReadOnly(),
Size: part.Size,
},
}
},
}

// replace the top-level partition payload with a new btrfs filesystem
part.Payload = btrfs
// replace the top-level partition payload with a new btrfs filesystem
part.Payload = btrfs

// reset the btrfs partition size - it will be grown later
part.Size = 0
// reset the btrfs partition size - it will be grown later
part.Size = 0

part.Type, err = getPartitionTypeIDfor(pt.Type, "data")
if err != nil {
return fmt.Errorf("error converting partition table to btrfs: %w", err)
}

} else {
return fmt.Errorf("unsupported parent for btrfs: %T", parent)
part.Type, err = getPartitionTypeIDfor(pt.Type, "data")
if err != nil {
return fmt.Errorf("error converting partition table to btrfs: %w", err)
}

return nil
Expand Down
Loading