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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2022-09-05 10:41:37 +05:30 committed by mergify[bot]
parent 9a54f05e66
commit 71dbc7dbb4

View File

@ -138,8 +138,6 @@ type rbdImage struct {
// an opened IOContext, call .openIoctx() before using // an opened IOContext, call .openIoctx() before using
ioctx *rados.IOContext ioctx *rados.IOContext
// Primary represent if the image is primary or not.
Primary bool
// Set metadata on volume // Set metadata on volume
EnableMetadata bool 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 // isInUse checks if there is a watcher on the image. It returns true if there
// is a watcher on the image, otherwise returns false. // 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) { func (ri *rbdImage) isInUse() (bool, error) {
image, err := ri.open() image, err := ri.open()
if err != nil { if err != nil {
@ -532,11 +534,16 @@ func (ri *rbdImage) isInUse() (bool, error) {
if err != nil { if err != nil {
return false, err 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 // because we opened the image, there is at least one watcher
defaultWatchers := 1 defaultWatchers := 1
if ri.Primary { if mirrorInfo.Primary {
// if rbd mirror daemon is running, a watcher will be added by the rbd // if rbd mirror daemon is running, a watcher will be added by the rbd
// mirror daemon for mirrored images. // mirror daemon for mirrored images.
defaultWatchers++ defaultWatchers++