From 30e8f43743e50ace7a89d4dc453f740df4f30a8b Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 3 May 2018 14:08:25 -0700 Subject: [PATCH 1/2] aufs: use a single logger Simplify the code by using a single logger instance. While at it, use WithError in Umount. Signed-off-by: Kir Kolyshkin Upstream-commit: c6e2af54256211b8ac757e9b25caa6fb6c9b3c6e Component: engine --- components/engine/daemon/graphdriver/aufs/aufs.go | 15 ++++++--------- .../engine/daemon/graphdriver/aufs/mount.go | 3 +-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/components/engine/daemon/graphdriver/aufs/aufs.go b/components/engine/daemon/graphdriver/aufs/aufs.go index 2fa5c6952a..5d1de2135d 100644 --- a/components/engine/daemon/graphdriver/aufs/aufs.go +++ b/components/engine/daemon/graphdriver/aufs/aufs.go @@ -62,6 +62,8 @@ var ( enableDirpermLock sync.Once enableDirperm bool + + logger = logrus.WithField("storage-driver", "aufs") ) func init() { @@ -109,7 +111,7 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap switch fsMagic { case graphdriver.FsMagicAufs, graphdriver.FsMagicBtrfs, graphdriver.FsMagicEcryptfs: - logrus.WithField("storage-driver", "aufs").Errorf("AUFS is not supported over %s", backingFs) + logger.Errorf("AUFS is not supported over %s", backingFs) return nil, graphdriver.ErrIncompatibleFS } @@ -143,7 +145,6 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap return nil, err } } - logger := logrus.WithField("storage-driver", "aufs") for _, path := range []string{"mnt", "diff"} { p := filepath.Join(root, path) @@ -306,10 +307,7 @@ func (a *Driver) Remove(id string) error { mountpoint = a.getMountpoint(id) } - logger := logrus.WithFields(logrus.Fields{ - "storage-driver": "aufs", - "layer": id, - }) + logger := logger.WithField("layer", id) var retries int for { @@ -439,7 +437,7 @@ func (a *Driver) Put(id string) error { err := a.unmount(m) if err != nil { - logrus.WithField("storage-driver", "aufs").Debugf("Failed to unmount %s aufs: %v", id, err) + logger.Debugf("Failed to unmount %s aufs: %v", id, err) } return err } @@ -597,7 +595,7 @@ func (a *Driver) Cleanup() error { for _, m := range dirs { if err := a.unmount(m); err != nil { - logrus.WithField("storage-driver", "aufs").Debugf("error unmounting %s: %s", m, err) + logger.Debugf("error unmounting %s: %s", m, err) } } return mountpk.RecursiveUnmount(a.root) @@ -652,7 +650,6 @@ func (a *Driver) aufsMount(ro []string, rw, target, mountLabel string) (err erro // useDirperm checks dirperm1 mount option can be used with the current // version of aufs. func useDirperm() bool { - logger := logrus.WithField("storage-driver", "aufs") enableDirpermLock.Do(func() { base, err := ioutil.TempDir("", "docker-aufs-base") if err != nil { diff --git a/components/engine/daemon/graphdriver/aufs/mount.go b/components/engine/daemon/graphdriver/aufs/mount.go index c0a89c1a01..9f5510380c 100644 --- a/components/engine/daemon/graphdriver/aufs/mount.go +++ b/components/engine/daemon/graphdriver/aufs/mount.go @@ -5,14 +5,13 @@ package aufs // import "github.com/docker/docker/daemon/graphdriver/aufs" import ( "os/exec" - "github.com/sirupsen/logrus" "golang.org/x/sys/unix" ) // Unmount the target specified. func Unmount(target string) error { if err := exec.Command("auplink", target, "flush").Run(); err != nil { - logrus.WithField("storage-driver", "aufs").Warnf("Couldn't run auplink before unmount %s: %s", target, err) + logger.WithError(err).Warnf("Couldn't run auplink before unmount %s", target) } return unix.Unmount(target, 0) } From 91ebfe260a43e7e23adb9031c7f153ae34cb4bb5 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 3 May 2018 14:09:32 -0700 Subject: [PATCH 2/2] aufs: log reason why aufs is not supported. In case aufs driver is not supported because supportsAufs() said so, it is not possible to get a real reason from the logs. To fix, log the error returned. Note we're not using WithError here as the error message itself is the sole message we want to print (i.e. there's nothing to add to it). Signed-off-by: Kir Kolyshkin Upstream-commit: 91f85d1c784f3dc9d892b2af2f51d6b6f3b0be69 Component: engine --- components/engine/daemon/graphdriver/aufs/aufs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/daemon/graphdriver/aufs/aufs.go b/components/engine/daemon/graphdriver/aufs/aufs.go index 5d1de2135d..9152252770 100644 --- a/components/engine/daemon/graphdriver/aufs/aufs.go +++ b/components/engine/daemon/graphdriver/aufs/aufs.go @@ -86,9 +86,9 @@ type Driver struct { // Init returns a new AUFS driver. // An error is returned if AUFS is not supported. func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - // Try to load the aufs kernel module if err := supportsAufs(); err != nil { + logger.Error(err) return nil, graphdriver.ErrNotSupported }