diff --git a/pkg/smb/nodeserver.go b/pkg/smb/nodeserver.go index 5bc75879cd7..aeffb6f6016 100644 --- a/pkg/smb/nodeserver.go +++ b/pkg/smb/nodeserver.go @@ -153,10 +153,11 @@ func (d *Driver) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequ return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("%s field is missing, current context: %v", sourceField, context)) } - if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired { + lockKey := fmt.Sprintf("%s-%s", volumeID, targetPath) + if acquired := d.volumeLocks.TryAcquire(lockKey); !acquired { return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID) } - defer d.volumeLocks.Release(volumeID) + defer d.volumeLocks.Release(lockKey) var username, password, domain string for k, v := range secrets { @@ -254,10 +255,11 @@ func (d *Driver) NodeUnstageVolume(_ context.Context, req *csi.NodeUnstageVolume return nil, status.Error(codes.InvalidArgument, "Staging target not provided") } - if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired { + lockKey := fmt.Sprintf("%s-%s", volumeID, stagingTargetPath) + if acquired := d.volumeLocks.TryAcquire(lockKey); !acquired { return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID) } - defer d.volumeLocks.Release(volumeID) + defer d.volumeLocks.Release(lockKey) klog.V(2).Infof("NodeUnstageVolume: CleanupMountPoint on %s with volume %s", stagingTargetPath, volumeID) if err := CleanupSMBMountPoint(d.mounter, stagingTargetPath, true /*extensiveMountPointCheck*/, volumeID); err != nil { diff --git a/pkg/smb/nodeserver_test.go b/pkg/smb/nodeserver_test.go index c7531f29253..af3fdca8e25 100644 --- a/pkg/smb/nodeserver_test.go +++ b/pkg/smb/nodeserver_test.go @@ -136,7 +136,7 @@ func TestNodeStageVolume(t *testing.T) { { desc: "[Error] Volume operation in progress", setup: func(d *Driver) { - d.volumeLocks.TryAcquire("vol_1") + d.volumeLocks.TryAcquire(fmt.Sprintf("%s-%s", "vol_1", sourceTest)) }, req: csi.NodeStageVolumeRequest{VolumeId: "vol_1", StagingTargetPath: sourceTest, VolumeCapability: &stdVolCap, @@ -146,7 +146,7 @@ func TestNodeStageVolume(t *testing.T) { DefaultError: status.Error(codes.Aborted, fmt.Sprintf(volumeOperationAlreadyExistsFmt, "vol_1")), }, cleanup: func(d *Driver) { - d.volumeLocks.Release("vol_1") + d.volumeLocks.Release(fmt.Sprintf("%s-%s", "vol_1", sourceTest)) }, }, { @@ -493,14 +493,14 @@ func TestNodeUnstageVolume(t *testing.T) { { desc: "[Error] Volume operation in progress", setup: func(d *Driver) { - d.volumeLocks.TryAcquire("vol_1") + d.volumeLocks.TryAcquire(fmt.Sprintf("%s-%s", "vol_1", targetFile)) }, req: csi.NodeUnstageVolumeRequest{StagingTargetPath: targetFile, VolumeId: "vol_1"}, expectedErr: testutil.TestError{ DefaultError: status.Error(codes.Aborted, fmt.Sprintf(volumeOperationAlreadyExistsFmt, "vol_1")), }, cleanup: func(d *Driver) { - d.volumeLocks.Release("vol_1") + d.volumeLocks.Release(fmt.Sprintf("%s-%s", "vol_1", targetFile)) }, }, {