From 182795cff6bbeb93090b5b973cf5b07884e8c5b8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 19 Sep 2020 18:45:41 +0200 Subject: [PATCH] Do not call mount.RecursiveUnmount() on Windows Signed-off-by: Sebastiaan van Stijn --- daemon/daemon_unix.go | 4 ++++ daemon/daemon_windows.go | 4 ++++ daemon/start.go | 3 +-- plugin/manager.go | 7 ++----- plugin/manager_linux.go | 4 ++++ plugin/manager_windows.go | 4 ++++ testutil/daemon/daemon.go | 10 ---------- testutil/daemon/daemon_unix.go | 10 ++++++++++ testutil/daemon/daemon_windows.go | 2 ++ volume/local/local.go | 20 +++----------------- volume/local/local_unix.go | 17 +++++++++++++++++ volume/local/local_windows.go | 5 +++++ 12 files changed, 56 insertions(+), 34 deletions(-) diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index efe8796d8d..2e4bbd6e8c 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -1711,3 +1711,7 @@ func (daemon *Daemon) RawSysInfo(quiet bool) *sysinfo.SysInfo { } return sysinfo.New(quiet, opts...) } + +func recursiveUnmount(target string) error { + return mount.RecursiveUnmount(target) +} diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index aee48d39c3..38c2ab8633 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -467,6 +467,10 @@ func (daemon *Daemon) cleanupMounts() error { return nil } +func recursiveUnmount(_ string) error { + return nil +} + func setupRemappedRoot(config *config.Config) (*idtools.IdentityMapping, error) { return &idtools.IdentityMapping{}, nil } diff --git a/daemon/start.go b/daemon/start.go index 6126efacbf..049eb686e2 100644 --- a/daemon/start.go +++ b/daemon/start.go @@ -12,7 +12,6 @@ import ( containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" "github.com/docker/docker/errdefs" - "github.com/moby/sys/mount" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -253,7 +252,7 @@ func (daemon *Daemon) Cleanup(container *container.Container) { logrus.Warnf("%s cleanup: failed to unmount secrets: %s", container.ID, err) } - if err := mount.RecursiveUnmount(container.Root); err != nil { + if err := recursiveUnmount(container.Root); err != nil { logrus.WithError(err).WithField("container", container.ID).Warn("Error while cleaning up container resource mounts.") } diff --git a/plugin/manager.go b/plugin/manager.go index db38fca016..c237378fa3 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -23,7 +23,6 @@ import ( "github.com/docker/docker/pkg/system" v2 "github.com/docker/docker/plugin/v2" "github.com/docker/docker/registry" - "github.com/moby/sys/mount" digest "github.com/opencontainers/go-digest" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" @@ -159,10 +158,8 @@ func (pm *Manager) HandleExitEvent(id string) error { if restart { pm.enable(p, c, true) - } else { - if err := mount.RecursiveUnmount(filepath.Join(pm.config.Root, id)); err != nil { - return errors.Wrap(err, "error cleaning up plugin mounts") - } + } else if err := recursiveUnmount(filepath.Join(pm.config.Root, id)); err != nil { + return errors.Wrap(err, "error cleaning up plugin mounts") } return nil } diff --git a/plugin/manager_linux.go b/plugin/manager_linux.go index a147df62f5..d2245143aa 100644 --- a/plugin/manager_linux.go +++ b/plugin/manager_linux.go @@ -346,3 +346,7 @@ func (pm *Manager) createPlugin(name string, configDigest, manifestDigest digest return p, nil } + +func recursiveUnmount(target string) error { + return mount.RecursiveUnmount(target) +} diff --git a/plugin/manager_windows.go b/plugin/manager_windows.go index 89595dfd84..003b2210f9 100644 --- a/plugin/manager_windows.go +++ b/plugin/manager_windows.go @@ -26,3 +26,7 @@ func (pm *Manager) restore(p *v2.Plugin, c *controller) error { // Shutdown plugins func (pm *Manager) Shutdown() { } + +func recursiveUnmount(_ string) error { + return nil +} diff --git a/testutil/daemon/daemon.go b/testutil/daemon/daemon.go index 3b9f039c8a..1b29654f6c 100644 --- a/testutil/daemon/daemon.go +++ b/testutil/daemon/daemon.go @@ -24,7 +24,6 @@ import ( "github.com/docker/docker/testutil/request" "github.com/docker/go-connections/sockets" "github.com/docker/go-connections/tlsconfig" - "github.com/moby/sys/mount" "github.com/pkg/errors" "gotest.tools/v3/assert" ) @@ -812,15 +811,6 @@ func (d *Daemon) Info(t testing.TB) types.Info { return info } -// cleanupMount unmounts the daemon root directory, or logs a message if -// unmounting failed. -func cleanupMount(t testing.TB, d *Daemon) { - t.Helper() - if err := mount.Unmount(d.Root); err != nil { - d.log.Logf("[%s] unable to unmount daemon root (%s): %v", d.id, d.Root, err) - } -} - // cleanupRaftDir removes swarmkit wal files if present func cleanupRaftDir(t testing.TB, d *Daemon) { t.Helper() diff --git a/testutil/daemon/daemon_unix.go b/testutil/daemon/daemon_unix.go index fac5297480..8b7e53f50e 100644 --- a/testutil/daemon/daemon_unix.go +++ b/testutil/daemon/daemon_unix.go @@ -11,10 +11,20 @@ import ( "syscall" "testing" + "github.com/docker/docker/pkg/mount" "golang.org/x/sys/unix" "gotest.tools/v3/assert" ) +// cleanupMount unmounts the daemon root directory, or logs a message if +// unmounting failed. +func cleanupMount(t testing.TB, d *Daemon) { + t.Helper() + if err := mount.Unmount(d.Root); err != nil { + d.log.Logf("[%s] unable to unmount daemon root (%s): %v", d.id, d.Root, err) + } +} + func cleanupNetworkNamespace(t testing.TB, d *Daemon) { t.Helper() // Cleanup network namespaces in the exec root of this diff --git a/testutil/daemon/daemon_windows.go b/testutil/daemon/daemon_windows.go index 601f60a54c..be94b52838 100644 --- a/testutil/daemon/daemon_windows.go +++ b/testutil/daemon/daemon_windows.go @@ -24,6 +24,8 @@ func signalDaemonReload(pid int) error { return fmt.Errorf("daemon reload not supported") } +func cleanupMount(_ testing.TB, _ *Daemon) {} + func cleanupNetworkNamespace(_ testing.TB, _ *Daemon) {} // CgroupNamespace returns the cgroup namespace the daemon is running in diff --git a/volume/local/local.go b/volume/local/local.go index bf97e181e1..89252cf627 100644 --- a/volume/local/local.go +++ b/volume/local/local.go @@ -18,8 +18,6 @@ import ( "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/quota" "github.com/docker/docker/volume" - "github.com/moby/sys/mount" - "github.com/moby/sys/mountinfo" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -96,9 +94,9 @@ func New(scope string, rootIdentity idtools.Identity) (*Root, error) { if !reflect.DeepEqual(opts, optsConfig{}) { v.opts = &opts } - - // unmount anything that may still be mounted (for example, from an unclean shutdown) - mount.Unmount(v.path) + // unmount anything that may still be mounted (for example, from an + // unclean shutdown). This is a no-op on windows + unmount(v.path) } } @@ -347,18 +345,6 @@ func (v *localVolume) Unmount(id string) error { return v.unmount() } -func (v *localVolume) unmount() error { - if v.needsMount() { - if err := mount.Unmount(v.path); err != nil { - if mounted, mErr := mountinfo.Mounted(v.path); mounted || mErr != nil { - return errdefs.System(err) - } - } - v.active.mounted = false - } - return nil -} - func (v *localVolume) Status() map[string]interface{} { return nil } diff --git a/volume/local/local_unix.go b/volume/local/local_unix.go index 9d4b37f53e..c8163ccd13 100644 --- a/volume/local/local_unix.go +++ b/volume/local/local_unix.go @@ -18,6 +18,7 @@ import ( "github.com/docker/docker/quota" units "github.com/docker/go-units" "github.com/moby/sys/mount" + "github.com/moby/sys/mountinfo" "github.com/pkg/errors" ) @@ -111,6 +112,10 @@ func validateOpts(opts map[string]string) error { return nil } +func unmount(path string) { + _ = mount.Unmount(path) +} + func (v *localVolume) needsMount() bool { if v.opts == nil { return false @@ -157,6 +162,18 @@ func (v *localVolume) postMount() error { return nil } +func (v *localVolume) unmount() error { + if v.needsMount() { + if err := mount.Unmount(v.path); err != nil { + if mounted, mErr := mountinfo.Mounted(v.path); mounted || mErr != nil { + return errdefs.System(err) + } + } + v.active.mounted = false + } + return nil +} + func (v *localVolume) CreatedAt() (time.Time, error) { fileInfo, err := os.Stat(v.path) if err != nil { diff --git a/volume/local/local_windows.go b/volume/local/local_windows.go index b05510d098..9fc2092720 100644 --- a/volume/local/local_windows.go +++ b/volume/local/local_windows.go @@ -39,6 +39,11 @@ func (v *localVolume) needsMount() bool { func (v *localVolume) mount() error { return nil } +func (v *localVolume) unmount() error { + return nil +} + +func unmount(_ string) {} func (v *localVolume) postMount() error { return nil