|
@@ -5,7 +5,7 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"io"
|
|
"io"
|
|
"os"
|
|
"os"
|
|
- "path/filepath"
|
|
|
|
|
|
+ "regexp"
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/Sirupsen/logrus"
|
|
@@ -28,91 +28,53 @@ func (daemon *Daemon) cleanupMountsFromReaderByID(reader io.Reader, id string, u
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
var errors []string
|
|
var errors []string
|
|
- mountRoot := ""
|
|
|
|
- shmSuffix := "/" + id + "/shm"
|
|
|
|
- mergedSuffix := "/" + id + "/merged"
|
|
|
|
|
|
+
|
|
|
|
+ regexps := getCleanPatterns(id)
|
|
sc := bufio.NewScanner(reader)
|
|
sc := bufio.NewScanner(reader)
|
|
for sc.Scan() {
|
|
for sc.Scan() {
|
|
- line := sc.Text()
|
|
|
|
- fields := strings.Fields(line)
|
|
|
|
- if strings.HasPrefix(fields[4], daemon.root) {
|
|
|
|
- logrus.Debugf("Mount base: %v", fields[4])
|
|
|
|
- mnt := fields[4]
|
|
|
|
- if strings.HasSuffix(mnt, shmSuffix) || strings.HasSuffix(mnt, mergedSuffix) {
|
|
|
|
- logrus.Debugf("Unmounting %v", mnt)
|
|
|
|
- if err := unmount(mnt); err != nil {
|
|
|
|
- logrus.Error(err)
|
|
|
|
- errors = append(errors, err.Error())
|
|
|
|
|
|
+ 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())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- } else if mountBase := filepath.Base(mnt); mountBase == id {
|
|
|
|
- mountRoot = mnt
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if mountRoot != "" {
|
|
|
|
- logrus.Debugf("Unmounting %v", mountRoot)
|
|
|
|
- if err := unmount(mountRoot); err != nil {
|
|
|
|
- logrus.Error(err)
|
|
|
|
- errors = append(errors, err.Error())
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if err := sc.Err(); err != nil {
|
|
if err := sc.Err(); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
if len(errors) > 0 {
|
|
if len(errors) > 0 {
|
|
- return fmt.Errorf("Error cleaningup mounts:\n%v", strings.Join(errors, "\n"))
|
|
|
|
|
|
+ return fmt.Errorf("Error cleaning up mounts:\n%v", strings.Join(errors, "\n"))
|
|
}
|
|
}
|
|
|
|
|
|
- logrus.Debugf("Cleaning up old container shm/mqueue/rootfs mounts: done.")
|
|
|
|
|
|
+ logrus.Debugf("Cleaning up old mountid %v: done.", id)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
// cleanupMounts umounts shm/mqueue mounts for old containers
|
|
// cleanupMounts umounts shm/mqueue mounts for old containers
|
|
func (daemon *Daemon) cleanupMounts() error {
|
|
func (daemon *Daemon) cleanupMounts() error {
|
|
- logrus.Debugf("Cleaning up old container shm/mqueue/rootfs mounts: start.")
|
|
|
|
- f, err := os.Open("/proc/self/mountinfo")
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- defer f.Close()
|
|
|
|
-
|
|
|
|
- return daemon.cleanupMountsFromReader(f, mount.Unmount)
|
|
|
|
|
|
+ return daemon.cleanupMountsByID("")
|
|
}
|
|
}
|
|
|
|
|
|
-func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(target string) error) error {
|
|
|
|
- if daemon.root == "" {
|
|
|
|
- return nil
|
|
|
|
|
|
+func getCleanPatterns(id string) (regexps []*regexp.Regexp) {
|
|
|
|
+ var patterns []string
|
|
|
|
+ if id == "" {
|
|
|
|
+ id = "[0-9a-f]{64}"
|
|
|
|
+ patterns = append(patterns, "containers/"+id+"/shm")
|
|
}
|
|
}
|
|
- sc := bufio.NewScanner(reader)
|
|
|
|
- var errors []string
|
|
|
|
- for sc.Scan() {
|
|
|
|
- line := sc.Text()
|
|
|
|
- fields := strings.Fields(line)
|
|
|
|
- if strings.HasPrefix(fields[4], daemon.root) {
|
|
|
|
- logrus.Debugf("Mount base: %v", fields[4])
|
|
|
|
- mnt := fields[4]
|
|
|
|
- mountBase := filepath.Base(mnt)
|
|
|
|
- if mountBase == "shm" || mountBase == "merged" {
|
|
|
|
- logrus.Debugf("Unmounting %v", mnt)
|
|
|
|
- if err := unmount(mnt); err != nil {
|
|
|
|
- logrus.Error(err)
|
|
|
|
- errors = append(errors, err.Error())
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ 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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- if err := sc.Err(); err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if len(errors) > 0 {
|
|
|
|
- return fmt.Errorf("Error cleaningup mounts:\n%v", strings.Join(errors, "\n"))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- logrus.Debugf("Cleaning up old container shm/mqueue/rootfs mounts: done.")
|
|
|
|
- return nil
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|