aboutsummaryrefslogtreecommitdiff
path: root/pkg/mountmanager/manager.go
diff options
context:
space:
mode:
authorchrislusf <chris.lu@gmail.com>2025-12-05 18:51:43 -0800
committerChris Lu <chrislusf@users.noreply.github.com>2025-12-06 18:53:22 -0800
commitff62b6653f2ba858a9ef9623a90ee20f20c69d75 (patch)
treebb99979c0c382ff0d4ee56115eaeb486ea4d743c /pkg/mountmanager/manager.go
parent5d6446572c832107ead53f2ec522cfbb5fe4c4eb (diff)
downloadseaweedfs-csi-driver-ff62b6653f2ba858a9ef9623a90ee20f20c69d75.tar.xz
seaweedfs-csi-driver-ff62b6653f2ba858a9ef9623a90ee20f20c69d75.zip
fix: improve ensureTargetClean to be non-recursive and always ensure directory exists
Address review feedback from gemini-code-assist: - Replace recursive approach with non-recursive to avoid potential stack overflow - Always call os.MkdirAll at the end to ensure directory exists after unmount - Add better error messages with context - Add logging for unmount operations
Diffstat (limited to 'pkg/mountmanager/manager.go')
-rw-r--r--pkg/mountmanager/manager.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/pkg/mountmanager/manager.go b/pkg/mountmanager/manager.go
index 7e94b89..e4e4329 100644
--- a/pkg/mountmanager/manager.go
+++ b/pkg/mountmanager/manager.go
@@ -169,22 +169,24 @@ func ensureTargetClean(targetPath string) error {
isMount, err := kubeMounter.IsMountPoint(targetPath)
if err != nil {
if os.IsNotExist(err) {
- return os.MkdirAll(targetPath, 0750)
- }
- if mount.IsCorruptedMnt(err) {
+ // Path does not exist, which is a clean state. Directory will be created below.
+ } else if mount.IsCorruptedMnt(err) {
+ glog.Warningf("Target path %s is a corrupted mount, attempting to unmount", targetPath)
if err := kubeMounter.Unmount(targetPath); err != nil {
- return err
+ return fmt.Errorf("failed to unmount corrupted mount %s: %w", targetPath, err)
}
- return ensureTargetClean(targetPath)
+ } else {
+ return err
}
- return err
- }
- if isMount {
+ } else if isMount {
+ glog.Infof("Target path %s is an existing mount, attempting to unmount", targetPath)
if err := kubeMounter.Unmount(targetPath); err != nil {
- return err
+ return fmt.Errorf("failed to unmount existing mount %s: %w", targetPath, err)
}
}
- return nil
+
+ // Ensure the path exists and is a directory.
+ return os.MkdirAll(targetPath, 0750)
}
func validateMountRequest(req *MountRequest) error {