mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
cleanup: move internal/rbd/errors.go to internal/rbd/errors pacakge
Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
@ -31,6 +31,7 @@ import (
|
||||
"github.com/ceph/ceph-csi/pkg/util/crypto"
|
||||
"github.com/ceph/ceph-csi/pkg/util/kernel"
|
||||
|
||||
rbderrors "github.com/ceph/ceph-csi/internal/rbd/errors"
|
||||
"github.com/ceph/ceph-csi/internal/rbd/types"
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
@ -537,7 +538,7 @@ func (ri *rbdImage) open() (*librbd.Image, error) {
|
||||
image, err := librbd.OpenImage(ri.ioctx, ri.RbdImageName, librbd.NoSnapshot)
|
||||
if err != nil {
|
||||
if errors.Is(err, librbd.ErrNotFound) {
|
||||
err = fmt.Errorf("Failed as %w (internal %w)", util.ErrImageNotFound, err)
|
||||
err = fmt.Errorf("Failed as %w (internal %w)", rbderrors.ErrImageNotFound, err)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
@ -555,7 +556,7 @@ func (ri *rbdImage) open() (*librbd.Image, error) {
|
||||
func (ri *rbdImage) isInUse() (bool, error) {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrImageNotFound) || errors.Is(err, util.ErrPoolNotFound) {
|
||||
if errors.Is(err, rbderrors.ErrImageNotFound) || errors.Is(err, util.ErrPoolNotFound) {
|
||||
return false, err
|
||||
}
|
||||
// any error should assume something else is using the image
|
||||
@ -698,7 +699,7 @@ func (ri *rbdImage) Delete(ctx context.Context) error {
|
||||
err = rbdImage.Trash(0)
|
||||
if err != nil {
|
||||
if errors.Is(err, librbd.ErrNotFound) {
|
||||
return fmt.Errorf("Failed as %w (internal %w)", util.ErrImageNotFound, err)
|
||||
return fmt.Errorf("Failed as %w (internal %w)", rbderrors.ErrImageNotFound, err)
|
||||
}
|
||||
|
||||
log.ErrorLog(ctx, "failed to delete rbd image: %s, error: %v", ri, err)
|
||||
@ -759,14 +760,14 @@ func (rv *rbdVolume) DeleteTempImage(ctx context.Context) error {
|
||||
snap.RadosNamespace = rv.RadosNamespace
|
||||
err := tempClone.deleteSnapshot(ctx, snap)
|
||||
if err != nil {
|
||||
if !errors.Is(err, util.ErrImageNotFound) && !errors.Is(err, ErrSnapNotFound) {
|
||||
if !errors.Is(err, rbderrors.ErrImageNotFound) && !errors.Is(err, rbderrors.ErrSnapNotFound) {
|
||||
return fmt.Errorf("failed to delete snapshot %q: %w", snap, err)
|
||||
}
|
||||
}
|
||||
|
||||
err = tempClone.Delete(ctx)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrImageNotFound) {
|
||||
if errors.Is(err, rbderrors.ErrImageNotFound) {
|
||||
return tempClone.ensureImageCleanup(ctx)
|
||||
} else {
|
||||
// return error if it is not ErrImageNotFound
|
||||
@ -805,7 +806,7 @@ func (ri *rbdImage) getCloneDepth(ctx context.Context) (uint, error) {
|
||||
// if the parent image is moved to trash the name will be present
|
||||
// in rbd image info but the image will be in trash, in that case
|
||||
// return the found depth
|
||||
if errors.Is(err, util.ErrImageNotFound) {
|
||||
if errors.Is(err, rbderrors.ErrImageNotFound) {
|
||||
return depth, nil
|
||||
}
|
||||
log.ErrorLog(ctx, "failed to check depth on image %s: %s", &vol, err)
|
||||
@ -900,7 +901,7 @@ func (ri *rbdImage) flattenRbdImage(
|
||||
return err
|
||||
}
|
||||
if forceFlatten || depth >= hardlimit {
|
||||
return fmt.Errorf("%w: flatten is in progress for image %s", ErrFlattenInProgress, ri.RbdImageName)
|
||||
return fmt.Errorf("%w: flatten is in progress for image %s", rbderrors.ErrFlattenInProgress, ri.RbdImageName)
|
||||
}
|
||||
log.DebugLog(ctx, "successfully added task to flatten image %q", ri)
|
||||
}
|
||||
@ -995,7 +996,7 @@ func (ri *rbdImage) checkImageChainHasFeature(ctx context.Context, feature uint6
|
||||
// is in the trash, when we try to open the parent image to get its
|
||||
// information it fails because it is already in trash. We should
|
||||
// treat error as nil if the parent is not found.
|
||||
if errors.Is(err, util.ErrImageNotFound) {
|
||||
if errors.Is(err, rbderrors.ErrImageNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
log.ErrorLog(ctx, "failed to get image info for %s: %s", rbdImg.String(), err)
|
||||
@ -1233,6 +1234,33 @@ func generateVolumeFromVolumeID(
|
||||
return rbdVol, err
|
||||
}
|
||||
|
||||
// ShouldRetryVolumeGeneration determines whether the process of finding or generating
|
||||
// volumes should continue based on the type of error encountered.
|
||||
//
|
||||
// It checks if the given error matches any of the following known errors:
|
||||
// - util.ErrKeyNotFound: The key required to locate the volume is missing in Rados omap.
|
||||
// - util.ErrPoolNotFound: The rbd pool where the volume/omap is expected doesn't exist.
|
||||
// - ErrImageNotFound: The image doesn't exist in the rbd pool.
|
||||
// - rados.ErrPermissionDenied: Permissions to access the pool is denied.
|
||||
//
|
||||
// If any of these errors are encountered, the function returns `true`, indicating
|
||||
// that the volume search should continue because of known error. Otherwise, it
|
||||
// returns `false`, meaning the search should stop.
|
||||
//
|
||||
// This helper function is used in scenarios where multiple attempts may be made
|
||||
// to retrieve or generate volume information, and we want to gracefully handle
|
||||
// specific failure cases while retrying for others.
|
||||
func ShouldRetryVolumeGeneration(err error) bool {
|
||||
if err == nil {
|
||||
return false // No error, do not retry
|
||||
}
|
||||
// Continue searching for specific known errors
|
||||
return (errors.Is(err, util.ErrKeyNotFound) ||
|
||||
errors.Is(err, util.ErrPoolNotFound) ||
|
||||
errors.Is(err, rbderrors.ErrImageNotFound) ||
|
||||
errors.Is(err, rados.ErrPermissionDenied))
|
||||
}
|
||||
|
||||
// GenVolFromVolID generates a rbdVolume structure from the provided identifier, updating
|
||||
// the structure with elements from on-disk image metadata as well.
|
||||
func GenVolFromVolID(
|
||||
@ -1249,11 +1277,11 @@ func GenVolFromVolID(
|
||||
err := vi.DecomposeCSIID(volumeID)
|
||||
if err != nil {
|
||||
return vol, fmt.Errorf("%w: error decoding volume ID (%w) (%s)",
|
||||
ErrInvalidVolID, err, volumeID)
|
||||
rbderrors.ErrInvalidVolID, err, volumeID)
|
||||
}
|
||||
|
||||
vol, err = generateVolumeFromVolumeID(ctx, volumeID, vi, cr, secrets)
|
||||
if !util.ShouldRetryVolumeGeneration(err) {
|
||||
if !ShouldRetryVolumeGeneration(err) {
|
||||
return vol, err
|
||||
}
|
||||
|
||||
@ -1264,7 +1292,7 @@ func GenVolFromVolID(
|
||||
}
|
||||
if mapping != nil {
|
||||
rbdVol, vErr := generateVolumeFromMapping(ctx, mapping, volumeID, vi, cr, secrets)
|
||||
if !util.ShouldRetryVolumeGeneration(vErr) {
|
||||
if !ShouldRetryVolumeGeneration(vErr) {
|
||||
return rbdVol, vErr
|
||||
}
|
||||
}
|
||||
@ -1317,7 +1345,7 @@ func generateVolumeFromMapping(
|
||||
// Add mapping poolID to Identifier
|
||||
nvi.LocationID = pID
|
||||
vol, err = generateVolumeFromVolumeID(ctx, volumeID, nvi, cr, secrets)
|
||||
if !util.ShouldRetryVolumeGeneration(err) {
|
||||
if !ShouldRetryVolumeGeneration(err) {
|
||||
return vol, err
|
||||
}
|
||||
}
|
||||
@ -1511,7 +1539,7 @@ func (ri *rbdImage) deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot) erro
|
||||
}
|
||||
err = snap.Remove()
|
||||
if errors.Is(err, librbd.ErrNotFound) {
|
||||
return fmt.Errorf("Failed as %w (internal %w)", ErrSnapNotFound, err)
|
||||
return fmt.Errorf("Failed as %w (internal %w)", rbderrors.ErrSnapNotFound, err)
|
||||
}
|
||||
|
||||
return err
|
||||
@ -1771,7 +1799,7 @@ func (ri *rbdImage) checkSnapExists(rbdSnap *rbdSnapshot) error {
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("%w: snap %s not found", ErrSnapNotFound, rbdSnap)
|
||||
return fmt.Errorf("%w: snap %s not found", rbderrors.ErrSnapNotFound, rbdSnap)
|
||||
}
|
||||
|
||||
// rbdImageMetadataStash strongly typed JSON spec for stashed RBD image metadata.
|
||||
@ -1853,7 +1881,7 @@ func lookupRBDImageMetadataStash(metaDataPath string) (rbdImageMetadataStash, er
|
||||
return imgMeta, fmt.Errorf("failed to read stashed JSON image metadata from path (%s): %w", fPath, err)
|
||||
}
|
||||
|
||||
return imgMeta, fmt.Errorf("Failed as %w (internal %w)", ErrMissingStash, err)
|
||||
return imgMeta, fmt.Errorf("Failed as %w (internal %w)", rbderrors.ErrMissingStash, err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(encodedBytes, &imgMeta)
|
||||
|
Reference in New Issue
Block a user