Skip to content

Commit

Permalink
rbd: use librbd.OpenImageById() if rbdVol.ImageID is set
Browse files Browse the repository at this point in the history
`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 <[email protected]>
  • Loading branch information
nixpanic committed Sep 6, 2023
1 parent 97df4e7 commit ce508b1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ce508b1

Please sign in to comment.