Explorar o código

daemon.cleanupMounts(): use mount.SingleEntryFilter

Use mount.SingleEntryFilter as we're only interested in a single entry.

Test case data of TestShouldUnmountRoot is modified accordingly, as
from now on:

1. `info` can't be nil;

2. the mountpoint check is not performed (as SingleEntryFilter
   guarantees it to be equal to daemon.root).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Kir Kolyshkin %!s(int64=7) %!d(string=hai) anos
pai
achega
d3ebcde82a
Modificáronse 2 ficheiros con 7 adicións e 21 borrados
  1. 7 9
      daemon/daemon_linux.go
  2. 0 12
      daemon/daemon_linux_test.go

+ 7 - 9
daemon/daemon_linux.go

@@ -74,18 +74,22 @@ func (daemon *Daemon) cleanupMounts() error {
 		return err
 		return err
 	}
 	}
 
 
-	infos, err := mount.GetMounts(nil)
+	info, err := mount.GetMounts(mount.SingleEntryFilter(daemon.root))
 	if err != nil {
 	if err != nil {
 		return errors.Wrap(err, "error reading mount table for cleanup")
 		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`).
 	// `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
 	// 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`
 	//   `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
 	// This is only done when the daemon is started up and `/daemon/root` is not
 	// already on a shared mountpoint.
 	// already on a shared mountpoint.
-	if !shouldUnmountRoot(daemon.root, info) {
+	if !shouldUnmountRoot(daemon.root, info[0]) {
 		return nil
 		return nil
 	}
 	}
 
 
@@ -114,12 +118,6 @@ func getRealPath(path string) (string, error) {
 }
 }
 
 
 func shouldUnmountRoot(root string, info *mount.Info) bool {
 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) {
 	if !strings.HasSuffix(root, info.Root) {
 		return false
 		return false
 	}
 	}

+ 0 - 12
daemon/daemon_linux_test.go

@@ -179,12 +179,6 @@ func TestShouldUnmountRoot(t *testing.T) {
 			info:   &mount.Info{Root: "/docker", Mountpoint: "/docker"},
 			info:   &mount.Info{Root: "/docker", Mountpoint: "/docker"},
 			expect: true,
 			expect: true,
 		},
 		},
-		{
-			desc:   "not a mountpoint",
-			root:   "/docker",
-			info:   nil,
-			expect: false,
-		},
 		{
 		{
 			desc:   "root is at in a submount from `/`",
 			desc:   "root is at in a submount from `/`",
 			root:   "/foo/docker",
 			root:   "/foo/docker",
@@ -197,12 +191,6 @@ func TestShouldUnmountRoot(t *testing.T) {
 			info:   &mount.Info{Root: "/docker/volumes/1234657/_data", Mountpoint: "/docker"},
 			info:   &mount.Info{Root: "/docker/volumes/1234657/_data", Mountpoint: "/docker"},
 			expect: false,
 			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) {
 		t.Run(test.desc, func(t *testing.T) {
 			for _, options := range []struct {
 			for _, options := range []struct {