From 38892c3068cfacf1f3b9595b681d30e31722ec2a Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 19 Aug 2020 14:54:27 +0530 Subject: [PATCH] rbd: rearrange the cleanup order incase clone fails in case of clone failure, we need to first delete the clone and the snapshot from which we created the clone, then as part of cleanup we need to remove the temporary cloned image and the temporary snapshot created on the parent image. Signed-off-by: Madhu Rajanna --- internal/rbd/clone.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/rbd/clone.go b/internal/rbd/clone.go index d4a266796..9d6a5e908 100644 --- a/internal/rbd/clone.go +++ b/internal/rbd/clone.go @@ -176,6 +176,13 @@ func (rv *rbdVolume) createCloneFromImage(ctx context.Context, parentVol *rbdVol } defer func() { + if err != nil || errClone != nil { + cErr := cleanUpSnapshot(ctx, tempClone, cloneSnap, rv, rv.conn.Creds) + if cErr != nil { + util.ErrorLog(ctx, "failed to cleanup image %s or snapshot %s: %v", cloneSnap, tempClone, cErr) + } + } + if err != nil || errFlatten != nil { if !errors.Is(errFlatten, ErrFlattenInProgress) { // cleanup snapshot @@ -185,12 +192,6 @@ func (rv *rbdVolume) createCloneFromImage(ctx context.Context, parentVol *rbdVol } } } - if err != nil || errClone != nil { - cErr := cleanUpSnapshot(ctx, tempClone, cloneSnap, rv, rv.conn.Creds) - if cErr != nil { - util.ErrorLog(ctx, "failed to cleanup image %s or snapshot %s: %v", cloneSnap, tempClone, cErr) - } - } }() // flatten clone errFlatten = tempClone.flattenRbdImage(ctx, rv.conn.Creds, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)