mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
Simplify a lot of the mount tuning code (#3285)
This commit is contained in:
@@ -7,61 +7,31 @@ import (
|
||||
)
|
||||
|
||||
// tuneMount is used to set config on a mount point
|
||||
func (b *SystemBackend) tuneMountTTLs(path string, me *MountEntry, newDefault, newMax *time.Duration) error {
|
||||
meConfig := &me.Config
|
||||
func (b *SystemBackend) tuneMountTTLs(path string, me *MountEntry, newDefault, newMax time.Duration) error {
|
||||
zero := time.Duration(0)
|
||||
|
||||
if newDefault == nil && newMax == nil {
|
||||
return nil
|
||||
}
|
||||
if newDefault == nil && newMax != nil &&
|
||||
*newMax == meConfig.MaxLeaseTTL {
|
||||
return nil
|
||||
}
|
||||
if newMax == nil && newDefault != nil &&
|
||||
*newDefault == meConfig.DefaultLeaseTTL {
|
||||
return nil
|
||||
}
|
||||
if newMax != nil && newDefault != nil &&
|
||||
*newDefault == meConfig.DefaultLeaseTTL &&
|
||||
*newMax == meConfig.MaxLeaseTTL {
|
||||
return nil
|
||||
}
|
||||
switch {
|
||||
case newDefault == zero && newMax == zero:
|
||||
// No checks needed
|
||||
|
||||
if newMax != nil && newDefault != nil && *newMax < *newDefault {
|
||||
return fmt.Errorf("new backend max lease TTL of %d less than new backend default lease TTL of %d",
|
||||
int(newMax.Seconds()), int(newDefault.Seconds()))
|
||||
}
|
||||
case newDefault == zero && newMax != zero:
|
||||
// No default/max conflict, no checks needed
|
||||
|
||||
if newMax != nil && newDefault == nil {
|
||||
if meConfig.DefaultLeaseTTL != 0 && *newMax < meConfig.DefaultLeaseTTL {
|
||||
return fmt.Errorf("new backend max lease TTL of %d less than backend default lease TTL of %d",
|
||||
int(newMax.Seconds()), int(meConfig.DefaultLeaseTTL.Seconds()))
|
||||
case newDefault != zero && newMax == zero:
|
||||
// No default/max conflict, no checks needed
|
||||
|
||||
case newDefault != zero && newMax != zero:
|
||||
if newMax < newDefault {
|
||||
return fmt.Errorf("backend max lease TTL of %d would be less than backend default lease TTL of %d",
|
||||
int(newMax.Seconds()), int(newDefault.Seconds()))
|
||||
}
|
||||
}
|
||||
|
||||
if newDefault != nil {
|
||||
if meConfig.MaxLeaseTTL == 0 {
|
||||
if newMax == nil && *newDefault > b.Core.maxLeaseTTL {
|
||||
return fmt.Errorf("new backend default lease TTL of %d greater than system max lease TTL of %d",
|
||||
int(newDefault.Seconds()), int(b.Core.maxLeaseTTL.Seconds()))
|
||||
}
|
||||
} else {
|
||||
if newMax == nil && *newDefault > meConfig.MaxLeaseTTL {
|
||||
return fmt.Errorf("new backend default lease TTL of %d greater than backend max lease TTL of %d",
|
||||
int(newDefault.Seconds()), int(meConfig.MaxLeaseTTL.Seconds()))
|
||||
}
|
||||
}
|
||||
}
|
||||
origMax := me.Config.MaxLeaseTTL
|
||||
origDefault := me.Config.DefaultLeaseTTL
|
||||
|
||||
origMax := meConfig.MaxLeaseTTL
|
||||
origDefault := meConfig.DefaultLeaseTTL
|
||||
|
||||
if newMax != nil {
|
||||
meConfig.MaxLeaseTTL = *newMax
|
||||
}
|
||||
if newDefault != nil {
|
||||
meConfig.DefaultLeaseTTL = *newDefault
|
||||
}
|
||||
me.Config.MaxLeaseTTL = newMax
|
||||
me.Config.DefaultLeaseTTL = newDefault
|
||||
|
||||
// Update the mount table
|
||||
var err error
|
||||
@@ -72,13 +42,12 @@ func (b *SystemBackend) tuneMountTTLs(path string, me *MountEntry, newDefault, n
|
||||
err = b.Core.persistMounts(b.Core.mounts, me.Local)
|
||||
}
|
||||
if err != nil {
|
||||
meConfig.MaxLeaseTTL = origMax
|
||||
meConfig.DefaultLeaseTTL = origDefault
|
||||
me.Config.MaxLeaseTTL = origMax
|
||||
me.Config.DefaultLeaseTTL = origDefault
|
||||
return fmt.Errorf("failed to update mount table, rolling back TTL changes")
|
||||
}
|
||||
|
||||
if b.Core.logger.IsInfo() {
|
||||
b.Core.logger.Info("core: mount tuning successful", "path", path)
|
||||
b.Core.logger.Info("core: mount tuning of leases successful", "path", path)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user