Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: remove unneeded updateSnapshotDetails() function #4840

Draft
wants to merge 2 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ func (cs *ControllerServer) createBackingImage(
}
}
}()
err = rbdVol.storeImageID(ctx, j)
err = rbdVol.repairImageID(ctx, j, true)
if err != nil {
return status.Error(codes.Internal, err.Error())
}
Expand Down
37 changes: 9 additions & 28 deletions internal/rbd/rbd_journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func undoVolReservation(ctx context.Context, rbdVol *rbdVolume, cr *util.Credent
// The volume handler won't remain same as its contains poolID,clusterID etc
// which are not same across clusters.
//
//nolint:gocyclo,cyclop,nestif // TODO: reduce complexity
//nolint:gocyclo,cyclop // TODO: reduce complexity
func RegenerateJournal(
volumeAttributes map[string]string,
claimName,
Expand Down Expand Up @@ -623,12 +623,12 @@ func RegenerateJournal(
rbdVol.ImageID = imageData.ImageAttributes.ImageID
rbdVol.Owner = imageData.ImageAttributes.Owner
rbdVol.RbdImageName = imageData.ImageAttributes.ImageName
if rbdVol.ImageID == "" {
err = rbdVol.storeImageID(ctx, j)
if err != nil {
return "", err
}

err = rbdVol.repairImageID(ctx, j, false)
if err != nil {
return "", err
}

if rbdVol.Owner != owner {
err = j.ResetVolumeOwner(ctx, rbdVol.JournalPool, rbdVol.ReservedID, owner)
if err != nil {
Expand Down Expand Up @@ -675,30 +675,11 @@ func RegenerateJournal(

log.DebugLog(ctx, "re-generated Volume ID (%s) and image name (%s) for request name (%s)",
rbdVol.VolID, rbdVol.RbdImageName, rbdVol.RequestName)
if rbdVol.ImageID == "" {
err = rbdVol.storeImageID(ctx, j)
if err != nil {
return "", err
}
}

return rbdVol.VolID, nil
}

// storeImageID retrieves the image ID and stores it in OMAP.
func (rv *rbdVolume) storeImageID(ctx context.Context, j *journal.Connection) error {
err := rv.getImageID()
if err != nil {
log.ErrorLog(ctx, "failed to get image id %s: %v", rv, err)

return err
}
err = j.StoreImageID(ctx, rv.JournalPool, rv.ReservedID, rv.ImageID)
err = rbdVol.repairImageID(ctx, j, false)
if err != nil {
log.ErrorLog(ctx, "failed to store volume id %s: %v", rv, err)

return err
return "", err
}

return nil
return rbdVol.VolID, nil
}
30 changes: 5 additions & 25 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,33 +1080,14 @@ func genSnapFromSnapID(
}
}

err = updateSnapshotDetails(ctx, rbdSnap)
err = rbdSnap.getImageInfo()
if err != nil {
return rbdSnap, fmt.Errorf("failed to update snapshot details for %q: %w", rbdSnap, err)
}

return rbdSnap, err
}

// updateSnapshotDetails will copy the details from the rbdVolume to the
// rbdSnapshot. example copying size from rbdVolume to rbdSnapshot.
func updateSnapshotDetails(ctx context.Context, rbdSnap *rbdSnapshot) error {
vol := rbdSnap.toVolume()
err := vol.Connect(rbdSnap.conn.Creds)
if err != nil {
return err
}
defer vol.Destroy(ctx)

err = vol.getImageInfo()
if err != nil {
return err
}
rbdSnap.VolSize = vol.VolSize

return nil
}

// generateVolumeFromVolumeID generates a rbdVolume structure from the provided identifier.
func generateVolumeFromVolumeID(
ctx context.Context,
Expand Down Expand Up @@ -1188,12 +1169,11 @@ func generateVolumeFromVolumeID(
}
}

if rbdVol.ImageID == "" {
err = rbdVol.storeImageID(ctx, j)
if err != nil {
return rbdVol, err
}
err = rbdVol.repairImageID(ctx, j, false)
if err != nil {
return rbdVol, err
}

err = rbdVol.getImageInfo()

return rbdVol, err
Expand Down