Add reference counting to aufs
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
1ba05cdb6a
commit
5b6b8df0c1
|
@ -70,6 +70,7 @@ type Driver struct {
|
||||||
root string
|
root string
|
||||||
uidMaps []idtools.IDMap
|
uidMaps []idtools.IDMap
|
||||||
gidMaps []idtools.IDMap
|
gidMaps []idtools.IDMap
|
||||||
|
ctr *graphdriver.RefCounter
|
||||||
pathCacheLock sync.Mutex
|
pathCacheLock sync.Mutex
|
||||||
pathCache map[string]string
|
pathCache map[string]string
|
||||||
}
|
}
|
||||||
|
@ -108,6 +109,7 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
||||||
uidMaps: uidMaps,
|
uidMaps: uidMaps,
|
||||||
gidMaps: gidMaps,
|
gidMaps: gidMaps,
|
||||||
pathCache: make(map[string]string),
|
pathCache: make(map[string]string),
|
||||||
|
ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicAufs)),
|
||||||
}
|
}
|
||||||
|
|
||||||
rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
|
rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
|
||||||
|
@ -320,6 +322,9 @@ func (a *Driver) Get(id, mountLabel string) (string, error) {
|
||||||
m = a.getMountpoint(id)
|
m = a.getMountpoint(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if count := a.ctr.Increment(m); count > 1 {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
// If a dir does not have a parent ( no layers )do not try to mount
|
// If a dir does not have a parent ( no layers )do not try to mount
|
||||||
// just return the diff path to the data
|
// just return the diff path to the data
|
||||||
|
@ -344,6 +349,9 @@ func (a *Driver) Put(id string) error {
|
||||||
a.pathCache[id] = m
|
a.pathCache[id] = m
|
||||||
}
|
}
|
||||||
a.pathCacheLock.Unlock()
|
a.pathCacheLock.Unlock()
|
||||||
|
if count := a.ctr.Decrement(m); count > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err := a.unmount(m)
|
err := a.unmount(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,9 +16,6 @@ type RefCounter struct {
|
||||||
|
|
||||||
// NewRefCounter returns a new RefCounter
|
// NewRefCounter returns a new RefCounter
|
||||||
func NewRefCounter(c Checker) *RefCounter {
|
func NewRefCounter(c Checker) *RefCounter {
|
||||||
if c == nil {
|
|
||||||
c = &defaultChecker{}
|
|
||||||
}
|
|
||||||
return &RefCounter{
|
return &RefCounter{
|
||||||
checker: c,
|
checker: c,
|
||||||
counts: make(map[string]*minfo),
|
counts: make(map[string]*minfo),
|
||||||
|
|
|
@ -47,7 +47,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
||||||
home: home,
|
home: home,
|
||||||
uidMaps: uidMaps,
|
uidMaps: uidMaps,
|
||||||
gidMaps: gidMaps,
|
gidMaps: gidMaps,
|
||||||
ctr: graphdriver.NewRefCounter(nil),
|
ctr: graphdriver.NewRefCounter(graphdriver.NewDefaultChecker()),
|
||||||
}
|
}
|
||||||
|
|
||||||
return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil
|
return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil
|
||||||
|
|
|
@ -113,6 +113,12 @@ type FileGetCloser interface {
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checker makes checks on specified filesystems.
|
||||||
|
type Checker interface {
|
||||||
|
// IsMounted returns true if the provided path is mounted for the specific checker
|
||||||
|
IsMounted(path string) bool
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
drivers = make(map[string]InitFunc)
|
drivers = make(map[string]InitFunc)
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,12 +91,6 @@ func GetFSMagic(rootpath string) (FsMagic, error) {
|
||||||
return FsMagic(buf.Type), nil
|
return FsMagic(buf.Type), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checker makes checks on specified filesystems.
|
|
||||||
type Checker interface {
|
|
||||||
// IsMounted returns true if the provided path is mounted for the specific checker
|
|
||||||
IsMounted(path string) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFsChecker returns a checker configured for the provied FsMagic
|
// NewFsChecker returns a checker configured for the provied FsMagic
|
||||||
func NewFsChecker(t FsMagic) Checker {
|
func NewFsChecker(t FsMagic) Checker {
|
||||||
return &fsChecker{
|
return &fsChecker{
|
||||||
|
@ -113,6 +107,12 @@ func (c *fsChecker) IsMounted(path string) bool {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDefaultChecker returns a check that parses /proc/mountinfo to check
|
||||||
|
// if the specified path is mounted.
|
||||||
|
func NewDefaultChecker() Checker {
|
||||||
|
return &defaultChecker{}
|
||||||
|
}
|
||||||
|
|
||||||
type defaultChecker struct {
|
type defaultChecker struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue