mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
rbd: make use of both listSnapshots and listChildren
Currently, CephCSI only uses listSnaps to determine
number of snapshots on a RBD image and uses snapshot
names as child image names to flatten them.
But child images may have different name(in case of
group snapshot) or they maybe in trash
(deleted k8s VolSnapshot with alive restored PVC).
The above problems are avoid by making use of both
snap and child image lists.
Signed-off-by: Rakshith R <rar@redhat.com>
(cherry picked from commit 09d848e017
)
This commit is contained in:
@ -573,7 +573,7 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C
|
||||
// are more than the `minSnapshotOnImage` Add a task to flatten all the
|
||||
// temporary cloned images.
|
||||
func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
|
||||
snaps, err := rbdVol.listSnapshots()
|
||||
snaps, children, err := rbdVol.listSnapAndChildren()
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrImageNotFound) {
|
||||
return status.Error(codes.InvalidArgument, err.Error())
|
||||
@ -589,9 +589,19 @@ func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *ut
|
||||
len(snaps),
|
||||
rbdVol,
|
||||
maxSnapshotsOnImage)
|
||||
|
||||
if len(children) == 0 {
|
||||
// if none of the child images(are in trash) exist, we can't flatten them.
|
||||
// return ResourceExhausted error message as we have reached the hard limit.
|
||||
log.ErrorLog(ctx, "child images of image %q cannot be flatten", rbdVol)
|
||||
|
||||
return status.Errorf(codes.ResourceExhausted,
|
||||
"rbd image %q has %d snapshots but child images cannot be flattened",
|
||||
rbdVol, len(snaps))
|
||||
}
|
||||
err = flattenClonedRbdImages(
|
||||
ctx,
|
||||
snaps,
|
||||
children,
|
||||
rbdVol.Pool,
|
||||
rbdVol.Monitors,
|
||||
rbdVol.RbdImageName,
|
||||
@ -610,13 +620,21 @@ func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *ut
|
||||
len(snaps),
|
||||
rbdVol,
|
||||
minSnapshotsOnImageToStartFlatten)
|
||||
if len(children) == 0 {
|
||||
// if none of the child images(are in trash) exist, we can't flatten them.
|
||||
// return nil since we have only reach the soft limit.
|
||||
log.DebugLog(ctx, "child images of image %q cannot be flatten", rbdVol)
|
||||
|
||||
return nil
|
||||
}
|
||||
// If we start flattening all the snapshots at one shot the volume
|
||||
// creation time will be affected,so we will flatten only the extra
|
||||
// snapshots.
|
||||
snaps = snaps[minSnapshotsOnImageToStartFlatten-1:]
|
||||
extraSnapshots := min(len(snaps)-int(minSnapshotsOnImageToStartFlatten), len(children))
|
||||
children = children[:extraSnapshots]
|
||||
err = flattenClonedRbdImages(
|
||||
ctx,
|
||||
snaps,
|
||||
children,
|
||||
rbdVol.Pool,
|
||||
rbdVol.Monitors,
|
||||
rbdVol.RbdImageName,
|
||||
|
Reference in New Issue
Block a user