From 069cc10a5b811a5936e638f1110c683750ff8e0c Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 21 Mar 2024 10:59:50 +0100 Subject: [PATCH] rbd: free snapshot resources after allocation Not all snapshot objects are free'd correctly after they were allocated. It is possible that some connections to the Ceph cluster were never closed. This does not need to be a noticeable problem, as connections are re-used where possible, but it isn't clean either. Signed-off-by: Niels de Vos --- internal/rbd/controllerserver.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 1c27cfa68783..03510b5dc2ba 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -340,6 +340,12 @@ func (cs *ControllerServer) CreateVolume( if err != nil { return nil, err } + if parentVol != nil { + defer parentVol.Destroy() + } + if rbdSnap != nil { + defer rbdSnap.Destroy() + } found, err := rbdVol.Exists(ctx, parentVol) if err != nil { @@ -642,6 +648,7 @@ func (cs *ControllerServer) createVolumeFromSnapshot( return status.Error(codes.Internal, err.Error()) } + defer rbdSnap.Destroy() // update parent name(rbd image name in snapshot) rbdSnap.RbdImageName = rbdSnap.RbdSnapName @@ -1445,6 +1452,7 @@ func (cs *ControllerServer) DeleteSnapshot( return nil, status.Error(codes.Internal, err.Error()) } + defer rbdSnap.Destroy() // safeguard against parallel create or delete requests against the same // name