Do not call mount.RecursiveUnmount() on Windows

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-09-19 18:45:41 +02:00
parent bb23f1bf61
commit 182795cff6
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
12 changed files with 56 additions and 34 deletions

View file

@ -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)
}

View file

@ -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
}

View file

@ -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.")
}

View file

@ -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
}

View file

@ -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)
}

View file

@ -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
}

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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 {

View file

@ -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