Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for snapshot metadata from fileset to filesystem for sc version2 #1072

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
31 changes: 26 additions & 5 deletions driver/csiplugin/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const (

discoverCGFileset = "DISCOVER_CG_FILESET"
discoverCGFilesetDisabled = "DISABLED"

snapshotReferencePath = ".csi" // will be pathToPrimaryFilesystem/.csi
)

type ScaleControllerServer struct {
Expand Down Expand Up @@ -2333,7 +2335,7 @@ func (cs *ScaleControllerServer) CheckNewSnapRequired(ctx context.Context, conn

func (cs *ScaleControllerServer) MakeSnapMetadataDir(ctx context.Context, conn connectors.SpectrumScaleConnector, filesystemName string, filesetName string, indepFileset string, cgSnapName string, metaSnapName string) error {
loggerId := utils.GetLoggerId(ctx)
path := fmt.Sprintf("%s/%s/%s", indepFileset, cgSnapName, metaSnapName)
path := fmt.Sprintf("%s/%s/%s/%s", snapshotReferencePath, indepFileset, cgSnapName, metaSnapName)
klog.Infof("[%s] MakeSnapMetadataDir - creating directory [%s] for fileset: [%s:%s]", loggerId, path, filesystemName, filesetName)
err := conn.MakeDirectory(ctx, filesystemName, path, "0", "0")
if err != nil {
Expand Down Expand Up @@ -2645,8 +2647,23 @@ func (cs *ScaleControllerServer) isExistingSnapUseableForVol(ctx context.Context

func (cs *ScaleControllerServer) DelSnapMetadataDir(ctx context.Context, conn connectors.SpectrumScaleConnector, filesystemName string, consistencyGroup string, filesetName string, cgSnapName string, metaSnapName string) (bool, error) {
loggerId := utils.GetLoggerId(ctx)
pathDir := fmt.Sprintf("%s/%s/%s", consistencyGroup, cgSnapName, metaSnapName)
err := conn.DeleteDirectory(ctx, filesystemName, pathDir, false)

// Check if the snapshot was created earlier at fileset level i.e. mountfs/cg-ns/snapshotpath
pathDir := fmt.Sprintf("%s/%s", consistencyGroup, cgSnapName)

snapExistsUnderFileset, err := conn.CheckIfFileDirPresent(ctx, filesystemName, pathDir)
if err != nil {
return false, status.Error(codes.Internal, fmt.Sprintf("unable to check if snapMetadir created under filset [%s] at path [%s] exists or not. Error [%v]", filesystemName, pathDir, err))
}
klog.Infof("[%s] DelSnapMetadataDir - snapExistsUnderFileset=%s", loggerId, snapExistsUnderFileset)

if snapExistsUnderFileset {
pathDir = fmt.Sprintf("%s/%s/%s", consistencyGroup, cgSnapName, metaSnapName)
} else {
pathDir = fmt.Sprintf("%s/%s/%s/%s", snapshotReferencePath, consistencyGroup, cgSnapName, metaSnapName)
}
klog.Infof("[%s] DelSnapMetadataDir - deleting directory [%s] for fileset: [%s:%s]", loggerId, pathDir, filesystemName, filesetName)
err = conn.DeleteDirectory(ctx, filesystemName, pathDir, false)
if err != nil {
if !(strings.Contains(err.Error(), "EFSSG0264C") ||
strings.Contains(err.Error(), "does not exist")) { // directory is already deleted
Expand All @@ -2655,7 +2672,11 @@ func (cs *ScaleControllerServer) DelSnapMetadataDir(ctx context.Context, conn co
}

// Now check if consistency group snapshot metadata directory can be deleted
pathDir = fmt.Sprintf("%s/%s", consistencyGroup, cgSnapName)
if snapExistsUnderFileset {
pathDir = fmt.Sprintf("%s/%s", consistencyGroup, cgSnapName)
} else {
pathDir = fmt.Sprintf("%s/%s/%s", snapshotReferencePath, consistencyGroup, cgSnapName)
}
statInfo, err := conn.StatDirectory(ctx, filesystemName, pathDir)
if err != nil {
if !(strings.Contains(err.Error(), "EFSSG0264C") ||
Expand Down Expand Up @@ -2720,7 +2741,7 @@ func (cs *ScaleControllerServer) DeleteSnapshot(ctx context.Context, req *csi.De
klog.Errorf("[%s] Invalid snapshot ID %s [%v]", loggerId, snapID, err)
return nil, err
}

klog.Infof("[%s] DeleteSnapshot - snapIdMembers : [%v]", loggerId, snapIdMembers)
conn, err := cs.getConnFromClusterID(ctx, snapIdMembers.ClusterId)
if err != nil {
return nil, err
Expand Down