diff --git a/internal/action/lvm.go b/internal/action/lvm.go index 7859208..f2f0cc4 100644 --- a/internal/action/lvm.go +++ b/internal/action/lvm.go @@ -89,13 +89,13 @@ func (a *CreateVolumeGroupAction) Success() string { type CreateLogicalVolumeAction struct { name string - volumeGroupPercent int + volumeGroupPercent uint64 volumeGroup string mode model.Mode lvmService service.LvmService } -func NewCreateLogicalVolumeAction(name string, volumeGroupPercent int, volumeGroup string, ls service.LvmService) *CreateLogicalVolumeAction { +func NewCreateLogicalVolumeAction(name string, volumeGroupPercent uint64, volumeGroup string, ls service.LvmService) *CreateLogicalVolumeAction { return &CreateLogicalVolumeAction{ name: name, volumeGroupPercent: volumeGroupPercent, @@ -212,13 +212,13 @@ func (a *ResizePhysicalVolumeAction) Success() string { type ResizeLogicalVolumeAction struct { name string - volumeGroupPercent int + volumeGroupPercent uint64 volumeGroup string mode model.Mode lvmService service.LvmService } -func NewResizeLogicalVolumeAction(name string, volumeGroupPercent int, volumeGroup string, ls service.LvmService) *ResizeLogicalVolumeAction { +func NewResizeLogicalVolumeAction(name string, volumeGroupPercent uint64, volumeGroup string, ls service.LvmService) *ResizeLogicalVolumeAction { return &ResizeLogicalVolumeAction{ name: name, volumeGroupPercent: volumeGroupPercent, diff --git a/internal/backend/lvm.go b/internal/backend/lvm.go index d1f53b6..4c11d12 100644 --- a/internal/backend/lvm.go +++ b/internal/backend/lvm.go @@ -51,7 +51,7 @@ const ( type LvmBackend interface { CreatePhysicalVolume(name string) action.Action CreateVolumeGroup(name string, physicalVolume string) action.Action - CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) action.Action + CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) action.Action ActivateLogicalVolume(name string, volumeGroup string) action.Action GetVolumeGroups(name string) []*model.VolumeGroup GetLogicalVolume(name string, volumeGroup string) (*model.LogicalVolume, error) @@ -59,8 +59,8 @@ type LvmBackend interface { SearchVolumeGroup(physicalVolume string) (*model.VolumeGroup, error) ShouldResizePhysicalVolume(name string) (bool, error) ResizePhysicalVolume(name string) action.Action - ShouldResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) (bool, error) - ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) action.Action + ShouldResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) (bool, error) + ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) action.Action From(config *config.Config) error } @@ -154,7 +154,7 @@ func (lb *LinuxLvmBackend) CreateVolumeGroup(name string, physicalVolume string) return action.NewCreateVolumeGroupAction(name, physicalVolume, lb.lvmService) } -func (lb *LinuxLvmBackend) CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) action.Action { +func (lb *LinuxLvmBackend) CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) action.Action { return action.NewCreateLogicalVolumeAction(name, volumeGroupPercent, volumeGroup, lb.lvmService) } @@ -178,7 +178,7 @@ func (lb *LinuxLvmBackend) ResizePhysicalVolume(name string) action.Action { return action.NewResizePhysicalVolumeAction(name, lb.lvmService) } -func (lb *LinuxLvmBackend) ShouldResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) (bool, error) { +func (lb *LinuxLvmBackend) ShouldResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) (bool, error) { left := float64(volumeGroupPercent) - LogicalVolumeResizeTolerance right := float64(volumeGroupPercent) + LogicalVolumeResizeTolerance lvn, err := lb.lvmGraph.GetLogicalVolume(name, volumeGroup) @@ -196,7 +196,7 @@ func (lb *LinuxLvmBackend) ShouldResizeLogicalVolume(name string, volumeGroup st return usedPerecent < left, nil } -func (lb *LinuxLvmBackend) ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) action.Action { +func (lb *LinuxLvmBackend) ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) action.Action { return action.NewResizeLogicalVolumeAction(name, volumeGroupPercent, volumeGroup, lb.lvmService) } diff --git a/internal/config/config.go b/internal/config/config.go index c4b3283..9138cf9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,7 +22,7 @@ type Flag struct { Remount bool MountOptions string Resize bool - LvmConsumption int + LvmConsumption uint64 } type Device struct { @@ -41,7 +41,7 @@ type Options struct { Remount bool `yaml:"remount"` MountOptions model.MountOptions `yaml:"mountOptions"` Resize bool `yaml:"resize"` - LvmConsumption int `yaml:"lvmConsumption"` + LvmConsumption uint64 `yaml:"lvmConsumption"` } // We don't export "overrides" as this is an attribute that is used @@ -99,7 +99,7 @@ func parseFlags(program string, args []string) (*Flag, error) { flags.BoolVar(&f.Remount, "remount", false, "override for remount") flags.StringVar(&f.MountOptions, "mount-options", "", "override for mount options") flags.BoolVar(&f.Resize, "resize", false, "override for resize filesystem") - flags.IntVar(&f.LvmConsumption, "lvm-consumption", 0, "override for lvm consumption") + flags.Uint64Var(&f.LvmConsumption, "lvm-consumption", 0, "override for lvm consumption") // Actually parse the flag err := flags.Parse(args) @@ -169,7 +169,7 @@ func (c *Config) GetResize(name string) bool { return c.overrides.Resize || c.Defaults.Resize || cd.Resize } -func (c *Config) GetLvmConsumption(name string) int { +func (c *Config) GetLvmConsumption(name string) uint64 { cd, found := c.Devices[name] if !found { return DefaultLvmConsumption diff --git a/internal/config/validator.go b/internal/config/validator.go index ba89ecf..42e0f0f 100644 --- a/internal/config/validator.go +++ b/internal/config/validator.go @@ -184,6 +184,6 @@ func (lcv *LvmConsumptionValidator) Validate(c *Config) error { return nil } -func (lcv *LvmConsumptionValidator) isValid(lc int) bool { - return lc >= 0 && lc <= 100 +func (lcv *LvmConsumptionValidator) isValid(lc uint64) bool { + return lc <= 100 } diff --git a/internal/service/lvm.go b/internal/service/lvm.go index c5c1fd0..c98ba36 100644 --- a/internal/service/lvm.go +++ b/internal/service/lvm.go @@ -16,10 +16,10 @@ type LvmService interface { GetLogicalVolumes() ([]*model.LogicalVolume, error) CreatePhysicalVolume(name string) error CreateVolumeGroup(name string, physicalVolume string) error - CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) error + CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) error ActivateLogicalVolume(name string, volumeGroup string) error ResizePhysicalVolume(name string) error - ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) error + ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) error } type LinuxLvmService struct { @@ -192,7 +192,7 @@ func (ls *LinuxLvmService) CreateVolumeGroup(name string, physicalVolume string) return err } -func (ls *LinuxLvmService) CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) error { +func (ls *LinuxLvmService) CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) error { r := ls.runnerFactory.Select(utils.LvCreate) _, err := r.Command("-l", fmt.Sprintf("%d%%VG", volumeGroupPercent), "-n", name, volumeGroup) return err @@ -210,7 +210,7 @@ func (ls *LinuxLvmService) ResizePhysicalVolume(name string) error { return err } -func (ls *LinuxLvmService) ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) error { +func (ls *LinuxLvmService) ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) error { r := ls.runnerFactory.Select(utils.LvExtend) _, err := r.Command("-l", fmt.Sprintf("%d%%VG", volumeGroupPercent), fmt.Sprintf("%s/%s", volumeGroup, name)) return err