mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
rbd: use go-ceph to get mirroring info
use go-ceph api to get image mirroring info. closes #2558 Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
b9beb2106b
commit
90ecd2d7e8
@ -481,12 +481,12 @@ func (rv *rbdVolume) isInUse() (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO replace this with logic to get mirroring information once
|
mirrorInfo, err := image.GetMirrorImageInfo()
|
||||||
// https://github.com/ceph/go-ceph/issues/379 is fixed
|
|
||||||
err = rv.updateVolWithImageInfo()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
rv.Primary = mirrorInfo.Primary
|
||||||
|
|
||||||
// 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 rv.Primary {
|
if rv.Primary {
|
||||||
@ -1463,51 +1463,6 @@ func (rv *rbdVolume) getImageInfo() error {
|
|||||||
return nil
|
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
|
checkSnapExists queries rbd about the snapshots of the given image and returns
|
||||||
ErrImageNotFound if provided image is not found, and ErrSnapNotFound if
|
ErrImageNotFound if provided image is not found, and ErrSnapNotFound if
|
||||||
|
Loading…
Reference in New Issue
Block a user