From d432e63322e0237f2f5ced3580f6233f401e9e48 Mon Sep 17 00:00:00 2001 From: chrislusf Date: Wed, 3 Dec 2025 19:42:31 -0800 Subject: 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 --- pkg/driver/nodeserver.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'pkg/driver/nodeserver.go') 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) } } -- cgit v1.2.3