mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Runtime: Add MountMethod to allow AUFS and device-mapper to coexist
This commit is contained in:
parent
f317a6b6fe
commit
53851474c0
1 changed files with 48 additions and 0 deletions
48
runtime.go
48
runtime.go
|
@ -17,6 +17,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
var defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
||||||
|
type MountMethod int
|
||||||
|
|
||||||
|
const (
|
||||||
|
MountMethodNone MountMethod = iota
|
||||||
|
MountMethodAUFS
|
||||||
|
MountMethodDeviceMapper
|
||||||
|
)
|
||||||
|
|
||||||
type Capabilities struct {
|
type Capabilities struct {
|
||||||
MemoryLimit bool
|
MemoryLimit bool
|
||||||
|
@ -39,6 +46,7 @@ type Runtime struct {
|
||||||
srv *Server
|
srv *Server
|
||||||
Dns []string
|
Dns []string
|
||||||
deviceSet DeviceSet
|
deviceSet DeviceSet
|
||||||
|
mountMethod MountMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
var sysInitPath string
|
var sysInitPath string
|
||||||
|
@ -76,6 +84,46 @@ func (runtime *Runtime) getContainerElement(id string) *list.Element {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasFilesystemSupport(fstype string) bool {
|
||||||
|
content, err := ioutil.ReadFile("/proc/filesystems")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("WARNING: Unable to read /proc/filesystems, assuming fs %s is not supported.", fstype)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
lines := strings.Split(string(content), "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
if strings.HasPrefix(line, "nodev") {
|
||||||
|
line = line[5:]
|
||||||
|
}
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if line == fstype {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (runtime *Runtime) GetMountMethod() MountMethod {
|
||||||
|
if runtime.mountMethod == MountMethodNone {
|
||||||
|
// Try to automatically pick a method
|
||||||
|
if hasFilesystemSupport("aufs") {
|
||||||
|
log.Printf("Using AUFS backend.")
|
||||||
|
runtime.mountMethod = MountMethodAUFS
|
||||||
|
} else {
|
||||||
|
_ = exec.Command("modprobe", "aufs").Run()
|
||||||
|
if hasFilesystemSupport("aufs") {
|
||||||
|
log.Printf("Using AUFS backend.")
|
||||||
|
runtime.mountMethod = MountMethodAUFS
|
||||||
|
} else {
|
||||||
|
log.Printf("Using device-mapper backend.")
|
||||||
|
runtime.mountMethod = MountMethodDeviceMapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return runtime.mountMethod
|
||||||
|
}
|
||||||
|
|
||||||
func (runtime *Runtime) GetDeviceSet() (DeviceSet, error) {
|
func (runtime *Runtime) GetDeviceSet() (DeviceSet, error) {
|
||||||
if runtime.deviceSet == nil {
|
if runtime.deviceSet == nil {
|
||||||
return nil, fmt.Errorf("No device set available")
|
return nil, fmt.Errorf("No device set available")
|
||||||
|
|
Loading…
Add table
Reference in a new issue