Skip to content

Commit

Permalink
rbd: add rbdSnap.Delete() function
Browse files Browse the repository at this point in the history
This function deletes rbd snap and rbd image
backing k8s snapshot.
The same function is used for deleting
individual snapshots in group snapshot.

Signed-off-by: Rakshith R <[email protected]>
(cherry picked from commit bc03fcc)
Signed-off-by: Praveen M <[email protected]>
  • Loading branch information
Rakshith-R authored and iPraveenParihar committed Dec 4, 2024
1 parent a32ba13 commit bdab65c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
16 changes: 3 additions & 13 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1471,23 +1471,13 @@ func (cs *ControllerServer) DeleteSnapshot(
// Deleting snapshot and cloned volume
log.DebugLog(ctx, "deleting cloned rbd volume %s", rbdSnap.RbdSnapName)

rbdVol := rbdSnap.toVolume()

err = rbdVol.Connect(cr)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
defer rbdVol.Destroy(ctx)

rbdVol.ImageID = rbdSnap.ImageID
// update parent name to delete the snapshot
rbdSnap.RbdImageName = rbdVol.RbdImageName
err = cleanUpSnapshot(ctx, rbdVol, rbdSnap, rbdVol)
err = rbdSnap.Delete(ctx)
if err != nil {
log.ErrorLog(ctx, "failed to delete image: %v", err)
log.ErrorLog(ctx, "failed to delete rbd snapshot: %s with error: %v", rbdSnap, err)

return nil, status.Error(codes.Internal, err.Error())
}

err = undoSnapReservation(ctx, rbdSnap, cr)
if err != nil {
log.ErrorLog(ctx, "failed to remove reservation for snapname (%s) with backing snap (%s) on image (%s) (%s)",
Expand Down
24 changes: 24 additions & 0 deletions internal/rbd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,30 @@ func (rbdSnap *rbdSnapshot) ToCSI(ctx context.Context) (*csi.Snapshot, error) {
}, nil
}

// Delete removes the snapshot from the RBD image and then
// the RBD image itself.
func (rbdSnap *rbdSnapshot) Delete(ctx context.Context) error {
rbdVol := rbdSnap.toVolume()

err := rbdVol.Connect(rbdSnap.conn.Creds)
if err != nil {
return err
}
defer rbdVol.Destroy(ctx)

rbdVol.ImageID = rbdSnap.ImageID
// update parent name to delete the snapshot
rbdSnap.RbdImageName = rbdVol.RbdImageName
err = cleanUpSnapshot(ctx, rbdVol, rbdSnap, rbdVol)
if err != nil {
log.ErrorLog(ctx, "failed to delete image: %v", err)

return err
}

return nil
}

func undoSnapshotCloning(
ctx context.Context,
parentVol *rbdVolume,
Expand Down

0 comments on commit bdab65c

Please sign in to comment.