Skip to content

Commit

Permalink
cleanup: cephfs resize code cleanup
Browse files Browse the repository at this point in the history
The ceph fs subvolume resize support is available
in all the active ceph releases. Hence removing the
code to check the supportability of the feature.

Signed-off-by: karthik-us <ksubrahm@redhat.com>
  • Loading branch information
karthik-us committed Nov 17, 2023
1 parent fcb10fc commit c106681
Showing 1 changed file with 13 additions and 32 deletions.
45 changes: 13 additions & 32 deletions internal/cephfs/core/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,13 @@ func (s *subVolumeClient) GetSubVolumeInfo(ctx context.Context) (*Subvolume, err
type operationState int64

const (
unknown operationState = iota
supported
supported operationState = iota
unsupported
)

type localClusterState struct {
// set the enum value i.e., unknown, supported,
// set the enum value i.e., supported or
// unsupported as per the state of the cluster.
resizeState operationState
subVolMetadataState operationState
subVolSnapshotMetadataState operationState
}
Expand Down Expand Up @@ -268,39 +266,22 @@ func (s *subVolumeClient) ExpandVolume(ctx context.Context, bytesQuota int64) er
return err
}

// ResizeVolume will try to use ceph fs subvolume resize command to resize the
// subvolume. If the command is not available as a fallback it will use
// CreateVolume to resize the subvolume.
// ResizeVolume will use the ceph fs subvolume resize command to resize the
// subvolume.
func (s *subVolumeClient) ResizeVolume(ctx context.Context, bytesQuota int64) error {
newLocalClusterState(s.clusterID)
// resize subvolume when either it's supported, or when corresponding
// clusterID key was not present.
if clusterAdditionalInfo[s.clusterID].resizeState == unknown ||
clusterAdditionalInfo[s.clusterID].resizeState == supported {
fsa, err := s.conn.GetFSAdmin()
if err != nil {
log.ErrorLog(ctx, "could not get FSAdmin, can not resize volume %s:", s.FsName, err)

return err
}
_, err = fsa.ResizeSubVolume(s.FsName, s.SubvolumeGroup, s.VolID, fsAdmin.ByteCount(bytesQuota), true)
if err == nil {
clusterAdditionalInfo[s.clusterID].resizeState = supported

return nil
}
var invalid fsAdmin.NotImplementedError
// In case the error is other than invalid command return error to the caller.
if !errors.As(err, &invalid) {
log.ErrorLog(ctx, "failed to resize subvolume %s in fs %s: %s", s.VolID, s.FsName, err)
fsa, err := s.conn.GetFSAdmin()
if err != nil {
log.ErrorLog(ctx, "could not get FSAdmin, can not resize volume %s:", s.FsName, err)

return err
}
return err
}
_, err = fsa.ResizeSubVolume(s.FsName, s.SubvolumeGroup, s.VolID, fsAdmin.ByteCount(bytesQuota), true)
if err != nil {
log.ErrorLog(ctx, "failed to resize subvolume %s in fs %s: %s", s.VolID, s.FsName, err)
}
clusterAdditionalInfo[s.clusterID].resizeState = unsupported
s.Size = bytesQuota

return s.CreateVolume(ctx)
return err
}

// PurgSubVolume removes the subvolume.
Expand Down

0 comments on commit c106681

Please sign in to comment.