Skip to content

Commit

Permalink
rbd: prevent re-use of destroyed resources
Browse files Browse the repository at this point in the history
When an `.Destroy()` is called on an rbdImage (or rbdVolume or
rbdSnapshot), the IOContext, Connection and other attributes are
invalid. When using a destroyed resource that points to an object that
was allocated through librbd, the process most likely ends with a panic.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
  • Loading branch information
nixpanic authored and mergify[bot] committed Sep 26, 2024
1 parent f1379e4 commit 8c252d5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,19 @@ func (ri *rbdImage) Connect(cr *util.Credentials) error {
func (ri *rbdImage) Destroy(ctx context.Context) {
if ri.ioctx != nil {
ri.ioctx.Destroy()
ri.ioctx = nil
}
if ri.conn != nil {
ri.conn.Destroy()
ri.conn = nil
}
if ri.isBlockEncrypted() {
ri.blockEncryption.Destroy()
ri.blockEncryption = nil
}
if ri.isFileEncrypted() {
ri.fileEncryption.Destroy()
ri.fileEncryption = nil
}
}

Expand Down

0 comments on commit 8c252d5

Please sign in to comment.