cephfs: make resizeVolume() a method of volumeOptions

This prepares resizeVolume() so that the volumeOptions.conn can be used
for connecting with go-ceph and use the connection cache.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-10-21 11:07:44 +02:00 committed by mergify[bot]
parent 48108bc549
commit d431402101
3 changed files with 15 additions and 15 deletions

View File

@ -100,7 +100,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
return cloneFailedErr return cloneFailedErr
case cephFSCloneComplete: case cephFSCloneComplete:
// This is a work around to fix sizing issue for cloned images // This is a work around to fix sizing issue for cloned images
err = resizeVolume(ctx, volOpt, cr, cloneID, volOpt.Size) err = volOpt.resizeVolume(ctx, cr, cloneID, volOpt.Size)
if err != nil { if err != nil {
util.ErrorLog(ctx, "failed to expand volume %s: %v", cloneID, err) util.ErrorLog(ctx, "failed to expand volume %s: %v", cloneID, err)
return err return err
@ -179,7 +179,7 @@ func createCloneFromSnapshot(ctx context.Context, parentVolOpt, volOptions *volu
// The clonedvolume currently does not reflect the proper size due to an issue in cephfs // The clonedvolume currently does not reflect the proper size due to an issue in cephfs
// however this is getting addressed in cephfs and the parentvolume size will be reflected // however this is getting addressed in cephfs and the parentvolume size will be reflected
// in the new cloned volume too. Till then we are explicitly making the size set // in the new cloned volume too. Till then we are explicitly making the size set
err = resizeVolume(ctx, volOptions, cr, volumeID(vID.FsSubvolName), volOptions.Size) err = volOptions.resizeVolume(ctx, cr, volumeID(vID.FsSubvolName), volOptions.Size)
if err != nil { if err != nil {
util.ErrorLog(ctx, "failed to expand volume %s with error: %v", vID.FsSubvolName, err) util.ErrorLog(ctx, "failed to expand volume %s with error: %v", vID.FsSubvolName, err)
return err return err

View File

@ -186,7 +186,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
// it will be fixed in cephfs soon with the parentvolume size. Till then by below // it will be fixed in cephfs soon with the parentvolume size. Till then by below
// resize we are making sure we return or satisfy the requested size by setting the size // resize we are making sure we return or satisfy the requested size by setting the size
// explictly // explictly
err = resizeVolume(ctx, volOptions, cr, volumeID(vID.FsSubvolName), volOptions.Size) err = volOptions.resizeVolume(ctx, cr, volumeID(vID.FsSubvolName), volOptions.Size)
if err != nil { if err != nil {
purgeErr := purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions, false) purgeErr := purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions, false)
if purgeErr != nil { if purgeErr != nil {
@ -426,7 +426,7 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi
RoundOffSize := util.RoundOffBytes(req.GetCapacityRange().GetRequiredBytes()) RoundOffSize := util.RoundOffBytes(req.GetCapacityRange().GetRequiredBytes())
if err = resizeVolume(ctx, volOptions, cr, volumeID(volIdentifier.FsSubvolName), RoundOffSize); err != nil { if err = volOptions.resizeVolume(ctx, cr, volumeID(volIdentifier.FsSubvolName), RoundOffSize); err != nil {
util.ErrorLog(ctx, "failed to expand volume %s: %v", volumeID(volIdentifier.FsSubvolName), err) util.ErrorLog(ctx, "failed to expand volume %s: %v", volumeID(volIdentifier.FsSubvolName), err)
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }

View File

@ -177,27 +177,27 @@ func createVolume(ctx context.Context, volOptions *volumeOptions, volID volumeID
// resizeVolume will try to use ceph fs subvolume resize command to resize the // 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 // subvolume. If the command is not available as a fallback it will use
// CreateVolume to resize the subvolume. // CreateVolume to resize the subvolume.
func resizeVolume(ctx context.Context, volOptions *volumeOptions, cr *util.Credentials, volID volumeID, bytesQuota int64) error { func (vo *volumeOptions) resizeVolume(ctx context.Context, cr *util.Credentials, volID volumeID, bytesQuota int64) error {
// keyPresent checks whether corresponding clusterID key is present in clusterAdditionalInfo // keyPresent checks whether corresponding clusterID key is present in clusterAdditionalInfo
var keyPresent bool var keyPresent bool
// verify if corresponding ClusterID key is present in the map, // verify if corresponding ClusterID key is present in the map,
// and if not, initialize with default values(false). // and if not, initialize with default values(false).
if _, keyPresent = clusterAdditionalInfo[volOptions.ClusterID]; !keyPresent { if _, keyPresent = clusterAdditionalInfo[vo.ClusterID]; !keyPresent {
clusterAdditionalInfo[volOptions.ClusterID] = &localClusterState{} clusterAdditionalInfo[vo.ClusterID] = &localClusterState{}
} }
// 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[volOptions.ClusterID].resizeSupported || !keyPresent { if clusterAdditionalInfo[vo.ClusterID].resizeSupported || !keyPresent {
args := []string{ args := []string{
"fs", "fs",
"subvolume", "subvolume",
"resize", "resize",
volOptions.FsName, vo.FsName,
string(volID), string(volID),
strconv.FormatInt(bytesQuota, 10), strconv.FormatInt(bytesQuota, 10),
"--group_name", "--group_name",
volOptions.SubvolumeGroup, vo.SubvolumeGroup,
"-m", volOptions.Monitors, "-m", vo.Monitors,
"-c", util.CephConfigPath, "-c", util.CephConfigPath,
"-n", cephEntityClientPrefix + cr.ID, "-n", cephEntityClientPrefix + cr.ID,
"--keyfile=" + cr.KeyFile, "--keyfile=" + cr.KeyFile,
@ -209,17 +209,17 @@ func resizeVolume(ctx context.Context, volOptions *volumeOptions, cr *util.Crede
args[:]...) args[:]...)
if err == nil { if err == nil {
clusterAdditionalInfo[volOptions.ClusterID].resizeSupported = true clusterAdditionalInfo[vo.ClusterID].resizeSupported = true
return nil return nil
} }
// Incase the error is other than invalid command return error to the caller. // Incase the error is other than invalid command return error to the caller.
if !strings.Contains(err.Error(), invalidCommand) { if !strings.Contains(err.Error(), invalidCommand) {
util.ErrorLog(ctx, "failed to resize subvolume %s in fs %s: %s", string(volID), volOptions.FsName, err) util.ErrorLog(ctx, "failed to resize subvolume %s in fs %s: %s", string(volID), vo.FsName, err)
return err return err
} }
} }
clusterAdditionalInfo[volOptions.ClusterID].resizeSupported = false clusterAdditionalInfo[vo.ClusterID].resizeSupported = false
return createVolume(ctx, volOptions, volID, bytesQuota) return createVolume(ctx, vo, volID, bytesQuota)
} }
func purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, volOptions *volumeOptions, force bool) error { func purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, volOptions *volumeOptions, force bool) error {