Skip to content

Support lazy/force unmount of mountpoint #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions pkg/mounter/utils/mounter_utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

package utils

import (
Expand Down Expand Up @@ -48,21 +51,32 @@ func (su *MounterOptsUtils) FuseMount(path string, comm string, args []string) e

func (su *MounterOptsUtils) FuseUnmount(path string) error {
klog.Info("-fuseUnmount-")
// directory exists
// check if mountpoint exists
isMount, checkMountErr := isMountpoint(path)
if isMount || checkMountErr != nil {
klog.Infof("isMountpoint %v", isMount)
err := unmount(path, 0)
if err != nil && checkMountErr == nil {
klog.Errorf("Cannot unmount. Trying force unmount %s", err)
//Do force unmount
err = unmount(path, 0)
if err != nil {
klog.Warningf("Standard unmount failed for %s: %v. Trying lazy unmount...", path, err)
// Try lazy (MNT_DETACH) unmount
err = unmount(path, syscall.MNT_DETACH)
if err != nil {
klog.Errorf("Cannot force unmount %s", err)
return fmt.Errorf("cannot force unmount %s: %v", path, err)
klog.Warningf("Lazy unmount failed for %s: %v. Trying force unmount...", path, err)
// Try force unmount as last resort
err = unmount(path, syscall.MNT_FORCE)
if err != nil {
klog.Errorf("Force unmount failed for %s: %v", path, err)
return fmt.Errorf("all unmount attempts failed for %s: %v", path, err)
}
klog.Infof("Force unmounted %s successfully", path)
} else {
klog.Infof("Lazy unmounted %s successfully", path)
}
} else {
klog.Infof("Unmounted %s with standard unmount successfully", path)
}
}

// as fuse quits immediately, we will try to wait until the process is done
process, err := findFuseMountProcess(path)
if err != nil {
Expand Down