mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
cleanup: add a helper function storeImageID
added a helper function storeImageID to reduce code duplication. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
b2fb43b335
commit
43fde0a30a
@ -494,15 +494,8 @@ func (cs *ControllerServer) createBackingImage(ctx context.Context, cr *util.Cre
|
||||
}
|
||||
}
|
||||
}()
|
||||
err = rbdVol.getImageID()
|
||||
err = rbdVol.storeImageID(ctx, j)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get volume id %s: %v", rbdVol, err)
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
err = j.StoreImageID(ctx, rbdVol.JournalPool, rbdVol.ReservedID, rbdVol.ImageID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to reserve volume %s: %v", rbdVol, err)
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
|
@ -543,14 +543,8 @@ func RegenerateJournal(imageName, volumeID, pool, journalPool, requestName strin
|
||||
rbdVol.ReservedID = imageData.ImageUUID
|
||||
rbdVol.ImageID = imageData.ImageAttributes.ImageID
|
||||
if rbdVol.ImageID == "" {
|
||||
err = rbdVol.getImageID()
|
||||
err = rbdVol.storeImageID(ctx, j)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get image id %s: %v", rbdVol, err)
|
||||
return err
|
||||
}
|
||||
err = j.StoreImageID(ctx, rbdVol.JournalPool, rbdVol.ReservedID, rbdVol.ImageID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to store volume id %s: %v", rbdVol, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -588,14 +582,8 @@ func RegenerateJournal(imageName, volumeID, pool, journalPool, requestName strin
|
||||
util.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.getImageID()
|
||||
err = rbdVol.storeImageID(ctx, j)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get image id %s: %v", rbdVol, err)
|
||||
return err
|
||||
}
|
||||
err = j.StoreImageID(ctx, rbdVol.JournalPool, rbdVol.ReservedID, rbdVol.ImageID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to store volume id %s: %v", rbdVol, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -606,6 +594,21 @@ func RegenerateJournal(imageName, volumeID, pool, journalPool, requestName strin
|
||||
return 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 {
|
||||
util.ErrorLog(ctx, "failed to get image id %s: %v", rv, err)
|
||||
return err
|
||||
}
|
||||
err = j.StoreImageID(ctx, rv.JournalPool, rv.ReservedID, rv.ImageID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to store volume id %s: %v", rv, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// addNewUUIDMapping creates the mapping between two volumeID.
|
||||
func (rv *rbdVolume) addNewUUIDMapping(ctx context.Context, imagePoolID int64, j *journal.Connection) error {
|
||||
var err error
|
||||
|
@ -752,14 +752,8 @@ func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials,
|
||||
}
|
||||
|
||||
if rbdVol.ImageID == "" {
|
||||
err = rbdVol.getImageID()
|
||||
err = rbdVol.storeImageID(ctx, j)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get image id %s: %v", rbdVol, err)
|
||||
return rbdVol, err
|
||||
}
|
||||
err = j.StoreImageID(ctx, rbdVol.JournalPool, rbdVol.ReservedID, rbdVol.ImageID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to store volume id %s: %v", rbdVol, err)
|
||||
return rbdVol, err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user