disk: new types LVMVolumeGroup and LVMLogicalVolume
Types to represent LVM2 setups with logical volumes being contained in volume groups. LVMVolumeGroup implements the following disk interfaces: - Entity - Container - VolumeContainer LVMLogicalVolume implements the following disk interfaces: - Entity - Container - Sizeable Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
parent
ef2fdf16a7
commit
f6f54b14ad
1 changed files with 77 additions and 0 deletions
77
internal/disk/lvm.go
Normal file
77
internal/disk/lvm.go
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
package disk
|
||||
|
||||
import "fmt"
|
||||
|
||||
type LVMVolumeGroup struct {
|
||||
Name string
|
||||
Description string
|
||||
|
||||
LogicalVolumes []LVMLogicalVolume
|
||||
}
|
||||
|
||||
func (vg *LVMVolumeGroup) IsContainer() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (vg *LVMVolumeGroup) GetItemCount() uint {
|
||||
return uint(len(vg.LogicalVolumes))
|
||||
}
|
||||
|
||||
func (vg *LVMVolumeGroup) GetChild(n uint) Entity {
|
||||
return &vg.LogicalVolumes[n]
|
||||
}
|
||||
|
||||
func (vg *LVMVolumeGroup) CreateVolume(mountpoint string, size uint64) (Entity, error) {
|
||||
filesystem := Filesystem{
|
||||
Type: "xfs",
|
||||
Mountpoint: mountpoint,
|
||||
FSTabOptions: "defaults",
|
||||
FSTabFreq: 0,
|
||||
FSTabPassNo: 0,
|
||||
}
|
||||
|
||||
lv := LVMLogicalVolume{
|
||||
Size: size,
|
||||
Payload: &filesystem,
|
||||
}
|
||||
|
||||
vg.LogicalVolumes = append(vg.LogicalVolumes, lv)
|
||||
|
||||
return &vg.LogicalVolumes[len(vg.LogicalVolumes)-1], nil
|
||||
}
|
||||
|
||||
type LVMLogicalVolume struct {
|
||||
Name string
|
||||
Size uint64
|
||||
Payload Entity
|
||||
}
|
||||
|
||||
func (lv *LVMLogicalVolume) IsContainer() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (lv *LVMLogicalVolume) GetItemCount() uint {
|
||||
if lv.Payload == nil {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
func (lv *LVMLogicalVolume) GetChild(n uint) Entity {
|
||||
if n != 0 {
|
||||
panic(fmt.Sprintf("invalid child index for LVMLogicalVolume: %d != 0", n))
|
||||
}
|
||||
return lv.Payload
|
||||
}
|
||||
|
||||
func (lv *LVMLogicalVolume) GetSize() uint64 {
|
||||
return lv.Size
|
||||
}
|
||||
|
||||
func (lv *LVMLogicalVolume) EnsureSize(s uint64) bool {
|
||||
if s > lv.Size {
|
||||
lv.Size = s
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue