mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
cleanup: resolve nlreturn linter issues
nlreturn linter requires a new line before return and branch statements except when the return is alone inside a statement group (such as an if statement) to increase code clarity. This commit addresses such issues. Updates: #1586 Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
@ -107,6 +107,7 @@ func isHealerContext(parameters map[string]string) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return healerContext
|
||||
}
|
||||
|
||||
@ -121,6 +122,7 @@ func isStaticVolume(parameters map[string]string) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return staticVol
|
||||
}
|
||||
|
||||
@ -130,6 +132,7 @@ func healerStageTransaction(ctx context.Context, cr *util.Credentials, volOps *r
|
||||
imgInfo, err := lookupRBDImageMetadataStash(metaDataPath)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to find image metadata, at stagingPath: %s, err: %v", metaDataPath, err)
|
||||
|
||||
return err
|
||||
}
|
||||
if imgInfo.DevicePath == "" {
|
||||
@ -141,6 +144,7 @@ func healerStageTransaction(ctx context.Context, cr *util.Credentials, volOps *r
|
||||
return err
|
||||
}
|
||||
util.DebugLog(ctx, "rbd volID: %s was successfully attached to device: %s", volOps.VolID, devicePath)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -177,6 +181,7 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
"invalid AccessMode for volume: %v",
|
||||
req.GetVolumeId(),
|
||||
)
|
||||
|
||||
return nil, status.Error(
|
||||
codes.InvalidArgument,
|
||||
"rbd: RWX access mode request is only valid for volumes with access type `block`",
|
||||
@ -196,6 +201,7 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
|
||||
if acquired := ns.VolumeLocks.TryAcquire(volID); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
}
|
||||
defer ns.VolumeLocks.Release(volID)
|
||||
@ -212,6 +218,7 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
} else if !isNotMnt {
|
||||
util.DebugLog(ctx, "rbd: volume %s is already mounted to %s, skipping", volID, stagingTargetPath)
|
||||
|
||||
return &csi.NodeStageVolumeResponse{}, nil
|
||||
}
|
||||
}
|
||||
@ -241,12 +248,14 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
err = vi.DecomposeCSIID(volID)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error decoding volume ID (%s): %w", volID, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
j, connErr := volJournal.Connect(volOptions.Monitors, volOptions.RadosNamespace, cr)
|
||||
if connErr != nil {
|
||||
util.ErrorLog(ctx, "failed to establish cluster connection: %v", connErr)
|
||||
|
||||
return nil, status.Error(codes.Internal, connErr.Error())
|
||||
}
|
||||
defer j.Destroy()
|
||||
@ -255,6 +264,7 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
ctx, volOptions.Pool, vi.ObjectUUID, false)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error fetching image attributes for volume ID (%s): %w", volID, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
volOptions.RbdImageName = imageAttributes.ImageName
|
||||
@ -268,6 +278,7 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
err = volOptions.Connect(cr)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to connect to volume %s: %v", volOptions, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
defer volOptions.Destroy()
|
||||
@ -277,6 +288,7 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &csi.NodeStageVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
@ -409,6 +421,7 @@ func (ns *NodeServer) stageTransaction(
|
||||
// #nosec - allow anyone to write inside the target path
|
||||
err = os.Chmod(stagingTargetPath, 0o777)
|
||||
}
|
||||
|
||||
return transaction, err
|
||||
}
|
||||
|
||||
@ -424,6 +437,7 @@ func (ns *NodeServer) undoStagingTransaction(
|
||||
err = ns.mounter.Unmount(stagingTargetPath)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to unmount stagingtargetPath: %s with error: %v", stagingTargetPath, err)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -458,6 +472,7 @@ func (ns *NodeServer) undoStagingTransaction(
|
||||
// Cleanup the stashed image metadata
|
||||
if err = cleanupRBDImageMetadataStash(req.GetStagingTargetPath()); err != nil {
|
||||
util.ErrorLog(ctx, "failed to cleanup image metadata stash (%v)", err)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -468,10 +483,12 @@ func (ns *NodeServer) createStageMountPoint(ctx context.Context, mountPath strin
|
||||
pathFile, err := os.OpenFile(mountPath, os.O_CREATE|os.O_RDWR, 0o600)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to create mountPath:%s with error: %v", mountPath, err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
if err = pathFile.Close(); err != nil {
|
||||
util.ErrorLog(ctx, "failed to close mountPath:%s with error: %v", mountPath, err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -482,6 +499,7 @@ func (ns *NodeServer) createStageMountPoint(ctx context.Context, mountPath strin
|
||||
if err != nil {
|
||||
if !os.IsExist(err) {
|
||||
util.ErrorLog(ctx, "failed to create mountPath:%s with error: %v", mountPath, err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
}
|
||||
@ -524,6 +542,7 @@ func (ns *NodeServer) NodePublishVolume(
|
||||
}
|
||||
|
||||
util.DebugLog(ctx, "rbd: successfully mounted stagingPath %s to targetPath %s", stagingPath, targetPath)
|
||||
|
||||
return &csi.NodePublishVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
@ -548,6 +567,7 @@ func (ns *NodeServer) mountVolumeToStagePath(
|
||||
existingFormat, err := diskMounter.GetDiskFormat(devicePath)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get disk format for path %s, error: %v", devicePath, err)
|
||||
|
||||
return readOnly, err
|
||||
}
|
||||
|
||||
@ -587,6 +607,7 @@ func (ns *NodeServer) mountVolumeToStagePath(
|
||||
cmdOut, cmdErr := diskMounter.Exec.Command("mkfs."+fsType, args...).CombinedOutput()
|
||||
if cmdErr != nil {
|
||||
util.ErrorLog(ctx, "failed to run mkfs error: %v, output: %v", cmdErr, string(cmdOut))
|
||||
|
||||
return readOnly, cmdErr
|
||||
}
|
||||
}
|
||||
@ -607,6 +628,7 @@ func (ns *NodeServer) mountVolumeToStagePath(
|
||||
req.GetVolumeId(),
|
||||
err)
|
||||
}
|
||||
|
||||
return readOnly, err
|
||||
}
|
||||
|
||||
@ -647,10 +669,12 @@ func (ns *NodeServer) createTargetMountPath(ctx context.Context, mountPath strin
|
||||
pathFile, e := os.OpenFile(mountPath, os.O_CREATE|os.O_RDWR, 0o750)
|
||||
if e != nil {
|
||||
util.DebugLog(ctx, "Failed to create mountPath:%s with error: %v", mountPath, err)
|
||||
|
||||
return notMnt, status.Error(codes.Internal, e.Error())
|
||||
}
|
||||
if err = pathFile.Close(); err != nil {
|
||||
util.DebugLog(ctx, "Failed to close mountPath:%s with error: %v", mountPath, err)
|
||||
|
||||
return notMnt, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
} else {
|
||||
@ -660,6 +684,7 @@ func (ns *NodeServer) createTargetMountPath(ctx context.Context, mountPath strin
|
||||
}
|
||||
}
|
||||
notMnt = true
|
||||
|
||||
return notMnt, err
|
||||
}
|
||||
|
||||
@ -680,14 +705,17 @@ func (ns *NodeServer) NodeUnpublishVolume(
|
||||
if os.IsNotExist(err) {
|
||||
// targetPath has already been deleted
|
||||
util.DebugLog(ctx, "targetPath: %s has already been deleted", targetPath)
|
||||
|
||||
return &csi.NodeUnpublishVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
return nil, status.Error(codes.NotFound, err.Error())
|
||||
}
|
||||
if notMnt {
|
||||
if err = os.RemoveAll(targetPath); err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &csi.NodeUnpublishVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
@ -730,6 +758,7 @@ func (ns *NodeServer) NodeUnstageVolume(
|
||||
|
||||
if acquired := ns.VolumeLocks.TryAcquire(volID); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
}
|
||||
defer ns.VolumeLocks.Release(volID)
|
||||
@ -750,6 +779,7 @@ func (ns *NodeServer) NodeUnstageVolume(
|
||||
err = ns.mounter.Unmount(stagingTargetPath)
|
||||
if err != nil {
|
||||
util.ExtendedLog(ctx, "failed to unmount targetPath: %s with error: %v", stagingTargetPath, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
util.DebugLog(ctx, "successfully unmounted volume (%s) from staging path (%s)",
|
||||
@ -762,6 +792,7 @@ func (ns *NodeServer) NodeUnstageVolume(
|
||||
// error
|
||||
if !os.IsNotExist(err) {
|
||||
util.ErrorLog(ctx, "failed to remove staging target path (%s): (%v)", stagingTargetPath, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
}
|
||||
@ -800,6 +831,7 @@ func (ns *NodeServer) NodeUnstageVolume(
|
||||
req.GetVolumeId(),
|
||||
stagingTargetPath,
|
||||
err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -807,6 +839,7 @@ func (ns *NodeServer) NodeUnstageVolume(
|
||||
|
||||
if err = cleanupRBDImageMetadataStash(stagingParentPath); err != nil {
|
||||
util.ErrorLog(ctx, "failed to cleanup image metadata stash (%v)", err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -837,6 +870,7 @@ func (ns *NodeServer) NodeExpandVolume(
|
||||
|
||||
if acquired := ns.VolumeLocks.TryAcquire(volumeID); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volumeID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volumeID)
|
||||
}
|
||||
defer ns.VolumeLocks.Release(volumeID)
|
||||
@ -853,6 +887,7 @@ func (ns *NodeServer) NodeExpandVolume(
|
||||
if !ok {
|
||||
return nil, status.Errorf(codes.Internal, "rbd: resize failed on path %s, error: %v", req.GetVolumePath(), err)
|
||||
}
|
||||
|
||||
return &csi.NodeExpandVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
@ -870,6 +905,7 @@ func getDevicePath(ctx context.Context, volumePath string) (string, error) {
|
||||
if found {
|
||||
return device, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("failed to get device for stagingtarget path %v", volumePath)
|
||||
}
|
||||
|
||||
@ -913,6 +949,7 @@ func (ns *NodeServer) processEncryptedDevice(
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get encryption status for rbd image %s: %v",
|
||||
imageSpec, err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
@ -928,6 +965,7 @@ func (ns *NodeServer) processEncryptedDevice(
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to setup encryption for rbd"+
|
||||
"image %s: %v", imageSpec, err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
@ -988,11 +1026,13 @@ func (ns *NodeServer) xfsSupportsReflink() bool {
|
||||
// mkfs.xfs should fail with an error message (and help text)
|
||||
if strings.Contains(string(out), "reflink=0|1") {
|
||||
xfsHasReflink = xfsReflinkSupport
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
xfsHasReflink = xfsReflinkNoSupport
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -1004,6 +1044,7 @@ func (ns *NodeServer) NodeGetVolumeStats(
|
||||
targetPath := req.GetVolumePath()
|
||||
if targetPath == "" {
|
||||
err = fmt.Errorf("targetpath %v is empty", targetPath)
|
||||
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
@ -1033,6 +1074,7 @@ func blockNodeGetVolumeStats(ctx context.Context, targetPath string) (*csi.NodeG
|
||||
if err != nil {
|
||||
err = fmt.Errorf("lsblk %v returned an error: %w", args, err)
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -1040,6 +1082,7 @@ func blockNodeGetVolumeStats(ctx context.Context, targetPath string) (*csi.NodeG
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to convert %q to bytes: %w", lsblkSize, err)
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user