mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
b1d2f52bb2
- Print the mount table as in /proc/self/mountinfo - Do not exit prematurely when one of the ipc mounts doesn't exist. - Do not exit prematurely when one of the ipc mounts cannot be unmounted. - Add a unit test to see if the cleanup really works. - Use syscall.MNT_DETACH to cleanup mounts after a crash. - Unmount IPC mounts when the daemon unregisters an old running container. Signed-off-by: David Calavera <david.calavera@gmail.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package daemon
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"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()
|
|
|
|
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
|
|
for sc.Scan() {
|
|
line := sc.Text()
|
|
fields := strings.Fields(line)
|
|
if strings.HasPrefix(fields[4], daemon.repository) {
|
|
logrus.Debugf("Mount base: %v, repository %s", fields[4], daemon.repository)
|
|
mnt := fields[4]
|
|
mountBase := filepath.Base(mnt)
|
|
if mountBase == "mqueue" || mountBase == "shm" {
|
|
logrus.Debugf("Unmounting %v", mnt)
|
|
if err := unmount(mnt); err != nil {
|
|
logrus.Error(err)
|
|
errors = append(errors, err.Error())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 shm/mqueue mounts: done.")
|
|
return nil
|
|
}
|