From 9ef61441ed825c327e44b2650efbe945223207d7 Mon Sep 17 00:00:00 2001 From: badri-pathak Date: Mon, 6 Jan 2025 09:59:31 -0800 Subject: [PATCH] cherry pick the unlink fset changes Signed-off-by: badri-pathak --- driver/csiplugin/connectors/connectors.go | 2 +- driver/csiplugin/connectors/rest_v2.go | 13 +++++++++---- driver/csiplugin/controllerserver.go | 16 +++++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/driver/csiplugin/connectors/connectors.go b/driver/csiplugin/connectors/connectors.go index aa18829ca..1500c0f74 100644 --- a/driver/csiplugin/connectors/connectors.go +++ b/driver/csiplugin/connectors/connectors.go @@ -43,7 +43,7 @@ type SpectrumScaleConnector interface { DeleteFileset(ctx context.Context, filesystemName string, filesetName string) error //LinkFileset(filesystemName string, filesetName string) error LinkFileset(ctx context.Context, filesystemName string, filesetName string, linkpath string) error - UnlinkFileset(ctx context.Context, filesystemName string, filesetName string) error + UnlinkFileset(ctx context.Context, filesystemName string, filesetName string, force bool) error //ListFilesets(filesystemName string) ([]resources.Volume, error) ListFileset(ctx context.Context, filesystemName string, filesetName string) (Fileset_v2, error) ListCSIIndependentFilesets(ctx context.Context, filesystemName string) ([]Fileset_v2, error) diff --git a/driver/csiplugin/connectors/rest_v2.go b/driver/csiplugin/connectors/rest_v2.go index 3dcf684f1..f3a8d4f4e 100644 --- a/driver/csiplugin/connectors/rest_v2.go +++ b/driver/csiplugin/connectors/rest_v2.go @@ -35,7 +35,7 @@ import ( const errConnectionRefused string = "connection refused" const errNoSuchHost string = "no such host" -const errContextDeadlineExceeded string = "context deadline exceeded" +const errContextDeadlineExceeded string = "context deadline exceeded" var GetLoggerId = utils.GetLoggerId @@ -657,10 +657,15 @@ func (s *SpectrumRestV2) LinkFileset(ctx context.Context, filesystemName string, return nil } -func (s *SpectrumRestV2) UnlinkFileset(ctx context.Context, filesystemName string, filesetName string) error { +func (s *SpectrumRestV2) UnlinkFileset(ctx context.Context, filesystemName string, filesetName string, force bool) error { klog.V(4).Infof("[%s] rest_v2 UnlinkFileset. filesystem: %s, fileset: %s", utils.GetLoggerId(ctx), filesystemName, filesetName) - unlinkFilesetURL := fmt.Sprintf("scalemgmt/v2/filesystems/%s/filesets/%s/link?force=True", filesystemName, filesetName) + var unlinkFilesetURL string + if force { + unlinkFilesetURL = fmt.Sprintf("scalemgmt/v2/filesystems/%s/filesets/%s/link?force=True", filesystemName, filesetName) + } else { + unlinkFilesetURL = fmt.Sprintf("scalemgmt/v2/filesystems/%s/filesets/%s/link", filesystemName, filesetName) + } unlinkFilesetResponse := GenericResponse{} err := s.doHTTP(ctx, unlinkFilesetURL, "DELETE", &unlinkFilesetResponse, nil) @@ -1039,7 +1044,7 @@ func (s *SpectrumRestV2) doHTTP(ctx context.Context, urlSuffix string, method st activeEndpointFound := false if err != nil { - if strings.Contains(err.Error(), errConnectionRefused) || strings.Contains(err.Error(), errNoSuchHost) || strings.Contains(err.Error(), errContextDeadlineExceeded){ + if strings.Contains(err.Error(), errConnectionRefused) || strings.Contains(err.Error(), errNoSuchHost) || strings.Contains(err.Error(), errContextDeadlineExceeded) { klog.Errorf("[%s] rest_v2 doHTTP: Error in connecting to GUI endpoint %s: %v, checking next endpoint", utils.GetLoggerId(ctx), endpoint, err) // Out of n endpoints, one has failed already, so loop over the // remaining n-1 endpoints till we get an active GUI endpoint. diff --git a/driver/csiplugin/controllerserver.go b/driver/csiplugin/controllerserver.go index 2dde839a1..f70f92414 100644 --- a/driver/csiplugin/controllerserver.go +++ b/driver/csiplugin/controllerserver.go @@ -50,6 +50,9 @@ const ( discoverCGFileset = "DISCOVER_CG_FILESET" discoverCGFilesetDisabled = "DISABLED" + + fsetLinkNotFoundErrCode = "EFSSG0449C" + fsetLinkNotFoundErrMsg = "is not linked" ) type ScaleControllerServer struct { @@ -1648,7 +1651,18 @@ func (cs *ScaleControllerServer) DeleteFilesetVol(ctx context.Context, Filesyste klog.Infof("[%s] there is no snapshot present in the fileset [%v], continue DeleteFilesetVol", loggerId, FilesetName) } - err := conn.DeleteFileset(ctx, FilesystemName, FilesetName) + err := conn.UnlinkFileset(ctx, FilesystemName, FilesetName, false) + if err != nil { + if strings.Contains(err.Error(), fsetLinkNotFoundErrCode) || + strings.Contains(err.Error(), fsetLinkNotFoundErrMsg) { // fileset seems to be already unlinked + klog.V(4).Infof("[%s] fileset seems to be already unlinked - %v", loggerId, err) + //return true, nil + } 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 { if strings.Contains(err.Error(), "EFSSG0072C") || strings.Contains(err.Error(), "400 Invalid value in 'filesetName'") { // fileset is already deleted