mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 14:20:19 +00:00
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:
parent
7b0f051fd4
commit
9adb25691c
@ -58,18 +58,18 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
|
|||||||
case errors.Is(err, ErrSnapNotFound):
|
case errors.Is(err, ErrSnapNotFound):
|
||||||
// check temporary image needs flatten, if yes add task to flatten the
|
// check temporary image needs flatten, if yes add task to flatten the
|
||||||
// temporary clone
|
// temporary clone
|
||||||
err = tempClone.flattenRbdImage(ctx, rv.conn.Creds, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
err = tempClone.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
// as the snapshot is not present, create new snapshot,clone and
|
// as the snapshot is not present, create new snapshot,clone and
|
||||||
// delete the temporary snapshot
|
// delete the temporary snapshot
|
||||||
err = createRBDClone(ctx, tempClone, rv, snap, rv.conn.Creds)
|
err = createRBDClone(ctx, tempClone, rv, snap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
// check image needs flatten, if yes add task to flatten the clone
|
// 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 {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
// check image needs flatten, if yes add task to flatten the clone
|
// 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 {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -212,14 +212,14 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro
|
|||||||
cloneSnap.Pool = rv.Pool
|
cloneSnap.Pool = rv.Pool
|
||||||
|
|
||||||
// create snapshot and temporary clone and delete snapshot
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil || errClone != nil {
|
if err != nil || errClone != nil {
|
||||||
cErr := cleanUpSnapshot(ctx, tempClone, cloneSnap, rv, rv.conn.Creds)
|
cErr := cleanUpSnapshot(ctx, tempClone, cloneSnap, rv)
|
||||||
if cErr != nil {
|
if cErr != nil {
|
||||||
log.ErrorLog(ctx, "failed to cleanup image %s or snapshot %s: %v", cloneSnap, tempClone, cErr)
|
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 err != nil || errFlatten != nil {
|
||||||
if !errors.Is(errFlatten, ErrFlattenInProgress) {
|
if !errors.Is(errFlatten, ErrFlattenInProgress) {
|
||||||
// cleanup snapshot
|
// cleanup snapshot
|
||||||
cErr := cleanUpSnapshot(ctx, parentVol, tempSnap, tempClone, rv.conn.Creds)
|
cErr := cleanUpSnapshot(ctx, parentVol, tempSnap, tempClone)
|
||||||
if cErr != nil {
|
if cErr != nil {
|
||||||
log.ErrorLog(ctx, "failed to cleanup image %s or snapshot %s: %v", tempSnap, tempClone, cErr)
|
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 {
|
} else {
|
||||||
// flatten clone
|
// flatten clone
|
||||||
errFlatten = tempClone.flattenRbdImage(ctx, rv.conn.Creds, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
errFlatten = tempClone.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||||
if errFlatten != nil {
|
if errFlatten != nil {
|
||||||
return errFlatten
|
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 snap of temp clone from temporary cloned image
|
||||||
// create final clone
|
// create final clone
|
||||||
// delete snap of temp clone
|
// delete snap of temp clone
|
||||||
errClone = createRBDClone(ctx, tempClone, rv, cloneSnap, rv.conn.Creds)
|
errClone = createRBDClone(ctx, tempClone, rv, cloneSnap)
|
||||||
if errClone != nil {
|
if errClone != nil {
|
||||||
// set errFlatten error to cleanup temporary snapshot and temporary clone
|
// set errFlatten error to cleanup temporary snapshot and temporary clone
|
||||||
errFlatten = errors.New("failed to create user requested cloned image")
|
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()
|
err := tempClone.getImageInfo()
|
||||||
if err == nil {
|
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) {
|
if !errors.Is(err, ErrImageNotFound) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv.flattenRbdImage(ctx, rv.conn.Creds, false, hardLimit, softLimit)
|
return rv.flattenRbdImage(ctx, false, hardLimit, softLimit)
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C
|
|||||||
rbdVol,
|
rbdVol,
|
||||||
err)
|
err)
|
||||||
} else if !thick {
|
} else if !thick {
|
||||||
err = deleteImage(ctx, rbdVol, cr)
|
err = rbdVol.deleteImage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Aborted, "failed to remove partially cloned volume %q: %s", rbdVol, err)
|
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,
|
parentVol *rbdVolume,
|
||||||
rbdSnap *rbdSnapshot,
|
rbdSnap *rbdSnapshot,
|
||||||
cr *util.Credentials) error {
|
cr *util.Credentials) error {
|
||||||
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, rbdVol, cr)
|
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, rbdVol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return status.Errorf(codes.Internal, "failed to remove partially cloned volume %q: %s", rbdVol, err)
|
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
|
// return success,the hardlimit is reached it starts a task to flatten the
|
||||||
// image and return Aborted.
|
// image and return Aborted.
|
||||||
func checkFlatten(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
|
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 err != nil {
|
||||||
if errors.Is(err, ErrFlattenInProgress) {
|
if errors.Is(err, ErrFlattenInProgress) {
|
||||||
return status.Error(codes.Aborted, err.Error())
|
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)
|
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", rbdVol, errDefer)
|
||||||
|
|
||||||
return status.Error(codes.Internal, err.Error())
|
return status.Error(codes.Internal, err.Error())
|
||||||
@ -660,7 +660,7 @@ func (cs *ControllerServer) createBackingImage(
|
|||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, ErrFlattenInProgress) {
|
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)
|
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 {
|
if rbdSnap != nil {
|
||||||
err = rbdVol.flattenRbdImage(ctx, cr, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
err = rbdVol.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, "failed to flatten image %s: %v", rbdVol, err)
|
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
|
// delete the temporary rbd image created as part of volume clone during
|
||||||
// create volume
|
// create volume
|
||||||
tempClone := rbdVol.generateTempClone()
|
tempClone := rbdVol.generateTempClone()
|
||||||
err = deleteImage(ctx, tempClone, cr)
|
err = tempClone.deleteImage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrImageNotFound) {
|
if errors.Is(err, ErrImageNotFound) {
|
||||||
err = tempClone.ensureImageCleanup(ctx)
|
err = tempClone.ensureImageCleanup(ctx)
|
||||||
@ -937,7 +937,7 @@ func cleanupRBDImage(ctx context.Context,
|
|||||||
|
|
||||||
// Deleting rbd image
|
// Deleting rbd image
|
||||||
log.DebugLog(ctx, "deleting image %s", rbdVol.RbdImageName)
|
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",
|
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v",
|
||||||
rbdVol, err)
|
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 errors.Is(err, ErrFlattenInProgress) {
|
||||||
// if flattening is in progress, return error and do not cleanup
|
// if flattening is in progress, return error and do not cleanup
|
||||||
return nil, status.Errorf(codes.Internal, err.Error())
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
@ -1210,7 +1210,7 @@ func (cs *ControllerServer) doSnapshotClone(
|
|||||||
return cloneRbd, err
|
return cloneRbd, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = createRBDClone(ctx, parentVol, cloneRbd, rbdSnap, cr)
|
err = createRBDClone(ctx, parentVol, cloneRbd, rbdSnap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, "failed to create snapshot: %v", err)
|
log.ErrorLog(ctx, "failed to create snapshot: %v", err)
|
||||||
|
|
||||||
@ -1221,7 +1221,7 @@ func (cs *ControllerServer) doSnapshotClone(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, ErrFlattenInProgress) {
|
if !errors.Is(err, ErrFlattenInProgress) {
|
||||||
// cleanup clone and snapshot
|
// cleanup clone and snapshot
|
||||||
errCleanUp := cleanUpSnapshot(ctx, cloneRbd, rbdSnap, cloneRbd, cr)
|
errCleanUp := cleanUpSnapshot(ctx, cloneRbd, rbdSnap, cloneRbd)
|
||||||
if errCleanUp != nil {
|
if errCleanUp != nil {
|
||||||
log.ErrorLog(ctx, "failed to cleanup snapshot and clone: %v", errCleanUp)
|
log.ErrorLog(ctx, "failed to cleanup snapshot and clone: %v", errCleanUp)
|
||||||
}
|
}
|
||||||
@ -1287,7 +1287,7 @@ func (cs *ControllerServer) doSnapshotClone(
|
|||||||
return cloneRbd, err
|
return cloneRbd, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cloneRbd.flattenRbdImage(ctx, cr, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
err = cloneRbd.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cloneRbd, err
|
return cloneRbd, err
|
||||||
}
|
}
|
||||||
@ -1387,7 +1387,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
|||||||
rbdVol.ImageID = rbdSnap.ImageID
|
rbdVol.ImageID = rbdSnap.ImageID
|
||||||
// update parent name to delete the snapshot
|
// update parent name to delete the snapshot
|
||||||
rbdSnap.RbdImageName = rbdVol.RbdImageName
|
rbdSnap.RbdImageName = rbdVol.RbdImageName
|
||||||
err = cleanUpSnapshot(ctx, rbdVol, rbdSnap, rbdVol, cr)
|
err = cleanUpSnapshot(ctx, rbdVol, rbdSnap, rbdVol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, "failed to delete image: %v", err)
|
log.ErrorLog(ctx, "failed to delete image: %v", err)
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ func deleteMigratedVolume(ctx context.Context, parsedMigHandle *migrationVolID,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer rv.Destroy()
|
defer rv.Destroy()
|
||||||
err = deleteImage(ctx, rv, cr)
|
err = rv.deleteImage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, "failed to delete rbd image: %s, err: %v", rv, err)
|
log.ErrorLog(ctx, "failed to delete rbd image: %s, err: %v", rv, err)
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ func (ns *NodeServer) stageTransaction(
|
|||||||
volOptions.readOnly = true
|
volOptions.readOnly = true
|
||||||
}
|
}
|
||||||
|
|
||||||
err = flattenImageBeforeMapping(ctx, volOptions, cr)
|
err = flattenImageBeforeMapping(ctx, volOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return transaction, err
|
return transaction, err
|
||||||
}
|
}
|
||||||
@ -527,8 +527,7 @@ func resizeEncryptedDevice(ctx context.Context, volID, stagingTargetPath, device
|
|||||||
|
|
||||||
func flattenImageBeforeMapping(
|
func flattenImageBeforeMapping(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
volOptions *rbdVolume,
|
volOptions *rbdVolume) error {
|
||||||
cr *util.Credentials) error {
|
|
||||||
var err error
|
var err error
|
||||||
var feature bool
|
var feature bool
|
||||||
var depth uint
|
var depth uint
|
||||||
@ -550,7 +549,7 @@ func flattenImageBeforeMapping(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if feature || depth != 0 {
|
if feature || depth != 0 {
|
||||||
err = volOptions.flattenRbdImage(ctx, cr, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
err = volOptions.flattenRbdImage(ctx, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -387,7 +387,7 @@ func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// nolint:errcheck // deleteImage() will log errors in
|
// nolint:errcheck // deleteImage() will log errors in
|
||||||
// case it fails, no need to log them here again
|
// 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)
|
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 {
|
if err != nil {
|
||||||
// nolint:errcheck // deleteImage() will log errors in
|
// nolint:errcheck // deleteImage() will log errors in
|
||||||
// case it fails, no need to log them here again
|
// 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)
|
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 {
|
if val.Name == rv.RbdImageName {
|
||||||
rv.ImageID = val.Id
|
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.
|
// deleteImage deletes a ceph image with provision and volume options.
|
||||||
func deleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
|
func (rv *rbdVolume) deleteImage(ctx context.Context) error {
|
||||||
image := pOpts.RbdImageName
|
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
|
// Support deleting the older rbd images whose imageID is not stored in omap
|
||||||
err := pOpts.getImageID()
|
err := rv.getImageID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if pOpts.isEncrypted() {
|
if rv.isEncrypted() {
|
||||||
log.DebugLog(ctx, "rbd: going to remove DEK for %q", pOpts)
|
log.DebugLog(ctx, "rbd: going to remove DEK for %q", rv)
|
||||||
if err = pOpts.encryption.RemoveDEK(pOpts.VolID); err != nil {
|
if err = rv.encryption.RemoveDEK(rv.VolID); err != nil {
|
||||||
log.WarningLog(ctx, "failed to clean the passphrase for volume %s: %s", pOpts.VolID, err)
|
log.WarningLog(ctx, "failed to clean the passphrase for volume %s: %s", rv.VolID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pOpts.openIoctx()
|
err = rv.openIoctx()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rbdImage := librbd.GetImage(pOpts.ioctx, image)
|
rbdImage := librbd.GetImage(rv.ioctx, image)
|
||||||
err = rbdImage.Trash(0)
|
err = rbdImage.Trash(0)
|
||||||
if err != nil {
|
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 err
|
||||||
}
|
}
|
||||||
|
|
||||||
return trashRemoveImage(ctx, pOpts, cr)
|
return rv.trashRemoveImage(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// trashRemoveImage adds a task to trash remove an image using ceph manager if supported,
|
// trashRemoveImage adds a task to trash remove an image using ceph manager if supported,
|
||||||
// otherwise removes the image from trash.
|
// 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
|
// attempt to use Ceph manager based deletion support if available
|
||||||
|
|
||||||
ra, err := pOpts.conn.GetRBDAdmin()
|
ra, err := rv.conn.GetRBDAdmin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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()
|
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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !rbdCephMgrSupported {
|
if !rbdCephMgrSupported {
|
||||||
err = librbd.TrashRemove(pOpts.ioctx, pOpts.ImageID, true)
|
err = librbd.TrashRemove(rv.ioctx, rv.ImageID, true)
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
return nil
|
||||||
@ -801,7 +801,7 @@ func flattenClonedRbdImages(
|
|||||||
|
|
||||||
for _, snapName := range origNameList {
|
for _, snapName := range origNameList {
|
||||||
rv.RbdImageName = snapName.origSnapName
|
rv.RbdImageName = snapName.origSnapName
|
||||||
err = rv.flattenRbdImage(ctx, cr, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
err = rv.flattenRbdImage(ctx, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, "failed to flatten %s; err %v", rv, err)
|
log.ErrorLog(ctx, "failed to flatten %s; err %v", rv, err)
|
||||||
|
|
||||||
@ -814,7 +814,6 @@ func flattenClonedRbdImages(
|
|||||||
|
|
||||||
func (rv *rbdVolume) flattenRbdImage(
|
func (rv *rbdVolume) flattenRbdImage(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
cr *util.Credentials,
|
|
||||||
forceFlatten bool,
|
forceFlatten bool,
|
||||||
hardlimit, softlimit uint) error {
|
hardlimit, softlimit uint) error {
|
||||||
var depth uint
|
var depth uint
|
||||||
|
@ -349,7 +349,7 @@ func repairDummyImage(ctx context.Context, dummyVol *rbdVolume) error {
|
|||||||
|
|
||||||
// deleting and recreating the dummy image will not impact anything as its
|
// deleting and recreating the dummy image will not impact anything as its
|
||||||
// a workaround to fix the scheduling problem.
|
// a workaround to fix the scheduling problem.
|
||||||
err := deleteImage(ctx, dummyVol, dummyVol.conn.Creds)
|
err := dummyVol.deleteImage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,7 @@ import (
|
|||||||
func createRBDClone(
|
func createRBDClone(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
parentVol, cloneRbdVol *rbdVolume,
|
parentVol, cloneRbdVol *rbdVolume,
|
||||||
snap *rbdSnapshot,
|
snap *rbdSnapshot) error {
|
||||||
cr *util.Credentials) error {
|
|
||||||
// create snapshot
|
// create snapshot
|
||||||
err := parentVol.createSnapshot(ctx, snap)
|
err := parentVol.createSnapshot(ctx, snap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -56,7 +55,7 @@ func createRBDClone(
|
|||||||
errSnap := parentVol.deleteSnapshot(ctx, snap)
|
errSnap := parentVol.deleteSnapshot(ctx, snap)
|
||||||
if errSnap != nil {
|
if errSnap != nil {
|
||||||
log.ErrorLog(ctx, "failed to delete snapshot: %v", errSnap)
|
log.ErrorLog(ctx, "failed to delete snapshot: %v", errSnap)
|
||||||
delErr := deleteImage(ctx, cloneRbdVol, cr)
|
delErr := cloneRbdVol.deleteImage(ctx)
|
||||||
if delErr != nil {
|
if delErr != nil {
|
||||||
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", cloneRbdVol, delErr)
|
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", cloneRbdVol, delErr)
|
||||||
}
|
}
|
||||||
@ -73,8 +72,7 @@ func cleanUpSnapshot(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
parentVol *rbdVolume,
|
parentVol *rbdVolume,
|
||||||
rbdSnap *rbdSnapshot,
|
rbdSnap *rbdSnapshot,
|
||||||
rbdVol *rbdVolume,
|
rbdVol *rbdVolume) error {
|
||||||
cr *util.Credentials) error {
|
|
||||||
err := parentVol.deleteSnapshot(ctx, rbdSnap)
|
err := parentVol.deleteSnapshot(ctx, rbdSnap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, ErrSnapNotFound) {
|
if !errors.Is(err, ErrSnapNotFound) {
|
||||||
@ -85,7 +83,7 @@ func cleanUpSnapshot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rbdVol != nil {
|
if rbdVol != nil {
|
||||||
err := deleteImage(ctx, rbdVol, cr)
|
err := rbdVol.deleteImage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, ErrImageNotFound) {
|
if !errors.Is(err, ErrImageNotFound) {
|
||||||
log.ErrorLog(ctx, "failed to delete rbd image %q with error: %v", rbdVol, err)
|
log.ErrorLog(ctx, "failed to delete rbd image %q with error: %v", rbdVol, err)
|
||||||
@ -122,7 +120,7 @@ func undoSnapshotCloning(
|
|||||||
rbdSnap *rbdSnapshot,
|
rbdSnap *rbdSnapshot,
|
||||||
cloneVol *rbdVolume,
|
cloneVol *rbdVolume,
|
||||||
cr *util.Credentials) error {
|
cr *util.Credentials) error {
|
||||||
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, cloneVol, cr)
|
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, cloneVol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, "failed to clean up %s or %s: %v", cloneVol, rbdSnap, err)
|
log.ErrorLog(ctx, "failed to clean up %s or %s: %v", cloneVol, rbdSnap, err)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user