Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/cephfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,24 @@ func (cs *cephfsControllerServer) CreateVolume(
defer parentVol.Destroy()
}

// Lock the source volume or snapshot to prevent deletion while creating from it
if pvID != nil {
if acquired := cs.VolumeLocks.TryAcquire(pvID.VolumeID); !acquired {
log.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, pvID.VolumeID)

return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, pvID.VolumeID)
}
defer cs.VolumeLocks.Release(pvID.VolumeID)
}
if sID != nil {
if acquired := cs.SnapshotLocks.TryAcquire(sID.SnapshotID); !acquired {
log.ErrorLog(ctx, util.SnapshotOperationAlreadyExistsFmt, sID.SnapshotID)

return nil, status.Errorf(codes.Aborted, util.SnapshotOperationAlreadyExistsFmt, sID.SnapshotID)
}
defer cs.SnapshotLocks.Release(sID.SnapshotID)
}

err = checkValidCreateVolumeRequest(volOptions, parentVol, pvID, sID, req)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
Expand Down
20 changes: 20 additions & 0 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ func checkValidCreateVolumeRequest(rbdVol, parentVol *rbdVolume, rbdSnap *rbdSna
}

// CreateVolume creates the volume in backend.
//
//nolint:gocyclo,cyclop // TODO: reduce complexity.
func (cs *ControllerServer) CreateVolume(
ctx context.Context,
req *csi.CreateVolumeRequest,
Expand Down Expand Up @@ -435,6 +437,24 @@ func (cs *ControllerServer) CreateVolume(
defer rbdSnap.Destroy(ctx)
}

// Lock the source volume or snapshot to prevent concurrent operations
if parentVol != nil {
if acquired := cs.VolumeLocks.TryAcquire(parentVol.VolID); !acquired {
log.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, parentVol.VolID)

return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, parentVol.VolID)
}
defer cs.VolumeLocks.Release(parentVol.VolID)
}
if rbdSnap != nil {
if acquired := cs.SnapshotLocks.TryAcquire(rbdSnap.VolID); !acquired {
Comment thread
nixpanic marked this conversation as resolved.
log.ErrorLog(ctx, util.SnapshotOperationAlreadyExistsFmt, rbdSnap.VolID)

return nil, status.Errorf(codes.Aborted, util.SnapshotOperationAlreadyExistsFmt, rbdSnap.VolID)
}
defer cs.SnapshotLocks.Release(rbdSnap.VolID)
}

err = updateTopologyConstraints(rbdVol, rbdSnap)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand Down