Skip to content

Commit 8df386a

Browse files
Rakshith-Rmergify[bot]
authored andcommitted
csi: add VolumeLocks to NodeGetVolumeStats for RBD and CephFS
Acquire a targetPath lock in NodeGetVolumeStats to prevent running multiple NodeGetVolumeStats call on same target path at once. This may happen when ceph cluster has problems. This also matches the semantics of locking in other gRPC calls. Assisted-by: Claude <noreply@anthropic.com> Signed-off-by: Rakshith R <rar@redhat.com> (cherry picked from commit 45d14a3)
1 parent 2c886d1 commit 8df386a

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

internal/cephfs/nodeserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,11 @@ func (ns *NodeServer) NodeGetVolumeStats(
915915
return nil, status.Error(codes.InvalidArgument, err.Error())
916916
}
917917

918+
if acquired := ns.VolumeLocks.TryAcquire(targetPath); !acquired {
919+
return nil, status.Errorf(codes.Aborted, util.TargetPathOperationAlreadyExistsFmt, targetPath)
920+
}
921+
defer ns.VolumeLocks.Release(targetPath)
922+
918923
// health check first, return without stats if unhealthy
919924
healthy, msg := ns.healthChecker.IsHealthy(volumeID, targetPath)
920925

internal/rbd/nodeserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,11 @@ func (ns *NodeServer) NodeGetVolumeStats(
15071507
return nil, status.Error(codes.InvalidArgument, err.Error())
15081508
}
15091509

1510+
if acquired := ns.VolumeLocks.TryAcquire(targetPath); !acquired {
1511+
return nil, status.Errorf(codes.Aborted, util.TargetPathOperationAlreadyExistsFmt, targetPath)
1512+
}
1513+
defer ns.VolumeLocks.Release(targetPath)
1514+
15101515
stat, err := os.Stat(targetPath)
15111516
if err != nil {
15121517
if util.IsCorruptedMountError(err) {

0 commit comments

Comments
 (0)