diff --git a/daemon/graphdriver/btrfs/btrfs.go b/daemon/graphdriver/btrfs/btrfs.go index c2eaa4ab37a0d..16d6c6251a218 100644 --- a/daemon/graphdriver/btrfs/btrfs.go +++ b/daemon/graphdriver/btrfs/btrfs.go @@ -37,6 +37,7 @@ import ( "github.com/containerd/containerd/pkg/userns" "github.com/containerd/log" "github.com/docker/docker/daemon/graphdriver" + "github.com/docker/docker/daemon/internal/fstype" "github.com/docker/docker/internal/containerfs" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/parsers" @@ -68,12 +69,12 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr testdir = filepath.Dir(testdir) } - fsMagic, err := graphdriver.GetFSMagic(testdir) + fsMagic, err := fstype.GetFSMagic(testdir) if err != nil { return nil, err } - if fsMagic != graphdriver.FsMagicBtrfs { + if fsMagic != fstype.FsMagicBtrfs { return nil, graphdriver.ErrPrerequisites } diff --git a/daemon/graphdriver/driver.go b/daemon/graphdriver/driver.go index 67b8270fe7fc9..440030c3378fc 100644 --- a/daemon/graphdriver/driver.go +++ b/daemon/graphdriver/driver.go @@ -15,14 +15,6 @@ import ( "github.com/vbatts/tar-split/tar/storage" ) -// FsMagic unsigned id of the filesystem in use. -type FsMagic uint32 - -const ( - // FsMagicUnsupported is a predefined constant value other than a valid filesystem id. - FsMagicUnsupported = FsMagic(0x00000000) -) - // All registered drivers var drivers map[string]InitFunc @@ -136,12 +128,6 @@ type FileGetCloser interface { 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() { drivers = make(map[string]InitFunc) } diff --git a/daemon/graphdriver/driver_linux.go b/daemon/graphdriver/driver_linux.go index f85fa30732203..0f39b996cd7fd 100644 --- a/daemon/graphdriver/driver_linux.go +++ b/daemon/graphdriver/driver_linux.go @@ -1,117 +1,4 @@ package graphdriver // import "github.com/docker/docker/daemon/graphdriver" -import ( - "github.com/moby/sys/mountinfo" - "golang.org/x/sys/unix" -) - -const ( - // FsMagicAufs filesystem id for Aufs - FsMagicAufs = FsMagic(0x61756673) - // FsMagicBtrfs filesystem id for Btrfs - FsMagicBtrfs = FsMagic(0x9123683E) - // FsMagicCramfs filesystem id for Cramfs - FsMagicCramfs = FsMagic(0x28cd3d45) - // FsMagicEcryptfs filesystem id for eCryptfs - FsMagicEcryptfs = FsMagic(0xf15f) - // FsMagicExtfs filesystem id for Extfs - FsMagicExtfs = FsMagic(0x0000EF53) - // FsMagicF2fs filesystem id for F2fs - FsMagicF2fs = FsMagic(0xF2F52010) - // FsMagicGPFS filesystem id for GPFS - FsMagicGPFS = FsMagic(0x47504653) - // FsMagicJffs2Fs filesystem if for Jffs2Fs - FsMagicJffs2Fs = FsMagic(0x000072b6) - // FsMagicJfs filesystem id for Jfs - FsMagicJfs = FsMagic(0x3153464a) - // FsMagicNfsFs filesystem id for NfsFs - FsMagicNfsFs = FsMagic(0x00006969) - // FsMagicRAMFs filesystem id for RamFs - FsMagicRAMFs = FsMagic(0x858458f6) - // FsMagicReiserFs filesystem id for ReiserFs - FsMagicReiserFs = FsMagic(0x52654973) - // FsMagicSmbFs filesystem id for SmbFs - FsMagicSmbFs = FsMagic(0x0000517B) - // FsMagicSquashFs filesystem id for SquashFs - FsMagicSquashFs = FsMagic(0x73717368) - // FsMagicTmpFs filesystem id for TmpFs - FsMagicTmpFs = FsMagic(0x01021994) - // FsMagicVxFS filesystem id for VxFs - FsMagicVxFS = FsMagic(0xa501fcf5) - // FsMagicXfs filesystem id for Xfs - FsMagicXfs = FsMagic(0x58465342) - // FsMagicZfs filesystem id for Zfs - FsMagicZfs = FsMagic(0x2fc12fc1) - // FsMagicOverlay filesystem id for overlay - FsMagicOverlay = FsMagic(0x794C7630) - // FsMagicFUSE filesystem id for FUSE - FsMagicFUSE = FsMagic(0x65735546) -) - -var ( - // List of drivers that should be used in an order - priority = "overlay2,fuse-overlayfs,btrfs,zfs,vfs" - - // FsNames maps filesystem id to name of the filesystem. - FsNames = map[FsMagic]string{ - FsMagicAufs: "aufs", - FsMagicBtrfs: "btrfs", - FsMagicCramfs: "cramfs", - FsMagicEcryptfs: "ecryptfs", - FsMagicExtfs: "extfs", - FsMagicF2fs: "f2fs", - FsMagicFUSE: "fuse", - FsMagicGPFS: "gpfs", - FsMagicJffs2Fs: "jffs2", - FsMagicJfs: "jfs", - FsMagicNfsFs: "nfs", - FsMagicOverlay: "overlayfs", - FsMagicRAMFs: "ramfs", - FsMagicReiserFs: "reiserfs", - FsMagicSmbFs: "smb", - FsMagicSquashFs: "squashfs", - FsMagicTmpFs: "tmpfs", - FsMagicUnsupported: "unsupported", - FsMagicVxFS: "vxfs", - FsMagicXfs: "xfs", - FsMagicZfs: "zfs", - } -) - -// GetFSMagic returns the filesystem id given the path. -func GetFSMagic(rootpath string) (FsMagic, error) { - var buf unix.Statfs_t - if err := unix.Statfs(rootpath, &buf); err != nil { - return 0, err - } - return FsMagic(buf.Type), nil -} - -// NewFsChecker returns a checker configured for the provided FsMagic -func NewFsChecker(t FsMagic) Checker { - return &fsChecker{ - t: t, - } -} - -type fsChecker struct { - t FsMagic -} - -func (c *fsChecker) IsMounted(path string) bool { - fsType, _ := GetFSMagic(path) - return fsType == c.t -} - -// NewDefaultChecker returns a check that parses /proc/mountinfo to check -// if the specified path is mounted. -func NewDefaultChecker() Checker { - return &defaultChecker{} -} - -type defaultChecker struct{} - -func (c *defaultChecker) IsMounted(path string) bool { - m, _ := mountinfo.Mounted(path) - return m -} +// List of drivers that should be used in an order +var priority = "overlay2,fuse-overlayfs,btrfs,zfs,vfs" diff --git a/daemon/graphdriver/driver_unsupported.go b/daemon/graphdriver/driver_unsupported.go index 3100bcb57b104..69d1a7a536e8d 100644 --- a/daemon/graphdriver/driver_unsupported.go +++ b/daemon/graphdriver/driver_unsupported.go @@ -4,8 +4,3 @@ package graphdriver // import "github.com/docker/docker/daemon/graphdriver" // List of drivers that should be used in an order var priority = "unsupported" - -// GetFSMagic returns the filesystem id given the path. -func GetFSMagic(rootpath string) (FsMagic, error) { - return FsMagicUnsupported, nil -} diff --git a/daemon/graphdriver/driver_windows.go b/daemon/graphdriver/driver_windows.go index e6470290dfed0..d45186e3645bf 100644 --- a/daemon/graphdriver/driver_windows.go +++ b/daemon/graphdriver/driver_windows.go @@ -2,9 +2,3 @@ package graphdriver // import "github.com/docker/docker/daemon/graphdriver" // List of drivers that should be used in order var priority = "windowsfilter" - -// GetFSMagic returns the filesystem id given the path. -func GetFSMagic(rootpath string) (FsMagic, error) { - // Note it is OK to return FsMagicUnsupported on Windows. - return FsMagicUnsupported, nil -} diff --git a/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go b/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go index b8e32a31d3b85..981303c8c3f3a 100644 --- a/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go +++ b/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go @@ -17,6 +17,8 @@ import ( "github.com/containerd/log" "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/internal/directory" "github.com/docker/docker/pkg/archive" @@ -58,7 +60,7 @@ const ( type Driver struct { home string idMap idtools.IdentityMapping - ctr *graphdriver.RefCounter + ctr *mountref.Counter naiveDiff graphdriver.DiffDriver locker *locker.Locker } @@ -97,7 +99,7 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr d := &Driver{ home: home, idMap: idMap, - ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicFUSE)), + ctr: mountref.NewCounter(isMounted), locker: locker.New(), } @@ -106,6 +108,12 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr return d, nil } +// isMounted checks whether the given path is a [fstype.FsMagicFUSE] mount. +func isMounted(path string) bool { + fsType, _ := fstype.GetFSMagic(path) + return fsType == fstype.FsMagicFUSE +} + func (d *Driver) String() string { return driverName } diff --git a/daemon/graphdriver/overlay2/overlay.go b/daemon/graphdriver/overlay2/overlay.go index 92af0815d7a23..a10d464f1bda7 100644 --- a/daemon/graphdriver/overlay2/overlay.go +++ b/daemon/graphdriver/overlay2/overlay.go @@ -19,6 +19,8 @@ import ( "github.com/containerd/log" "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/internal/directory" "github.com/docker/docker/pkg/archive" @@ -92,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 @@ -142,11 +144,11 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr return nil, graphdriver.ErrNotSupported } - fsMagic, err := graphdriver.GetFSMagic(testdir) + fsMagic, err := fstype.GetFSMagic(testdir) if err != nil { return nil, err } - if fsName, ok := graphdriver.FsNames[fsMagic]; ok { + if fsName, ok := fstype.FsNames[fsMagic]; ok { backingFs = fsName } @@ -178,7 +180,7 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr d := &Driver{ home: home, idMap: idMap, - ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)), + ctr: mountref.NewCounter(isMounted), supportsDType: supportsDType, usingMetacopy: usingMetacopy, locker: locker.New(), @@ -224,6 +226,12 @@ func Init(home string, options []string, idMap idtools.IdentityMapping) (graphdr return d, nil } +// isMounted checks whether the given path is a [fstype.FsMagicOverlay] mount. +func isMounted(path string) bool { + fsType, _ := fstype.GetFSMagic(path) + return fsType == fstype.FsMagicOverlay +} + func parseOptions(options []string) (*overlayOptions, error) { o := &overlayOptions{} for _, option := range options { diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index 7980824f56852..8b85bad204664 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -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" @@ -72,12 +73,6 @@ func init() { } } -type checker struct{} - -func (c *checker) IsMounted(path string) bool { - return false -} - type storageOptions struct { size uint64 } @@ -86,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 @@ -132,12 +127,18 @@ func InitFilter(home string, options []string, _ idtools.IdentityMapping) (graph Flavour: filterDriver, }, cache: make(map[string]string), - ctr: graphdriver.NewRefCounter(&checker{}), + ctr: mountref.NewCounter(isMounted), defaultStorageOpts: opts, } return d, nil } +// isMounted checks whether the given path is mounted. It always returns +// false for the WindowsFilter graphdriver. +func isMounted(string) bool { + return false +} + // String returns the string representation of a driver. This should match // the name the graph driver has been registered with. func (d *Driver) String() string { diff --git a/daemon/graphdriver/zfs/zfs.go b/daemon/graphdriver/zfs/zfs.go index d62a6185156b5..cca34d6284739 100644 --- a/daemon/graphdriver/zfs/zfs.go +++ b/daemon/graphdriver/zfs/zfs.go @@ -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,12 +119,19 @@ func Init(base string, opt []string, idMap idtools.IdentityMapping) (graphdriver options: options, filesystemsCache: filesystemsCache, idMap: idMap, - ctr: graphdriver.NewRefCounter(graphdriver.NewDefaultChecker()), + ctr: mountref.NewCounter(isMounted), locker: locker.New(), } return graphdriver.NewNaiveDiffDriver(d, idMap), nil } +// isMounted parses /proc/mountinfo to check whether the specified path +// is mounted. +func isMounted(path string) bool { + m, _ := mountinfo.Mounted(path) + return m +} + func parseOptions(opt []string) (zfsOptions, error) { var options zfsOptions options.fsName = "" @@ -175,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 } diff --git a/daemon/graphdriver/zfs/zfs_linux.go b/daemon/graphdriver/zfs/zfs_linux.go index fb40308226746..4ef6fdb1e1d4a 100644 --- a/daemon/graphdriver/zfs/zfs_linux.go +++ b/daemon/graphdriver/zfs/zfs_linux.go @@ -5,19 +5,20 @@ import ( "github.com/containerd/log" "github.com/docker/docker/daemon/graphdriver" + "github.com/docker/docker/daemon/internal/fstype" ) func checkRootdirFs(rootDir string) error { - fsMagic, err := graphdriver.GetFSMagic(rootDir) + fsMagic, err := fstype.GetFSMagic(rootDir) if err != nil { return err } backingFS := "unknown" - if fsName, ok := graphdriver.FsNames[fsMagic]; ok { + if fsName, ok := fstype.FsNames[fsMagic]; ok { backingFS = fsName } - if fsMagic != graphdriver.FsMagicZfs { + if fsMagic != fstype.FsMagicZfs { log.G(context.TODO()).WithField("root", rootDir).WithField("backingFS", backingFS).WithField("storage-driver", "zfs").Error("No zfs dataset found for root") return graphdriver.ErrPrerequisites } diff --git a/daemon/internal/fstype/fstype.go b/daemon/internal/fstype/fstype.go new file mode 100644 index 0000000000000..50b7519f5ca7f --- /dev/null +++ b/daemon/internal/fstype/fstype.go @@ -0,0 +1,63 @@ +package fstype + +// FsMagic unsigned id of the filesystem in use. +type FsMagic uint32 + +const ( + FsMagicUnsupported FsMagic = 0x00000000 // FsMagicUnsupported is a predefined constant value other than a valid filesystem id. + + FsMagicAufs FsMagic = 0x61756673 // FsMagicAufs filesystem id for Aufs. + FsMagicBtrfs FsMagic = 0x9123683E // FsMagicBtrfs filesystem id for Btrfs. + FsMagicCramfs FsMagic = 0x28cd3d45 // FsMagicCramfs filesystem id for Cramfs. + FsMagicEcryptfs FsMagic = 0xf15f // FsMagicEcryptfs filesystem id for eCryptfs. + FsMagicExtfs FsMagic = 0x0000EF53 // FsMagicExtfs filesystem id for Extfs. + FsMagicF2fs FsMagic = 0xF2F52010 // FsMagicF2fs filesystem id for F2fs. + FsMagicGPFS FsMagic = 0x47504653 // FsMagicGPFS filesystem id for GPFS. + FsMagicJffs2Fs FsMagic = 0x000072b6 // FsMagicJffs2Fs filesystem if for Jffs2Fs. + FsMagicJfs FsMagic = 0x3153464a // FsMagicJfs filesystem id for Jfs. + FsMagicNfsFs FsMagic = 0x00006969 // FsMagicNfsFs filesystem id for NfsFs. + FsMagicRAMFs FsMagic = 0x858458f6 // FsMagicRAMFs filesystem id for RamFs. + FsMagicReiserFs FsMagic = 0x52654973 // FsMagicReiserFs filesystem id for ReiserFs. + FsMagicSmbFs FsMagic = 0x0000517B // FsMagicSmbFs filesystem id for SmbFs. + FsMagicSquashFs FsMagic = 0x73717368 // FsMagicSquashFs filesystem id for SquashFs. + FsMagicTmpFs FsMagic = 0x01021994 // FsMagicTmpFs filesystem id for TmpFs. + FsMagicVxFS FsMagic = 0xa501fcf5 // FsMagicVxFS filesystem id for VxFs. + FsMagicXfs FsMagic = 0x58465342 // FsMagicXfs filesystem id for Xfs. + FsMagicZfs FsMagic = 0x2fc12fc1 // FsMagicZfs filesystem id for Zfs. + FsMagicOverlay FsMagic = 0x794C7630 // FsMagicOverlay filesystem id for overlayFs. + FsMagicFUSE FsMagic = 0x65735546 // FsMagicFUSE filesystem id for FUSE. +) + +// FsNames maps filesystem id to name of the filesystem. +var FsNames = map[FsMagic]string{ + FsMagicUnsupported: "unsupported", + + FsMagicAufs: "aufs", + FsMagicBtrfs: "btrfs", + FsMagicCramfs: "cramfs", + FsMagicEcryptfs: "ecryptfs", + FsMagicExtfs: "extfs", + FsMagicF2fs: "f2fs", + FsMagicFUSE: "fuse", + FsMagicGPFS: "gpfs", + FsMagicJffs2Fs: "jffs2", + FsMagicJfs: "jfs", + FsMagicNfsFs: "nfs", + FsMagicOverlay: "overlayfs", + FsMagicRAMFs: "ramfs", + FsMagicReiserFs: "reiserfs", + FsMagicSmbFs: "smb", + FsMagicSquashFs: "squashfs", + FsMagicTmpFs: "tmpfs", + FsMagicVxFS: "vxfs", + FsMagicXfs: "xfs", + FsMagicZfs: "zfs", +} + +// GetFSMagic returns the filesystem id given the path. It returns an error +// when failing to detect the filesystem. it returns [FsMagicUnsupported] +// if detection is not supported by the platform, but no error is returned +// in this case. +func GetFSMagic(rootpath string) (FsMagic, error) { + return getFSMagic(rootpath) +} diff --git a/daemon/internal/fstype/fstype_linux.go b/daemon/internal/fstype/fstype_linux.go new file mode 100644 index 0000000000000..bbd702c324121 --- /dev/null +++ b/daemon/internal/fstype/fstype_linux.go @@ -0,0 +1,12 @@ +package fstype + +import "golang.org/x/sys/unix" + +// getFSMagic returns the filesystem id given the path. +func getFSMagic(rootpath string) (FsMagic, error) { + var buf unix.Statfs_t + if err := unix.Statfs(rootpath, &buf); err != nil { + return 0, err + } + return FsMagic(buf.Type), nil +} diff --git a/daemon/internal/fstype/fstype_unsupported.go b/daemon/internal/fstype/fstype_unsupported.go new file mode 100644 index 0000000000000..8dabc8c81a7dc --- /dev/null +++ b/daemon/internal/fstype/fstype_unsupported.go @@ -0,0 +1,8 @@ +//go:build !linux + +package fstype + +// getFSMagic returns the filesystem id given the path. +func getFSMagic(rootpath string) (FsMagic, error) { + return FsMagicUnsupported, nil +} diff --git a/daemon/graphdriver/counter.go b/daemon/internal/mountref/counter.go similarity index 54% rename from daemon/graphdriver/counter.go rename to daemon/internal/mountref/counter.go index 2772bd247d847..f005b19ca7312 100644 --- a/daemon/graphdriver/counter.go +++ b/daemon/internal/mountref/counter.go @@ -1,4 +1,4 @@ -package graphdriver // import "github.com/docker/docker/daemon/graphdriver" +package mountref import "sync" @@ -7,36 +7,40 @@ type minfo struct { count int } -// RefCounter is a generic counter for use by graphdriver Get/Put calls -type RefCounter struct { - counts map[string]*minfo - mu sync.Mutex - checker Checker +// Counter is a generic counter for use by graphdriver Get/Put calls +type Counter struct { + counts map[string]*minfo + mu sync.Mutex + isMounted Checker } -// NewRefCounter returns a new RefCounter -func NewRefCounter(c Checker) *RefCounter { - return &RefCounter{ - checker: c, - counts: make(map[string]*minfo), +// Checker checks whether the provided path is mounted. +type Checker func(path string) bool + +// NewCounter returns a new Counter. It accepts a [Checker] to +// determine whether a path is mounted. +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 { @@ -48,7 +52,7 @@ func (c *RefCounter) incdec(path string, infoOp func(minfo *minfo)) int { // count if it is mounted as it is in use. if !m.check { m.check = true - if c.checker.IsMounted(path) { + if c.isMounted(path) { m.count++ } } diff --git a/daemon/snapshotter/mount.go b/daemon/snapshotter/mount.go index 68c727174f054..1f94901c9255e 100644 --- a/daemon/snapshotter/mount.go +++ b/daemon/snapshotter/mount.go @@ -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(checker()), + rc: mountref.NewCounter(isMounted), locker: locker.New(), } } type refCountMounter struct { - rc *graphdriver.RefCounter + rc *mountref.Counter locker *locker.Locker base mounter } diff --git a/daemon/snapshotter/mount_default.go b/daemon/snapshotter/mount_unix.go similarity index 51% rename from daemon/snapshotter/mount_default.go rename to daemon/snapshotter/mount_unix.go index 8203a9c47936b..ccb80735095b5 100644 --- a/daemon/snapshotter/mount_default.go +++ b/daemon/snapshotter/mount_unix.go @@ -4,12 +4,15 @@ package snapshotter import ( "github.com/containerd/containerd/mount" - "github.com/docker/docker/daemon/graphdriver" + "github.com/moby/sys/mountinfo" "golang.org/x/sys/unix" ) -func checker() graphdriver.Checker { - return graphdriver.NewDefaultChecker() +// isMounted parses /proc/mountinfo to check whether the specified path +// is mounted. +func isMounted(path string) bool { + m, _ := mountinfo.Mounted(path) + return m } func unmount(target string) error { diff --git a/daemon/snapshotter/mount_windows.go b/daemon/snapshotter/mount_windows.go index 19f1ebea7dace..de82e1c609641 100644 --- a/daemon/snapshotter/mount_windows.go +++ b/daemon/snapshotter/mount_windows.go @@ -2,15 +2,7 @@ package snapshotter import "github.com/containerd/containerd/mount" -type winChecker struct{} - -func (c *winChecker) IsMounted(path string) bool { - return false -} - -func checker() *winChecker { - return &winChecker{} -} +func isMounted(string) bool { return false } func unmount(target string) error { return mount.Unmount(target, 0)