Skip to content

Commit

Permalink
Allow for larger preset property values, do not override
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Carroll <jim.carroll@docker.com>
  • Loading branch information
Jim Carroll committed Mar 22, 2018
1 parent 2bf6330 commit 4f39e1c
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions drivers/overlay/ostweaks_linux.go
Expand Up @@ -3,6 +3,7 @@ package overlay
import (
"io/ioutil"
"path"
"strconv"
"strings"

"github.com/sirupsen/logrus"
Expand All @@ -21,10 +22,43 @@ func writeSystemProperty(key, value string) error {
return ioutil.WriteFile(path.Join("/proc/sys", keyPath), []byte(value), 0644)
}

func readSystemProperty(key string) ([]byte, error) {
keyPath := strings.Replace(key, ".", "/", -1)
return ioutil.ReadFile(path.Join("/proc/sys", keyPath))
}

func byte2int(b []byte) int {
s := string(b)
s2 := s[:len(s)-1] // remove trailing newline
i := str2int(s2)
return i
}

func str2int(s string) int {
i, err := strconv.Atoi(s)
if err != nil {
logrus.Errorf("error converting string %v to int, err: %s", s, err)
}
return i
}

func applyOStweaks() {
for k, v := range sysctlConf {
if err := writeSystemProperty(k, v); err != nil {
logrus.Errorf("error setting the kernel parameter %s = %s, err: %s", k, v, err)
oldv_b, err := readSystemProperty(k)

if err != nil {
logrus.Errorf("error reading the kernel parameter %s = %s, err: %s", k, v, err)
}

oldv_i := byte2int(oldv_b)
newv_i := str2int(v)

// Apply new property value, only if new value is larger than existing value
if newv_i > oldv_i {
new_v := strconv.Itoa(newv_i)
if err := writeSystemProperty(k, new_v); err != nil {
logrus.Errorf("error setting the kernel parameter %s = %s, err: %s", k, v, err)
}
}
}
}

0 comments on commit 4f39e1c

Please sign in to comment.