From ce508b1842a16f48c14e612135d3a2c0a8fa624e Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 6 Sep 2023 09:01:04 +0200 Subject: [PATCH] rbd: use `librbd.OpenImageById()` if `rbdVol.ImageID` is set `librbd.OpenImageById()` works if the image is in the trash, so it makes it possible to get the parent of the image. Signed-off-by: Niels de Vos --- internal/rbd/rbd_util.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index c5893256b7b2..5e00d4c7a200 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -505,7 +505,14 @@ func (ri *rbdImage) open() (*librbd.Image, error) { return nil, err } - image, err := librbd.OpenImage(ri.ioctx, ri.RbdImageName, librbd.NoSnapshot) + var image *librbd.Image + + // try to open by id, that works for images in trash too + if ri.ImageID != "" { + image, err = librbd.OpenImageById(ri.ioctx, ri.ImageID, librbd.NoSnapshot) + } else { + image, err = librbd.OpenImage(ri.ioctx, ri.RbdImageName, librbd.NoSnapshot) + } if err != nil { if errors.Is(err, librbd.ErrNotFound) { err = util.JoinErrors(ErrImageNotFound, err)