1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #456 from dotcloud/453-generic_kernel_detection-fix

453 generic kernel detection fix
This commit is contained in:
Guillaume J. Charmes 2013-04-22 18:20:17 -07:00
commit 7a8ac76299
4 changed files with 86 additions and 56 deletions

View file

@ -0,0 +1,9 @@
package docker
import (
"fmt"
)
func getKernelVersion() (*KernelVersionInfo, error) {
return nil, fmt.Errorf("Kernel version detection is not available on darwin")
}

69
getKernelVersion_linux.go Normal file
View file

@ -0,0 +1,69 @@
package docker
import (
"bytes"
"strconv"
"strings"
"syscall"
)
func getKernelVersion() (*KernelVersionInfo, error) {
var (
uts syscall.Utsname
flavor string
kernel, major, minor int
err error
)
if err := syscall.Uname(&uts); err != nil {
return nil, err
}
release := make([]byte, len(uts.Release))
i := 0
for _, c := range uts.Release {
release[i] = byte(c)
i++
}
// Remove the \x00 from the release for Atoi to parse correctly
release = release[:bytes.IndexByte(release, 0)]
tmp := strings.SplitN(string(release), "-", 2)
tmp2 := strings.SplitN(tmp[0], ".", 3)
if len(tmp2) > 0 {
kernel, err = strconv.Atoi(tmp2[0])
if err != nil {
return nil, err
}
}
if len(tmp2) > 1 {
major, err = strconv.Atoi(tmp2[1])
if err != nil {
return nil, err
}
}
if len(tmp2) > 2 {
minor, err = strconv.Atoi(tmp2[2])
if err != nil {
return nil, err
}
}
if len(tmp) == 2 {
flavor = tmp[1]
} else {
flavor = ""
}
return &KernelVersionInfo{
Kernel: kernel,
Major: major,
Minor: minor,
Flavor: flavor,
}, nil
}

View file

@ -295,15 +295,14 @@ func NewRuntime() (*Runtime, error) {
return nil, err return nil, err
} }
k, err := GetKernelVersion() if k, err := GetKernelVersion(); err != nil {
if err != nil { log.Printf("WARNING: %s\n", err)
return nil, err } else {
}
runtime.kernelVersion = k runtime.kernelVersion = k
if CompareKernelVersion(k, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}) < 0 { if CompareKernelVersion(k, &KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}) < 0 {
log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String()) log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String())
} }
}
if cgroupMemoryMountpoint, err := FindCgroupMountpoint("memory"); err != nil { if cgroupMemoryMountpoint, err := FindCgroupMountpoint("memory"); err != nil {
log.Printf("WARNING: %s\n", err) log.Printf("WARNING: %s\n", err)

View file

@ -14,10 +14,8 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"strconv"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
) )
@ -407,52 +405,7 @@ type KernelVersionInfo struct {
// FIXME: this doens't build on Darwin // FIXME: this doens't build on Darwin
func GetKernelVersion() (*KernelVersionInfo, error) { func GetKernelVersion() (*KernelVersionInfo, error) {
var uts syscall.Utsname return getKernelVersion()
if err := syscall.Uname(&uts); err != nil {
return nil, err
}
release := make([]byte, len(uts.Release))
i := 0
for _, c := range uts.Release {
release[i] = byte(c)
i++
}
tmp := strings.SplitN(string(release), "-", 2)
if len(tmp) != 2 {
return nil, fmt.Errorf("Unrecognized kernel version")
}
tmp2 := strings.SplitN(tmp[0], ".", 3)
if len(tmp2) != 3 {
return nil, fmt.Errorf("Unrecognized kernel version")
}
kernel, err := strconv.Atoi(tmp2[0])
if err != nil {
return nil, err
}
major, err := strconv.Atoi(tmp2[1])
if err != nil {
return nil, err
}
minor, err := strconv.Atoi(tmp2[2])
if err != nil {
return nil, err
}
flavor := tmp[1]
return &KernelVersionInfo{
Kernel: kernel,
Major: major,
Minor: minor,
Flavor: flavor,
}, nil
} }
func (k *KernelVersionInfo) String() string { func (k *KernelVersionInfo) String() string {