From 4442465fcf10e9590aac52e7abba2edc9275f685 Mon Sep 17 00:00:00 2001 From: Praveen M Date: Mon, 3 Mar 2025 13:49:08 +0530 Subject: [PATCH] rbd: check for volume group existence Signed-off-by: Praveen M (cherry picked from commit 8d9f353f15674bd4831e44eae298fc4948286395) # Conflicts: # internal/rbd/group/util.go --- internal/rbd/group/util.go | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/internal/rbd/group/util.go b/internal/rbd/group/util.go index d2e62bee3..350ba016d 100644 --- a/internal/rbd/group/util.go +++ b/internal/rbd/group/util.go @@ -64,6 +64,7 @@ type commonVolumeGroup struct { journal journal.VolumeGroupJournal } +<<<<<<< HEAD func (cvg *commonVolumeGroup) initCommonVolumeGroup( ctx context.Context, id string, @@ -76,6 +77,10 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup( return fmt.Errorf("failed to decompose volume group id %q: %w", id, err) } +======= +// generateVolumeGroup generates a commonVolumeGroup structure from the volumeGroup identifier. +func (cvg *commonVolumeGroup) generateVolumeGroup(ctx context.Context, csiID util.CSIIdentifier) error { +>>>>>>> 8d9f353f (rbd: check for volume group existence) mons, err := util.Mons(util.CsiConfigFile, csiID.ClusterID) if err != nil { return fmt.Errorf("failed to get MONs for cluster id %q: %w", csiID.ClusterID, err) @@ -98,16 +103,25 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup( cvg.namespace = namespace cvg.pool = pool + // Check if the volume group exists in the journal. + _, err = cvg.getVolumeGroupAttributes(ctx) + if err != nil { + return err + } + return nil } // generateVolumeGroupFromMapping checks the clusterID and poolID mapping and // generates commonVolumeGroup structure for the mapped clusterID and poolID. +// If the mapping is not found, it returns ErrGroupNotFound. func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping( ctx context.Context, csiID util.CSIIdentifier, mapping *[]util.ClusterMappingInfo, ) error { + var volumeGroupGenerationError error + mcsiID := csiID existingClusterID := csiID.ClusterID existingPoolID := strconv.FormatInt(csiID.LocationID, 10) @@ -138,18 +152,18 @@ func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping( return err } mcsiID.LocationID = mPID - err = cvg.generateVolumeGroup(mcsiID) - if ShouldRetryVolumeGroupGeneration(err) { - continue + volumeGroupGenerationError = cvg.generateVolumeGroup(ctx, mcsiID) + if !ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) { + return volumeGroupGenerationError } - return err + log.DebugLog(ctx, "volume group not found for poolID mapping %s: %v", cvg.id, mappedPoolID) } } } } - return util.ErrPoolNotFound + return rbderrors.ErrGroupNotFound } func (cvg *commonVolumeGroup) initCommonVolumeGroup( @@ -158,6 +172,7 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup( csiDriver string, creds *util.Credentials, ) error { + var volumeGroupGenerationError error csiID := util.CSIIdentifier{} err := csiID.DecomposeCSIID(id) @@ -178,15 +193,15 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup( ======= // cvg.monitors, cvg.namespace, cvg.pool are set in generateVolumeGroup - err = cvg.generateVolumeGroup(csiID) + volumeGroupGenerationError = cvg.generateVolumeGroup(ctx, csiID) // If the error is not a retryable error, return from here. - if err != nil && !ShouldRetryVolumeGroupGeneration(err) { - return err + if volumeGroupGenerationError != nil && !ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) { + return volumeGroupGenerationError } - // If the error is a retryable error, we should try to get the cluster mapping - // and generate the volume group from the mapping. - if ShouldRetryVolumeGroupGeneration(err) { + // If Volume Group doesn't exists or the error is a retryable error, + // we should try to get the cluster mapping and generate the volume group from the mapping. + if ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) { mapping, err := util.GetClusterMappingInfo(csiID.ClusterID) if err != nil { return err @@ -443,7 +458,7 @@ func (cvg *commonVolumeGroup) GetCreationTime(ctx context.Context) (*time.Time, // // It checks if the given error matches any of the following known errors: // - ErrPoolNotFound: The rbd pool where the volumegroup/omap is expected doesn't exist. -// - ErrRBDGroupNotFound: The volumegroup doesn't exist in the rbd pool. +// - ErrGroupNotFound: The volumegroup doesn't exist in the rbd pool. // - rados.ErrPermissionDenied: Permissions to access the pool is denied. // // If any of these errors are encountered, the function returns `true`, indicating