From 76c2f3c109236d8e631bdb277f78c4aecae19f52 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Sun, 12 Jul 2020 10:12:19 +0530 Subject: [PATCH] cleanup: re-use flattenTemporaryClonedImages to reduce duplicate code re-use flattenTemporaryClonedImages to avoid code duplication Signed-off-by: Madhu Rajanna --- internal/rbd/controllerserver.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index c267e3b93..20f3a868b 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -765,24 +765,12 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS }, }, nil } - var snaps []snapshotInfo - // check the number of snapshots on image - snaps, err = rbdVol.listSnapshots(ctx, cr) + + err = flattenTemporaryClonedImages(ctx, rbdVol, cr) if err != nil { - var einf ErrImageNotFound - if errors.As(err, &einf) { - return nil, status.Error(codes.InvalidArgument, err.Error()) - } - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } - if len(snaps) > int(maxSnapshotsOnImage) { - err = flattenClonedRbdImages(ctx, snaps, rbdVol.Pool, rbdVol.Monitors, cr) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return nil, status.Errorf(codes.ResourceExhausted, "rbd image %s has %d snapshots", rbdVol, len(snaps)) - } err = reserveSnap(ctx, rbdSnap, rbdVol, cr) if err != nil { return nil, status.Error(codes.Internal, err.Error())