1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

overlay2: use global logger instance

This simplifies the code a lot.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2018-10-11 12:50:45 -07:00
parent 889ddcd328
commit a55d32546a
3 changed files with 14 additions and 18 deletions

View file

@ -12,7 +12,6 @@ import (
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -27,7 +26,7 @@ func doesSupportNativeDiff(d string) error {
} }
defer func() { defer func() {
if err := os.RemoveAll(td); err != nil { if err := os.RemoveAll(td); err != nil {
logrus.WithField("storage-driver", "overlay2").Warnf("Failed to remove check directory %v: %v", td, err) logger.Warnf("Failed to remove check directory %v: %v", td, err)
} }
}() }()
@ -62,7 +61,7 @@ func doesSupportNativeDiff(d string) error {
} }
defer func() { defer func() {
if err := unix.Unmount(filepath.Join(td, "merged"), 0); err != nil { if err := unix.Unmount(filepath.Join(td, "merged"), 0); err != nil {
logrus.WithField("storage-driver", "overlay2").Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err) logger.Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err)
} }
}() }()
@ -113,7 +112,7 @@ func supportsMultipleLowerDir(d string) error {
} }
defer func() { defer func() {
if err := os.RemoveAll(td); err != nil { if err := os.RemoveAll(td); err != nil {
logrus.WithField("storage-driver", "overlay2").Warnf("Failed to remove check directory %v: %v", td, err) logger.Warnf("Failed to remove check directory %v: %v", td, err)
} }
}() }()
@ -128,7 +127,7 @@ func supportsMultipleLowerDir(d string) error {
return errors.Wrap(err, "failed to mount overlay") return errors.Wrap(err, "failed to mount overlay")
} }
if err := unix.Unmount(filepath.Join(td, "merged"), 0); err != nil { if err := unix.Unmount(filepath.Join(td, "merged"), 0); err != nil {
logrus.WithField("storage-driver", "overlay2").Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err) logger.Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err)
} }
return nil return nil
} }

View file

@ -106,6 +106,7 @@ type Driver struct {
} }
var ( var (
logger = logrus.WithField("storage-driver", "overlay2")
backingFs = "<unknown>" backingFs = "<unknown>"
projectQuotaSupported = false projectQuotaSupported = false
@ -155,8 +156,6 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
backingFs = fsName backingFs = fsName
} }
logger := logrus.WithField("storage-driver", "overlay2")
switch fsMagic { switch fsMagic {
case graphdriver.FsMagicAufs, graphdriver.FsMagicEcryptfs, graphdriver.FsMagicNfsFs, graphdriver.FsMagicOverlay, graphdriver.FsMagicZfs: case graphdriver.FsMagicAufs, graphdriver.FsMagicEcryptfs, graphdriver.FsMagicNfsFs, graphdriver.FsMagicOverlay, graphdriver.FsMagicZfs:
logger.Errorf("'overlay2' is not supported over %s", backingFs) logger.Errorf("'overlay2' is not supported over %s", backingFs)
@ -277,14 +276,14 @@ func supportsOverlay() error {
return nil return nil
} }
} }
logrus.WithField("storage-driver", "overlay2").Error("'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.") logger.Error("'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.")
return graphdriver.ErrNotSupported return graphdriver.ErrNotSupported
} }
func useNaiveDiff(home string) bool { func useNaiveDiff(home string) bool {
useNaiveDiffLock.Do(func() { useNaiveDiffLock.Do(func() {
if err := doesSupportNativeDiff(home); err != nil { if err := doesSupportNativeDiff(home); err != nil {
logrus.WithField("storage-driver", "overlay2").Warnf("Not using native diff for overlay2, this may cause degraded performance for building images: %v", err) logger.Warnf("Not using native diff for overlay2, this may cause degraded performance for building images: %v", err)
useNaiveDiffOnly = true useNaiveDiffOnly = true
} }
}) })
@ -522,9 +521,9 @@ func (d *Driver) Remove(id string) error {
lid, err := ioutil.ReadFile(path.Join(dir, "link")) lid, err := ioutil.ReadFile(path.Join(dir, "link"))
if err == nil { if err == nil {
if len(lid) == 0 { if len(lid) == 0 {
logrus.WithField("storage-driver", "overlay2").Errorf("refusing to remove empty link for layer %v", id) logger.Errorf("refusing to remove empty link for layer %v", id)
} else if err := os.RemoveAll(path.Join(d.home, linkDir, string(lid))); err != nil { } else if err := os.RemoveAll(path.Join(d.home, linkDir, string(lid))); err != nil {
logrus.WithField("storage-driver", "overlay2").Debugf("Failed to remove link: %v", err) logger.Debugf("Failed to remove link: %v", err)
} }
} }
@ -561,11 +560,11 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
if retErr != nil { if retErr != nil {
if c := d.ctr.Decrement(mergedDir); c <= 0 { if c := d.ctr.Decrement(mergedDir); c <= 0 {
if mntErr := unix.Unmount(mergedDir, 0); mntErr != nil { if mntErr := unix.Unmount(mergedDir, 0); mntErr != nil {
logrus.WithField("storage-driver", "overlay2").Errorf("error unmounting %v: %v", mergedDir, mntErr) logger.Errorf("error unmounting %v: %v", mergedDir, mntErr)
} }
// Cleanup the created merged directory; see the comment in Put's rmdir // Cleanup the created merged directory; see the comment in Put's rmdir
if rmErr := unix.Rmdir(mergedDir); rmErr != nil && !os.IsNotExist(rmErr) { if rmErr := unix.Rmdir(mergedDir); rmErr != nil && !os.IsNotExist(rmErr) {
logrus.WithField("storage-driver", "overlay2").Debugf("Failed to remove %s: %v: %v", id, rmErr, err) logger.Debugf("Failed to remove %s: %v: %v", id, rmErr, err)
} }
} }
} }
@ -648,7 +647,6 @@ func (d *Driver) Put(id string) error {
} }
mountpoint := path.Join(dir, "merged") mountpoint := path.Join(dir, "merged")
logger := logrus.WithField("storage-driver", "overlay2")
if count := d.ctr.Decrement(mountpoint); count > 0 { if count := d.ctr.Decrement(mountpoint); count > 0 {
return nil return nil
} }
@ -704,7 +702,7 @@ func (d *Driver) ApplyDiff(id string, parent string, diff io.Reader) (size int64
applyDir := d.getDiffPath(id) applyDir := d.getDiffPath(id)
logrus.WithField("storage-driver", "overlay2").Debugf("Applying tar in %s", applyDir) logger.Debugf("Applying tar in %s", applyDir)
// Overlay doesn't need the parent id to apply the diff // Overlay doesn't need the parent id to apply the diff
if err := untar(diff, applyDir, &archive.TarOptions{ if err := untar(diff, applyDir, &archive.TarOptions{
UIDMaps: d.uidMaps, UIDMaps: d.uidMaps,
@ -742,7 +740,7 @@ func (d *Driver) Diff(id, parent string) (io.ReadCloser, error) {
} }
diffPath := d.getDiffPath(id) diffPath := d.getDiffPath(id)
logrus.WithField("storage-driver", "overlay2").Debugf("Tar with options on %s", diffPath) logger.Debugf("Tar with options on %s", diffPath)
return archive.TarWithOptions(diffPath, &archive.TarOptions{ return archive.TarWithOptions(diffPath, &archive.TarOptions{
Compression: archive.Uncompressed, Compression: archive.Uncompressed,
UIDMaps: d.uidMaps, UIDMaps: d.uidMaps,

View file

@ -11,7 +11,6 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -47,7 +46,7 @@ func generateID(l int) string {
if retryOnError(err) && retries < maxretries { if retryOnError(err) && retries < maxretries {
count += n count += n
retries++ retries++
logrus.Errorf("error generating version 4 uuid, retrying: %v", err) logger.Errorf("error generating version 4 uuid, retrying: %v", err)
continue continue
} }