mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-03-06 07:29:29 +00:00
rbd: check for volume group existence
Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
parent
c1b3325677
commit
c429894704
@ -91,11 +91,18 @@ func (cvg *commonVolumeGroup) generateVolumeGroup(csiID util.CSIIdentifier) erro
|
|||||||
|
|
||||||
// generateVolumeGroupFromMapping checks the clusterID and poolID mapping and
|
// generateVolumeGroupFromMapping checks the clusterID and poolID mapping and
|
||||||
// generates commonVolumeGroup structure for the mapped clusterID and poolID.
|
// generates commonVolumeGroup structure for the mapped clusterID and poolID.
|
||||||
|
// If the mapping is not found, it returns ErrRBDGroupNotFound.
|
||||||
func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping(
|
func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
csiID util.CSIIdentifier,
|
csiID util.CSIIdentifier,
|
||||||
mapping *[]util.ClusterMappingInfo,
|
mapping *[]util.ClusterMappingInfo,
|
||||||
) error {
|
) error {
|
||||||
|
var (
|
||||||
|
volumeGroupGenerationError error
|
||||||
|
volumeGroupExistsError error
|
||||||
|
volumeGroupExists bool
|
||||||
|
)
|
||||||
|
|
||||||
mcsiID := csiID
|
mcsiID := csiID
|
||||||
existingClusterID := csiID.ClusterID
|
existingClusterID := csiID.ClusterID
|
||||||
existingPoolID := strconv.FormatInt(csiID.LocationID, 10)
|
existingPoolID := strconv.FormatInt(csiID.LocationID, 10)
|
||||||
@ -126,18 +133,27 @@ func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mcsiID.LocationID = mPID
|
mcsiID.LocationID = mPID
|
||||||
err = cvg.generateVolumeGroup(mcsiID)
|
volumeGroupGenerationError = cvg.generateVolumeGroup(mcsiID)
|
||||||
if ShouldRetryVolumeGroupGeneration(err) {
|
if volumeGroupGenerationError == nil {
|
||||||
|
// Check if the volume group exists in the journal.
|
||||||
|
volumeGroupExists, volumeGroupExistsError = cvg.Exists(ctx)
|
||||||
|
if !errors.Is(volumeGroupExistsError, rbd_errors.ErrRBDGroupNotFound) {
|
||||||
|
return volumeGroupExistsError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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 !volumeGroupExists || ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return volumeGroupGenerationError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return util.ErrPoolNotFound
|
return volumeGroupGenerationError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cvg *commonVolumeGroup) initCommonVolumeGroup(
|
func (cvg *commonVolumeGroup) initCommonVolumeGroup(
|
||||||
@ -146,6 +162,11 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
|
|||||||
csiDriver string,
|
csiDriver string,
|
||||||
creds *util.Credentials,
|
creds *util.Credentials,
|
||||||
) error {
|
) error {
|
||||||
|
var (
|
||||||
|
volumeGroupGenerationError error
|
||||||
|
volumeGroupExistsError error
|
||||||
|
volumeGroupExists bool
|
||||||
|
)
|
||||||
csiID := util.CSIIdentifier{}
|
csiID := util.CSIIdentifier{}
|
||||||
|
|
||||||
err := csiID.DecomposeCSIID(id)
|
err := csiID.DecomposeCSIID(id)
|
||||||
@ -160,15 +181,21 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
|
|||||||
cvg.objectUUID = csiID.ObjectUUID
|
cvg.objectUUID = csiID.ObjectUUID
|
||||||
// cvg.monitors, cvg.namespace, cvg.pool are set in generateVolumeGroup
|
// cvg.monitors, cvg.namespace, cvg.pool are set in generateVolumeGroup
|
||||||
|
|
||||||
err = cvg.generateVolumeGroup(csiID)
|
volumeGroupGenerationError = cvg.generateVolumeGroup(csiID)
|
||||||
// If the error is not a retryable error, return from here.
|
// If the error is not a retryable error, return from here.
|
||||||
if err != nil && !ShouldRetryVolumeGroupGeneration(err) {
|
if volumeGroupGenerationError != nil && !ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
|
||||||
return err
|
return volumeGroupGenerationError
|
||||||
|
} else {
|
||||||
|
// Check if the volume group exists in the journal.
|
||||||
|
volumeGroupExists, volumeGroupExistsError = cvg.Exists(ctx)
|
||||||
|
if !errors.Is(volumeGroupExistsError, rbd_errors.ErrRBDGroupNotFound) {
|
||||||
|
return volumeGroupExistsError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the error is a retryable error, we should try to get the cluster mapping
|
// If Volume Group doesn't exists or the error is a retryable error,
|
||||||
// and generate the volume group from the mapping.
|
// we should try to get the cluster mapping and generate the volume group from the mapping.
|
||||||
if ShouldRetryVolumeGroupGeneration(err) {
|
if !volumeGroupExists || ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
|
||||||
mapping, err := util.GetClusterMappingInfo(csiID.ClusterID)
|
mapping, err := util.GetClusterMappingInfo(csiID.ClusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -443,3 +470,13 @@ func ShouldRetryVolumeGroupGeneration(err error) bool {
|
|||||||
errors.Is(err, rbd_errors.ErrRBDGroupNotFound) ||
|
errors.Is(err, rbd_errors.ErrRBDGroupNotFound) ||
|
||||||
errors.Is(err, rados.ErrPermissionDenied))
|
errors.Is(err, rados.ErrPermissionDenied))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exists checks if the volume group exists in the journal.
|
||||||
|
func (cvg *commonVolumeGroup) Exists(ctx context.Context) (bool, error) {
|
||||||
|
_, err := cvg.getVolumeGroupAttributes(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
@ -73,4 +73,7 @@ type VolumeGroup interface {
|
|||||||
// The Snapshots are crash consistent, and created as a consistency
|
// The Snapshots are crash consistent, and created as a consistency
|
||||||
// group.
|
// group.
|
||||||
CreateSnapshots(ctx context.Context, cr *util.Credentials, name string) ([]Snapshot, error)
|
CreateSnapshots(ctx context.Context, cr *util.Credentials, name string) ([]Snapshot, error)
|
||||||
|
|
||||||
|
// Exists checks if the volume group exists in the journal.
|
||||||
|
Exists(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user