From 5a6556c4d4ba790b17faa11b615df69589d6798c Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 29 Mar 2024 13:32:02 +0100 Subject: [PATCH] cleanup: destroy connections after .Copy() an other one Everytime a connection is copied with the .Copy() function, it needs to be destroyed once the object is not needed anymore. This was not done consistently, a few more locations require the freeing of the connection resources. Signed-off-by: Niels de Vos --- internal/rbd/clone.go | 2 ++ internal/rbd/controllerserver.go | 1 + internal/rbd/rbd_util.go | 1 + 3 files changed, 4 insertions(+) diff --git a/internal/rbd/clone.go b/internal/rbd/clone.go index c5ff1e52ff2..b2ce33ba508 100644 --- a/internal/rbd/clone.go +++ b/internal/rbd/clone.go @@ -183,6 +183,8 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro // generate temp cloned volume tempClone := rv.generateTempClone() + defer tempClone.Destroy() + // snapshot name is same as temporary cloned image, This helps to // flatten the temporary cloned images as we cannot have more than 510 // snapshots on an rbd image diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 4f07ce5f0d3..29e4af59933 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -669,6 +669,7 @@ func (cs *ControllerServer) createVolumeFromSnapshot( parentVol := rbdSnap.toVolume() // as we are operating on single cluster reuse the connection parentVol.conn = rbdVol.conn.Copy() + defer parentVol.Destroy() // create clone image and delete snapshot err = rbdVol.cloneRbdImageFromSnapshot(ctx, rbdSnap, parentVol) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 31b330b4d37..c50ebedd2c9 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -1662,6 +1662,7 @@ func (ri *rbdImage) flattenParent(ctx context.Context, hardLimit, softLimit uint if parentImage == nil { return nil } + defer parentImage.Destroy() return parentImage.flattenRbdImage(ctx, false, hardLimit, softLimit) }