@@ -23,7 +23,7 @@ const (
2323 targetImageLayersLabel = "containerd.io/snapshot/cri.image-layers"
2424)
2525
26- type filesystem struct {
26+ type Filesystem struct {
2727 fsAbsoluteMountpoint string
2828 mountedLayers map [string ]string
2929 mountedLayersLock sync.Mutex
@@ -50,10 +50,10 @@ func NewFilesystem(ctx context.Context, root string, config *Config) (snapshot.F
5050 if _ , err := os .Stat (absolutePath ); err != nil {
5151 log .G (ctx ).WithField ("absolutePath" , absolutePath ).Warning ("Impossible to stat the absolute path, is the filesystem mounted properly? Error: " , err )
5252 }
53- return & filesystem {fsAbsoluteMountpoint : absolutePath , mountedLayers : mountedLayersMap }, nil
53+ return & Filesystem {fsAbsoluteMountpoint : absolutePath , mountedLayers : mountedLayersMap }, nil
5454}
5555
56- func (fs * filesystem ) Mount (ctx context.Context , mountpoint string , labels map [string ]string ) error {
56+ func (fs * Filesystem ) Mount (ctx context.Context , mountpoint string , labels map [string ]string ) error {
5757 log .G (ctx ).Info ("Mount layer from cvmfs" )
5858 digest , ok := labels [targetDigestLabelCRI ]
5959 if ! ok {
@@ -81,7 +81,7 @@ func (fs *filesystem) Mount(ctx context.Context, mountpoint string, labels map[s
8181 return nil
8282}
8383
84- func (fs * filesystem ) Check (ctx context.Context , mountpoint string , labels map [string ]string ) error {
84+ func (fs * Filesystem ) Check (ctx context.Context , mountpoint string , labels map [string ]string ) error {
8585 log .G (ctx ).WithField ("snapshotter" , "cvmfs" ).WithField ("mountpoint" , mountpoint ).Warning ("checking layer" )
8686 fs .mountedLayersLock .Lock ()
8787 path , ok := fs .mountedLayers [mountpoint ]
@@ -109,7 +109,7 @@ func (fs *filesystem) Check(ctx context.Context, mountpoint string, labels map[s
109109 return statErr
110110}
111111
112- func (fs * filesystem ) Unmount (ctx context.Context , mountpoint string ) error {
112+ func (fs * Filesystem ) Unmount (ctx context.Context , mountpoint string ) error {
113113 // maybe we lost track of something somehow, does not hurt to try to unmount the mountpoint anyway
114114
115115 fs .mountedLayersLock .Lock ()
@@ -123,3 +123,18 @@ func (fs *filesystem) Unmount(ctx context.Context, mountpoint string) error {
123123 }
124124 return syscall .Unmount (mountpoint , syscall .MNT_FORCE )
125125}
126+
127+ func (fs * Filesystem ) UnmountAll () {
128+ m := make ([]string , 0 )
129+ fs .mountedLayersLock .Lock ()
130+ for mountpoint := range fs .mountedLayers {
131+ m = append (m , mountpoint )
132+ delete (fs .mountedLayers , mountpoint )
133+ }
134+ fs .mountedLayersLock .Unlock ()
135+ for _ , mountpoint := range m {
136+ if err := syscall .Unmount (mountpoint , syscall .MNT_FORCE ); err != nil {
137+ log .G (context .TODO ()).WithError (err ).WithField ("mountpoint" , mountpoint ).Error ("Error in unmounting before to exit" )
138+ }
139+ }
140+ }
0 commit comments