Skip to content

Commit 2040d64

Browse files
committed
Merge branch 'volume-cloning-feature' of https://github.com/amacaskill/gcp-compute-persistent-disk-csi-driver into volume-cloning-feature
2 parents 503bee1 + 14e11f4 commit 2040d64

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

pkg/gce-pd-csi-driver/controller.go

+14-20
Original file line numberDiff line numberDiff line change
@@ -208,29 +208,24 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
208208
if content.GetVolume() != nil {
209209
volumeContentSourceVolumeID = content.GetVolume().GetVolumeId()
210210
// Verify that the source VolumeID is in the correct format.
211-
_, _, err := common.VolumeIDToKey(volumeContentSourceVolumeID)
211+
project, volKey, err := common.VolumeIDToKey(volumeContentSourceVolumeID)
212212
if err != nil {
213213
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("CreateVolume source volume ID is invalid: %v", err))
214214
}
215-
// Verify the volume in VolumeContentSource exists.
216-
if acquired := gceCS.volumeLocks.TryAcquire(volumeContentSourceVolumeID); acquired {
217-
return nil, status.Errorf(codes.NotFound, "CreateVolume source volume %s does not exist", volumeContentSourceVolumeID)
215+
216+
// Verify that the volume in VolumeContentSource exists.
217+
diskFromSourceVolume, err := gceCS.CloudProvider.GetDisk(ctx, project, volKey, gceAPIVersion)
218+
if err != nil {
219+
if gce.IsGCEError(err, "notFound") {
220+
return nil, status.Errorf(codes.NotFound, "CreateVolume source volume %s does not exist", volumeContentSourceVolumeID)
221+
} else {
222+
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume unknown get disk error when validating: %v", err))
223+
}
224+
}
225+
// Verify the zone, region, and disk type of the clone must be the same as that of the source disk.
226+
if err := gce.ValidateDiskParameters(diskFromSourceVolume, params); err != nil {
227+
return nil, status.Errorf(codes.InvalidArgument, `CreateVolume source volume parameters do not match CreateVolumeRequest Parameters: %v`, err)
218228
}
219-
defer gceCS.volumeLocks.Release(volumeContentSourceVolumeID)
220-
221-
// // Verify that the volume in VolumeContentSource exists.
222-
// diskFromSourceVolume, err := gceCS.CloudProvider.GetDisk(ctx, project, volKey, gceAPIVersion)
223-
// if err != nil {
224-
// if gce.IsGCEError(err, "notFound") {
225-
// return nil, status.Errorf(codes.NotFound, "CreateVolume source volume %s does not exist", volumeContentSourceVolumeID)
226-
// } else {
227-
// return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume unknown get disk error when validating: %v", err))
228-
// }
229-
// }
230-
// Verify the zone, region, and disk type of the clone must be the same as that of the source disk.
231-
// if err := gce.ValidateDiskParameters(diskFromSourceVolume, params); err != nil {
232-
// return nil, status.Errorf(codes.InvalidArgument, `CreateVolume source volume parameters do not match CreateVolumeRequest Parameters: %v`, err)
233-
// }
234229
// // Verify the source disk is ready.
235230
// if err == nil {
236231
// ready, err := isDiskReady(diskFromSourceVolume)
@@ -276,7 +271,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
276271

277272
klog.V(4).Infof("CreateVolume succeeded for disk %v", volKey)
278273
return generateCreateVolumeResponse(disk, zones), nil
279-
280274
}
281275

282276
func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {

0 commit comments

Comments
 (0)