From 84615de82863bed74a157e92f4d31f11b4fd612e Mon Sep 17 00:00:00 2001 From: Hans Rakers Date: Tue, 18 Jun 2024 14:02:54 +0200 Subject: [PATCH] fix(locking): Remove locking at node publish/unpublish ops Considering kubelet makes sure the unstage and unpublish operations are serialized, we dont need any extra locking in node publish/unpublish Credit to https://github.com/ceph/ceph-csi/pull/2149 --- pkg/driver/node.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/driver/node.go b/pkg/driver/node.go index 3ed2ee6..a73ac02 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -224,11 +224,8 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis deviceID = req.GetPublishContext()[deviceIDContextKey] } - if acquired := ns.volumeLocks.TryAcquire(volumeID); !acquired { - ctxzap.Extract(ctx).Sugar().Errorf(util.VolumeOperationAlreadyExistsFmt, volumeID) - return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volumeID) - } - defer ns.volumeLocks.Release(volumeID) + // Considering kubelet ensures the stage and publish operations + // are serialized, we don't need any extra locking in NodePublishVolume. if req.GetVolumeCapability().GetMount() != nil { source := req.GetStagingTargetPath() @@ -323,11 +320,8 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu return nil, status.Error(codes.InvalidArgument, "Target path missing in request") } - if acquired := ns.volumeLocks.TryAcquire(volumeID); !acquired { - ctxzap.Extract(ctx).Sugar().Errorf(util.VolumeOperationAlreadyExistsFmt, volumeID) - return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volumeID) - } - defer ns.volumeLocks.Release(volumeID) + // Considering that kubelet ensures the stage and publish operations + // are serialized, we don't need any extra locking in NodeUnpublishVolume. if _, err := ns.connector.GetVolumeByID(ctx, volumeID); err == cloud.ErrNotFound { return nil, status.Errorf(codes.NotFound, "Volume %v not found", volumeID)