cleanup: move cephfs errors to new util package

As part of the refactoring, moving the cephfs errors file to a new
package.

Updates: #852
Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2021-08-25 12:16:03 +05:30
committed by mergify[bot]
parent aeebd5d03b
commit b383af20b4
10 changed files with 69 additions and 59 deletions

View File

@ -21,6 +21,7 @@ import (
"errors"
"fmt"
cerrors "github.com/ceph/ceph-csi/internal/cephfs/errors"
csicommon "github.com/ceph/ceph-csi/internal/csi-common"
"github.com/ceph/ceph-csi/internal/util"
"github.com/ceph/ceph-csi/internal/util/log"
@ -119,7 +120,7 @@ func checkContentSource(
snapshotID := req.VolumeContentSource.GetSnapshot().GetSnapshotId()
volOpt, _, sid, err := newSnapshotOptionsFromID(ctx, snapshotID, cr)
if err != nil {
if errors.Is(err, ErrSnapNotFound) {
if errors.Is(err, cerrors.ErrSnapNotFound) {
return nil, nil, nil, status.Error(codes.NotFound, err.Error())
}
@ -132,7 +133,7 @@ func checkContentSource(
volID := req.VolumeContentSource.GetVolume().GetVolumeId()
parentVol, pvID, err := newVolumeOptionsFromVolID(ctx, volID, nil, req.Secrets)
if err != nil {
if !errors.Is(err, ErrVolumeNotFound) {
if !errors.Is(err, cerrors.ErrVolumeNotFound) {
return nil, nil, nil, status.Error(codes.NotFound, err.Error())
}
@ -219,7 +220,7 @@ func (cs *ControllerServer) CreateVolume(
if purgeErr != nil {
log.ErrorLog(ctx, "failed to delete volume %s: %v", requestName, purgeErr)
// All errors other than ErrVolumeNotFound should return an error back to the caller
if !errors.Is(purgeErr, ErrVolumeNotFound) {
if !errors.Is(purgeErr, cerrors.ErrVolumeNotFound) {
return nil, status.Error(codes.Internal, purgeErr.Error())
}
}
@ -288,7 +289,7 @@ func (cs *ControllerServer) CreateVolume(
if purgeErr != nil {
log.ErrorLog(ctx, "failed to delete volume %s: %v", vID.FsSubvolName, purgeErr)
// All errors other than ErrVolumeNotFound should return an error back to the caller
if !errors.Is(purgeErr, ErrVolumeNotFound) {
if !errors.Is(purgeErr, cerrors.ErrVolumeNotFound) {
// If the subvolume deletion is failed, we should not cleanup
// the OMAP entry it will stale subvolume in cluster.
// set err=nil so that when we get the request again we can get
@ -375,7 +376,7 @@ func (cs *ControllerServer) DeleteVolume(
log.ErrorLog(ctx, "Error returned from newVolumeOptionsFromVolID: %v", err)
// All errors other than ErrVolumeNotFound should return an error back to the caller
if !errors.Is(err, ErrVolumeNotFound) {
if !errors.Is(err, cerrors.ErrVolumeNotFound) {
return nil, status.Error(codes.Internal, err.Error())
}
@ -413,11 +414,11 @@ func (cs *ControllerServer) DeleteVolume(
if err = volOptions.purgeVolume(ctx, volumeID(vID.FsSubvolName), false); err != nil {
log.ErrorLog(ctx, "failed to delete volume %s: %v", volID, err)
if errors.Is(err, ErrVolumeHasSnapshots) {
if errors.Is(err, cerrors.ErrVolumeHasSnapshots) {
return nil, status.Error(codes.FailedPrecondition, err.Error())
}
if !errors.Is(err, ErrVolumeNotFound) {
if !errors.Is(err, cerrors.ErrVolumeNotFound) {
return nil, status.Error(codes.Internal, err.Error())
}
}
@ -554,7 +555,7 @@ func (cs *ControllerServer) CreateSnapshot(
return nil, status.Error(codes.NotFound, err.Error())
}
if errors.Is(err, ErrVolumeNotFound) {
if errors.Is(err, cerrors.ErrVolumeNotFound) {
return nil, status.Error(codes.NotFound, err.Error())
}
@ -598,7 +599,7 @@ func (cs *ControllerServer) CreateSnapshot(
// Check error code value against ErrInvalidCommand to understand the cluster
// support it or not, It's safe to evaluate as the filtering
// is already done from getSubVolumeInfo() and send out the error here.
if errors.Is(err, ErrInvalidCommand) {
if errors.Is(err, cerrors.ErrInvalidCommand) {
return nil, status.Error(
codes.FailedPrecondition,
"subvolume info command not supported in current ceph cluster")
@ -775,7 +776,7 @@ func (cs *ControllerServer) DeleteSnapshot(
// or partially complete (snap and snapOMap are garbage collected already), hence return
// success as deletion is complete
return &csi.DeleteSnapshotResponse{}, nil
case errors.Is(err, ErrSnapNotFound):
case errors.Is(err, cerrors.ErrSnapNotFound):
err = undoSnapReservation(ctx, volOpt, *sid, sid.FsSnapshotName, cr)
if err != nil {
log.ErrorLog(ctx, "failed to remove reservation for snapname (%s) with backing snap (%s) (%s)",
@ -785,7 +786,7 @@ func (cs *ControllerServer) DeleteSnapshot(
}
return &csi.DeleteSnapshotResponse{}, nil
case errors.Is(err, ErrVolumeNotFound):
case errors.Is(err, cerrors.ErrVolumeNotFound):
// if the error is ErrVolumeNotFound, the subvolume is already deleted
// from backend, Hence undo the omap entries and return success
log.ErrorLog(ctx, "Volume not present")