Skip to content

Commit 1ba05cd

Browse files
committed
Add fast path for fsmagic supported drivers
For things that we can check if they are mounted by using their fsmagic we should use that and for others do it the slow way. Signed-off-by: Michael Crosby <[email protected]>
1 parent 31e903b commit 1ba05cd

5 files changed

Lines changed: 49 additions & 16 deletions

File tree

daemon/graphdriver/counter.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package graphdriver
22

3-
import (
4-
"sync"
5-
6-
"github.com/docker/docker/pkg/mount"
7-
)
3+
import "sync"
84

95
type minfo struct {
106
check bool
@@ -13,13 +9,20 @@ type minfo struct {
139

1410
// RefCounter is a generic counter for use by graphdriver Get/Put calls
1511
type RefCounter struct {
16-
counts map[string]*minfo
17-
mu sync.Mutex
12+
counts map[string]*minfo
13+
mu sync.Mutex
14+
checker Checker
1815
}
1916

2017
// NewRefCounter returns a new RefCounter
21-
func NewRefCounter() *RefCounter {
22-
return &RefCounter{counts: make(map[string]*minfo)}
18+
func NewRefCounter(c Checker) *RefCounter {
19+
if c == nil {
20+
c = &defaultChecker{}
21+
}
22+
return &RefCounter{
23+
checker: c,
24+
counts: make(map[string]*minfo),
25+
}
2326
}
2427

2528
// Increment increaes the ref count for the given id and returns the current count
@@ -35,8 +38,7 @@ func (c *RefCounter) Increment(path string) int {
3538
// count if it is mounted as it is in use.
3639
if !m.check {
3740
m.check = true
38-
mntd, _ := mount.Mounted(path)
39-
if mntd {
41+
if c.checker.IsMounted(path) {
4042
m.count++
4143
}
4244
}
@@ -58,8 +60,7 @@ func (c *RefCounter) Decrement(path string) int {
5860
// count if it is mounted as it is in use.
5961
if !m.check {
6062
m.check = true
61-
mntd, _ := mount.Mounted(path)
62-
if mntd {
63+
if c.checker.IsMounted(path) {
6364
m.count++
6465
}
6566
}

daemon/graphdriver/devmapper/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
4747
home: home,
4848
uidMaps: uidMaps,
4949
gidMaps: gidMaps,
50-
ctr: graphdriver.NewRefCounter(),
50+
ctr: graphdriver.NewRefCounter(nil),
5151
}
5252

5353
return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil

daemon/graphdriver/driver_linux.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package graphdriver
55
import (
66
"path/filepath"
77
"syscall"
8+
9+
"github.com/docker/docker/pkg/mount"
810
)
911

1012
const (
@@ -89,6 +91,36 @@ func GetFSMagic(rootpath string) (FsMagic, error) {
8991
return FsMagic(buf.Type), nil
9092
}
9193

94+
// Checker makes checks on specified filesystems.
95+
type Checker interface {
96+
// IsMounted returns true if the provided path is mounted for the specific checker
97+
IsMounted(path string) bool
98+
}
99+
100+
// NewFsChecker returns a checker configured for the provied FsMagic
101+
func NewFsChecker(t FsMagic) Checker {
102+
return &fsChecker{
103+
t: t,
104+
}
105+
}
106+
107+
type fsChecker struct {
108+
t FsMagic
109+
}
110+
111+
func (c *fsChecker) IsMounted(path string) bool {
112+
m, _ := Mounted(c.t, path)
113+
return m
114+
}
115+
116+
type defaultChecker struct {
117+
}
118+
119+
func (c *defaultChecker) IsMounted(path string) bool {
120+
m, _ := mount.Mounted(path)
121+
return m
122+
}
123+
92124
// Mounted checks if the given path is mounted as the fs type
93125
func Mounted(fsType FsMagic, mountPath string) (bool, error) {
94126
var buf syscall.Statfs_t

daemon/graphdriver/overlay/overlay.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
141141
home: home,
142142
uidMaps: uidMaps,
143143
gidMaps: gidMaps,
144-
ctr: graphdriver.NewRefCounter(),
144+
ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)),
145145
}
146146

147147
return NaiveDiffDriverWithApply(d, uidMaps, gidMaps), nil

daemon/graphdriver/zfs/zfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdri
105105
filesystemsCache: filesystemsCache,
106106
uidMaps: uidMaps,
107107
gidMaps: gidMaps,
108-
ctr: graphdriver.NewRefCounter(),
108+
ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicZfs)),
109109
}
110110
return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil
111111
}

0 commit comments

Comments
 (0)