File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -139,9 +139,33 @@ func (f *flistModule) cleanUnusedMounts() error {
139
139
}
140
140
141
141
if err := os .Remove (path ); err != nil {
142
- log .Error ().Err (err ).Msgf ("failed to clean mountpoint %s" , path )
142
+ if err := f .forceUnmountAndRemove (path ); err != nil {
143
+ log .Error ().Err (err ).Msgf ("failed to clean mountpoint %s" , path )
144
+ }
143
145
}
144
146
}
145
147
146
148
return nil
147
149
}
150
+
151
+ func (f * flistModule ) forceUnmountAndRemove (path string ) error {
152
+ log .Debug ().Msgf ("trying to forcibly clean up : %+v" , path )
153
+ // Try normal unmount first
154
+ err := f .system .Unmount (path , 0 )
155
+ if err != nil {
156
+ log .Warn ().Err (err ).Msgf ("normal unmount failed for %s, trying lazy unmount" , path )
157
+
158
+ // Try lazy unmount (MNT_DETACH)
159
+ err = syscall .Unmount (path , syscall .MNT_DETACH )
160
+ if err != nil {
161
+ log .Error ().Err (err ).Msgf ("lazy unmount also failed for %s" , path )
162
+ return err
163
+ }
164
+ }
165
+ // Now try to remove the directory
166
+ if err := os .RemoveAll (path ); err != nil {
167
+ log .Error ().Err (err ).Msgf ("failed to remove mountpoint %s" , path )
168
+ return err
169
+ }
170
+ return nil
171
+ }
You can’t perform that action at this time.
0 commit comments