From c21cba2c52668aaa0769b22daf7eebba44ca60fc Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 27 Nov 2023 18:03:27 +0100 Subject: [PATCH] rbd: skip flattening if an image in trash Signed-off-by: Niels de Vos --- internal/rbd/rbd_util.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 2dbb7d5fe..a42fff59b 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -841,7 +841,9 @@ func (ri *rbdImage) flattenRbdImage( _, err = ta.AddFlatten(admin.NewImageSpec(ri.Pool, ri.RadosNamespace, ri.RbdImageName)) rbdCephMgrSupported := isCephMgrSupported(ctx, ri.ClusterID, err) if rbdCephMgrSupported { - if err != nil { + // it is not possible to flatten an image that is in trash (ErrNotFoun) + switch { + case err != nil && !errors.Is(err, librbd.ErrNotFound): // discard flattening error if the image does not have any parent rbdFlattenNoParent := fmt.Sprintf("Image %s/%s does not have a parent", ri.Pool, ri.RbdImageName) if strings.Contains(err.Error(), rbdFlattenNoParent) { @@ -850,11 +852,11 @@ func (ri *rbdImage) flattenRbdImage( log.ErrorLog(ctx, "failed to add task flatten for %s : %v", ri, err) return err - } - if forceFlatten || depth >= hardlimit { + case forceFlatten || depth >= hardlimit: return fmt.Errorf("%w: flatten is in progress for image %s", ErrFlattenInProgress, ri.RbdImageName) + default: + log.DebugLog(ctx, "successfully added task to flatten image %q", ri) } - log.DebugLog(ctx, "successfully added task to flatten image %q", ri) } if !rbdCephMgrSupported { log.ErrorLog(