From 8fcb438794464d68ca78f581a1428737470c790d Mon Sep 17 00:00:00 2001 From: Rakshith R Date: Thu, 5 Dec 2024 19:47:55 +0530 Subject: [PATCH] rbd: add layering & deep flattenfeatures for groupsnapshot image Signed-off-by: Rakshith R (cherry picked from commit 50b2a0528e9b97f50b0bcf712789ee37a63b8ad5) --- internal/rbd/controllerserver.go | 6 ++++-- internal/rbd/snapshot.go | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 7457befc8..ec230ec66 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -629,8 +629,10 @@ func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *ut } // 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. - extraSnapshots := min(len(snaps)-int(minSnapshotsOnImageToStartFlatten), len(children)) + // snapshots. Use the min of the extra snapshots and the number of children + // to avoid scenario where number of children are less than the extra snapshots. + // This occurs when the child images are in trash and not yet deleted. + extraSnapshots := min((len(snaps) - int(minSnapshotsOnImageToStartFlatten)), len(children)) children = children[:extraSnapshots] err = flattenClonedRbdImages( ctx, diff --git a/internal/rbd/snapshot.go b/internal/rbd/snapshot.go index ba6f640ab..8fd0bfa12 100644 --- a/internal/rbd/snapshot.go +++ b/internal/rbd/snapshot.go @@ -276,6 +276,10 @@ func (rv *rbdVolume) NewSnapshotByID( return nil, err } + // set the features for the clone image. + f := []string{librbd.FeatureNameLayering, librbd.FeatureNameDeepFlatten} + rv.ImageFeatureSet = librbd.FeatureSetFromNames(f) + options, err := rv.constructImageOptions(ctx) if err != nil { return nil, err