2015-08-04 01:05:34 +03:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2015-08-26 15:00:01 +03:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2015-08-04 01:05:34 +03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// cleanupMounts umounts shm/mqueue mounts for old containers
|
|
|
|
func (daemon *Daemon) cleanupMounts() error {
|
|
|
|
logrus.Debugf("Cleaning up old shm/mqueue mounts: start.")
|
|
|
|
f, err := os.Open("/proc/self/mountinfo")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
2015-08-26 15:00:01 +03:00
|
|
|
return daemon.cleanupMountsFromReader(f, detachMounted)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(target string) error) error {
|
|
|
|
sc := bufio.NewScanner(reader)
|
|
|
|
var errors []string
|
2015-08-04 01:05:34 +03:00
|
|
|
for sc.Scan() {
|
|
|
|
line := sc.Text()
|
2015-08-26 15:00:01 +03:00
|
|
|
fields := strings.Fields(line)
|
2015-08-04 01:05:34 +03:00
|
|
|
if strings.HasPrefix(fields[4], daemon.repository) {
|
2015-08-26 15:00:01 +03:00
|
|
|
logrus.Debugf("Mount base: %v, repository %s", fields[4], daemon.repository)
|
2015-08-04 01:05:34 +03:00
|
|
|
mnt := fields[4]
|
|
|
|
mountBase := filepath.Base(mnt)
|
|
|
|
if mountBase == "mqueue" || mountBase == "shm" {
|
2015-08-26 15:00:01 +03:00
|
|
|
logrus.Debugf("Unmounting %v", mnt)
|
|
|
|
if err := unmount(mnt); err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
errors = append(errors, err.Error())
|
2015-08-04 01:05:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := sc.Err(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-08-26 15:00:01 +03:00
|
|
|
if len(errors) > 0 {
|
|
|
|
return fmt.Errorf("Error cleaningup mounts:\n%v", strings.Join(errors, "\n"))
|
|
|
|
}
|
|
|
|
|
2015-08-04 01:05:34 +03:00
|
|
|
logrus.Debugf("Cleaning up old shm/mqueue mounts: done.")
|
|
|
|
return nil
|
|
|
|
}
|