瀏覽代碼

Do not call mount.RecursiveUnmount() on Windows

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 4 年之前
父節點
當前提交
182795cff6

+ 4 - 0
daemon/daemon_unix.go

@@ -1711,3 +1711,7 @@ func (daemon *Daemon) RawSysInfo(quiet bool) *sysinfo.SysInfo {
 	}
 	}
 	return sysinfo.New(quiet, opts...)
 	return sysinfo.New(quiet, opts...)
 }
 }
+
+func recursiveUnmount(target string) error {
+	return mount.RecursiveUnmount(target)
+}

+ 4 - 0
daemon/daemon_windows.go

@@ -467,6 +467,10 @@ func (daemon *Daemon) cleanupMounts() error {
 	return nil
 	return nil
 }
 }
 
 
+func recursiveUnmount(_ string) error {
+	return nil
+}
+
 func setupRemappedRoot(config *config.Config) (*idtools.IdentityMapping, error) {
 func setupRemappedRoot(config *config.Config) (*idtools.IdentityMapping, error) {
 	return &idtools.IdentityMapping{}, nil
 	return &idtools.IdentityMapping{}, nil
 }
 }

+ 1 - 2
daemon/start.go

@@ -12,7 +12,6 @@ import (
 	containertypes "github.com/docker/docker/api/types/container"
 	containertypes "github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/errdefs"
-	"github.com/moby/sys/mount"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 	"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)
 		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.")
 		logrus.WithError(err).WithField("container", container.ID).Warn("Error while cleaning up container resource mounts.")
 	}
 	}
 
 

+ 2 - 5
plugin/manager.go

@@ -23,7 +23,6 @@ import (
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/pkg/system"
 	v2 "github.com/docker/docker/plugin/v2"
 	v2 "github.com/docker/docker/plugin/v2"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
-	"github.com/moby/sys/mount"
 	digest "github.com/opencontainers/go-digest"
 	digest "github.com/opencontainers/go-digest"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
@@ -159,10 +158,8 @@ func (pm *Manager) HandleExitEvent(id string) error {
 
 
 	if restart {
 	if restart {
 		pm.enable(p, c, true)
 		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
 	return nil
 }
 }

+ 4 - 0
plugin/manager_linux.go

@@ -346,3 +346,7 @@ func (pm *Manager) createPlugin(name string, configDigest, manifestDigest digest
 
 
 	return p, nil
 	return p, nil
 }
 }
+
+func recursiveUnmount(target string) error {
+	return mount.RecursiveUnmount(target)
+}

+ 4 - 0
plugin/manager_windows.go

@@ -26,3 +26,7 @@ func (pm *Manager) restore(p *v2.Plugin, c *controller) error {
 // Shutdown plugins
 // Shutdown plugins
 func (pm *Manager) Shutdown() {
 func (pm *Manager) Shutdown() {
 }
 }
+
+func recursiveUnmount(_ string) error {
+	return nil
+}

+ 0 - 10
testutil/daemon/daemon.go

@@ -24,7 +24,6 @@ import (
 	"github.com/docker/docker/testutil/request"
 	"github.com/docker/docker/testutil/request"
 	"github.com/docker/go-connections/sockets"
 	"github.com/docker/go-connections/sockets"
 	"github.com/docker/go-connections/tlsconfig"
 	"github.com/docker/go-connections/tlsconfig"
-	"github.com/moby/sys/mount"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 	"gotest.tools/v3/assert"
 	"gotest.tools/v3/assert"
 )
 )
@@ -812,15 +811,6 @@ func (d *Daemon) Info(t testing.TB) types.Info {
 	return 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
 // cleanupRaftDir removes swarmkit wal files if present
 func cleanupRaftDir(t testing.TB, d *Daemon) {
 func cleanupRaftDir(t testing.TB, d *Daemon) {
 	t.Helper()
 	t.Helper()

+ 10 - 0
testutil/daemon/daemon_unix.go

@@ -11,10 +11,20 @@ import (
 	"syscall"
 	"syscall"
 	"testing"
 	"testing"
 
 
+	"github.com/docker/docker/pkg/mount"
 	"golang.org/x/sys/unix"
 	"golang.org/x/sys/unix"
 	"gotest.tools/v3/assert"
 	"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) {
 func cleanupNetworkNamespace(t testing.TB, d *Daemon) {
 	t.Helper()
 	t.Helper()
 	// Cleanup network namespaces in the exec root of this
 	// Cleanup network namespaces in the exec root of this

+ 2 - 0
testutil/daemon/daemon_windows.go

@@ -24,6 +24,8 @@ func signalDaemonReload(pid int) error {
 	return fmt.Errorf("daemon reload not supported")
 	return fmt.Errorf("daemon reload not supported")
 }
 }
 
 
+func cleanupMount(_ testing.TB, _ *Daemon) {}
+
 func cleanupNetworkNamespace(_ testing.TB, _ *Daemon) {}
 func cleanupNetworkNamespace(_ testing.TB, _ *Daemon) {}
 
 
 // CgroupNamespace returns the cgroup namespace the daemon is running in
 // CgroupNamespace returns the cgroup namespace the daemon is running in

+ 3 - 17
volume/local/local.go

@@ -18,8 +18,6 @@ import (
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/quota"
 	"github.com/docker/docker/quota"
 	"github.com/docker/docker/volume"
 	"github.com/docker/docker/volume"
-	"github.com/moby/sys/mount"
-	"github.com/moby/sys/mountinfo"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 )
 )
@@ -96,9 +94,9 @@ func New(scope string, rootIdentity idtools.Identity) (*Root, error) {
 			if !reflect.DeepEqual(opts, optsConfig{}) {
 			if !reflect.DeepEqual(opts, optsConfig{}) {
 				v.opts = &opts
 				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()
 	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{} {
 func (v *localVolume) Status() map[string]interface{} {
 	return nil
 	return nil
 }
 }

+ 17 - 0
volume/local/local_unix.go

@@ -18,6 +18,7 @@ import (
 	"github.com/docker/docker/quota"
 	"github.com/docker/docker/quota"
 	units "github.com/docker/go-units"
 	units "github.com/docker/go-units"
 	"github.com/moby/sys/mount"
 	"github.com/moby/sys/mount"
+	"github.com/moby/sys/mountinfo"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 )
 )
 
 
@@ -111,6 +112,10 @@ func validateOpts(opts map[string]string) error {
 	return nil
 	return nil
 }
 }
 
 
+func unmount(path string) {
+	_ = mount.Unmount(path)
+}
+
 func (v *localVolume) needsMount() bool {
 func (v *localVolume) needsMount() bool {
 	if v.opts == nil {
 	if v.opts == nil {
 		return false
 		return false
@@ -157,6 +162,18 @@ func (v *localVolume) postMount() error {
 	return nil
 	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) {
 func (v *localVolume) CreatedAt() (time.Time, error) {
 	fileInfo, err := os.Stat(v.path)
 	fileInfo, err := os.Stat(v.path)
 	if err != nil {
 	if err != nil {

+ 5 - 0
volume/local/local_windows.go

@@ -39,6 +39,11 @@ func (v *localVolume) needsMount() bool {
 func (v *localVolume) mount() error {
 func (v *localVolume) mount() error {
 	return nil
 	return nil
 }
 }
+func (v *localVolume) unmount() error {
+	return nil
+}
+
+func unmount(_ string) {}
 
 
 func (v *localVolume) postMount() error {
 func (v *localVolume) postMount() error {
 	return nil
 	return nil