From 90ecd2d7e84449288529b2884164b612c26b106c Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 7 Oct 2021 10:27:17 +0530 Subject: [PATCH] rbd: use go-ceph to get mirroring info use go-ceph api to get image mirroring info. closes #2558 Signed-off-by: Madhu Rajanna --- internal/rbd/rbd_util.go | 51 +++------------------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 0cc663c54..1f963108d 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -481,12 +481,12 @@ func (rv *rbdVolume) isInUse() (bool, error) { return false, err } - // TODO replace this with logic to get mirroring information once - // https://github.com/ceph/go-ceph/issues/379 is fixed - err = rv.updateVolWithImageInfo() + mirrorInfo, err := image.GetMirrorImageInfo() if err != nil { return false, err } + rv.Primary = mirrorInfo.Primary + // because we opened the image, there is at least one watcher defaultWatchers := 1 if rv.Primary { @@ -1463,51 +1463,6 @@ func (rv *rbdVolume) getImageInfo() error { return nil } -// imageInfo strongly typed JSON spec for image info. -type imageInfo struct { - Mirroring mirroring `json:"mirroring"` -} - -// parentInfo spec for parent volume info. -type mirroring struct { - Primary bool `json:"primary"` -} - -// updateVolWithImageInfo updates provided rbdVolume with information from on-disk data -// regarding the same. -func (rv *rbdVolume) updateVolWithImageInfo() error { - // rbd --format=json info [image-spec | snap-spec] - var imgInfo imageInfo - - stdout, stderr, err := util.ExecCommand( - context.TODO(), - "rbd", - "-m", rv.Monitors, - "--id", rv.conn.Creds.ID, - "--keyfile="+rv.conn.Creds.KeyFile, - "-c", util.CephConfigPath, - "--format="+"json", - "info", rv.String()) - if err != nil { - if strings.Contains(stderr, "rbd: error opening image "+rv.RbdImageName+ - ": (2) No such file or directory") { - return util.JoinErrors(ErrImageNotFound, err) - } - - return err - } - - if stdout != "" { - err = json.Unmarshal([]byte(stdout), &imgInfo) - if err != nil { - return fmt.Errorf("unmarshal failed (%w), raw buffer response: %s", err, stdout) - } - rv.Primary = imgInfo.Mirroring.Primary - } - - return nil -} - /* checkSnapExists queries rbd about the snapshots of the given image and returns ErrImageNotFound if provided image is not found, and ErrSnapNotFound if