diff options
| author | chrislusf <chris.lu@gmail.com> | 2025-12-03 19:42:31 -0800 |
|---|---|---|
| committer | chrislusf <chris.lu@gmail.com> | 2025-12-03 19:42:31 -0800 |
| commit | 098fd583dc5a5704dec3f2af433fbe28e60e1097 (patch) | |
| tree | 88b0f12883402ca7d5e179f2fa02a51bef2d1405 | |
| parent | 51aef3c1d61bc4fd095a51c989c3957692a2a172 (diff) | |
| download | seaweedfs-csi-driver-098fd583dc5a5704dec3f2af433fbe28e60e1097.tar.xz seaweedfs-csi-driver-098fd583dc5a5704dec3f2af433fbe28e60e1097.zip | |
fix: preserve healthy mounts in NodeStageVolume instead of re-staging
Address CodeRabbit review - when a healthy staging path exists after driver
restart, rebuild the cache using rebuildVolumeFromStaging() instead of
cleaning up and re-staging. This:
- Maintains consistency with NodePublishVolume behavior
- Avoids disrupting existing published volumes that are bind-mounted
- Makes NodeStageVolume idempotent as per CSI spec
| -rw-r--r-- | pkg/driver/nodeserver.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 95b556f..d861ddc 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -62,20 +62,20 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol // 1. The CSI driver restarted and lost its in-memory state // 2. The FUSE process died leaving a stale mount if isStagingPathHealthy(stagingTargetPath) { - // The staging path is healthy - this means the FUSE mount is still active - // (possibly from before driver restart). We need to clean it up and re-stage - // because we don't have the unmounter reference to properly manage it. - glog.Infof("volume %s has existing healthy mount at %s, will re-stage to get proper control", volumeID, stagingTargetPath) + // The staging path is healthy - rebuild the cache from the existing mount + // This preserves the existing FUSE mount and avoids disrupting any published volumes + glog.Infof("volume %s has existing healthy mount at %s, rebuilding cache", volumeID, stagingTargetPath) + volume := ns.rebuildVolumeFromStaging(volumeID, stagingTargetPath) + ns.volumes.Store(volumeID, volume) + glog.Infof("volume %s cache rebuilt from existing staging at %s", volumeID, stagingTargetPath) + return &csi.NodeStageVolumeResponse{}, nil + } + + // Check if there's a stale/corrupted mount that needs cleanup + if _, err := os.Stat(stagingTargetPath); err == nil || mount.IsCorruptedMnt(err) { + glog.Infof("volume %s has stale staging path at %s, cleaning up", volumeID, stagingTargetPath) if err := cleanupStaleStagingPath(stagingTargetPath); err != nil { - glog.Warningf("failed to cleanup existing healthy staging path %s: %v, will try to stage anyway", stagingTargetPath, err) - } - } else { - // Check if there's a stale/corrupted mount that needs cleanup - if _, err := os.Stat(stagingTargetPath); err == nil || mount.IsCorruptedMnt(err) { - glog.Infof("volume %s has stale staging path at %s, cleaning up", volumeID, stagingTargetPath) - if err := cleanupStaleStagingPath(stagingTargetPath); err != nil { - glog.Warningf("failed to cleanup stale staging path %s: %v, will try to stage anyway", stagingTargetPath, err) - } + glog.Warningf("failed to cleanup stale staging path %s: %v, will try to stage anyway", stagingTargetPath, err) } } |
