Skip to content

Commit d27a392

Browse files
andyzhangxk8s-infra-cherrypick-robot
authored andcommitted
fix: reduce mount lock to avoid volumeID collision issue
1 parent 27a6bf9 commit d27a392

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pkg/azurefile/nodeserver.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
240240
return nil, status.Errorf(codes.InvalidArgument, "fsGroupChangePolicy(%s) is not supported, supported fsGroupChangePolicy list: %v", fsGroupChangePolicy, supportedFSGroupChangePolicyList)
241241
}
242242

243-
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
243+
lockKey := fmt.Sprintf("%s-%s", volumeID, targetPath)
244+
if acquired := d.volumeLocks.TryAcquire(lockKey); !acquired {
244245
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
245246
}
246-
defer d.volumeLocks.Release(volumeID)
247+
defer d.volumeLocks.Release(lockKey)
247248

248249
if strings.TrimSpace(storageEndpointSuffix) == "" {
249250
if d.cloud.Environment.StorageEndpointSuffix != "" {
@@ -393,10 +394,11 @@ func (d *Driver) NodeUnstageVolume(_ context.Context, req *csi.NodeUnstageVolume
393394
return nil, status.Error(codes.InvalidArgument, "Staging target not provided")
394395
}
395396

396-
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
397+
lockKey := fmt.Sprintf("%s-%s", volumeID, stagingTargetPath)
398+
if acquired := d.volumeLocks.TryAcquire(lockKey); !acquired {
397399
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
398400
}
399-
defer d.volumeLocks.Release(volumeID)
401+
defer d.volumeLocks.Release(lockKey)
400402

401403
mc := metrics.NewMetricContext(azureFileCSIDriverName, "node_unstage_volume", d.cloud.ResourceGroup, "", d.Name)
402404
isOperationSucceeded := false

pkg/azurefile/nodeserver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func TestNodeStageVolume(t *testing.T) {
525525
{
526526
desc: "[Error] Volume operation in progress",
527527
setup: func() {
528-
d.volumeLocks.TryAcquire("vol_1##")
528+
d.volumeLocks.TryAcquire(fmt.Sprintf("%s-%s", "vol_1##", sourceTest))
529529
},
530530
req: csi.NodeStageVolumeRequest{VolumeId: "vol_1##", StagingTargetPath: sourceTest,
531531
VolumeCapability: &stdVolCap,
@@ -535,7 +535,7 @@ func TestNodeStageVolume(t *testing.T) {
535535
DefaultError: status.Error(codes.Aborted, fmt.Sprintf(volumeOperationAlreadyExistsFmt, "vol_1##")),
536536
},
537537
cleanup: func() {
538-
d.volumeLocks.Release("vol_1##")
538+
d.volumeLocks.Release(fmt.Sprintf("%s-%s", "vol_1##", sourceTest))
539539
},
540540
},
541541
{
@@ -784,14 +784,14 @@ func TestNodeUnstageVolume(t *testing.T) {
784784
{
785785
desc: "[Error] Volume operation in progress",
786786
setup: func() {
787-
d.volumeLocks.TryAcquire("vol_1")
787+
d.volumeLocks.TryAcquire(fmt.Sprintf("%s-%s", "vol_1", targetFile))
788788
},
789789
req: csi.NodeUnstageVolumeRequest{StagingTargetPath: targetFile, VolumeId: "vol_1"},
790790
expectedErr: testutil.TestError{
791791
DefaultError: status.Error(codes.Aborted, fmt.Sprintf(volumeOperationAlreadyExistsFmt, "vol_1")),
792792
},
793793
cleanup: func() {
794-
d.volumeLocks.Release("vol_1")
794+
d.volumeLocks.Release(fmt.Sprintf("%s-%s", "vol_1", targetFile))
795795
},
796796
},
797797
{

0 commit comments

Comments
 (0)