2015-08-03 18:05:34 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2015-08-26 08:00:01 -04:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2015-08-03 18:05:34 -04:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2015-10-30 14:55:52 -04:00
|
|
|
"github.com/docker/docker/pkg/mount"
|
2015-08-03 18:05:34 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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-10-30 14:55:52 -04:00
|
|
|
return daemon.cleanupMountsFromReader(f, mount.Unmount)
|
2015-08-26 08:00:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(target string) error) error {
|
2015-08-25 03:58:33 -04:00
|
|
|
if daemon.repository == "" {
|
|
|
|
return nil
|
|
|
|
}
|
2015-08-26 08:00:01 -04:00
|
|
|
sc := bufio.NewScanner(reader)
|
|
|
|
var errors []string
|
2015-08-03 18:05:34 -04:00
|
|
|
for sc.Scan() {
|
|
|
|
line := sc.Text()
|
2015-08-26 08:00:01 -04:00
|
|
|
fields := strings.Fields(line)
|
2015-08-03 18:05:34 -04:00
|
|
|
if strings.HasPrefix(fields[4], daemon.repository) {
|
2015-08-26 08:00:01 -04:00
|
|
|
logrus.Debugf("Mount base: %v, repository %s", fields[4], daemon.repository)
|
2015-08-03 18:05:34 -04:00
|
|
|
mnt := fields[4]
|
|
|
|
mountBase := filepath.Base(mnt)
|
|
|
|
if mountBase == "mqueue" || mountBase == "shm" {
|
2015-08-26 08:00:01 -04:00
|
|
|
logrus.Debugf("Unmounting %v", mnt)
|
|
|
|
if err := unmount(mnt); err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
errors = append(errors, err.Error())
|
2015-08-03 18:05:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := sc.Err(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-08-26 08:00:01 -04:00
|
|
|
if len(errors) > 0 {
|
|
|
|
return fmt.Errorf("Error cleaningup mounts:\n%v", strings.Join(errors, "\n"))
|
|
|
|
}
|
|
|
|
|
2015-08-03 18:05:34 -04:00
|
|
|
logrus.Debugf("Cleaning up old shm/mqueue mounts: done.")
|
|
|
|
return nil
|
|
|
|
}
|