Skip to content

Commit

Permalink
cleanup: destroy connections after .Copy() an other one
Browse files Browse the repository at this point in the history
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 <ndevos@ibm.com>
  • Loading branch information
nixpanic committed Mar 29, 2024
1 parent 33a888f commit 8001b18
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/rbd/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 8001b18

Please sign in to comment.