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