From 53851474c0b8127442ce11ab38fa0ae8d5c694f0 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 10 Sep 2013 22:15:18 +0200 Subject: [PATCH] Runtime: Add MountMethod to allow AUFS and device-mapper to coexist --- runtime.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/runtime.go b/runtime.go index 2ae7c03a03..1a89340075 100644 --- a/runtime.go +++ b/runtime.go @@ -17,6 +17,13 @@ import ( ) var defaultDns = []string{"8.8.8.8", "8.8.4.4"} +type MountMethod int + +const ( + MountMethodNone MountMethod = iota + MountMethodAUFS + MountMethodDeviceMapper +) type Capabilities struct { MemoryLimit bool @@ -39,6 +46,7 @@ type Runtime struct { srv *Server Dns []string deviceSet DeviceSet + mountMethod MountMethod } var sysInitPath string @@ -76,6 +84,46 @@ func (runtime *Runtime) getContainerElement(id string) *list.Element { 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) { if runtime.deviceSet == nil { return nil, fmt.Errorf("No device set available")