Skip to content

Commit a55d325

Browse files
committed
overlay2: use global logger instance
This simplifies the code a lot. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 889ddcd commit a55d325

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

‎daemon/graphdriver/overlay2/check.go‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/docker/docker/pkg/system"
1414
"github.com/pkg/errors"
15-
"github.com/sirupsen/logrus"
1615
"golang.org/x/sys/unix"
1716
)
1817

@@ -27,7 +26,7 @@ func doesSupportNativeDiff(d string) error {
2726
}
2827
defer func() {
2928
if err := os.RemoveAll(td); err != nil {
30-
logrus.WithField("storage-driver", "overlay2").Warnf("Failed to remove check directory %v: %v", td, err)
29+
logger.Warnf("Failed to remove check directory %v: %v", td, err)
3130
}
3231
}()
3332

@@ -62,7 +61,7 @@ func doesSupportNativeDiff(d string) error {
6261
}
6362
defer func() {
6463
if err := unix.Unmount(filepath.Join(td, "merged"), 0); err != nil {
65-
logrus.WithField("storage-driver", "overlay2").Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err)
64+
logger.Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err)
6665
}
6766
}()
6867

@@ -113,7 +112,7 @@ func supportsMultipleLowerDir(d string) error {
113112
}
114113
defer func() {
115114
if err := os.RemoveAll(td); err != nil {
116-
logrus.WithField("storage-driver", "overlay2").Warnf("Failed to remove check directory %v: %v", td, err)
115+
logger.Warnf("Failed to remove check directory %v: %v", td, err)
117116
}
118117
}()
119118

@@ -128,7 +127,7 @@ func supportsMultipleLowerDir(d string) error {
128127
return errors.Wrap(err, "failed to mount overlay")
129128
}
130129
if err := unix.Unmount(filepath.Join(td, "merged"), 0); err != nil {
131-
logrus.WithField("storage-driver", "overlay2").Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err)
130+
logger.Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err)
132131
}
133132
return nil
134133
}

‎daemon/graphdriver/overlay2/overlay.go‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ type Driver struct {
106106
}
107107

108108
var (
109+
logger = logrus.WithField("storage-driver", "overlay2")
109110
backingFs = "<unknown>"
110111
projectQuotaSupported = false
111112

@@ -155,8 +156,6 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
155156
backingFs = fsName
156157
}
157158

158-
logger := logrus.WithField("storage-driver", "overlay2")
159-
160159
switch fsMagic {
161160
case graphdriver.FsMagicAufs, graphdriver.FsMagicEcryptfs, graphdriver.FsMagicNfsFs, graphdriver.FsMagicOverlay, graphdriver.FsMagicZfs:
162161
logger.Errorf("'overlay2' is not supported over %s", backingFs)
@@ -277,14 +276,14 @@ func supportsOverlay() error {
277276
return nil
278277
}
279278
}
280-
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.")
279+
logger.Error("'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.")
281280
return graphdriver.ErrNotSupported
282281
}
283282

284283
func useNaiveDiff(home string) bool {
285284
useNaiveDiffLock.Do(func() {
286285
if err := doesSupportNativeDiff(home); err != nil {
287-
logrus.WithField("storage-driver", "overlay2").Warnf("Not using native diff for overlay2, this may cause degraded performance for building images: %v", err)
286+
logger.Warnf("Not using native diff for overlay2, this may cause degraded performance for building images: %v", err)
288287
useNaiveDiffOnly = true
289288
}
290289
})
@@ -522,9 +521,9 @@ func (d *Driver) Remove(id string) error {
522521
lid, err := ioutil.ReadFile(path.Join(dir, "link"))
523522
if err == nil {
524523
if len(lid) == 0 {
525-
logrus.WithField("storage-driver", "overlay2").Errorf("refusing to remove empty link for layer %v", id)
524+
logger.Errorf("refusing to remove empty link for layer %v", id)
526525
} else if err := os.RemoveAll(path.Join(d.home, linkDir, string(lid))); err != nil {
527-
logrus.WithField("storage-driver", "overlay2").Debugf("Failed to remove link: %v", err)
526+
logger.Debugf("Failed to remove link: %v", err)
528527
}
529528
}
530529

@@ -561,11 +560,11 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e
561560
if retErr != nil {
562561
if c := d.ctr.Decrement(mergedDir); c <= 0 {
563562
if mntErr := unix.Unmount(mergedDir, 0); mntErr != nil {
564-
logrus.WithField("storage-driver", "overlay2").Errorf("error unmounting %v: %v", mergedDir, mntErr)
563+
logger.Errorf("error unmounting %v: %v", mergedDir, mntErr)
565564
}
566565
// Cleanup the created merged directory; see the comment in Put's rmdir
567566
if rmErr := unix.Rmdir(mergedDir); rmErr != nil && !os.IsNotExist(rmErr) {
568-
logrus.WithField("storage-driver", "overlay2").Debugf("Failed to remove %s: %v: %v", id, rmErr, err)
567+
logger.Debugf("Failed to remove %s: %v: %v", id, rmErr, err)
569568
}
570569
}
571570
}
@@ -648,7 +647,6 @@ func (d *Driver) Put(id string) error {
648647
}
649648

650649
mountpoint := path.Join(dir, "merged")
651-
logger := logrus.WithField("storage-driver", "overlay2")
652650
if count := d.ctr.Decrement(mountpoint); count > 0 {
653651
return nil
654652
}
@@ -704,7 +702,7 @@ func (d *Driver) ApplyDiff(id string, parent string, diff io.Reader) (size int64
704702

705703
applyDir := d.getDiffPath(id)
706704

707-
logrus.WithField("storage-driver", "overlay2").Debugf("Applying tar in %s", applyDir)
705+
logger.Debugf("Applying tar in %s", applyDir)
708706
// Overlay doesn't need the parent id to apply the diff
709707
if err := untar(diff, applyDir, &archive.TarOptions{
710708
UIDMaps: d.uidMaps,
@@ -742,7 +740,7 @@ func (d *Driver) Diff(id, parent string) (io.ReadCloser, error) {
742740
}
743741

744742
diffPath := d.getDiffPath(id)
745-
logrus.WithField("storage-driver", "overlay2").Debugf("Tar with options on %s", diffPath)
743+
logger.Debugf("Tar with options on %s", diffPath)
746744
return archive.TarWithOptions(diffPath, &archive.TarOptions{
747745
Compression: archive.Uncompressed,
748746
UIDMaps: d.uidMaps,

‎daemon/graphdriver/overlay2/randomid.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"syscall"
1212
"time"
1313

14-
"github.com/sirupsen/logrus"
1514
"golang.org/x/sys/unix"
1615
)
1716

@@ -47,7 +46,7 @@ func generateID(l int) string {
4746
if retryOnError(err) && retries < maxretries {
4847
count += n
4948
retries++
50-
logrus.Errorf("error generating version 4 uuid, retrying: %v", err)
49+
logger.Errorf("error generating version 4 uuid, retrying: %v", err)
5150
continue
5251
}
5352

0 commit comments

Comments
 (0)