mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
rbd: fix clone problem
This commit fixes a bug in checkCloneImage() which was caused by checking cloned image before checking on temp-clone image snap in a subsequent request which lead to stale images. This was solved by checking temp-clone image snap and flattening temp-clone if needed. This commit also fixes comparison bug in flattenCloneImage(). Signed-off-by: Rakshith R <rar@redhat.com> Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
916c97b4a8
commit
a5a8952716
@ -52,31 +52,7 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
|
||||
snap.RbdSnapName = rv.RbdImageName
|
||||
snap.Pool = rv.Pool
|
||||
|
||||
// check if cloned image exists
|
||||
err := rv.getImageInfo()
|
||||
if err == nil {
|
||||
// check if do we have temporary snapshot on temporary cloned image
|
||||
sErr := tempClone.checkSnapExists(snap)
|
||||
if sErr != nil {
|
||||
if errors.Is(err, ErrSnapNotFound) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
err = tempClone.deleteSnapshot(ctx, snap)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
if !errors.Is(err, ErrImageNotFound) {
|
||||
// return error if its not image not found
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = tempClone.checkSnapExists(snap)
|
||||
err := tempClone.checkSnapExists(snap)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, ErrSnapNotFound):
|
||||
@ -92,6 +68,11 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
|
||||
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)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
case !errors.Is(err, ErrImageNotFound):
|
||||
@ -116,6 +97,11 @@ 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)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
@ -162,7 +148,7 @@ func (rv *rbdVolume) createCloneFromImage(ctx context.Context, parentVol *rbdVol
|
||||
|
||||
err = rv.doSnapClone(ctx, parentVol)
|
||||
if err != nil {
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
err = rv.getImageID()
|
||||
@ -284,10 +270,10 @@ func (rv *rbdVolume) flattenCloneImage(ctx context.Context) error {
|
||||
softLimit := rbdSoftMaxCloneDepth
|
||||
// choosing 2 so that we don't need to flatten the image in the request.
|
||||
const depthToAvoidFlatten = 2
|
||||
if rbdHardMaxCloneDepth < depthToAvoidFlatten {
|
||||
if rbdHardMaxCloneDepth > depthToAvoidFlatten {
|
||||
hardLimit = rbdHardMaxCloneDepth - depthToAvoidFlatten
|
||||
}
|
||||
if rbdSoftMaxCloneDepth < depthToAvoidFlatten {
|
||||
if rbdSoftMaxCloneDepth > depthToAvoidFlatten {
|
||||
softLimit = rbdSoftMaxCloneDepth - depthToAvoidFlatten
|
||||
}
|
||||
err := tempClone.getImageInfo()
|
||||
|
@ -311,6 +311,7 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er
|
||||
|
||||
return false, err
|
||||
}
|
||||
// TODO: check image needs flattening and completed?
|
||||
|
||||
err = rv.repairImageID(ctx, j)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user