Skip to content

Commit

Permalink
disk/lvm: split up CreateMountpoint
Browse files Browse the repository at this point in the history
Extract a `CreateLogicalVolume` method from `CreateMountpoint`
and implement the latter via the former. This makes it possible
to create a Logical Volume for an existing payload.
  • Loading branch information
gicmo committed Nov 16, 2022
1 parent 587e043 commit 1da3fd0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/disk/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ func (vg *LVMVolumeGroup) GetChild(n uint) Entity {
}

func (vg *LVMVolumeGroup) CreateMountpoint(mountpoint string, size uint64) (Entity, error) {
if vg == nil {
panic("LVMVolumeGroup.CreateMountpoint: nil entity")
}

filesystem := Filesystem{
Type: "xfs",
Mountpoint: mountpoint,
Expand All @@ -72,12 +70,20 @@ func (vg *LVMVolumeGroup) CreateMountpoint(mountpoint string, size uint64) (Enti
FSTabPassNo: 0,
}

return vg.CreateLogicalVolume(mountpoint, size, &filesystem)
}

func (vg *LVMVolumeGroup) CreateLogicalVolume(lvName string, size uint64, payload Entity) (Entity, error) {
if vg == nil {
panic("LVMVolumeGroup.CreateLogicalVolume: nil entity")
}

names := make(map[string]bool, len(vg.LogicalVolumes))
for _, lv := range vg.LogicalVolumes {
names[lv.Name] = true
}

base := lvname(mountpoint)
base := lvname(lvName)
var exists bool
name := base

Expand All @@ -100,7 +106,7 @@ func (vg *LVMVolumeGroup) CreateMountpoint(mountpoint string, size uint64) (Enti
lv := LVMLogicalVolume{
Name: name,
Size: size,
Payload: &filesystem,
Payload: payload,
}

vg.LogicalVolumes = append(vg.LogicalVolumes, lv)
Expand Down

0 comments on commit 1da3fd0

Please sign in to comment.