1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Clean up container rootf mounts on daemon start fixes #19679

When the daemon shutdown ungracefully, it will left the running
containers' rootfs still be mounted. This will cause some error
when trying to remove the containers.

Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
Lei Jitang 2016-02-03 20:52:32 -05:00
parent 5b0183e91c
commit af614a19dc

View file

@ -14,7 +14,7 @@ import (
// 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 shm/mqueue mounts: start.") logrus.Debugf("Cleaning up old container shm/mqueue/rootfs mounts: start.")
f, err := os.Open("/proc/self/mountinfo") f, err := os.Open("/proc/self/mountinfo")
if err != nil { if err != nil {
return err return err
@ -33,11 +33,11 @@ func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(tar
for sc.Scan() { for sc.Scan() {
line := sc.Text() line := sc.Text()
fields := strings.Fields(line) fields := strings.Fields(line)
if strings.HasPrefix(fields[4], daemon.repository) { if strings.HasPrefix(fields[4], daemon.root) {
logrus.Debugf("Mount base: %v, repository %s", fields[4], daemon.repository) logrus.Debugf("Mount base: %v", fields[4])
mnt := fields[4] mnt := fields[4]
mountBase := filepath.Base(mnt) mountBase := filepath.Base(mnt)
if mountBase == "mqueue" || mountBase == "shm" { if mountBase == "mqueue" || mountBase == "shm" || mountBase == "merged" {
logrus.Debugf("Unmounting %v", mnt) logrus.Debugf("Unmounting %v", mnt)
if err := unmount(mnt); err != nil { if err := unmount(mnt); err != nil {
logrus.Error(err) logrus.Error(err)
@ -55,6 +55,6 @@ func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(tar
return fmt.Errorf("Error cleaningup mounts:\n%v", strings.Join(errors, "\n")) return fmt.Errorf("Error cleaningup mounts:\n%v", strings.Join(errors, "\n"))
} }
logrus.Debugf("Cleaning up old shm/mqueue mounts: done.") logrus.Debugf("Cleaning up old container shm/mqueue/rootfs mounts: done.")
return nil return nil
} }