mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
rbd: make replication operations as rbdImage methods
added replication related operations as a method of rbdImage as these methods can be easily used when we introduce volumesnaphot mirroring operations. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
c822ad460d
commit
233954bc10
@ -27,88 +27,88 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// enableImageMirroring enables mirroring on an image.
|
// enableImageMirroring enables mirroring on an image.
|
||||||
func (rv *rbdVolume) enableImageMirroring(mode librbd.ImageMirrorMode) error {
|
func (ri *rbdImage) enableImageMirroring(mode librbd.ImageMirrorMode) error {
|
||||||
image, err := rv.open()
|
image, err := ri.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open image %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
defer image.Close()
|
defer image.Close()
|
||||||
|
|
||||||
err = image.MirrorEnable(mode)
|
err = image.MirrorEnable(mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to enable mirroring on %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to enable mirroring on %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// disableImageMirroring disables mirroring on an image.
|
// disableImageMirroring disables mirroring on an image.
|
||||||
func (rv *rbdVolume) disableImageMirroring(force bool) error {
|
func (ri *rbdImage) disableImageMirroring(force bool) error {
|
||||||
image, err := rv.open()
|
image, err := ri.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open image %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
defer image.Close()
|
defer image.Close()
|
||||||
|
|
||||||
err = image.MirrorDisable(force)
|
err = image.MirrorDisable(force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to disable mirroring on %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to disable mirroring on %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getImageMirroringInfo gets mirroring information of an image.
|
// getImageMirroringInfo gets mirroring information of an image.
|
||||||
func (rv *rbdVolume) getImageMirroringInfo() (*librbd.MirrorImageInfo, error) {
|
func (ri *rbdImage) getImageMirroringInfo() (*librbd.MirrorImageInfo, error) {
|
||||||
image, err := rv.open()
|
image, err := ri.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open image %q with error: %w", rv.String(), err)
|
return nil, fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
defer image.Close()
|
defer image.Close()
|
||||||
|
|
||||||
info, err := image.GetMirrorImageInfo()
|
info, err := image.GetMirrorImageInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get mirroring info of %q with error: %w", rv.String(), err)
|
return nil, fmt.Errorf("failed to get mirroring info of %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// promoteImage promotes image to primary.
|
// promoteImage promotes image to primary.
|
||||||
func (rv *rbdVolume) promoteImage(force bool) error {
|
func (ri *rbdImage) promoteImage(force bool) error {
|
||||||
image, err := rv.open()
|
image, err := ri.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open image %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
defer image.Close()
|
defer image.Close()
|
||||||
err = image.MirrorPromote(force)
|
err = image.MirrorPromote(force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to promote image %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to promote image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// demoteImage demotes image to secondary.
|
// demoteImage demotes image to secondary.
|
||||||
func (rv *rbdVolume) demoteImage() error {
|
func (ri *rbdImage) demoteImage() error {
|
||||||
image, err := rv.open()
|
image, err := ri.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open image %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
defer image.Close()
|
defer image.Close()
|
||||||
err = image.MirrorDemote()
|
err = image.MirrorDemote()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to demote image %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to demote image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// resyncImage resync image to correct the split-brain.
|
// resyncImage resync image to correct the split-brain.
|
||||||
func (rv *rbdVolume) resyncImage() error {
|
func (ri *rbdImage) resyncImage() error {
|
||||||
image, err := rv.open()
|
image, err := ri.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open image %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
defer image.Close()
|
defer image.Close()
|
||||||
err = image.MirrorResync()
|
err = image.MirrorResync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to resync image %q with error: %w", rv.String(), err)
|
return fmt.Errorf("failed to resync image %q with error: %w", ri.String(), err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -122,23 +122,23 @@ type imageMirrorStatus struct {
|
|||||||
|
|
||||||
// FIXME: once https://github.com/ceph/go-ceph/issues/460 is fixed use go-ceph.
|
// FIXME: once https://github.com/ceph/go-ceph/issues/460 is fixed use go-ceph.
|
||||||
// getImageMirroingStatus get the mirroring status of an image.
|
// getImageMirroingStatus get the mirroring status of an image.
|
||||||
func (rv *rbdVolume) getImageMirroingStatus() (*imageMirrorStatus, error) {
|
func (ri *rbdImage) getImageMirroingStatus() (*imageMirrorStatus, error) {
|
||||||
// rbd mirror image status --format=json info [image-spec | snap-spec]
|
// rbd mirror image status --format=json info [image-spec | snap-spec]
|
||||||
var imgStatus imageMirrorStatus
|
var imgStatus imageMirrorStatus
|
||||||
stdout, stderr, err := util.ExecCommand(
|
stdout, stderr, err := util.ExecCommand(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
"rbd",
|
"rbd",
|
||||||
"-m", rv.Monitors,
|
"-m", ri.Monitors,
|
||||||
"--id", rv.conn.Creds.ID,
|
"--id", ri.conn.Creds.ID,
|
||||||
"--keyfile="+rv.conn.Creds.KeyFile,
|
"--keyfile="+ri.conn.Creds.KeyFile,
|
||||||
"-c", util.CephConfigPath,
|
"-c", util.CephConfigPath,
|
||||||
"--format="+"json",
|
"--format="+"json",
|
||||||
"mirror",
|
"mirror",
|
||||||
"image",
|
"image",
|
||||||
"status",
|
"status",
|
||||||
rv.String())
|
ri.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(stderr, "rbd: error opening image "+rv.RbdImageName+
|
if strings.Contains(stderr, "rbd: error opening image "+ri.RbdImageName+
|
||||||
": (2) No such file or directory") {
|
": (2) No such file or directory") {
|
||||||
return nil, util.JoinErrors(ErrImageNotFound, err)
|
return nil, util.JoinErrors(ErrImageNotFound, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user