From 995879d34981265f466c5d8244ee1ebb4079d431 Mon Sep 17 00:00:00 2001 From: Yati Padia Date: Tue, 22 Dec 2020 13:10:06 +0530 Subject: [PATCH] cephfs: use enum to check resize is supported or not Currently, we are using bool pointer to find out the ceph cluster supports resize or not. This commit replaces the bool pointer with enum. Signed-off-by: Yati Padia Fixes#1764 --- internal/cephfs/volume.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/internal/cephfs/volume.go b/internal/cephfs/volume.go index 0d4496107..50e3ea462 100644 --- a/internal/cephfs/volume.go +++ b/internal/cephfs/volume.go @@ -119,9 +119,18 @@ func (vo *volumeOptions) getSubVolumeInfo(ctx context.Context, volID volumeID) ( return &subvol, nil } +type operationState int64 + +const ( + unknown operationState = iota + supported + unsupported +) + type localClusterState struct { - // set true if cluster supports resize functionality. - resizeSupported *bool + // set the enum value i.e., unknown, supported, + // unsupported as per the state of the cluster. + resizeState operationState // set true once a subvolumegroup is created // for corresponding cluster. subVolumeGroupCreated bool @@ -183,19 +192,16 @@ func (vo *volumeOptions) resizeVolume(ctx context.Context, volID volumeID, bytes } // resize subvolume when either it's supported, or when corresponding // clusterID key was not present. - if clusterAdditionalInfo[vo.ClusterID].resizeSupported == nil || *clusterAdditionalInfo[vo.ClusterID].resizeSupported { - if clusterAdditionalInfo[vo.ClusterID].resizeSupported == nil { - clusterAdditionalInfo[vo.ClusterID].resizeSupported = new(bool) - } + if clusterAdditionalInfo[vo.ClusterID].resizeState == unknown || + clusterAdditionalInfo[vo.ClusterID].resizeState == supported { fsa, err := vo.conn.GetFSAdmin() if err != nil { util.ErrorLog(ctx, "could not get FSAdmin, can not resize volume %s:", vo.FsName, err) return err } - _, err = fsa.ResizeSubVolume(vo.FsName, vo.SubvolumeGroup, string(volID), fsAdmin.ByteCount(bytesQuota), true) if err == nil { - *clusterAdditionalInfo[vo.ClusterID].resizeSupported = true + clusterAdditionalInfo[vo.ClusterID].resizeState = supported return nil } var invalid fsAdmin.NotImplementedError @@ -205,7 +211,7 @@ func (vo *volumeOptions) resizeVolume(ctx context.Context, volID volumeID, bytes return err } } - *clusterAdditionalInfo[vo.ClusterID].resizeSupported = false + clusterAdditionalInfo[vo.ClusterID].resizeState = unsupported return createVolume(ctx, vo, volID, bytesQuota) }