2016-12-16 14:13:23 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/parsers/kernel"
|
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// SysInfo stores information about which features a kernel supports.
|
|
|
|
SysInfo *sysinfo.SysInfo
|
|
|
|
)
|
|
|
|
|
|
|
|
func cpuCfsPeriod() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.CPUCfsPeriod
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func cpuCfsQuota() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.CPUCfsQuota
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func cpuShare() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.CPUShares
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func oomControl() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.OomKillDisable
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func pidsLimit() bool {
|
|
|
|
return SysInfo.PidsLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
func kernelMemorySupport() bool {
|
2019-01-04 12:23:36 +00:00
|
|
|
// TODO remove this once kmem support in RHEL kernels is fixed. See https://github.com/opencontainers/runc/pull/1921
|
|
|
|
daemonV, err := kernel.ParseRelease(testEnv.DaemonInfo.KernelVersion)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
requiredV := kernel.VersionInfo{Kernel: 3, Major: 10}
|
|
|
|
if kernel.CompareKernelVersion(*daemonV, requiredV) < 1 {
|
|
|
|
// On Kernel 3.10 and under, don't consider kernel memory to be supported,
|
|
|
|
// even if the kernel (and thus the daemon) reports it as being supported
|
|
|
|
return false
|
|
|
|
}
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.KernelMemory
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func memoryLimitSupport() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.MemoryLimit
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func memoryReservationSupport() bool {
|
|
|
|
return SysInfo.MemoryReservation
|
|
|
|
}
|
|
|
|
|
|
|
|
func swapMemorySupport() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.SwapLimit
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func memorySwappinessSupport() bool {
|
2018-12-24 12:25:53 +00:00
|
|
|
return testEnv.IsLocalDaemon() && SysInfo.MemorySwappiness
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func blkioWeight() bool {
|
2018-12-24 12:25:53 +00:00
|
|
|
return testEnv.IsLocalDaemon() && SysInfo.BlkioWeight
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func cgroupCpuset() bool {
|
2017-09-11 14:23:59 +00:00
|
|
|
return testEnv.DaemonInfo.CPUSet
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func seccompEnabled() bool {
|
|
|
|
return supportsSeccomp && SysInfo.Seccomp
|
|
|
|
}
|
|
|
|
|
|
|
|
func bridgeNfIptables() bool {
|
|
|
|
return !SysInfo.BridgeNFCallIPTablesDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func bridgeNfIP6tables() bool {
|
|
|
|
return !SysInfo.BridgeNFCallIP6TablesDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func unprivilegedUsernsClone() bool {
|
|
|
|
content, err := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
|
|
|
|
return err != nil || !strings.Contains(string(content), "0")
|
|
|
|
}
|
|
|
|
|
|
|
|
func ambientCapabilities() bool {
|
|
|
|
content, err := ioutil.ReadFile("/proc/self/status")
|
|
|
|
return err != nil || strings.Contains(string(content), "CapAmb:")
|
|
|
|
}
|
|
|
|
|
|
|
|
func overlayFSSupported() bool {
|
|
|
|
cmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "cat /proc/filesystems")
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return bytes.Contains(out, []byte("overlay\n"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func overlay2Supported() bool {
|
|
|
|
if !overlayFSSupported() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-08-25 22:48:36 +00:00
|
|
|
daemonV, err := kernel.ParseRelease(testEnv.DaemonInfo.KernelVersion)
|
2016-12-16 14:13:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
requiredV := kernel.VersionInfo{Kernel: 4}
|
|
|
|
return kernel.CompareKernelVersion(*daemonV, requiredV) > -1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-12-24 12:25:53 +00:00
|
|
|
if testEnv.IsLocalDaemon() {
|
2017-09-11 14:23:59 +00:00
|
|
|
SysInfo = sysinfo.New(true)
|
|
|
|
}
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|