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>
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
"github.com/docker/docker/pkg/locker" |
| 17 | 17 |
"github.com/docker/docker/pkg/mount" |
| 18 | 18 |
units "github.com/docker/go-units" |
| 19 |
+ "github.com/pkg/errors" |
|
| 19 | 20 |
"github.com/sirupsen/logrus" |
| 20 | 21 |
"golang.org/x/sys/unix" |
| 21 | 22 |
) |
| ... | ... |
@@ -121,12 +122,18 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {
|
| 121 | 121 |
// Cleanup unmounts a device. |
| 122 | 122 |
func (d *Driver) Cleanup() error {
|
| 123 | 123 |
err := d.DeviceSet.Shutdown(d.home) |
| 124 |
+ umountErr := mount.RecursiveUnmount(d.home) |
|
| 124 | 125 |
|
| 125 |
- if err2 := mount.RecursiveUnmount(d.home); err == nil {
|
|
| 126 |
- err = err2 |
|
| 126 |
+ // in case we have two errors, prefer the one from Shutdown() |
|
| 127 |
+ if err != nil {
|
|
| 128 |
+ return err |
|
| 127 | 129 |
} |
| 128 | 130 |
|
| 129 |
- return err |
|
| 131 |
+ if umountErr != nil {
|
|
| 132 |
+ return errors.Wrapf(umountErr, "error unmounting %s", d.home) |
|
| 133 |
+ } |
|
| 134 |
+ |
|
| 135 |
+ return nil |
|
| 130 | 136 |
} |
| 131 | 137 |
|
| 132 | 138 |
// CreateReadWrite creates a layer that is writable for use as a container |