Skip to content

Commit ce26f28

Browse files
authored
Merge pull request #1193 from andyzhangx/reduce-mount-lock
fix: reduce mount lock to avoid volumeID collision issue
2 parents 060da8c + ec7152d commit ce26f28

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pkg/blob/nodeserver.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
230230
return nil, status.Error(codes.InvalidArgument, "Volume capability not provided")
231231
}
232232

233-
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
233+
lockKey := fmt.Sprintf("%s-%s", volumeID, targetPath)
234+
if acquired := d.volumeLocks.TryAcquire(lockKey); !acquired {
234235
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
235236
}
236-
defer d.volumeLocks.Release(volumeID)
237+
defer d.volumeLocks.Release(lockKey)
237238

238239
mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags()
239240
attrib := req.GetVolumeContext()
@@ -445,10 +446,11 @@ func (d *Driver) NodeUnstageVolume(_ context.Context, req *csi.NodeUnstageVolume
445446
return nil, status.Error(codes.InvalidArgument, "Staging target not provided")
446447
}
447448

448-
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
449+
lockKey := fmt.Sprintf("%s-%s", volumeID, stagingTargetPath)
450+
if acquired := d.volumeLocks.TryAcquire(lockKey); !acquired {
449451
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
450452
}
451-
defer d.volumeLocks.Release(volumeID)
453+
defer d.volumeLocks.Release(lockKey)
452454

453455
mc := metrics.NewMetricContext(blobCSIDriverName, "node_unstage_volume", d.cloud.ResourceGroup, "", d.Name)
454456
isOperationSucceeded := false

pkg/blob/nodeserver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ func TestNodeStageVolume(t *testing.T) {
435435
VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
436436
}
437437
d := NewFakeDriver()
438-
d.volumeLocks.TryAcquire("unit-test")
439-
defer d.volumeLocks.Release("unit-test")
438+
d.volumeLocks.TryAcquire(fmt.Sprintf("%s-%s", "unit-test", "unit-test"))
439+
defer d.volumeLocks.Release(fmt.Sprintf("%s-%s", "unit-test", "unit-test"))
440440
_, err := d.NodeStageVolume(context.TODO(), req)
441441
expectedErr := status.Error(codes.Aborted, fmt.Sprintf(volumeOperationAlreadyExistsFmt, "unit-test"))
442442
if !reflect.DeepEqual(err, expectedErr) {
@@ -606,8 +606,8 @@ func TestNodeUnstageVolume(t *testing.T) {
606606
VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
607607
}
608608
d := NewFakeDriver()
609-
d.volumeLocks.TryAcquire("unit-test")
610-
defer d.volumeLocks.Release("unit-test")
609+
d.volumeLocks.TryAcquire(fmt.Sprintf("%s-%s", "unit-test", "unit-test"))
610+
defer d.volumeLocks.Release(fmt.Sprintf("%s-%s", "unit-test", "unit-test"))
611611
_, err := d.NodeStageVolume(context.TODO(), req)
612612
expectedErr := status.Error(codes.Aborted, fmt.Sprintf(volumeOperationAlreadyExistsFmt, "unit-test"))
613613
if !reflect.DeepEqual(err, expectedErr) {

0 commit comments

Comments
 (0)