rbd: remove redundant util.Credentials arg from flattenRbdImage()

With introduction of go-ceph rbd admin task api, credentials are
no longer required to be passed as cli cmd is not invoked.

Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
Rakshith R 2021-11-10 15:08:32 +05:30 committed by mergify[bot]
parent 7b0f051fd4
commit 9adb25691c
7 changed files with 59 additions and 63 deletions

View File

@ -58,18 +58,18 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
case errors.Is(err, ErrSnapNotFound):
// check temporary image needs flatten, if yes add task to flatten the
// temporary clone
err = tempClone.flattenRbdImage(ctx, rv.conn.Creds, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err = tempClone.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
return false, err
}
// as the snapshot is not present, create new snapshot,clone and
// delete the temporary snapshot
err = createRBDClone(ctx, tempClone, rv, snap, rv.conn.Creds)
err = createRBDClone(ctx, tempClone, rv, snap)
if err != nil {
return false, err
}
// check image needs flatten, if yes add task to flatten the clone
err = rv.flattenRbdImage(ctx, rv.conn.Creds, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err = rv.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
return false, err
}
@ -115,7 +115,7 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
return false, err
}
// check image needs flatten, if yes add task to flatten the clone
err = rv.flattenRbdImage(ctx, rv.conn.Creds, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err = rv.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
return false, err
}
@ -212,14 +212,14 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro
cloneSnap.Pool = rv.Pool
// create snapshot and temporary clone and delete snapshot
err := createRBDClone(ctx, parentVol, tempClone, tempSnap, rv.conn.Creds)
err := createRBDClone(ctx, parentVol, tempClone, tempSnap)
if err != nil {
return err
}
defer func() {
if err != nil || errClone != nil {
cErr := cleanUpSnapshot(ctx, tempClone, cloneSnap, rv, rv.conn.Creds)
cErr := cleanUpSnapshot(ctx, tempClone, cloneSnap, rv)
if cErr != nil {
log.ErrorLog(ctx, "failed to cleanup image %s or snapshot %s: %v", cloneSnap, tempClone, cErr)
}
@ -228,7 +228,7 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro
if err != nil || errFlatten != nil {
if !errors.Is(errFlatten, ErrFlattenInProgress) {
// cleanup snapshot
cErr := cleanUpSnapshot(ctx, parentVol, tempSnap, tempClone, rv.conn.Creds)
cErr := cleanUpSnapshot(ctx, parentVol, tempSnap, tempClone)
if cErr != nil {
log.ErrorLog(ctx, "failed to cleanup image %s or snapshot %s: %v", tempSnap, tempClone, cErr)
}
@ -243,7 +243,7 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro
}
} else {
// flatten clone
errFlatten = tempClone.flattenRbdImage(ctx, rv.conn.Creds, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
errFlatten = tempClone.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if errFlatten != nil {
return errFlatten
}
@ -251,7 +251,7 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro
// create snap of temp clone from temporary cloned image
// create final clone
// delete snap of temp clone
errClone = createRBDClone(ctx, tempClone, rv, cloneSnap, rv.conn.Creds)
errClone = createRBDClone(ctx, tempClone, rv, cloneSnap)
if errClone != nil {
// set errFlatten error to cleanup temporary snapshot and temporary clone
errFlatten = errors.New("failed to create user requested cloned image")
@ -288,11 +288,11 @@ func (rv *rbdVolume) flattenCloneImage(ctx context.Context) error {
}
err := tempClone.getImageInfo()
if err == nil {
return tempClone.flattenRbdImage(ctx, tempClone.conn.Creds, false, hardLimit, softLimit)
return tempClone.flattenRbdImage(ctx, false, hardLimit, softLimit)
}
if !errors.Is(err, ErrImageNotFound) {
return err
}
return rv.flattenRbdImage(ctx, rv.conn.Creds, false, hardLimit, softLimit)
return rv.flattenRbdImage(ctx, false, hardLimit, softLimit)
}

View File

@ -363,7 +363,7 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C
rbdVol,
err)
} else if !thick {
err = deleteImage(ctx, rbdVol, cr)
err = rbdVol.deleteImage(ctx)
if err != nil {
return nil, status.Errorf(codes.Aborted, "failed to remove partially cloned volume %q: %s", rbdVol, err)
}
@ -434,7 +434,7 @@ func cleanupThickClone(ctx context.Context,
parentVol *rbdVolume,
rbdSnap *rbdSnapshot,
cr *util.Credentials) error {
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, rbdVol, cr)
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, rbdVol)
if err != nil {
return status.Errorf(codes.Internal, "failed to remove partially cloned volume %q: %s", rbdVol, err)
}
@ -521,12 +521,12 @@ func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *ut
// return success,the hardlimit is reached it starts a task to flatten the
// image and return Aborted.
func checkFlatten(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
err := rbdVol.flattenRbdImage(ctx, cr, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err := rbdVol.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
if errors.Is(err, ErrFlattenInProgress) {
return status.Error(codes.Aborted, err.Error())
}
if errDefer := deleteImage(ctx, rbdVol, cr); errDefer != nil {
if errDefer := rbdVol.deleteImage(ctx); errDefer != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", rbdVol, errDefer)
return status.Error(codes.Internal, err.Error())
@ -660,7 +660,7 @@ func (cs *ControllerServer) createBackingImage(
defer func() {
if err != nil {
if !errors.Is(err, ErrFlattenInProgress) {
if deleteErr := deleteImage(ctx, rbdVol, cr); deleteErr != nil {
if deleteErr := rbdVol.deleteImage(ctx); deleteErr != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", rbdVol, deleteErr)
}
}
@ -672,7 +672,7 @@ func (cs *ControllerServer) createBackingImage(
}
if rbdSnap != nil {
err = rbdVol.flattenRbdImage(ctx, cr, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err = rbdVol.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
log.ErrorLog(ctx, "failed to flatten image %s: %v", rbdVol, err)
@ -919,7 +919,7 @@ func cleanupRBDImage(ctx context.Context,
// delete the temporary rbd image created as part of volume clone during
// create volume
tempClone := rbdVol.generateTempClone()
err = deleteImage(ctx, tempClone, cr)
err = tempClone.deleteImage(ctx)
if err != nil {
if errors.Is(err, ErrImageNotFound) {
err = tempClone.ensureImageCleanup(ctx)
@ -937,7 +937,7 @@ func cleanupRBDImage(ctx context.Context,
// Deleting rbd image
log.DebugLog(ctx, "deleting image %s", rbdVol.RbdImageName)
if err = deleteImage(ctx, rbdVol, cr); err != nil {
if err = rbdVol.deleteImage(ctx); err != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v",
rbdVol, err)
@ -1142,7 +1142,7 @@ func cloneFromSnapshot(
}
}
err = vol.flattenRbdImage(ctx, cr, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err = vol.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if errors.Is(err, ErrFlattenInProgress) {
// if flattening is in progress, return error and do not cleanup
return nil, status.Errorf(codes.Internal, err.Error())
@ -1210,7 +1210,7 @@ func (cs *ControllerServer) doSnapshotClone(
return cloneRbd, err
}
err = createRBDClone(ctx, parentVol, cloneRbd, rbdSnap, cr)
err = createRBDClone(ctx, parentVol, cloneRbd, rbdSnap)
if err != nil {
log.ErrorLog(ctx, "failed to create snapshot: %v", err)
@ -1221,7 +1221,7 @@ func (cs *ControllerServer) doSnapshotClone(
if err != nil {
if !errors.Is(err, ErrFlattenInProgress) {
// cleanup clone and snapshot
errCleanUp := cleanUpSnapshot(ctx, cloneRbd, rbdSnap, cloneRbd, cr)
errCleanUp := cleanUpSnapshot(ctx, cloneRbd, rbdSnap, cloneRbd)
if errCleanUp != nil {
log.ErrorLog(ctx, "failed to cleanup snapshot and clone: %v", errCleanUp)
}
@ -1287,7 +1287,7 @@ func (cs *ControllerServer) doSnapshotClone(
return cloneRbd, err
}
err = cloneRbd.flattenRbdImage(ctx, cr, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err = cloneRbd.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
return cloneRbd, err
}
@ -1387,7 +1387,7 @@ func (cs *ControllerServer) DeleteSnapshot(
rbdVol.ImageID = rbdSnap.ImageID
// update parent name to delete the snapshot
rbdSnap.RbdImageName = rbdVol.RbdImageName
err = cleanUpSnapshot(ctx, rbdVol, rbdSnap, rbdVol, cr)
err = cleanUpSnapshot(ctx, rbdVol, rbdSnap, rbdVol)
if err != nil {
log.ErrorLog(ctx, "failed to delete image: %v", err)

View File

@ -82,7 +82,7 @@ func deleteMigratedVolume(ctx context.Context, parsedMigHandle *migrationVolID,
return err
}
defer rv.Destroy()
err = deleteImage(ctx, rv, cr)
err = rv.deleteImage(ctx)
if err != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s, err: %v", rv, err)
}

View File

@ -375,7 +375,7 @@ func (ns *NodeServer) stageTransaction(
volOptions.readOnly = true
}
err = flattenImageBeforeMapping(ctx, volOptions, cr)
err = flattenImageBeforeMapping(ctx, volOptions)
if err != nil {
return transaction, err
}
@ -527,8 +527,7 @@ func resizeEncryptedDevice(ctx context.Context, volID, stagingTargetPath, device
func flattenImageBeforeMapping(
ctx context.Context,
volOptions *rbdVolume,
cr *util.Credentials) error {
volOptions *rbdVolume) error {
var err error
var feature bool
var depth uint
@ -550,7 +549,7 @@ func flattenImageBeforeMapping(
return err
}
if feature || depth != 0 {
err = volOptions.flattenRbdImage(ctx, cr, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err = volOptions.flattenRbdImage(ctx, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
return err
}

View File

@ -387,7 +387,7 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
if err != nil {
// nolint:errcheck // deleteImage() will log errors in
// case it fails, no need to log them here again
_ = deleteImage(ctx, pOpts, cr)
_ = pOpts.deleteImage(ctx)
return fmt.Errorf("failed to thick provision image: %w", err)
}
@ -396,7 +396,7 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
if err != nil {
// nolint:errcheck // deleteImage() will log errors in
// case it fails, no need to log them here again
_ = deleteImage(ctx, pOpts, cr)
_ = pOpts.deleteImage(ctx)
return fmt.Errorf("failed to mark image as thick-provisioned: %w", err)
}
@ -640,7 +640,7 @@ func (rv *rbdVolume) ensureImageCleanup(ctx context.Context) error {
if val.Name == rv.RbdImageName {
rv.ImageID = val.Id
return trashRemoveImage(ctx, rv, rv.conn.Creds)
return rv.trashRemoveImage(ctx)
}
}
@ -648,71 +648,71 @@ func (rv *rbdVolume) ensureImageCleanup(ctx context.Context) error {
}
// deleteImage deletes a ceph image with provision and volume options.
func deleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
image := pOpts.RbdImageName
func (rv *rbdVolume) deleteImage(ctx context.Context) error {
image := rv.RbdImageName
log.DebugLog(ctx, "rbd: delete %s using mon %s, pool %s", image, pOpts.Monitors, pOpts.Pool)
log.DebugLog(ctx, "rbd: delete %s using mon %s, pool %s", image, rv.Monitors, rv.Pool)
// Support deleting the older rbd images whose imageID is not stored in omap
err := pOpts.getImageID()
err := rv.getImageID()
if err != nil {
return err
}
if pOpts.isEncrypted() {
log.DebugLog(ctx, "rbd: going to remove DEK for %q", pOpts)
if err = pOpts.encryption.RemoveDEK(pOpts.VolID); err != nil {
log.WarningLog(ctx, "failed to clean the passphrase for volume %s: %s", pOpts.VolID, err)
if rv.isEncrypted() {
log.DebugLog(ctx, "rbd: going to remove DEK for %q", rv)
if err = rv.encryption.RemoveDEK(rv.VolID); err != nil {
log.WarningLog(ctx, "failed to clean the passphrase for volume %s: %s", rv.VolID, err)
}
}
err = pOpts.openIoctx()
err = rv.openIoctx()
if err != nil {
return err
}
rbdImage := librbd.GetImage(pOpts.ioctx, image)
rbdImage := librbd.GetImage(rv.ioctx, image)
err = rbdImage.Trash(0)
if err != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s, error: %v", pOpts, err)
log.ErrorLog(ctx, "failed to delete rbd image: %s, error: %v", rv, err)
return err
}
return trashRemoveImage(ctx, pOpts, cr)
return rv.trashRemoveImage(ctx)
}
// trashRemoveImage adds a task to trash remove an image using ceph manager if supported,
// otherwise removes the image from trash.
func trashRemoveImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
func (rv *rbdVolume) trashRemoveImage(ctx context.Context) error {
// attempt to use Ceph manager based deletion support if available
ra, err := pOpts.conn.GetRBDAdmin()
ra, err := rv.conn.GetRBDAdmin()
if err != nil {
return err
}
log.DebugLog(ctx, "rbd: adding task to remove image %s with id %s from trash", pOpts, pOpts.ImageID)
log.DebugLog(ctx, "rbd: adding task to remove image %s with id %s from trash", rv, rv.ImageID)
ta := ra.Task()
_, err = ta.AddTrashRemove(admin.NewImageSpec(pOpts.Pool, pOpts.RadosNamespace, pOpts.ImageID))
_, err = ta.AddTrashRemove(admin.NewImageSpec(rv.Pool, rv.RadosNamespace, rv.ImageID))
rbdCephMgrSupported := isCephMgrSupported(ctx, pOpts.ClusterID, err)
rbdCephMgrSupported := isCephMgrSupported(ctx, rv.ClusterID, err)
if rbdCephMgrSupported && err != nil {
log.ErrorLog(ctx, "failed to add task to delete rbd image: %s, %v", pOpts, err)
log.ErrorLog(ctx, "failed to add task to delete rbd image: %s, %v", rv, err)
return err
}
if !rbdCephMgrSupported {
err = librbd.TrashRemove(pOpts.ioctx, pOpts.ImageID, true)
err = librbd.TrashRemove(rv.ioctx, rv.ImageID, true)
if err != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s, %v", pOpts, err)
log.ErrorLog(ctx, "failed to delete rbd image: %s, %v", rv, err)
return err
}
} else {
log.DebugLog(ctx, "rbd: successfully added task to move image %s with id %s to trash", pOpts, pOpts.ImageID)
log.DebugLog(ctx, "rbd: successfully added task to move image %s with id %s to trash", rv, rv.ImageID)
}
return nil
@ -801,7 +801,7 @@ func flattenClonedRbdImages(
for _, snapName := range origNameList {
rv.RbdImageName = snapName.origSnapName
err = rv.flattenRbdImage(ctx, cr, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
err = rv.flattenRbdImage(ctx, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
log.ErrorLog(ctx, "failed to flatten %s; err %v", rv, err)
@ -814,7 +814,6 @@ func flattenClonedRbdImages(
func (rv *rbdVolume) flattenRbdImage(
ctx context.Context,
cr *util.Credentials,
forceFlatten bool,
hardlimit, softlimit uint) error {
var depth uint

View File

@ -349,7 +349,7 @@ func repairDummyImage(ctx context.Context, dummyVol *rbdVolume) error {
// deleting and recreating the dummy image will not impact anything as its
// a workaround to fix the scheduling problem.
err := deleteImage(ctx, dummyVol, dummyVol.conn.Creds)
err := dummyVol.deleteImage(ctx)
if err != nil {
return err
}

View File

@ -27,8 +27,7 @@ import (
func createRBDClone(
ctx context.Context,
parentVol, cloneRbdVol *rbdVolume,
snap *rbdSnapshot,
cr *util.Credentials) error {
snap *rbdSnapshot) error {
// create snapshot
err := parentVol.createSnapshot(ctx, snap)
if err != nil {
@ -56,7 +55,7 @@ func createRBDClone(
errSnap := parentVol.deleteSnapshot(ctx, snap)
if errSnap != nil {
log.ErrorLog(ctx, "failed to delete snapshot: %v", errSnap)
delErr := deleteImage(ctx, cloneRbdVol, cr)
delErr := cloneRbdVol.deleteImage(ctx)
if delErr != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", cloneRbdVol, delErr)
}
@ -73,8 +72,7 @@ func cleanUpSnapshot(
ctx context.Context,
parentVol *rbdVolume,
rbdSnap *rbdSnapshot,
rbdVol *rbdVolume,
cr *util.Credentials) error {
rbdVol *rbdVolume) error {
err := parentVol.deleteSnapshot(ctx, rbdSnap)
if err != nil {
if !errors.Is(err, ErrSnapNotFound) {
@ -85,7 +83,7 @@ func cleanUpSnapshot(
}
if rbdVol != nil {
err := deleteImage(ctx, rbdVol, cr)
err := rbdVol.deleteImage(ctx)
if err != nil {
if !errors.Is(err, ErrImageNotFound) {
log.ErrorLog(ctx, "failed to delete rbd image %q with error: %v", rbdVol, err)
@ -122,7 +120,7 @@ func undoSnapshotCloning(
rbdSnap *rbdSnapshot,
cloneVol *rbdVolume,
cr *util.Credentials) error {
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, cloneVol, cr)
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, cloneVol)
if err != nil {
log.ErrorLog(ctx, "failed to clean up %s or %s: %v", cloneVol, rbdSnap, err)