Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 83 additions & 44 deletions driver/csiplugin/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ type ScaleControllerServer struct {
csi.UnimplementedControllerServer
}

func (cs *ScaleControllerServer) IfSameVolReqInProcess(scVol *scaleVolume) (bool, error) {
func (cs *ScaleControllerServer) IfSameVolReqInProcess(scVol *scaleVolume, requestedSize int64) (bool, error) {
capacity, volpresent := cs.Driver.reqmap[scVol.VolName]
if volpresent {
/* #nosec G115 -- false positive */
if capacity == int64(scVol.VolSize) {
if capacity == requestedSize {
return true, nil
} else {
return false, status.Error(codes.Internal, fmt.Sprintf("Volume %v present in map but requested size %v does not match with size %v in map", scVol.VolName, scVol.VolSize, capacity))
Expand Down Expand Up @@ -1127,7 +1127,7 @@ func (cs *ScaleControllerServer) CreateVolume(newctx context.Context, req *csi.C
return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
VolumeId: volID,
CapacityBytes: int64(scaleVol.VolSize), // #nosec G115 -- false positive
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(), // #nosec G115 -- false positive
VolumeContext: req.GetParameters(),
ContentSource: volSrc,
},
Expand All @@ -1148,8 +1148,20 @@ func (cs *ScaleControllerServer) CreateVolume(newctx context.Context, req *csi.C
}

}

volReqInProcess, err := cs.IfSameVolReqInProcess(scaleVol)
filesystemName := scaleVol.VolBackendFs
klog.Info("Filesystemname", filesystemName)
filesystemDetails, err := cs.Driver.connmap["primary"].GetFilesystemDetails(ctx, filesystemName)
if err != nil {
klog.Errorf("%s Unable to get the filesystemdetails for Filesystem %s. Error: %v", utils.GetLoggerId(ctx), filesystemName, err)
return nil, status.Error(codes.Internal, fmt.Sprintf("unable to get filesystem details for Filesystem %s. Error: %v", filesystemName, err))
}
klog.V(4).Infof("[%s] filesystemDetails: %+v", utils.GetLoggerId(ctx), filesystemDetails)
blockInfo := filesystemDetails.Block.BlockSize
if blockInfo == 0 {
klog.Errorf("[%s] volume:[%v] - unable to get block size for filesystem %s", loggerId, scaleVol.VolName, filesystemName)
return nil, status.Error(codes.Internal, fmt.Sprintf("unable to get block size for filesystem %s", filesystemName))
}
volReqInProcess, err := cs.IfSameVolReqInProcess(scaleVol, int64(blockInfo))
if err != nil {
return nil, err
}
Expand All @@ -1158,6 +1170,9 @@ func (cs *ScaleControllerServer) CreateVolume(newctx context.Context, req *csi.C
klog.Errorf("[%s] volume:[%v] - volume creation already in process ", loggerId, scaleVol.VolName)
return nil, status.Error(codes.Aborted, fmt.Sprintf("volume creation already in process : %v", scaleVol.VolName))
}
// Add sleep time after the IfSameVolReqInProcess function call
klog.Infof("[%s] Sleeping for 4 minutes after checking IfSameVolReqInProcess", loggerId)
time.Sleep(4 * time.Minute)

volResponse, err := cs.getCopyJobStatus(ctx, req, volSrc, scaleVol, isVolSource, isSnapSource, snapIdMembers)
if err != nil {
Expand Down Expand Up @@ -1269,7 +1284,7 @@ func (cs *ScaleControllerServer) CreateVolume(newctx context.Context, req *csi.C
return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
VolumeId: volID,
CapacityBytes: int64(scaleVol.VolSize), // #nosec G115 -- false positive
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(), // #nosec G115 -- false positive
VolumeContext: req.GetParameters(),
ContentSource: volSrc,
},
Expand Down Expand Up @@ -1427,6 +1442,23 @@ func (cs *ScaleControllerServer) setScaleVolume(ctx context.Context, req *csi.Cr
isCGVolume = true
}
scaleVol.VolName = volName
// changing capacity here for pvc size in decimal units to align with scale block size of filesystem
//getting the filesystemname
filesystemName := scaleVol.VolBackendFs
klog.Info("Filesystemname", filesystemName)
filesystemDetails, err := cs.Driver.connmap["primary"].GetFilesystemDetails(ctx, filesystemName)
if err != nil {
klog.Errorf("%s Unable to get the filesystemdetails for Filesystem %s. Error: %v", utils.GetLoggerId(ctx), filesystemName, err)
return nil, false, "", status.Error(codes.Internal, fmt.Sprintf("unable to get filesystem details for Filesystem %s. Error: %v", filesystemName, err))
}
klog.V(4).Infof("[%s] filesystemDetails: %+v", utils.GetLoggerId(ctx), filesystemDetails)
blockInfo := filesystemDetails.Block.BlockSize
if blockInfo == 0 {
klog.Errorf("[%s] volume:[%v] - unable to get block size for filesystem %s", utils.GetLoggerId(ctx), scaleVol.VolName, filesystemName)
return nil, false, "", status.Error(codes.Internal, fmt.Sprintf("unable to get block size for filesystem %s", filesystemName))
}
roundedBlock := int64(math.Floor(float64(volSize) / float64(blockInfo)))
volSize = roundedBlock * int64(blockInfo)

// #nosec G115 -- false positive
if uint64(volSize) > maximumPVSize { // larger than allowed pv size not allowed
Expand Down Expand Up @@ -2060,18 +2092,18 @@ func (cs *ScaleControllerServer) checkCacheVolumeSupport(assembledScaleversion s
}

/*func (cs *ScaleControllerServer) checkGuiHASupport(ctx context.Context, conn connectors.SpectrumScaleConnector) error {
// Verify IBM Storage Scale Version is not below 5.1.5-0
// Verify IBM Storage Scale Version is not below 5.1.5-0

versionCheck, err := cs.checkMinScaleVersion(ctx, conn, "5150")
if err != nil {
return err
}
versionCheck, err := cs.checkMinScaleVersion(ctx, conn, "5150")
if err != nil {
return err
}

if !versionCheck {
return status.Error(codes.FailedPrecondition, "the minimum required IBM Storage Scale version for GUI HA support with CSI is 5.1.5-0")
}
return nil
}*/
if !versionCheck {
return status.Error(codes.FailedPrecondition, "the minimum required IBM Storage Scale version for GUI HA support with CSI is 5.1.5-0")
}
return nil
}*/

func (cs *ScaleControllerServer) validateSnapId(ctx context.Context, scaleVol *scaleVolume, sourcesnapshot *scaleSnapId, newvolume *scaleVolume, assembledScaleversion string) error {

Expand Down Expand Up @@ -2132,12 +2164,12 @@ func (cs *ScaleControllerServer) validateSnapId(ctx context.Context, scaleVol *s
filesetToCheck = sourcesnapshot.ConsistencyGroup
}
/*isFsetLinked, err := conn.IsFilesetLinked(ctx, sourcesnapshot.FsName, filesetToCheck)
if err != nil {
return status.Error(codes.Internal, fmt.Sprintf("unable to get fileset link information for [%v]", filesetToCheck))
}
if !isFsetLinked {
return status.Error(codes.Internal, fmt.Sprintf("fileset [%v] of source snapshot is not linked", filesetToCheck))
}*/
if err != nil {
return status.Error(codes.Internal, fmt.Sprintf("unable to get fileset link information for [%v]", filesetToCheck))
}
if !isFsetLinked {
return status.Error(codes.Internal, fmt.Sprintf("fileset [%v] of source snapshot is not linked", filesetToCheck))
}*/

err = cs.checkFileSetLink(ctx, conn, scaleVol, sourcesnapshot.FsName, filesetToCheck, "source snapshot")
if err != nil {
Expand Down Expand Up @@ -2500,18 +2532,18 @@ func (cs *ScaleControllerServer) DeleteFilesetVol(ctx context.Context, Filesyste
}

/* err := conn.UnlinkFileset(ctx, FilesystemName, FilesetName, false)
if err != nil {
if strings.Contains(err.Error(), fsetNotFoundErrCode) ||
strings.Contains(err.Error(), fsetNotFoundErrMsg) { // fileset is already deleted
klog.V(4).Infof("[%s] fileset seems already deleted - %v", loggerId, err)
return true, nil
} else if strings.Contains(err.Error(), fsetLinkNotFoundErrCode) ||
strings.Contains(err.Error(), fsetLinkNotFoundErrMsg) { // fileset is already unlinked
klog.V(4).Infof("[%s] fileset seems already unlinked - %v", loggerId, err)
} else {
return false, status.Error(codes.Internal, fmt.Sprintf("unable to unlink Fileset [%v] for FS [%v] and clusterId [%v].Error : [%v]", FilesetName, FilesystemName, volumeIdMembers.ClusterId, err))
}
}*/
if err != nil {
if strings.Contains(err.Error(), fsetNotFoundErrCode) ||
strings.Contains(err.Error(), fsetNotFoundErrMsg) { // fileset is already deleted
klog.V(4).Infof("[%s] fileset seems already deleted - %v", loggerId, err)
return true, nil
} else if strings.Contains(err.Error(), fsetLinkNotFoundErrCode) ||
strings.Contains(err.Error(), fsetLinkNotFoundErrMsg) { // fileset is already unlinked
klog.V(4).Infof("[%s] fileset seems already unlinked - %v", loggerId, err)
} else {
return false, status.Error(codes.Internal, fmt.Sprintf("unable to unlink Fileset [%v] for FS [%v] and clusterId [%v].Error : [%v]", FilesetName, FilesystemName, volumeIdMembers.ClusterId, err))
}
}*/

err := conn.DeleteFileset(ctx, FilesystemName, FilesetName)
if err != nil {
Expand Down Expand Up @@ -2737,14 +2769,14 @@ func (cs *ScaleControllerServer) DeleteVolume(newctx context.Context, req *csi.D
pfsName := ""
// getting the primary filesystem name from the path when primary fs is not provided in the cr and pvc is older
/* if symlinkExists && ifPrimaryDisable {
parts := strings.Split(volumeIdMembers.Path, "/")
for i, part := range parts {
if part == ".volumes" && i >= 2 {
pfsName = parts[i-2]
klog.Infof("[%s] DeleteVolume :primary fs from path is [%v]", loggerId, pfsName)
}
}
}*/
parts := strings.Split(volumeIdMembers.Path, "/")
for i, part := range parts {
if part == ".volumes" && i >= 2 {
pfsName = parts[i-2]
klog.Infof("[%s] DeleteVolume :primary fs from path is [%v]", loggerId, pfsName)
}
}
}*/

relPath := ""
if volumeIdMembers.StorageClassType != STORAGECLASS_CLASSIC || volumeIdMembers.VolType == FILE_SHALLOWCOPY_VOLUME || !symlinkExists {
Expand Down Expand Up @@ -4071,7 +4103,6 @@ func (cs *ScaleControllerServer) ControllerExpandVolume(ctx context.Context, req
return nil, status.Error(codes.InvalidArgument, "capacity range not provided")
}
capacity := uint64(capRange.GetRequiredBytes()) // #nosec G115 -- false positive

volumeIDMembers, err := getVolIDMembers(volID)

if err != nil {
Expand Down Expand Up @@ -4107,9 +4138,17 @@ func (cs *ScaleControllerServer) ControllerExpandVolume(ctx context.Context, req
klog.Errorf("[%s] ControllerExpandVolume - unable to get filesystem Name for Filesystem Uid [%v] and clusterId [%v]. Error [%v]", loggerId, volumeIDMembers.FsUUID, volumeIDMembers.ClusterId, err)
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerExpandVolume - unable to get filesystem Name for Filesystem Uid [%v] and clusterId [%v]. Error [%v]", volumeIDMembers.FsUUID, volumeIDMembers.ClusterId, err))
}
// changing capacity here for pvc size in decimal units to align with scale block size
filesystemDetails, err := conn.GetFilesystemDetails(ctx, filesystemName)
if err != nil {
klog.Errorf("[%s] ControllerExpandVolume - unable to get filesystem details for Filesystem Uid [%v] and clusterId [%v]. Error [%v]", loggerId, volumeIDMembers.FsUUID, volumeIDMembers.ClusterId, err)
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerExpandVolume - unable to get filesystem details for Filesystem [%v] Error [%v]", filesystemName, err))
}
blockInfo := filesystemDetails.Block.BlockSize
roundedBlock := uint64(math.Floor(float64(capacity) / float64(blockInfo)))
capacity = roundedBlock * uint64(blockInfo)

filesetName := volumeIDMembers.FsetName

// Check if fileset exists
fsetExist, err := conn.CheckIfFilesetExist(ctx, filesystemName, filesetName)
if err != nil {
Expand Down