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 <ndevos@ibm.com>
This commit is contained in:
Niels de Vos 2023-09-06 09:01:04 +02:00
parent b2e69069a0
commit a228b14200

View File

@ -505,7 +505,14 @@ func (ri *rbdImage) open() (*librbd.Image, error) {
return nil, err 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 err != nil {
if errors.Is(err, librbd.ErrNotFound) { if errors.Is(err, librbd.ErrNotFound) {
err = util.JoinErrors(ErrImageNotFound, err) err = util.JoinErrors(ErrImageNotFound, err)