Skip to content

Commit d1c31f3

Browse files
black-dragon74mergify[bot]
authored andcommitted
rbd: open image as read-only for get calls
Signed-off-by: Niraj Yadav <niryadav@redhat.com> (cherry picked from commit 6148377)
1 parent 32b8908 commit d1c31f3

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

internal/rbd/rbd_util.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func (ri *rbdImage) getImageID() error {
529529
if ri.ImageID != "" {
530530
return nil
531531
}
532-
image, err := ri.open()
532+
image, err := ri.openReadOnly()
533533
if err != nil {
534534
return err
535535
}
@@ -635,7 +635,7 @@ func (ri *rbdImage) openReadOnly() (*librbd.Image, error) {
635635
// isInUse is called with exponential backoff to check the image is used by
636636
// anyone else the returned bool value is discarded if its a RWX access.
637637
func (ri *rbdImage) isInUse() (bool, error) {
638-
image, err := ri.open()
638+
image, err := ri.openReadOnly()
639639
if err != nil {
640640
if errors.Is(err, rbderrors.ErrImageNotFound) || errors.Is(err, util.ErrPoolNotFound) {
641641
return false, err
@@ -661,8 +661,8 @@ func (ri *rbdImage) isInUse() (bool, error) {
661661
return false, fmt.Errorf("cannot map image %s it is not primary", ri)
662662
}
663663

664-
// because we opened the image, there is at least one watcher
665-
defaultWatchers := 1
664+
// openReadOnly does not register a watcher on the image
665+
defaultWatchers := 0
666666
if mirrorInfo.Primary {
667667
count, err := util.GetRBDMirrorDaemonCount(util.CsiConfigFile, ri.ClusterID)
668668
if err != nil {
@@ -1788,7 +1788,7 @@ func (ri *rbdImage) GetCreationTime(ctx context.Context) (*time.Time, error) {
17881788
// getImageInfo queries rbd about the given image and returns its metadata, and returns
17891789
// ErrImageNotFound if provided image is not found.
17901790
func (ri *rbdImage) getImageInfo() error {
1791-
image, err := ri.open()
1791+
image, err := ri.openReadOnly()
17921792
if err != nil {
17931793
return err
17941794
}
@@ -2061,7 +2061,7 @@ func (ri *rbdImage) resize(newSize int64) error {
20612061
}
20622062

20632063
func (ri *rbdImage) GetMetadata(key string) (string, error) {
2064-
image, err := ri.open()
2064+
image, err := ri.openReadOnly()
20652065
if err != nil {
20662066
return "", err
20672067
}

0 commit comments

Comments
 (0)