devmapper cleanup: improve error msg

1. Make sure it's clear the error is from unmount.

2. Simplify the code a bit to make it more readable.

[v2: use errors.Wrap]
[v3: use errors.Wrapf]
[v4: lowercase the error message]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2018-01-23 17:17:13 -08:00
parent 8830ef804f
commit 9d00aedebc
1 changed files with 10 additions and 3 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/docker/docker/pkg/locker" "github.com/docker/docker/pkg/locker"
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
units "github.com/docker/go-units" units "github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -121,12 +122,18 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {
// Cleanup unmounts a device. // Cleanup unmounts a device.
func (d *Driver) Cleanup() error { func (d *Driver) Cleanup() error {
err := d.DeviceSet.Shutdown(d.home) err := d.DeviceSet.Shutdown(d.home)
umountErr := mount.RecursiveUnmount(d.home)
if err2 := mount.RecursiveUnmount(d.home); err == nil { // in case we have two errors, prefer the one from Shutdown()
err = err2 if err != nil {
return err
} }
return err if umountErr != nil {
return errors.Wrapf(umountErr, "error unmounting %s", d.home)
}
return nil
} }
// CreateReadWrite creates a layer that is writable for use as a container // CreateReadWrite creates a layer that is writable for use as a container