Skip to content

Commit ea533f1

Browse files
authored
Merge pull request #1194 from k8s-infra-cherrypick-robot/cherry-pick-1193-to-release-1.23
[release-1.23] fix: reduce mount lock to avoid volumeID collision issue
2 parents cc86f63 + a7adb51 commit ea533f1

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
@@ -229,10 +229,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
229229
return nil, status.Error(codes.InvalidArgument, "Volume capability not provided")
230230
}
231231

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

237238
mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags()
238239
attrib := req.GetVolumeContext()
@@ -437,10 +438,11 @@ func (d *Driver) NodeUnstageVolume(_ context.Context, req *csi.NodeUnstageVolume
437438
return nil, status.Error(codes.InvalidArgument, "Staging target not provided")
438439
}
439440

440-
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
441+
lockKey := fmt.Sprintf("%s-%s", volumeID, stagingTargetPath)
442+
if acquired := d.volumeLocks.TryAcquire(lockKey); !acquired {
441443
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
442444
}
443-
defer d.volumeLocks.Release(volumeID)
445+
defer d.volumeLocks.Release(lockKey)
444446

445447
klog.V(2).Infof("NodeUnstageVolume: volume %s unmounting on %s", volumeID, stagingTargetPath)
446448
err := mount.CleanupMountPoint(stagingTargetPath, d.mounter, true /*extensiveMountPointCheck*/)

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)