66 "os"
77 "path/filepath"
88 "strings"
9+ "sync"
910 "syscall"
1011
1112 "github.com/containerd/containerd/log"
@@ -22,10 +23,10 @@ const (
2223 targetImageLayersLabel = "containerd.io/snapshot/cri.image-layers"
2324)
2425
25-
2626type filesystem struct {
27- repository string
28- mountedLayers map [string ]string
27+ repository string
28+ mountedLayers map [string ]string
29+ mountedLayersLock sync.Mutex
2930}
3031
3132type Config struct {
@@ -63,13 +64,17 @@ func (fs *filesystem) Mount(ctx context.Context, mountpoint string, labels map[s
6364 log .G (ctx ).WithError (err ).WithField ("layer digest" , digest ).WithField ("mountpoint" , mountpoint ).Debug ("cvmfs: Error in bind mounting the layer." )
6465 return err
6566 }
67+ fs .mountedLayersLock .Lock ()
68+ defer fs .mountedLayersLock .Unlock ()
6669 fs .mountedLayers [mountpoint ] = path
6770 return nil
6871}
6972
70- func (fs * filesystem ) Check (ctx context.Context , mountpoint string ) error {
73+ func (fs * filesystem ) Check (ctx context.Context , mountpoint string , labels map [ string ] string ) error {
7174 log .G (ctx ).WithField ("snapshotter" , "cvmfs" ).WithField ("mountpoint" , mountpoint ).Warning ("checking layer" )
75+ fs .mountedLayersLock .Lock ()
7276 path , ok := fs .mountedLayers [mountpoint ]
77+ fs .mountedLayersLock .Unlock ()
7378 if ! ok {
7479 err := fmt .Errorf ("Mountpoint: %s was not mounted" , mountpoint )
7580 log .G (ctx ).WithError (err ).WithField ("mountpoint" , mountpoint ).Error ("cvmfs: the requested mountpoint does not seem to be mounted" )
@@ -92,3 +97,18 @@ func (fs *filesystem) Check(ctx context.Context, mountpoint string) error {
9297 }
9398 return statErr
9499}
100+
101+ func (fs * filesystem ) Unmount (ctx context.Context , mountpoint string ) error {
102+ // maybe we lost track of something somehow, does not hurt to try to unmount the mountpoint anyway
103+
104+ fs .mountedLayersLock .Lock ()
105+ _ , ok := fs .mountedLayers [mountpoint ]
106+ delete (fs .mountedLayers , mountpoint )
107+ fs .mountedLayersLock .Unlock ()
108+
109+ if ! ok {
110+ err := fmt .Errorf ("Trying to unmount mountpoint that does not seems mounted: %s" , mountpoint )
111+ log .G (ctx ).WithError (err ).Error ("Layer does not seems mounted." )
112+ }
113+ return syscall .Unmount (mountpoint , syscall .MNT_FORCE )
114+ }
0 commit comments