rbd: prevent re-use of destroyed resources

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>
This commit is contained in:
Niels de Vos 2024-09-25 11:36:32 +02:00 committed by mergify[bot]
parent f1379e4cc4
commit 8c252d58ea

View File

@ -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
}
}