disk/lvm: split up CreateMountpoint
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.
This commit is contained in:
parent
a1a3e5ba2d
commit
93875576e9
1 changed files with 11 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue