@@ -112,7 +112,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
112
112
// Resource names (e.g. "keyRings", "cryptoKeys", etc.) are case sensitive, so do not change case
113
113
diskEncryptionKmsKey = v
114
114
default :
115
- return nil , status .Errorf (codes .InvalidArgument ,"CreateVolume invalid option %q" , k )
115
+ return nil , status .Errorf (codes .InvalidArgument , "CreateVolume invalid option %q" , k )
116
116
}
117
117
}
118
118
// Determine the zone or zones+region of the disk
@@ -122,10 +122,10 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
122
122
case replicationTypeNone :
123
123
zones , err = pickZones (gceCS , req .GetAccessibilityRequirements (), 1 )
124
124
if err != nil {
125
- return nil , status .Errorf (codes .InvalidArgument ,"CreateVolume failed to pick zones for disk: %v" , err )
125
+ return nil , status .Errorf (codes .InvalidArgument , "CreateVolume failed to pick zones for disk: %v" , err )
126
126
}
127
127
if len (zones ) != 1 {
128
- return nil , status .Errorf (codes .Internal ,"Failed to pick exactly 1 zone for zonal disk, got %v instead" , len (zones ))
128
+ return nil , status .Errorf (codes .Internal , "Failed to pick exactly 1 zone for zonal disk, got %v instead" , len (zones ))
129
129
}
130
130
volKey = meta .ZonalKey (name , zones [0 ])
131
131
@@ -143,10 +143,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
143
143
return nil , status .Errorf (codes .InvalidArgument , "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 .Errorf (codes .Aborted , "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 .Errorf (codes .NotFound , "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 .Errorf (codes .Aborted , "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 .Errorf (codes .NotFound , "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 .Errorf (codes .Aborted , "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 .Errorf (codes .Aborted , "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 .Errorf (codes .NotFound , "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 .Errorf (codes .Aborted , "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 .Errorf (codes .NotFound , "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 .Errorf (codes .Aborted , "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