Skip to content

Commit

Permalink
cephfs: remove subvolume during clone
Browse files Browse the repository at this point in the history
If any operations like Resize, Deleting
snapshot fails, we need to remove
both snapshot and the clone to avoid
resource leak.

closes: #4218

Signed-off-by: Madhu Rajanna <[email protected]>
  • Loading branch information
Madhu-1 committed Nov 2, 2023
1 parent c09700b commit 5a4f3e1
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions internal/cephfs/core/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ func (s *subVolumeClient) CreateCloneFromSubvolume(
return err
}

// if cloneErr is not nil we will delete the snapshot
var cloneErr error

defer func() {
if cloneErr != nil {
// if any error occurs while cloning, resizing or deleting the snapshot
// fails then we need to delete the clone and snapshot.
if err != nil {
if err = s.PurgeVolume(ctx, true); err != nil {
log.ErrorLog(ctx, "failed to delete volume %s: %v", s.VolID, err)
}
Expand All @@ -81,18 +80,19 @@ func (s *subVolumeClient) CreateCloneFromSubvolume(
}
}
}()
cloneErr = snapClient.CloneSnapshot(ctx, s.SubVolume)
if cloneErr != nil {
log.ErrorLog(ctx, "failed to clone snapshot %s %s to %s %v", parentvolOpt.VolID, snapshotID, s.VolID, cloneErr)
err = snapClient.CloneSnapshot(ctx, s.SubVolume)
if err != nil {
log.ErrorLog(ctx, "failed to clone snapshot %s %s to %s %v", parentvolOpt.VolID, snapshotID, s.VolID, err)

return cloneErr
return err
}

cloneState, cloneErr := s.GetCloneState(ctx)
if cloneErr != nil {
log.ErrorLog(ctx, "failed to get clone state: %v", cloneErr)
cloneState := cephFSCloneState{}
cloneState, err = s.GetCloneState(ctx)
if err != nil {
log.ErrorLog(ctx, "failed to get clone state: %v", err)

return cloneErr
return err
}

err = cloneState.ToError()
Expand Down Expand Up @@ -157,8 +157,9 @@ func (s *subVolumeClient) CreateCloneFromSnapshot(
}
}
}()

cloneState, err := s.GetCloneState(ctx)
cloneState := cephFSCloneState{}
// avoid err variable shadowing
cloneState, err = s.GetCloneState(ctx)
if err != nil {
log.ErrorLog(ctx, "failed to get clone state: %v", err)

Expand Down

0 comments on commit 5a4f3e1

Please sign in to comment.