mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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>
This commit is contained in:
parent
bb934c6aca
commit
d3ebcde82a
2 changed files with 7 additions and 21 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue