mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rbd: add context to mirror interface
adding required ctx to the mirror interface as ctx is required for the volumegroup operations. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
8788e5ec08
commit
37970ae212
@ -988,7 +988,7 @@ func (cs *ControllerServer) DeleteVolume(
|
||||
func cleanupRBDImage(ctx context.Context,
|
||||
rbdVol *rbdVolume, cr *util.Credentials,
|
||||
) (*csi.DeleteVolumeResponse, error) {
|
||||
info, err := rbdVol.GetMirroringInfo()
|
||||
info, err := rbdVol.GetMirroringInfo(ctx)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, err.Error())
|
||||
|
||||
@ -1007,7 +1007,7 @@ func cleanupRBDImage(ctx context.Context,
|
||||
// the image on all the remote (secondary) clusters will get
|
||||
// auto-deleted. This helps in garbage collecting the OMAP, PVC and PV
|
||||
// objects after failback operation.
|
||||
sts, rErr := rbdVol.GetGlobalMirroringStatus()
|
||||
sts, rErr := rbdVol.GetGlobalMirroringStatus(ctx)
|
||||
if rErr != nil {
|
||||
return nil, status.Error(codes.Internal, rErr.Error())
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func (rv *rbdVolume) HandleParentImageExistence(
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get parent of image %s: %w", rv, err)
|
||||
}
|
||||
parentMirroringInfo, err := parent.GetMirroringInfo()
|
||||
parentMirroringInfo, err := parent.GetMirroringInfo(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"failed to get mirroring info of parent %q of image %q: %w",
|
||||
@ -82,7 +82,7 @@ func (rv *rbdVolume) HandleParentImageExistence(
|
||||
var _ types.Mirror = &rbdVolume{}
|
||||
|
||||
// EnableMirroring enables mirroring on an image.
|
||||
func (ri *rbdImage) EnableMirroring(mode librbd.ImageMirrorMode) error {
|
||||
func (ri *rbdImage) EnableMirroring(_ context.Context, mode librbd.ImageMirrorMode) error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
@ -98,7 +98,7 @@ func (ri *rbdImage) EnableMirroring(mode librbd.ImageMirrorMode) error {
|
||||
}
|
||||
|
||||
// DisableMirroring disables mirroring on an image.
|
||||
func (ri *rbdImage) DisableMirroring(force bool) error {
|
||||
func (ri *rbdImage) DisableMirroring(_ context.Context, force bool) error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
@ -114,7 +114,7 @@ func (ri *rbdImage) DisableMirroring(force bool) error {
|
||||
}
|
||||
|
||||
// GetMirroringInfo gets mirroring information of an image.
|
||||
func (ri *rbdImage) GetMirroringInfo() (types.MirrorInfo, error) {
|
||||
func (ri *rbdImage) GetMirroringInfo(_ context.Context) (types.MirrorInfo, error) {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
@ -130,7 +130,7 @@ func (ri *rbdImage) GetMirroringInfo() (types.MirrorInfo, error) {
|
||||
}
|
||||
|
||||
// Promote promotes image to primary.
|
||||
func (ri *rbdImage) Promote(force bool) error {
|
||||
func (ri *rbdImage) Promote(_ context.Context, force bool) error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
@ -147,7 +147,7 @@ func (ri *rbdImage) Promote(force bool) error {
|
||||
// ForcePromote promotes image to primary with force option with 2 minutes
|
||||
// timeout. If there is no response within 2 minutes,the rbd CLI process will be
|
||||
// killed and an error is returned.
|
||||
func (rv *rbdVolume) ForcePromote(cr *util.Credentials) error {
|
||||
func (rv *rbdVolume) ForcePromote(ctx context.Context, cr *util.Credentials) error {
|
||||
promoteArgs := []string{
|
||||
"mirror", "image", "promote",
|
||||
rv.String(),
|
||||
@ -157,7 +157,7 @@ func (rv *rbdVolume) ForcePromote(cr *util.Credentials) error {
|
||||
"--keyfile=" + cr.KeyFile,
|
||||
}
|
||||
_, stderr, err := util.ExecCommandWithTimeout(
|
||||
context.TODO(),
|
||||
ctx,
|
||||
// 2 minutes timeout as the Replication RPC timeout is 2.5 minutes.
|
||||
2*time.Minute,
|
||||
"rbd",
|
||||
@ -175,7 +175,7 @@ func (rv *rbdVolume) ForcePromote(cr *util.Credentials) error {
|
||||
}
|
||||
|
||||
// Demote demotes image to secondary.
|
||||
func (ri *rbdImage) Demote() error {
|
||||
func (ri *rbdImage) Demote(_ context.Context) error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
@ -190,7 +190,7 @@ func (ri *rbdImage) Demote() error {
|
||||
}
|
||||
|
||||
// Resync resync image to correct the split-brain.
|
||||
func (ri *rbdImage) Resync() error {
|
||||
func (ri *rbdImage) Resync(_ context.Context) error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
@ -208,7 +208,7 @@ func (ri *rbdImage) Resync() error {
|
||||
}
|
||||
|
||||
// GetGlobalMirroringStatus get the mirroring status of an image.
|
||||
func (ri *rbdImage) GetGlobalMirroringStatus() (types.GlobalStatus, error) {
|
||||
func (ri *rbdImage) GetGlobalMirroringStatus(_ context.Context) (types.GlobalStatus, error) {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
|
@ -46,6 +46,7 @@ func (rv *rbdVolume) RepairResyncedImageID(ctx context.Context, ready bool) erro
|
||||
}
|
||||
|
||||
func DisableVolumeReplication(mirror types.Mirror,
|
||||
ctx context.Context,
|
||||
primary,
|
||||
force bool,
|
||||
) error {
|
||||
@ -62,7 +63,7 @@ func DisableVolumeReplication(mirror types.Mirror,
|
||||
// disabled the image on all the remote (secondary) clusters will get
|
||||
// auto-deleted. This helps in garbage collecting the volume
|
||||
// replication Kubernetes artifacts after failback operation.
|
||||
sts, rErr := mirror.GetGlobalMirroringStatus()
|
||||
sts, rErr := mirror.GetGlobalMirroringStatus(ctx)
|
||||
if rErr != nil {
|
||||
return fmt.Errorf("failed to get global state: %w", rErr)
|
||||
}
|
||||
@ -78,13 +79,13 @@ func DisableVolumeReplication(mirror types.Mirror,
|
||||
return fmt.Errorf("%w: secondary image status is up=%t and state=%s",
|
||||
ErrInvalidArgument, localStatus.IsUP(), localStatus.GetState())
|
||||
}
|
||||
err := mirror.DisableMirroring(force)
|
||||
err := mirror.DisableMirroring(ctx, force)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to disable image mirroring: %w", err)
|
||||
}
|
||||
// the image state can be still disabling once we disable the mirroring
|
||||
// check the mirroring is disabled or not
|
||||
info, err := mirror.GetMirroringInfo()
|
||||
info, err := mirror.GetMirroringInfo(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get mirroring info of image: %w", err)
|
||||
}
|
||||
|
@ -39,21 +39,21 @@ const (
|
||||
// Mirror is the interface for managing mirroring on an RBD image or a group.
|
||||
type Mirror interface {
|
||||
// EnableMirroring enables mirroring on the resource with the specified mode.
|
||||
EnableMirroring(mode librbd.ImageMirrorMode) error
|
||||
EnableMirroring(ctx context.Context, mode librbd.ImageMirrorMode) error
|
||||
// DisableMirroring disables mirroring on the resource with the option to force the operation
|
||||
DisableMirroring(force bool) error
|
||||
DisableMirroring(ctx context.Context, force bool) error
|
||||
// Promote promotes the resource to primary status with the option to force the operation
|
||||
Promote(force bool) error
|
||||
Promote(ctx context.Context, force bool) error
|
||||
// ForcePromote promotes the resource to primary status with a timeout
|
||||
ForcePromote(cr *util.Credentials) error
|
||||
ForcePromote(ctx context.Context, cr *util.Credentials) error
|
||||
// Demote demotes the resource to secondary status
|
||||
Demote() error
|
||||
Demote(ctx context.Context) error
|
||||
// Resync resynchronizes the resource
|
||||
Resync() error
|
||||
Resync(ctx context.Context) error
|
||||
// GetMirroringInfo returns the mirroring information of the resource
|
||||
GetMirroringInfo() (MirrorInfo, error)
|
||||
GetMirroringInfo(ctx context.Context) (MirrorInfo, error)
|
||||
// GetMirroringInfo returns the mirroring information of the resource
|
||||
GetGlobalMirroringStatus() (GlobalStatus, error)
|
||||
GetGlobalMirroringStatus(ctx context.Context) (GlobalStatus, error)
|
||||
// AddSnapshotScheduling adds a snapshot scheduling to the resource
|
||||
AddSnapshotScheduling(interval admin.Interval, startTime admin.StartTime) error
|
||||
}
|
||||
|
Reference in New Issue
Block a user