@@ -179,9 +179,8 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
179
179
if err != nil {
180
180
return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume disk %v had error checking ready status: %v" , volKey , err ))
181
181
}
182
-
183
182
if ! ready {
184
- return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume disk %v is not ready" , volKey ))
183
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume existing disk %v is not ready. Existing disk state= name: %v, ID: %v, status: %v, zone: %v, location-type: %v " , volKey , existingDisk . GetName (), existingDisk . GetSourceDiskId (), existingDisk . GetStatus (), existingDisk . GetZone (), existingDisk . LocationType () ))
185
184
}
186
185
187
186
// If there is no validation error, immediately return success
@@ -207,12 +206,17 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
207
206
208
207
if content .GetVolume () != nil {
209
208
volumeContentSourceVolumeID = content .GetVolume ().GetVolumeId ()
210
-
211
209
// Verify that the source VolumeID is in the correct format.
212
- project , volKey , err := common .VolumeIDToKey (volumeContentSourceVolumeID )
210
+ _ , _ , err := common .VolumeIDToKey (volumeContentSourceVolumeID )
213
211
if err != nil {
214
212
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("CreateVolume source volume ID is invalid: %v" , err ))
215
213
}
214
+ // Verify the volume in VolumeContentSource exists.
215
+ if acquired := gceCS .volumeLocks .TryAcquire (volumeContentSourceVolumeID ); acquired {
216
+ return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
217
+ }
218
+ defer gceCS .volumeLocks .Release (volumeContentSourceVolumeID )
219
+
216
220
// Verify that the volume in VolumeContentSource exists.
217
221
diskFromSourceVolume , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gceAPIVersion )
218
222
if err != nil {
@@ -222,12 +226,10 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
222
226
return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume unknown get disk error when validating: %v" , err ))
223
227
}
224
228
}
225
-
226
- // Verify the zone, region, and disk type of the clone must be the same as that of the source disk.
229
+ // Verify the zone, region, and disk type of the clone must be the same as that of the source disk.
227
230
if err := gce .ValidateDiskParameters (diskFromSourceVolume , params ); err != nil {
228
231
return nil , status .Errorf (codes .InvalidArgument , `CreateVolume source volume parameters do not match CreateVolumeRequest Parameters: %v` , err )
229
232
}
230
-
231
233
// Verify the source disk is ready.
232
234
if err == nil {
233
235
ready , err := isDiskReady (diskFromSourceVolume )
@@ -238,8 +240,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
238
240
return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume disk from source volume %v is not ready" , volKey ))
239
241
}
240
242
}
241
- //TODO does this go inside of err == nil?
242
-
243
243
}
244
244
}
245
245
// Create the disk
@@ -1089,7 +1089,7 @@ func generateCreateVolumeResponse(disk *gce.CloudDisk, zones []string) *csi.Crea
1089
1089
},
1090
1090
}
1091
1091
snapshotID := disk .GetSnapshotId ()
1092
- diskID := disk .GetDiskId ()
1092
+ diskID := disk .GetSourceDiskId ()
1093
1093
if diskID != "" || snapshotID != "" {
1094
1094
contentSource := & csi.VolumeContentSource {}
1095
1095
if snapshotID != "" {
@@ -1101,7 +1101,6 @@ func generateCreateVolumeResponse(disk *gce.CloudDisk, zones []string) *csi.Crea
1101
1101
},
1102
1102
}
1103
1103
}
1104
- diskID := disk .GetDiskId ()
1105
1104
if diskID != "" {
1106
1105
contentSource = & csi.VolumeContentSource {
1107
1106
Type : & csi.VolumeContentSource_Volume {
0 commit comments