@@ -143,10 +143,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
143
143
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("CreateVolume replication type '%s' is not supported" , replicationType ))
144
144
}
145
145
146
- if acquired := gceCS .volumes .TryAcquire (volKey .String ()); ! acquired {
147
- return nil , status .Error (codes .Aborted , fmt .Sprintf ("An operation with the given Volume Key %s already exists" , volKey .String ()))
146
+ volumeID , err := common .KeyToVolumeID (volKey , gceCS .CloudProvider .GetProject ())
147
+ if err != nil {
148
+ return nil , status .Errorf (codes .Internal , "Failed to convert volume key to volume ID: %v" , err )
149
+ }
150
+ if acquired := gceCS .volumes .TryAcquire (volumeID ); ! acquired {
151
+ return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , volumeID )
148
152
}
149
- defer gceCS .volumes .Release (volKey . String () )
153
+ defer gceCS .volumes .Release (volumeID )
150
154
151
155
// Validate if disk already exists
152
156
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , volKey )
@@ -231,10 +235,10 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
231
235
return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find volume with ID %v: %v" , volumeID , err ))
232
236
}
233
237
234
- if acquired := gceCS .volumes .TryAcquire (volKey . String () ); ! acquired {
235
- return nil , status .Error (codes .Aborted , fmt . Sprintf ( "An operation with the given Volume Key %s already exists" , volKey . String ()) )
238
+ if acquired := gceCS .volumes .TryAcquire (volumeID ); ! acquired {
239
+ return nil , status .Errorf (codes .Aborted , common . VolumeOperationAlreadyExistsFmt , volumeID )
236
240
}
237
- defer gceCS .volumes .Release (volKey . String () )
241
+ defer gceCS .volumes .Release (volumeID )
238
242
239
243
err = gceCS .CloudProvider .DeleteDisk (ctx , volKey )
240
244
if err != nil {
@@ -272,11 +276,11 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
272
276
return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find volume with ID %v: %v" , volumeID , err ))
273
277
}
274
278
275
- volKeyStr := volKey . String ( )
276
- if acquired := gceCS .volumes .TryAcquire (nodeID + "/" + volKeyStr ); ! acquired {
277
- return nil , status .Error (codes .Aborted , fmt . Sprintf ( "An operation with the given Volume Key %s or Node ID %s already exists" , volKeyStr , nodeID ) )
279
+ lockingVolumeID := fmt . Sprintf ( "%s/%s" , nodeID , volumeID )
280
+ if acquired := gceCS .volumes .TryAcquire (lockingVolumeID ); ! acquired {
281
+ return nil , status .Errorf (codes .Aborted , common . VolumeOperationAlreadyExistsFmt , lockingVolumeID )
278
282
}
279
- defer gceCS .volumes .Release (nodeID + "/" + volKeyStr )
283
+ defer gceCS .volumes .Release (lockingVolumeID )
280
284
281
285
// TODO(#253): Check volume capability matches for ALREADY_EXISTS
282
286
if err = validateVolumeCapability (volumeCapability ); err != nil {
@@ -363,11 +367,11 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
363
367
return nil , err
364
368
}
365
369
366
- volKeyStr := volKey . String ( )
367
- if acquired := gceCS .volumes .TryAcquire (nodeID + "/" + volKeyStr ); ! acquired {
368
- return nil , status .Error (codes .Aborted , fmt . Sprintf ( "An operation with the given Volume Key %s or Node ID %s already exists" , volKeyStr , nodeID ) )
370
+ lockingVolumeID := fmt . Sprintf ( "%s/%s" , nodeID , volumeID )
371
+ if acquired := gceCS .volumes .TryAcquire (lockingVolumeID ); ! acquired {
372
+ return nil , status .Errorf (codes .Aborted , common . VolumeOperationAlreadyExistsFmt , lockingVolumeID )
369
373
}
370
- defer gceCS .volumes .Release (nodeID + "/" + volKeyStr )
374
+ defer gceCS .volumes .Release (lockingVolumeID )
371
375
372
376
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
373
377
if err != nil {
@@ -416,10 +420,10 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
416
420
return nil , status .Error (codes .NotFound , fmt .Sprintf ("Volume ID is of improper format, got %v" , volumeID ))
417
421
}
418
422
419
- if acquired := gceCS .volumes .TryAcquire (volKey . String () ); ! acquired {
420
- return nil , status .Error (codes .Aborted , fmt . Sprintf ( "An operation with the given Volume Key %s already exists" , volKey . String ()) )
423
+ if acquired := gceCS .volumes .TryAcquire (volumeID ); ! acquired {
424
+ return nil , status .Errorf (codes .Aborted , common . VolumeOperationAlreadyExistsFmt , volumeID )
421
425
}
422
- defer gceCS .volumes .Release (volKey . String () )
426
+ defer gceCS .volumes .Release (volumeID )
423
427
424
428
_ , err = gceCS .CloudProvider .GetDisk (ctx , volKey )
425
429
if err != nil {
@@ -528,10 +532,10 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
528
532
return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find volume with ID %v: %v" , volumeID , err ))
529
533
}
530
534
531
- if acquired := gceCS .volumes .TryAcquire (volKey . String () ); ! acquired {
532
- return nil , status .Error (codes .Aborted , fmt . Sprintf ( "An operation with the given Volume Key %s already exists" , volKey . String ()) )
535
+ if acquired := gceCS .volumes .TryAcquire (volumeID ); ! acquired {
536
+ return nil , status .Errorf (codes .Aborted , common . VolumeOperationAlreadyExistsFmt , volumeID )
533
537
}
534
- defer gceCS .volumes .Release (volKey . String () )
538
+ defer gceCS .volumes .Release (volumeID )
535
539
536
540
// Check if snapshot already exists
537
541
var snapshot * compute.Snapshot
0 commit comments