Skip to content

Commit

Permalink
rbd: let parseVolCreateRequest() return a connected rbdVolume
Browse files Browse the repository at this point in the history
By returning a connected rbdVolume in parseVolCreateRequest(), the
CreateVolume() function can be simplified a little. There is no need to
call the additional Connect() and detect failures with it.

Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic authored and mergify[bot] committed Mar 28, 2024
1 parent 7b2b125 commit a517290
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func validateStriping(parameters map[string]string) error {
func (cs *ControllerServer) parseVolCreateRequest(
ctx context.Context,
req *csi.CreateVolumeRequest,
cr *util.Credentials,
) (*rbdVolume, error) {
// TODO (sbezverk) Last check for not exceeding total storage capacity

Expand Down Expand Up @@ -226,6 +227,13 @@ func (cs *ControllerServer) parseVolCreateRequest(
return nil, status.Error(codes.InvalidArgument, err.Error())
}

err = rbdVol.Connect(cr)
if err != nil {
log.ErrorLog(ctx, "failed to connect to volume %v: %v", rbdVol.RbdImageName, err)

return nil, status.Error(codes.Internal, err.Error())
}

// NOTE: rbdVol does not contain VolID and RbdImageName populated, everything
// else is populated post create request parsing
return rbdVol, nil
Expand Down Expand Up @@ -324,7 +332,7 @@ func (cs *ControllerServer) CreateVolume(
return nil, status.Error(codes.InvalidArgument, err.Error())
}
defer cr.DeleteCredentials()
rbdVol, err := cs.parseVolCreateRequest(ctx, req)
rbdVol, err := cs.parseVolCreateRequest(ctx, req, cr)
if err != nil {
return nil, err
}
Expand All @@ -337,13 +345,6 @@ func (cs *ControllerServer) CreateVolume(
}
defer cs.VolumeLocks.Release(req.GetName())

err = rbdVol.Connect(cr)
if err != nil {
log.ErrorLog(ctx, "failed to connect to volume %v: %v", rbdVol.RbdImageName, err)

return nil, status.Error(codes.Internal, err.Error())
}

parentVol, rbdSnap, err := checkContentSource(ctx, req, cr)
if err != nil {
return nil, err
Expand Down

0 comments on commit a517290

Please sign in to comment.