cleanup: reformat generateVolFromSnap() to rbdSnapshot.toVolume()

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos 2024-03-26 09:51:19 +01:00 committed by mergify[bot]
parent a517290ea7
commit ba05c0f5f1
4 changed files with 25 additions and 24 deletions

View File

@ -666,7 +666,7 @@ func (cs *ControllerServer) createVolumeFromSnapshot(
// update parent name(rbd image name in snapshot) // update parent name(rbd image name in snapshot)
rbdSnap.RbdImageName = rbdSnap.RbdSnapName rbdSnap.RbdImageName = rbdSnap.RbdSnapName
parentVol := generateVolFromSnap(rbdSnap) parentVol := rbdSnap.toVolume()
// as we are operating on single cluster reuse the connection // as we are operating on single cluster reuse the connection
parentVol.conn = rbdVol.conn.Copy() parentVol.conn = rbdVol.conn.Copy()
@ -1237,7 +1237,7 @@ func cloneFromSnapshot(
cr *util.Credentials, cr *util.Credentials,
parameters map[string]string, parameters map[string]string,
) (*csi.CreateSnapshotResponse, error) { ) (*csi.CreateSnapshotResponse, error) {
vol := generateVolFromSnap(rbdSnap) vol := rbdSnap.toVolume()
err := vol.Connect(cr) err := vol.Connect(cr)
if err != nil { if err != nil {
uErr := undoSnapshotCloning(ctx, rbdVol, rbdSnap, vol, cr) uErr := undoSnapshotCloning(ctx, rbdVol, rbdSnap, vol, cr)
@ -1322,7 +1322,7 @@ func (cs *ControllerServer) doSnapshotClone(
cr *util.Credentials, cr *util.Credentials,
) (*rbdVolume, error) { ) (*rbdVolume, error) {
// generate cloned volume details from snapshot // generate cloned volume details from snapshot
cloneRbd := generateVolFromSnap(rbdSnap) cloneRbd := rbdSnap.toVolume()
defer cloneRbd.Destroy() defer cloneRbd.Destroy()
// add image feature for cloneRbd // add image feature for cloneRbd
f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten} f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten}
@ -1480,7 +1480,7 @@ func (cs *ControllerServer) DeleteSnapshot(
// Deleting snapshot and cloned volume // Deleting snapshot and cloned volume
log.DebugLog(ctx, "deleting cloned rbd volume %s", rbdSnap.RbdSnapName) log.DebugLog(ctx, "deleting cloned rbd volume %s", rbdSnap.RbdSnapName)
rbdVol := generateVolFromSnap(rbdSnap) rbdVol := rbdSnap.toVolume()
err = rbdVol.Connect(cr) err = rbdVol.Connect(cr)
if err != nil { if err != nil {
@ -1511,7 +1511,7 @@ func (cs *ControllerServer) DeleteSnapshot(
// cleanUpImageAndSnapReservation cleans up the image from the trash and // cleanUpImageAndSnapReservation cleans up the image from the trash and
// snapshot reservation in rados OMAP. // snapshot reservation in rados OMAP.
func cleanUpImageAndSnapReservation(ctx context.Context, rbdSnap *rbdSnapshot, cr *util.Credentials) error { func cleanUpImageAndSnapReservation(ctx context.Context, rbdSnap *rbdSnapshot, cr *util.Credentials) error {
rbdVol := generateVolFromSnap(rbdSnap) rbdVol := rbdSnap.toVolume()
err := rbdVol.Connect(cr) err := rbdVol.Connect(cr)
if err != nil { if err != nil {
return status.Error(codes.Internal, err.Error()) return status.Error(codes.Internal, err.Error())

View File

@ -162,7 +162,7 @@ func checkSnapCloneExists(
snapData.ImagePool, rbdSnap.Pool) snapData.ImagePool, rbdSnap.Pool)
} }
vol := generateVolFromSnap(rbdSnap) vol := rbdSnap.toVolume()
defer vol.Destroy() defer vol.Destroy()
err = vol.Connect(cr) err = vol.Connect(cr)
if err != nil { if err != nil {

View File

@ -1053,7 +1053,7 @@ func genSnapFromSnapID(
// updateSnapshotDetails will copy the details from the rbdVolume to the // updateSnapshotDetails will copy the details from the rbdVolume to the
// rbdSnapshot. example copying size from rbdVolume to rbdSnapshot. // rbdSnapshot. example copying size from rbdVolume to rbdSnapshot.
func updateSnapshotDetails(rbdSnap *rbdSnapshot) error { func updateSnapshotDetails(rbdSnap *rbdSnapshot) error {
vol := generateVolFromSnap(rbdSnap) vol := rbdSnap.toVolume()
err := vol.Connect(rbdSnap.conn.Creds) err := vol.Connect(rbdSnap.conn.Creds)
if err != nil { if err != nil {
return err return err

View File

@ -98,23 +98,24 @@ func cleanUpSnapshot(
return nil return nil
} }
func generateVolFromSnap(rbdSnap *rbdSnapshot) *rbdVolume { func (rbdSnap *rbdSnapshot) toVolume() *rbdVolume {
vol := new(rbdVolume) return &rbdVolume{
vol.ClusterID = rbdSnap.ClusterID rbdImage: rbdImage{
vol.VolID = rbdSnap.VolID ClusterID: rbdSnap.ClusterID,
vol.Monitors = rbdSnap.Monitors VolID: rbdSnap.VolID,
vol.Pool = rbdSnap.Pool Monitors: rbdSnap.Monitors,
vol.JournalPool = rbdSnap.JournalPool Pool: rbdSnap.Pool,
vol.RadosNamespace = rbdSnap.RadosNamespace JournalPool: rbdSnap.JournalPool,
vol.RbdImageName = rbdSnap.RbdSnapName RadosNamespace: rbdSnap.RadosNamespace,
vol.ImageID = rbdSnap.ImageID RbdImageName: rbdSnap.RbdSnapName,
ImageID: rbdSnap.ImageID,
// copyEncryptionConfig cannot be used here because the volume and the // copyEncryptionConfig cannot be used here because the volume and the
// snapshot will have the same volumeID which cases the panic in // snapshot will have the same volumeID which cases the panic in
// copyEncryptionConfig function. // copyEncryptionConfig function.
vol.blockEncryption = rbdSnap.blockEncryption blockEncryption: rbdSnap.blockEncryption,
vol.fileEncryption = rbdSnap.fileEncryption fileEncryption: rbdSnap.fileEncryption,
},
return vol }
} }
func undoSnapshotCloning( func undoSnapshotCloning(