mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
![Mrunal Patel](/assets/img/avatar_default.png)
This changeset creates /dev/shm and /dev/mqueue mounts for each container under /var/lib/containers/<id>/ and bind mounts them into the container. When --ipc:container<id/name> is used, then the /dev/shm and /dev/mqueue of the ipc container are used instead of creating new ones for the container. Signed-off-by: Mrunal Patel <mrunalp@gmail.com> Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
44 lines
912 B
Go
44 lines
912 B
Go
package daemon
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/docker/docker/pkg/mount"
|
|
)
|
|
|
|
// 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()
|
|
|
|
sc := bufio.NewScanner(f)
|
|
for sc.Scan() {
|
|
line := sc.Text()
|
|
fields := strings.Split(line, " ")
|
|
if strings.HasPrefix(fields[4], daemon.repository) {
|
|
mnt := fields[4]
|
|
mountBase := filepath.Base(mnt)
|
|
if mountBase == "mqueue" || mountBase == "shm" {
|
|
logrus.Debugf("Unmounting %+v", mnt)
|
|
if err := mount.Unmount(mnt); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if err := sc.Err(); err != nil {
|
|
return err
|
|
}
|
|
|
|
logrus.Debugf("Cleaning up old shm/mqueue mounts: done.")
|
|
return nil
|
|
}
|