mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon/graphdriver: move RefCounter to an internal package
The RefCounter is used in both graphdrivers and snapshotters. Move it to a separate package to help decoupling snapshotters and graphdrivers, and make it internal, as it's not intended to be used as a generic utility package (we can still make it public if there would be a need). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
"github.com/docker/docker/daemon/graphdriver/overlayutils"
|
||||
"github.com/docker/docker/daemon/internal/fstype"
|
||||
"github.com/docker/docker/daemon/internal/mountref"
|
||||
"github.com/docker/docker/internal/containerfs"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/chrootarchive"
|
||||
@@ -59,7 +60,7 @@ const (
|
||||
type Driver struct {
|
||||
home string
|
||||
idMap idtools.IdentityMapping
|
||||
ctr *graphdriver.RefCounter
|
||||
ctr *mountref.Counter
|
||||
naiveDiff graphdriver.DiffDriver
|
||||
locker *locker.Locker
|
||||
}
|
||||
@@ -98,7 +99,7 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr
|
||||
d := &Driver{
|
||||
home: home,
|
||||
idMap: idMap,
|
||||
ctr: graphdriver.NewRefCounter(isMounted),
|
||||
ctr: mountref.NewCounter(isMounted),
|
||||
locker: locker.New(),
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
"github.com/docker/docker/daemon/graphdriver/overlayutils"
|
||||
"github.com/docker/docker/daemon/internal/fstype"
|
||||
"github.com/docker/docker/daemon/internal/mountref"
|
||||
"github.com/docker/docker/internal/containerfs"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/chrootarchive"
|
||||
@@ -93,7 +94,7 @@ type overlayOptions struct {
|
||||
type Driver struct {
|
||||
home string
|
||||
idMap idtools.IdentityMapping
|
||||
ctr *graphdriver.RefCounter
|
||||
ctr *mountref.Counter
|
||||
quotaCtl *quota.Control
|
||||
options overlayOptions
|
||||
naiveDiff graphdriver.DiffDriver
|
||||
@@ -179,7 +180,7 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr
|
||||
d := &Driver{
|
||||
home: home,
|
||||
idMap: idMap,
|
||||
ctr: graphdriver.NewRefCounter(isMounted),
|
||||
ctr: mountref.NewCounter(isMounted),
|
||||
supportsDType: supportsDType,
|
||||
usingMetacopy: usingMetacopy,
|
||||
locker: locker.New(),
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/Microsoft/hcsshim/osversion"
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
"github.com/docker/docker/daemon/internal/mountref"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
@@ -80,7 +81,7 @@ type storageOptions struct {
|
||||
type Driver struct {
|
||||
// info stores the shim driver information
|
||||
info hcsshim.DriverInfo
|
||||
ctr *graphdriver.RefCounter
|
||||
ctr *mountref.Counter
|
||||
// it is safe for windows to use a cache here because it does not support
|
||||
// restoring containers when the daemon dies.
|
||||
cacheMu sync.Mutex
|
||||
@@ -126,7 +127,7 @@ func InitFilter(home string, options []string, _ idtools.IdentityMapping) (graph
|
||||
Flavour: filterDriver,
|
||||
},
|
||||
cache: make(map[string]string),
|
||||
ctr: graphdriver.NewRefCounter(isMounted),
|
||||
ctr: mountref.NewCounter(isMounted),
|
||||
defaultStorageOpts: opts,
|
||||
}
|
||||
return d, nil
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
"github.com/docker/docker/daemon/internal/mountref"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
zfs "github.com/mistifyio/go-zfs/v3"
|
||||
@@ -118,7 +119,7 @@ func Init(base string, opt []string, idMap idtools.IdentityMapping) (graphdriver
|
||||
options: options,
|
||||
filesystemsCache: filesystemsCache,
|
||||
idMap: idMap,
|
||||
ctr: graphdriver.NewRefCounter(isMounted),
|
||||
ctr: mountref.NewCounter(isMounted),
|
||||
locker: locker.New(),
|
||||
}
|
||||
return graphdriver.NewNaiveDiffDriver(d, idMap), nil
|
||||
@@ -182,7 +183,7 @@ type Driver struct {
|
||||
sync.Mutex // protects filesystem cache against concurrent access
|
||||
filesystemsCache map[string]bool
|
||||
idMap idtools.IdentityMapping
|
||||
ctr *graphdriver.RefCounter
|
||||
ctr *mountref.Counter
|
||||
locker *locker.Locker
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package graphdriver // import "github.com/docker/docker/daemon/graphdriver"
|
||||
package mountref
|
||||
|
||||
import "sync"
|
||||
|
||||
@@ -7,8 +7,8 @@ type minfo struct {
|
||||
count int
|
||||
}
|
||||
|
||||
// RefCounter is a generic counter for use by graphdriver Get/Put calls
|
||||
type RefCounter struct {
|
||||
// Counter is a generic counter for use by graphdriver Get/Put calls
|
||||
type Counter struct {
|
||||
counts map[string]*minfo
|
||||
mu sync.Mutex
|
||||
isMounted Checker
|
||||
@@ -17,30 +17,30 @@ type RefCounter struct {
|
||||
// Checker checks whether the provided path is mounted.
|
||||
type Checker func(path string) bool
|
||||
|
||||
// NewRefCounter returns a new RefCounter. It accepts a [Checker] to
|
||||
// NewCounter returns a new Counter. It accepts a [Checker] to
|
||||
// determine whether a path is mounted.
|
||||
func NewRefCounter(c Checker) *RefCounter {
|
||||
return &RefCounter{
|
||||
func NewCounter(c Checker) *Counter {
|
||||
return &Counter{
|
||||
isMounted: c,
|
||||
counts: make(map[string]*minfo),
|
||||
}
|
||||
}
|
||||
|
||||
// Increment increases the ref count for the given id and returns the current count
|
||||
func (c *RefCounter) Increment(path string) int {
|
||||
func (c *Counter) Increment(path string) int {
|
||||
return c.incdec(path, func(minfo *minfo) {
|
||||
minfo.count++
|
||||
})
|
||||
}
|
||||
|
||||
// Decrement decreases the ref count for the given id and returns the current count
|
||||
func (c *RefCounter) Decrement(path string) int {
|
||||
func (c *Counter) Decrement(path string) int {
|
||||
return c.incdec(path, func(minfo *minfo) {
|
||||
minfo.count--
|
||||
})
|
||||
}
|
||||
|
||||
func (c *RefCounter) incdec(path string, infoOp func(minfo *minfo)) int {
|
||||
func (c *Counter) incdec(path string, infoOp func(minfo *minfo)) int {
|
||||
c.mu.Lock()
|
||||
m := c.counts[path]
|
||||
if m == nil {
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
"github.com/docker/docker/daemon/internal/mountref"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/moby/locker"
|
||||
"github.com/moby/sys/mountinfo"
|
||||
@@ -32,13 +32,13 @@ func NewMounter(home string, snapshotter string, idMap idtools.IdentityMapping)
|
||||
snapshotter: snapshotter,
|
||||
idMap: idMap,
|
||||
},
|
||||
rc: graphdriver.NewRefCounter(isMounted),
|
||||
rc: mountref.NewCounter(isMounted),
|
||||
locker: locker.New(),
|
||||
}
|
||||
}
|
||||
|
||||
type refCountMounter struct {
|
||||
rc *graphdriver.RefCounter
|
||||
rc *mountref.Counter
|
||||
locker *locker.Locker
|
||||
base mounter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user