From d2c4cacb399f0ac4e386224afa2eed9f6970bad1 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 18 Jun 2021 11:38:58 +0200 Subject: [PATCH] rbd: restart thick-provisioned PVC snapshot restoring after aborting In case restoring a snapshot of a thick-PVC failed during DeepCopy(), the image will exist, but have partial contents. Only when the image has the thick-provisioned metadata set, it has completed DeepCopy(). When the metadata is missing, the image is deleted, and an error is returned to the caller. Kubernetes will automatically retry provisioning on the ABORTED error, and the restoring will get restarted from the beginning. Signed-off-by: Niels de Vos --- internal/rbd/controllerserver.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 41c6ed6a4..ad25382f9 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -362,6 +362,27 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C // rbdVol is a restore from snapshot, rbdSnap is passed case vcs.GetSnapshot() != nil: + // When restoring of a thick-provisioned volume was happening, + // the image should be marked as thick-provisioned, unless it + // was aborted in flight. In order to restart the + // thick-restoring, delete the volume and let the caller retry + // from the start. + if isThickProvisionRequest(req.GetParameters()) { + thick, err := rbdVol.isThickProvisioned() + if err != nil { + return nil, status.Errorf(codes.Aborted, "failed to verify thick-provisioned volume %q: %s", rbdVol, err) + } else if !thick { + err = deleteImage(ctx, rbdVol, cr) + if err != nil { + return nil, status.Errorf(codes.Aborted, "failed to remove partially cloned volume %q: %s", rbdVol, err) + } + err = undoVolReservation(ctx, rbdVol, cr) + if err != nil { + return nil, status.Errorf(codes.Aborted, "failed to remove volume %q from journal: %s", rbdVol, err) + } + return nil, status.Errorf(codes.Aborted, "restoring thick-provisioned volume %q has been interrupted, please retry", rbdVol) + } + } // restore from snapshot imploes rbdSnap != nil // check if image depth is reached limit and requires flatten err := checkFlatten(ctx, rbdVol, cr)