From 43c3cc8de6718ce148e8a4441ddf70bd3cd0a6f8 Mon Sep 17 00:00:00 2001 From: Rakshith R Date: Tue, 18 Feb 2025 15:04:05 +0530 Subject: [PATCH] rbd: fix bug in rbdVol.Exists() in PVC-PVC clone case This commit fixes a bug in rbdVol.Exists() which caused VolID not to be set in PVC-PVC clone case. Signed-off-by: Rakshith R (cherry picked from commit b05d4676798121c180a423f4e66fd2ac37c47645) # Conflicts: # internal/rbd/rbd_journal.go --- internal/rbd/rbd_journal.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/internal/rbd/rbd_journal.go b/internal/rbd/rbd_journal.go index 67e13daba..04d354889 100644 --- a/internal/rbd/rbd_journal.go +++ b/internal/rbd/rbd_journal.go @@ -297,24 +297,28 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er requestSize := rv.VolSize // Fetch on-disk image attributes and compare against request err = rv.getImageInfo() - if err != nil { - if errors.Is(err, ErrImageNotFound) { - // Need to check cloned info here not on createvolume, - if parentVol != nil { - found, cErr := rv.checkCloneImage(ctx, parentVol) - switch { - case found && cErr == nil: - return true, nil - case cErr != nil: - return false, cErr - } - } - err = j.UndoReservation(ctx, rv.JournalPool, rv.Pool, - rv.RbdImageName, rv.RequestName) + switch { + case errors.Is(err, ErrImageNotFound) && parentVol != nil: + // Need to check cloned info here not on createvolume + found, cErr := rv.checkCloneImage(ctx, parentVol) + if cErr != nil { + return false, cErr + } + + if !found { + // image not found, undo the reservation + err = j.UndoReservation(ctx, rv.JournalPool, rv.Pool, rv.RbdImageName, rv.RequestName) return false, err } + case errors.Is(err, ErrImageNotFound) && parentVol == nil: + // image not found, undo the reservation + err = j.UndoReservation(ctx, rv.JournalPool, rv.Pool, rv.RbdImageName, rv.RequestName) + + return false, err + + case err != nil: return false, err }