Skip to content

Commit af77b7c

Browse files
committed
force unmount and remove in flist clean up if the path is not mountpoint but the module can not delete it
1 parent bbb4b56 commit af77b7c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pkg/flist/cleanup.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,33 @@ func (f *flistModule) cleanUnusedMounts() error {
139139
}
140140

141141
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+
}
143145
}
144146
}
145147

146148
return nil
147149
}
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+
}

0 commit comments

Comments
 (0)