diff --git a/daemon/daemon_linux.go b/daemon/daemon_linux.go index bbac8a4fbc..ccb0974096 100644 --- a/daemon/daemon_linux.go +++ b/daemon/daemon_linux.go @@ -74,18 +74,22 @@ func (daemon *Daemon) cleanupMounts() error { return err } - infos, err := mount.GetMounts(nil) + info, err := mount.GetMounts(mount.SingleEntryFilter(daemon.root)) if err != nil { return errors.Wrap(err, "error reading mount table for cleanup") } - info := getMountInfo(infos, daemon.root) + if len(info) < 1 { + // no mount found, we're done here + return nil + } + // `info.Root` here is the root mountpoint of the passed in path (`daemon.root`). // The ony cases that need to be cleaned up is when the daemon has performed a // `mount --bind /daemon/root /daemon/root && mount --make-shared /daemon/root` // This is only done when the daemon is started up and `/daemon/root` is not // already on a shared mountpoint. - if !shouldUnmountRoot(daemon.root, info) { + if !shouldUnmountRoot(daemon.root, info[0]) { return nil } @@ -114,12 +118,6 @@ func getRealPath(path string) (string, error) { } func shouldUnmountRoot(root string, info *mount.Info) bool { - if info == nil { - return false - } - if info.Mountpoint != root { - return false - } if !strings.HasSuffix(root, info.Root) { return false } diff --git a/daemon/daemon_linux_test.go b/daemon/daemon_linux_test.go index 195afb1e0f..671e6f461f 100644 --- a/daemon/daemon_linux_test.go +++ b/daemon/daemon_linux_test.go @@ -179,12 +179,6 @@ func TestShouldUnmountRoot(t *testing.T) { info: &mount.Info{Root: "/docker", Mountpoint: "/docker"}, expect: true, }, - { - desc: "not a mountpoint", - root: "/docker", - info: nil, - expect: false, - }, { desc: "root is at in a submount from `/`", root: "/foo/docker", @@ -197,12 +191,6 @@ func TestShouldUnmountRoot(t *testing.T) { info: &mount.Info{Root: "/docker/volumes/1234657/_data", Mountpoint: "/docker"}, expect: false, }, - { - desc: "root is mounted in from a parent mount namespace different root dir", - root: "/foo/bar", - info: &mount.Info{Root: "/docker/volumes/1234657/_data", Mountpoint: "/foo/bar"}, - expect: false, - }, } { t.Run(test.desc, func(t *testing.T) { for _, options := range []struct {