From d3b174b6a12fdbfe31eb68b0babd9b1091b79c9f Mon Sep 17 00:00:00 2001 From: Badri Nath Pathak Date: Sat, 4 May 2024 11:09:50 +0530 Subject: [PATCH] removed unnecessary gui mount fs checks (#1128) * removed unnecessary gui mount fs checks Signed-off-by: badri-pathak --- driver/csiplugin/controllerserver.go | 266 +++++++++++---------------- 1 file changed, 107 insertions(+), 159 deletions(-) diff --git a/driver/csiplugin/controllerserver.go b/driver/csiplugin/controllerserver.go index 2db6876c8..39a209797 100644 --- a/driver/csiplugin/controllerserver.go +++ b/driver/csiplugin/controllerserver.go @@ -692,16 +692,6 @@ func (cs *ScaleControllerServer) CreateVolume(ctx context.Context, req *csi.Crea } } - if scaleVol.PrimaryFS != scaleVol.VolBackendFs { - // primary filesytem must be mounted on GUI node so that we can create the softlink - // skip if primary and volume filesystem is same - err := checkFilesystemMountOnGUI(ctx, scaleVol.PrimaryConnector, scaleVol.PrimaryFS, scaleVol.VolName, "primary") - - if err != nil { - return nil, err - } - } - volFsInfo, err := checkVolumeFilesystemMountOnPrimary(ctx, scaleVol) if err != nil { return nil, err @@ -733,14 +723,14 @@ func (cs *ScaleControllerServer) CreateVolume(ctx context.Context, req *csi.Crea err = cs.validateSnapId(ctx, scaleVol, &snapIdMembers, scaleVol, primaryClusterID, assembledScaleversion) if err != nil { klog.Errorf("[%s] volume:[%v] - Error in source snapshot validation [%v]", loggerId, volName, err) - return nil,err + return nil, err } - if isShallowCopyVolume{ + if isShallowCopyVolume { err = cs.validateShallowCopyVolume(ctx, &snapIdMembers, scaleVol) - if err != nil{ + if err != nil { klog.Errorf("[%s] volume:[%v] - Error in validating shallow copy volume", loggerId, volName) - return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume ValidateShallowCopyVolume failed: %v",err)) + return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume ValidateShallowCopyVolume failed: %v", err)) } } @@ -961,23 +951,6 @@ func (cs *ScaleControllerServer) checkFileSetLink(ctx context.Context, connector return nil } -func checkFilesystemMountOnGUI(ctx context.Context, connector connectors.SpectrumScaleConnector, fsName string, scaleVolName string, primaryOrNone string) error { - loggerId := utils.GetLoggerId(ctx) - // primary filesytem must be mounted on GUI node so that we can create the softlink - // skip if primary and volume filesystem is same - klog.V(4).Infof("[%s] volume:[%v] - check if %s filesystem [%v] is mounted on GUI node of %s cluster", loggerId, scaleVolName, primaryOrNone, fsName, primaryOrNone) - isFsMounted, err := connector.IsFilesystemMountedOnGUINode(ctx, fsName) - if err != nil { - klog.Errorf("[%s] volume:[%v] - unable to get filesystem mount details for %s on %s cluster. Error: %v", loggerId, scaleVolName, fsName, primaryOrNone, err) - return status.Error(codes.Internal, fmt.Sprintf("unable to get filesystem mount details for %s on GUI cluster. Error: %v", fsName, err)) - } - if !isFsMounted { - klog.Errorf("[%s] volume:[%v] - %s filesystem %s is not mounted on GUI node of GUI cluster", loggerId, scaleVolName, primaryOrNone, fsName) - return status.Error(codes.Internal, fmt.Sprintf("%s filesystem %s is not mounted on GUI node of %s cluster", primaryOrNone, fsName, primaryOrNone)) - } - return nil -} - func checkVolumeFilesystemMountOnPrimary(ctx context.Context, scaleVol *scaleVolume) (connectors.FileSystem_v2, error) { loggerId := utils.GetLoggerId(ctx) klog.V(6).Infof("[%s] volume:[%v] - check if volume filesystem [%v] is mounted on GUI node of Primary cluster", loggerId, scaleVol.VolName, scaleVol.VolBackendFs) @@ -1258,23 +1231,23 @@ func (cs *ScaleControllerServer) copySnapContent(ctx context.Context, scVol *sca func (cs *ScaleControllerServer) copyShallowVolumeContent(ctx context.Context, newvolume *scaleVolume, sourcevolume scaleVolId, fsDetails connectors.FileSystem_v2, targetPath string, volID string) error { loggerId := utils.GetLoggerId(ctx) - klog.Infof("[%s] copyShallowVolContent volume ID: [%v], scaleVolume: [%v], volume name: [%v]", loggerId, sourcevolume, newvolume, newvolume.VolName) - conn, err := cs.getConnFromClusterID(ctx, sourcevolume.ClusterId) - if err != nil { - return err - } + klog.Infof("[%s] copyShallowVolContent volume ID: [%v], scaleVolume: [%v], volume name: [%v]", loggerId, sourcevolume, newvolume, newvolume.VolName) + conn, err := cs.getConnFromClusterID(ctx, sourcevolume.ClusterId) + if err != nil { + return err + } - fsMntPt := fsDetails.Mount.MountPoint - targetPath = fmt.Sprintf("%s/%s", fsMntPt, targetPath) + fsMntPt := fsDetails.Mount.MountPoint + targetPath = fmt.Sprintf("%s/%s", fsMntPt, targetPath) - jobDetails := VolCopyJobDetails{VOLCOPY_JOB_NOT_STARTED, volID} - response := connectors.GenericResponse{} + jobDetails := VolCopyJobDetails{VOLCOPY_JOB_NOT_STARTED, volID} + response := connectors.GenericResponse{} - sLinkRelPath := strings.Replace(sourcevolume.Path, fsMntPt, "", 1) - sLinkRelPath = strings.Trim(sLinkRelPath, "!/") + sLinkRelPath := strings.Replace(sourcevolume.Path, fsMntPt, "", 1) + sLinkRelPath = strings.Trim(sLinkRelPath, "!/") - if fsDetails.Type == filesystemTypeRemote{ - remotefsDetails,err := conn.GetFilesystemDetails(ctx, newvolume.VolBackendFs) + if fsDetails.Type == filesystemTypeRemote { + remotefsDetails, err := conn.GetFilesystemDetails(ctx, newvolume.VolBackendFs) if err != nil { if strings.Contains(err.Error(), "Invalid value in filesystemName") { klog.Errorf("[%s] filesystem %s in not known to cluster %s. Error: %v", loggerId, newvolume.VolBackendFs, newvolume.ClusterId, err) @@ -1287,45 +1260,45 @@ func (cs *ScaleControllerServer) copyShallowVolumeContent(ctx context.Context, n targetPath = strings.Replace(targetPath, fsMntPt, remoteMntPt, 1) } - jobStatus, jobID, jobErr := conn.CopyDirectoryPath(ctx, sourcevolume.FsName, sLinkRelPath, targetPath, newvolume.NodeClass) + jobStatus, jobID, jobErr := conn.CopyDirectoryPath(ctx, sourcevolume.FsName, sLinkRelPath, targetPath, newvolume.NodeClass) - if jobErr != nil { - klog.Errorf("[%s] failed to clone volume from volume. Error: [%v]", loggerId, jobErr) - return status.Error(codes.Internal, fmt.Sprintf("failed to clone volume from shallow copy volume. Error: [%v]", jobErr)) - } + if jobErr != nil { + klog.Errorf("[%s] failed to clone volume from volume. Error: [%v]", loggerId, jobErr) + return status.Error(codes.Internal, fmt.Sprintf("failed to clone volume from shallow copy volume. Error: [%v]", jobErr)) + } - jobDetails = VolCopyJobDetails{VOLCOPY_JOB_RUNNING, volID} - cs.Driver.volcopyjobstatusmap.Store(newvolume.VolName, jobDetails) - response, err = conn.WaitForJobCompletionWithResp(ctx, jobStatus, jobID) + jobDetails = VolCopyJobDetails{VOLCOPY_JOB_RUNNING, volID} + cs.Driver.volcopyjobstatusmap.Store(newvolume.VolName, jobDetails) + response, err = conn.WaitForJobCompletionWithResp(ctx, jobStatus, jobID) if err != nil { - klog.Errorf("[%s] failed while calling WaitForJobCompletionWithResp: %v.", loggerId, err) - } + klog.Errorf("[%s] failed while calling WaitForJobCompletionWithResp: %v.", loggerId, err) + } + + isResponseStatusUnknown := false + if len(response.Jobs) != 0 { + if response.Jobs[0].Status == ResponseStatusUnknown { + isResponseStatusUnknown = true + } + } - isResponseStatusUnknown := false - if len(response.Jobs) != 0 { - if response.Jobs[0].Status == ResponseStatusUnknown { - isResponseStatusUnknown = true - } - } - if err != nil || isResponseStatusUnknown { - klog.Errorf("[%s] unable to clone shallow copy volume: %v.", loggerId, err) - if err != nil && strings.Contains(err.Error(), "EFSSG0632C") { - jobDetails.jobStatus = VOLCOPY_JOB_NOT_STARTED - } else if isResponseStatusUnknown { - jobDetails.jobStatus = JOB_STATUS_UNKNOWN - } else { - jobDetails.jobStatus = VOLCOPY_JOB_FAILED - } - klog.Errorf("[%s] logging volume cloning error for VolName: [%s] Error: [%v] JobDetails: [%v]", loggerId, newvolume.VolName, err, jobDetails) - cs.Driver.volcopyjobstatusmap.Store(newvolume.VolName, jobDetails) - return err - } - - klog.Infof("[%s] volume copy completed for volumeID: [%v], scaleVolume: [%v]", loggerId, sourcevolume, newvolume) - jobDetails.jobStatus = VOLCOPY_JOB_COMPLETED - cs.Driver.volcopyjobstatusmap.Store(newvolume.VolName, jobDetails) - return nil + klog.Errorf("[%s] unable to clone shallow copy volume: %v.", loggerId, err) + if err != nil && strings.Contains(err.Error(), "EFSSG0632C") { + jobDetails.jobStatus = VOLCOPY_JOB_NOT_STARTED + } else if isResponseStatusUnknown { + jobDetails.jobStatus = JOB_STATUS_UNKNOWN + } else { + jobDetails.jobStatus = VOLCOPY_JOB_FAILED + } + klog.Errorf("[%s] logging volume cloning error for VolName: [%s] Error: [%v] JobDetails: [%v]", loggerId, newvolume.VolName, err, jobDetails) + cs.Driver.volcopyjobstatusmap.Store(newvolume.VolName, jobDetails) + return err + } + + klog.Infof("[%s] volume copy completed for volumeID: [%v], scaleVolume: [%v]", loggerId, sourcevolume, newvolume) + jobDetails.jobStatus = VOLCOPY_JOB_COMPLETED + cs.Driver.volcopyjobstatusmap.Store(newvolume.VolName, jobDetails) + return nil } @@ -1521,7 +1494,6 @@ func (cs *ScaleControllerServer) checkCGSupport(ctx context.Context, conn connec return nil }*/ - func (cs *ScaleControllerServer) validateSnapId(ctx context.Context, scaleVol *scaleVolume, sourcesnapshot *scaleSnapId, newvolume *scaleVolume, pCid string, assembledScaleversion string) error { loggerId := utils.GetLoggerId(ctx) @@ -1576,21 +1548,6 @@ func (cs *ScaleControllerServer) validateSnapId(ctx context.Context, scaleVol *s return status.Error(codes.Internal, fmt.Sprintf("unable to get filesystem Name for Id [%v] and clusterId [%v]. Error [%v]", sourcesnapshot.FsUUID, sourcesnapshot.ClusterId, err)) } - if sourcesnapshot.FsName != newvolume.VolBackendFs { - /* isFsMounted, err := conn.IsFilesystemMountedOnGUINode(ctx, sourcesnapshot.FsName) - if err != nil { - return status.Error(codes.Internal, fmt.Sprintf("error in getting filesystem mount details for %s", sourcesnapshot.FsName)) - } - if !isFsMounted { - return status.Error(codes.Internal, fmt.Sprintf("filesystem %s is not mounted on GUI node", sourcesnapshot.FsName)) - }*/ - err = checkFilesystemMountOnGUI(ctx, conn, sourcesnapshot.FsName, "", "") - - if err != nil { - return err - } - } - filesetToCheck := sourcesnapshot.FsetName if sourcesnapshot.StorageClassType == STORAGECLASS_ADVANCED { filesetToCheck = sourcesnapshot.ConsistencyGroup @@ -1619,15 +1576,14 @@ func (cs *ScaleControllerServer) validateSnapId(ctx context.Context, scaleVol *s return nil } - func (cs *ScaleControllerServer) validateShallowCopyVolume(ctx context.Context, sourcesnapshot *scaleSnapId, newvolume *scaleVolume) error { loggerId := utils.GetLoggerId(ctx) - - if sourcesnapshot.VolType == "" && sourcesnapshot.ConsistencyGroup == ""{ + + if sourcesnapshot.VolType == "" && sourcesnapshot.ConsistencyGroup == "" { klog.Errorf("[%s] creating shallow copy volume is not supported for static volume or old snapshot handle", loggerId) return status.Error(codes.Internal, fmt.Sprintf("creating shallow copy volume is not supported for static volume or old snapshot handle")) } - + if !newvolume.IsFilesetBased { klog.Errorf("[%s] creating shallow copy volume as directory based volume is not supported", loggerId) return status.Error(codes.Internal, fmt.Sprintf("creating shallow copy volume as directory based volume is not supported")) @@ -1642,19 +1598,19 @@ func (cs *ScaleControllerServer) validateShallowCopyVolume(ctx context.Context, if newvolume.StorageClassType != sourcesnapshot.StorageClassType { klog.Errorf("[%s] validation of shallow copy volume [%s] failed as storage class type is different from source pvc [%s]", loggerId, newvolume.VolName, sourcesnapshot.SnapName) return status.Error(codes.Internal, fmt.Sprintf("validation of shallow copy volume [%s] failed as storage class type is different from source pvc [%s]", newvolume.VolName, sourcesnapshot.SnapName)) - }else{ + } else { if newvolume.VolBackendFs != sourcesnapshot.FsName { - klog.Errorf("[%s] validation of shallow copy volume [%s] failed as filesystem [%s] is different from source pvc [%s] failed ", loggerId, newvolume.VolName, - newvolume.VolBackendFs, sourcesnapshot.SnapName) + klog.Errorf("[%s] validation of shallow copy volume [%s] failed as filesystem [%s] is different from source pvc [%s] failed ", loggerId, newvolume.VolName, + newvolume.VolBackendFs, sourcesnapshot.SnapName) return status.Error(codes.Internal, fmt.Sprintf("validation of shallow copy volume [%s] failed as filesystem [%s] is different from source pvc [%s] failed", newvolume.VolName, newvolume.VolBackendFs, sourcesnapshot.SnapName)) - }else{ + } else { if sourcesnapshot.StorageClassType == STORAGECLASS_CLASSIC { - if !((newvolume.FilesetType == independentFileset && sourcesnapshot.VolType == FILE_INDEPENDENTFILESET_VOLUME) || (newvolume.FilesetType == dependentFileset && sourcesnapshot.VolType == FILE_DEPENDENTFILESET_VOLUME)) { + if !((newvolume.FilesetType == independentFileset && sourcesnapshot.VolType == FILE_INDEPENDENTFILESET_VOLUME) || (newvolume.FilesetType == dependentFileset && sourcesnapshot.VolType == FILE_DEPENDENTFILESET_VOLUME)) { klog.Errorf("[%s] Filesettype is not same for both source snapshot and new volume", loggerId) - return status.Error(codes.Internal, fmt.Sprintf("Filesettype is not same for both source snapshot and new volume")) - } + return status.Error(codes.Internal, fmt.Sprintf("Filesettype is not same for both source snapshot and new volume")) + } - } + } } } } @@ -1748,14 +1704,6 @@ func (cs *ScaleControllerServer) validateCloneRequest(ctx context.Context, scale } } - /* isFsetLinked, err := conn.IsFilesetLinked(ctx, sourcevolume.FsName, sourcevolume.FsetName) - if err != nil { - return status.Error(codes.Internal, fmt.Sprintf("unable to get fileset link information for [%v]", sourcevolume.FsetName)) - } - if !isFsetLinked { - return status.Error(codes.Internal, fmt.Sprintf("fileset [%v] of source volume is not linked", sourcevolume.FsetName)) - }*/ - if sourcevolume.VolType != FILE_SHALLOWCOPY_VOLUME { err = cs.checkFileSetLink(ctx, conn, scaleVol, sourcevolume.FsName, sourcevolume.FsetName, "source") if err != nil { @@ -1958,7 +1906,7 @@ func (cs *ScaleControllerServer) DeleteVolume(ctx context.Context, req *csi.Dele } relPath := "" - if volumeIdMembers.StorageClassType == STORAGECLASS_ADVANCED || volumeIdMembers.VolType == FILE_SHALLOWCOPY_VOLUME{ + if volumeIdMembers.StorageClassType == STORAGECLASS_ADVANCED || volumeIdMembers.VolType == FILE_SHALLOWCOPY_VOLUME { relPath = strings.Replace(volumeIdMembers.Path, mountInfo.MountPoint, "", 1) } else { primaryFSMountPoint, err := cs.getPrimaryFSMountPoint(ctx) @@ -1971,21 +1919,21 @@ func (cs *ScaleControllerServer) DeleteVolume(ctx context.Context, req *csi.Dele isPvcFromSnapshot := false var shallowCopyRefPath string var snapshotName string - var independentFileset string - if volumeIdMembers.VolType == FILE_SHALLOWCOPY_VOLUME{ - if relPath != "" && strings.Contains(relPath, ".snapshots"){ - volPath := strings.Split(relPath, "/") - if len(volPath) > 2{ - if volPath[1] == ".snapshots"{ - isPvcFromSnapshot = true + var independentFileset string + if volumeIdMembers.VolType == FILE_SHALLOWCOPY_VOLUME { + if relPath != "" && strings.Contains(relPath, ".snapshots") { + volPath := strings.Split(relPath, "/") + if len(volPath) > 2 { + if volPath[1] == ".snapshots" { + isPvcFromSnapshot = true snapshotName = volPath[2] independentFileset = volPath[0] - shallowCopyRefPath = fmt.Sprintf("%s/%s",volPath[0],volPath[2]) - } - }else{ - klog.Errorf("[%s] Invalid volume path to delete shallow copy volume reference", loggerId) + shallowCopyRefPath = fmt.Sprintf("%s/%s", volPath[0], volPath[2]) + } + } else { + klog.Errorf("[%s] Invalid volume path to delete shallow copy volume reference", loggerId) } - } + } } if volumeIdMembers.IsFilesetBased { @@ -2002,7 +1950,7 @@ func (cs *ScaleControllerServer) DeleteVolume(ctx context.Context, req *csi.Dele } if FilesetName != "" && isPvcFromSnapshot { - err := cs.DeleteShallowCopyRefPath(ctx, FilesystemName, FilesetName, shallowCopyRefPath, volumeIdMembers.StorageClassType, independentFileset, snapshotName, conn) + err := cs.DeleteShallowCopyRefPath(ctx, FilesystemName, FilesetName, shallowCopyRefPath, volumeIdMembers.StorageClassType, independentFileset, snapshotName, conn) if err != nil { return nil, err } @@ -2081,7 +2029,7 @@ func (cs *ScaleControllerServer) DeleteVolume(ctx context.Context, req *csi.Dele return &csi.DeleteVolumeResponse{}, nil } -func (cs *ScaleControllerServer) DeleteShallowCopyRefPath (ctx context.Context, FilesystemName, FilesetName, ShallowCopyRefPath, storageClassType, independentFileset, snapshotName string, conn connectors.SpectrumScaleConnector) error{ +func (cs *ScaleControllerServer) DeleteShallowCopyRefPath(ctx context.Context, FilesystemName, FilesetName, ShallowCopyRefPath, storageClassType, independentFileset, snapshotName string, conn connectors.SpectrumScaleConnector) error { loggerId := utils.GetLoggerId(ctx) klog.Infof("[%s] Deleting shallow copy reference path [%s]", loggerId, ShallowCopyRefPath) @@ -2095,47 +2043,47 @@ func (cs *ScaleControllerServer) DeleteShallowCopyRefPath (ctx context.Context, if strings.Contains(err.Error(), "EFSSG0264C") || strings.Contains(err.Error(), "does not exist") { // directory is already deleted isShallowCopyRefPathDeleted = true - }else{ + } else { return status.Error(codes.Internal, fmt.Sprintf("unable to Delete shallow copy reference Dir using FS [%s] Error [%v]", FilesystemName, err)) - } + } } else { isShallowCopyRefPathDeleted = true } - - if isShallowCopyRefPathDeleted{ + + if isShallowCopyRefPathDeleted { statInfo, err := conn.StatDirectory(ctx, FilesystemName, ShallowCopyRefPath) - if err != nil{ + if err != nil { if strings.Contains(err.Error(), "EFSSG0264C") || - strings.Contains(err.Error(), "does not exist") { + strings.Contains(err.Error(), "does not exist") { klog.Infof("[%s] snapshot path [%s] is already deleted", loggerId, ShallowCopyRefPath) return nil } else { - klog.Errorf("[%s] unable to stat directory using FS [%s] at path [%s]. Error [%v]", loggerId, FilesystemName, ShallowCopyRefPath, err) - return err + klog.Errorf("[%s] unable to stat directory using FS [%s] at path [%s]. Error [%v]", loggerId, FilesystemName, ShallowCopyRefPath, err) + return err + } + } else { + nlink, err := parseStatDirInfo(statInfo) + if err != nil { + klog.Errorf("[%s] invalid number of links [%d] returned in stat output for FS [%s] at path [%s]", loggerId, nlink, FilesystemName, ShallowCopyRefPath) + return err } - }else{ - nlink,err := parseStatDirInfo(statInfo) - if err != nil{ - klog.Errorf("[%s] invalid number of links [%d] returned in stat output for FS [%s] at path [%s]", loggerId, nlink, FilesystemName, ShallowCopyRefPath) - return err - } - - if nlink == 2{ - err = conn.DeleteDirectory(ctx, FilesystemName, ShallowCopyRefPath, false) - if err != nil { - return status.Error(codes.Internal,fmt.Sprintf("unable to Delete shallow copy reference parent dir using FS [%s] Error [%v]", FilesystemName, err)) - } - - if storageClassType == STORAGECLASS_ADVANCED{ - snaperr := conn.DeleteSnapshot(ctx, FilesystemName, independentFileset, snapshotName) + + if nlink == 2 { + err = conn.DeleteDirectory(ctx, FilesystemName, ShallowCopyRefPath, false) + if err != nil { + return status.Error(codes.Internal, fmt.Sprintf("unable to Delete shallow copy reference parent dir using FS [%s] Error [%v]", FilesystemName, err)) + } + + if storageClassType == STORAGECLASS_ADVANCED { + snaperr := conn.DeleteSnapshot(ctx, FilesystemName, independentFileset, snapshotName) if snaperr != nil { - return status.Error(codes.Internal, fmt.Sprintf("unable to delete snapshot dir [%s] Error [%v]", snapshotName, err)) - }else{ - klog.Infof("[%s] delete snapshot reference directory [%s] successfully", loggerId, snapshotName) - } + return status.Error(codes.Internal, fmt.Sprintf("unable to delete snapshot dir [%s] Error [%v]", snapshotName, err)) + } else { + klog.Infof("[%s] delete snapshot reference directory [%s] successfully", loggerId, snapshotName) + } } - } - + } + } } @@ -2915,7 +2863,7 @@ func (cs *ScaleControllerServer) ControllerExpandVolume(ctx context.Context, req return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("ControllerExpandVolume - Error in source Volume ID %v: %v", volID, err)) } - if volumeIDMembers.VolType == FILE_SHALLOWCOPY_VOLUME{ + if volumeIDMembers.VolType == FILE_SHALLOWCOPY_VOLUME { klog.Errorf("[%s] ControllerExpandVolume - volume expansion is not supported for shallow copy volume", loggerId) return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerExpandVolume - volume expansion is not supported for shallow copy volume %s", volID)) }