From 05d501a728995fc1d3b9ccd10f012a0519410cbc Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 16 Sep 2024 18:24:58 +0200 Subject: [PATCH] rbd: prevent panic when using rbdImage that is not connected When an `rbdVolume` or `rbdSnapshot` is not connected with credentials to the Ceph cluster, operations may try to get the IOContext which then causes a panic. Signed-off-by: Niels de Vos --- internal/rbd/rbd_util.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 703809c95..e363e391c 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -468,6 +468,10 @@ func (ri *rbdImage) openIoctx() error { return nil } + if ri.conn == nil { + return fmt.Errorf("can not get IOContext of unconnected image %q", ri) + } + ioctx, err := ri.conn.GetIoctx(ri.Pool) if err != nil { // GetIoctx() can return util.ErrPoolNotFound