Skip to content

Commit

Permalink
Merge pull request docker-archive#142 from cpuguy83/cherry-pick-33960
Browse files Browse the repository at this point in the history
[17.06] Fix error handling with not-exist errors on remove
  • Loading branch information
vieux authored Jul 26, 2017
2 parents 235eb00 + ce5708a commit 6e9cbb3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion daemon/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo
if container.RWLayer != nil {
metadata, err := daemon.layerStore.ReleaseRWLayer(container.RWLayer)
layer.LogReleaseMetadata(metadata)
if err != nil && err != layer.ErrMountDoesNotExist {
if err != nil && err != layer.ErrMountDoesNotExist && !os.IsNotExist(errors.Cause(err)) {
return errors.Wrapf(err, "driver %q failed to remove root filesystem for %s", daemon.GraphDriverName(), container.ID)
}
}
Expand Down
54 changes: 33 additions & 21 deletions daemon/graphdriver/aufs/aufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import (
"time"

"github.com/Sirupsen/logrus"
"github.com/vbatts/tar-split/tar/storage"

"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/chrootarchive"
Expand All @@ -47,9 +45,11 @@ import (
"github.com/docker/docker/pkg/locker"
mountpk "github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/system"
"github.com/vbatts/tar-split/tar/storage"

rsystem "github.com/opencontainers/runc/libcontainer/system"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -284,30 +284,41 @@ func (a *Driver) Remove(id string) error {
mountpoint = a.getMountpoint(id)
}

logger := logrus.WithFields(logrus.Fields{
"module": "graphdriver",
"driver": "aufs",
"layer": id,
})

var retries int
for {
mounted, err := a.mounted(mountpoint)
if err != nil {
if os.IsNotExist(err) {
break
}
return err
}
if !mounted {
break
}

if err := a.unmount(mountpoint); err != nil {
if err != syscall.EBUSY {
return fmt.Errorf("aufs: unmount error: %s: %v", mountpoint, err)
}
if retries >= 5 {
return fmt.Errorf("aufs: unmount error after retries: %s: %v", mountpoint, err)
}
// If unmount returns EBUSY, it could be a transient error. Sleep and retry.
retries++
logrus.Warnf("unmount failed due to EBUSY: retry count: %d", retries)
time.Sleep(100 * time.Millisecond)
continue
err = a.unmount(mountpoint)
if err == nil {
break
}

if err != syscall.EBUSY {
return errors.Wrapf(err, "aufs: unmount error: %s", mountpoint)
}
if retries >= 5 {
return errors.Wrapf(err, "aufs: unmount error after retries: %s", mountpoint)
}
break
// If unmount returns EBUSY, it could be a transient error. Sleep and retry.
retries++
logger.Warnf("unmount failed due to EBUSY: retry count: %d", retries)
time.Sleep(100 * time.Millisecond)
continue
}

// Atomically remove each directory in turn by first moving it out of the
Expand All @@ -316,21 +327,22 @@ func (a *Driver) Remove(id string) error {
tmpMntPath := path.Join(a.mntPath(), fmt.Sprintf("%s-removing", id))
if err := os.Rename(mountpoint, tmpMntPath); err != nil && !os.IsNotExist(err) {
if err == syscall.EBUSY {
logrus.Warn("os.Rename err due to EBUSY")
logger.WithField("dir", mountpoint).WithError(err).Warn("os.Rename err due to EBUSY")
}
return err
return errors.Wrapf(err, "error preparing atomic delete of aufs mountpoint for id: %s", id)
}
if err := system.EnsureRemoveAll(tmpMntPath); err != nil {
return errors.Wrapf(err, "error removing aufs layer %s", id)
}
defer system.EnsureRemoveAll(tmpMntPath)

tmpDiffpath := path.Join(a.diffPath(), fmt.Sprintf("%s-removing", id))
if err := os.Rename(a.getDiffPath(id), tmpDiffpath); err != nil && !os.IsNotExist(err) {
return err
return errors.Wrapf(err, "error preparing atomic delete of aufs diff dir for id: %s", id)
}
defer system.EnsureRemoveAll(tmpDiffpath)

// Remove the layers file for the id
if err := os.Remove(path.Join(a.rootPath(), "layers", id)); err != nil && !os.IsNotExist(err) {
return err
return errors.Wrapf(err, "error removing layers dir for %s", id)
}

a.pathCacheLock.Lock()
Expand Down

0 comments on commit 6e9cbb3

Please sign in to comment.