c8291f71 |
package daemon
import (
"bufio" |
b1d2f52b |
"fmt"
"io" |
c8291f71 |
"os" |
05cc737f |
"regexp" |
c8291f71 |
"strings"
|
8e71b1e2 |
"github.com/docker/docker/pkg/fileutils" |
78bd17e8 |
"github.com/docker/docker/pkg/mount" |
1009e6a4 |
"github.com/sirupsen/logrus" |
c8291f71 |
)
|
26517a01 |
// On Linux, plugins use a static path for storing execution state,
// instead of deriving path from daemon's exec-root. This is because
// plugin socket files are created here and they cannot exceed max
// path length of 108 bytes.
func getPluginExecRoot(root string) string {
return "/run/docker/plugins"
}
|
9c4570a9 |
func (daemon *Daemon) cleanupMountsByID(id string) error {
logrus.Debugf("Cleaning up old mountid %s: start.", id)
f, err := os.Open("/proc/self/mountinfo")
if err != nil {
return err
}
defer f.Close()
return daemon.cleanupMountsFromReaderByID(f, id, mount.Unmount)
}
func (daemon *Daemon) cleanupMountsFromReaderByID(reader io.Reader, id string, unmount func(target string) error) error {
if daemon.root == "" {
return nil
}
var errors []string |
05cc737f |
regexps := getCleanPatterns(id) |
9c4570a9 |
sc := bufio.NewScanner(reader)
for sc.Scan() { |
05cc737f |
if fields := strings.Fields(sc.Text()); len(fields) >= 4 {
if mnt := fields[4]; strings.HasPrefix(mnt, daemon.root) {
for _, p := range regexps {
if p.MatchString(mnt) {
if err := unmount(mnt); err != nil {
logrus.Error(err)
errors = append(errors, err.Error())
}
} |
9c4570a9 |
}
}
}
}
if err := sc.Err(); err != nil {
return err
}
if len(errors) > 0 { |
05cc737f |
return fmt.Errorf("Error cleaning up mounts:\n%v", strings.Join(errors, "\n")) |
9c4570a9 |
}
|
05cc737f |
logrus.Debugf("Cleaning up old mountid %v: done.", id) |
9c4570a9 |
return nil
}
|
c8291f71 |
// cleanupMounts umounts shm/mqueue mounts for old containers
func (daemon *Daemon) cleanupMounts() error { |
05cc737f |
return daemon.cleanupMountsByID("") |
b1d2f52b |
}
|
05cc737f |
func getCleanPatterns(id string) (regexps []*regexp.Regexp) {
var patterns []string
if id == "" {
id = "[0-9a-f]{64}"
patterns = append(patterns, "containers/"+id+"/shm") |
213a0f9d |
} |
05cc737f |
patterns = append(patterns, "aufs/mnt/"+id+"$", "overlay/"+id+"/merged$", "zfs/graph/"+id+"$")
for _, p := range patterns {
r, err := regexp.Compile(p)
if err == nil {
regexps = append(regexps, r) |
c8291f71 |
}
} |
05cc737f |
return |
c8291f71 |
} |
8e71b1e2 |
func getRealPath(path string) (string, error) {
return fileutils.ReadSymlinkedDirectory(path)
} |