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 <ypadia@redhat.com>

Fixes#1764
This commit is contained in:
Yati Padia 2020-12-22 13:10:06 +05:30 committed by mergify[bot]
parent 61a16012b7
commit 995879d349

View File

@ -119,9 +119,18 @@ func (vo *volumeOptions) getSubVolumeInfo(ctx context.Context, volID volumeID) (
return &subvol, nil return &subvol, nil
} }
type operationState int64
const (
unknown operationState = iota
supported
unsupported
)
type localClusterState struct { type localClusterState struct {
// set true if cluster supports resize functionality. // set the enum value i.e., unknown, supported,
resizeSupported *bool // unsupported as per the state of the cluster.
resizeState operationState
// set true once a subvolumegroup is created // set true once a subvolumegroup is created
// for corresponding cluster. // for corresponding cluster.
subVolumeGroupCreated bool 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 // resize subvolume when either it's supported, or when corresponding
// clusterID key was not present. // clusterID key was not present.
if clusterAdditionalInfo[vo.ClusterID].resizeSupported == nil || *clusterAdditionalInfo[vo.ClusterID].resizeSupported { if clusterAdditionalInfo[vo.ClusterID].resizeState == unknown ||
if clusterAdditionalInfo[vo.ClusterID].resizeSupported == nil { clusterAdditionalInfo[vo.ClusterID].resizeState == supported {
clusterAdditionalInfo[vo.ClusterID].resizeSupported = new(bool)
}
fsa, err := vo.conn.GetFSAdmin() fsa, err := vo.conn.GetFSAdmin()
if err != nil { if err != nil {
util.ErrorLog(ctx, "could not get FSAdmin, can not resize volume %s:", vo.FsName, err) util.ErrorLog(ctx, "could not get FSAdmin, can not resize volume %s:", vo.FsName, err)
return err return err
} }
_, err = fsa.ResizeSubVolume(vo.FsName, vo.SubvolumeGroup, string(volID), fsAdmin.ByteCount(bytesQuota), true) _, err = fsa.ResizeSubVolume(vo.FsName, vo.SubvolumeGroup, string(volID), fsAdmin.ByteCount(bytesQuota), true)
if err == nil { if err == nil {
*clusterAdditionalInfo[vo.ClusterID].resizeSupported = true clusterAdditionalInfo[vo.ClusterID].resizeState = supported
return nil return nil
} }
var invalid fsAdmin.NotImplementedError var invalid fsAdmin.NotImplementedError
@ -205,7 +211,7 @@ func (vo *volumeOptions) resizeVolume(ctx context.Context, volID volumeID, bytes
return err return err
} }
} }
*clusterAdditionalInfo[vo.ClusterID].resizeSupported = false clusterAdditionalInfo[vo.ClusterID].resizeState = unsupported
return createVolume(ctx, vo, volID, bytesQuota) return createVolume(ctx, vo, volID, bytesQuota)
} }