From 71dbc7dbb45d771e4885efef8535708c76f6a453 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 5 Sep 2022 10:41:37 +0530 Subject: [PATCH] rbd: map only primary image If the image is mirroring enabled and primary consider it for mapping, if the image is mirroring enabled but not primary yet. return error message until the image is marked as primary. Signed-off-by: Madhu Rajanna --- internal/rbd/rbd_util.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 398557318..d32c4d391 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -138,8 +138,6 @@ type rbdImage struct { // an opened IOContext, call .openIoctx() before using ioctx *rados.IOContext - // Primary represent if the image is primary or not. - Primary bool // Set metadata on volume EnableMetadata bool } @@ -512,6 +510,10 @@ func (ri *rbdImage) open() (*librbd.Image, error) { // isInUse checks if there is a watcher on the image. It returns true if there // is a watcher on the image, otherwise returns false. +// In case of mirroring, the image should be primary to check watchers if the +// image is secondary it returns an error. +// isInUse is called with exponential backoff to check the image is used by +// anyone else the returned bool value is discarded if its a RWX access. func (ri *rbdImage) isInUse() (bool, error) { image, err := ri.open() if err != nil { @@ -532,11 +534,16 @@ func (ri *rbdImage) isInUse() (bool, error) { if err != nil { return false, err } - ri.Primary = mirrorInfo.Primary + + if mirrorInfo.State == librbd.MirrorImageEnabled && !mirrorInfo.Primary { + // Mapping secondary image can cause issues.returning error as the + // bool value is discarded if it its RWX access. + return false, fmt.Errorf("cannot map image %s it is not primary", ri) + } // because we opened the image, there is at least one watcher defaultWatchers := 1 - if ri.Primary { + if mirrorInfo.Primary { // if rbd mirror daemon is running, a watcher will be added by the rbd // mirror daemon for mirrored images. defaultWatchers++