mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: update go-ceph to v0.8.0
Updating go-ceph to v0.8.0. Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
e6098520d1
commit
32d78c4f7f
258
vendor/github.com/ceph/go-ceph/rbd/group.go
generated
vendored
Normal file
258
vendor/github.com/ceph/go-ceph/rbd/group.go
generated
vendored
Normal file
@ -0,0 +1,258 @@
|
||||
package rbd
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -lrbd
|
||||
#include <stdlib.h>
|
||||
#include <rbd/librbd.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/internal/cutil"
|
||||
"github.com/ceph/go-ceph/internal/retry"
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
// GroupCreate is used to create an image group.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_create(rados_ioctx_t p, const char *name);
|
||||
func GroupCreate(ioctx *rados.IOContext, name string) error {
|
||||
cName := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cName))
|
||||
|
||||
ret := C.rbd_group_create(cephIoctx(ioctx), cName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupRemove is used to remove an image group.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_remove(rados_ioctx_t p, const char *name);
|
||||
func GroupRemove(ioctx *rados.IOContext, name string) error {
|
||||
cName := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cName))
|
||||
|
||||
ret := C.rbd_group_remove(cephIoctx(ioctx), cName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupRename will rename an existing image group.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_rename(rados_ioctx_t p, const char *src_name,
|
||||
// const char *dest_name);
|
||||
func GroupRename(ioctx *rados.IOContext, src, dest string) error {
|
||||
cSrc := C.CString(src)
|
||||
defer C.free(unsafe.Pointer(cSrc))
|
||||
cDest := C.CString(dest)
|
||||
defer C.free(unsafe.Pointer(cDest))
|
||||
|
||||
ret := C.rbd_group_rename(cephIoctx(ioctx), cSrc, cDest)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupList returns a slice of image group names.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_list(rados_ioctx_t p, char *names, size_t *size);
|
||||
func GroupList(ioctx *rados.IOContext) ([]string, error) {
|
||||
var (
|
||||
buf []byte
|
||||
err error
|
||||
ret C.int
|
||||
)
|
||||
retry.WithSizes(1024, 262144, func(size int) retry.Hint {
|
||||
cSize := C.size_t(size)
|
||||
buf = make([]byte, cSize)
|
||||
ret = C.rbd_group_list(
|
||||
cephIoctx(ioctx),
|
||||
(*C.char)(unsafe.Pointer(&buf[0])),
|
||||
&cSize)
|
||||
err = getErrorIfNegative(ret)
|
||||
return retry.Size(int(cSize)).If(err == errRange)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// cSize is not set to the expected size when it is sufficiently large
|
||||
// but ret will be set to the size in a non-error condition.
|
||||
groups := cutil.SplitBuffer(buf[:ret])
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
// GroupImageAdd will add the specified image to the named group.
|
||||
// An io context must be supplied for both the group and image.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_image_add(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// rados_ioctx_t image_p,
|
||||
// const char *image_name);
|
||||
func GroupImageAdd(groupIoctx *rados.IOContext, groupName string,
|
||||
imageIoctx *rados.IOContext, imageName string) error {
|
||||
|
||||
cGroupName := C.CString(groupName)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
cImageName := C.CString(imageName)
|
||||
defer C.free(unsafe.Pointer(cImageName))
|
||||
|
||||
ret := C.rbd_group_image_add(
|
||||
cephIoctx(groupIoctx),
|
||||
cGroupName,
|
||||
cephIoctx(imageIoctx),
|
||||
cImageName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupImageRemove will remove the specified image from the named group.
|
||||
// An io context must be supplied for both the group and image.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_image_remove(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// rados_ioctx_t image_p,
|
||||
// const char *image_name);
|
||||
func GroupImageRemove(groupIoctx *rados.IOContext, groupName string,
|
||||
imageIoctx *rados.IOContext, imageName string) error {
|
||||
|
||||
cGroupName := C.CString(groupName)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
cImageName := C.CString(imageName)
|
||||
defer C.free(unsafe.Pointer(cImageName))
|
||||
|
||||
ret := C.rbd_group_image_remove(
|
||||
cephIoctx(groupIoctx),
|
||||
cGroupName,
|
||||
cephIoctx(imageIoctx),
|
||||
cImageName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupImageRemoveByID will remove the specified image from the named group.
|
||||
// An io context must be supplied for both the group and image.
|
||||
//
|
||||
// Implements:
|
||||
// CEPH_RBD_API int rbd_group_image_remove_by_id(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// rados_ioctx_t image_p,
|
||||
// const char *image_id);
|
||||
func GroupImageRemoveByID(groupIoctx *rados.IOContext, groupName string,
|
||||
imageIoctx *rados.IOContext, imageID string) error {
|
||||
|
||||
cGroupName := C.CString(groupName)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
cid := C.CString(imageID)
|
||||
defer C.free(unsafe.Pointer(cid))
|
||||
|
||||
ret := C.rbd_group_image_remove_by_id(
|
||||
cephIoctx(groupIoctx),
|
||||
cGroupName,
|
||||
cephIoctx(imageIoctx),
|
||||
cid)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupImageState indicates an image's state in a group.
|
||||
type GroupImageState int
|
||||
|
||||
const (
|
||||
// GroupImageStateAttached is equivalent to RBD_GROUP_IMAGE_STATE_ATTACHED
|
||||
GroupImageStateAttached = GroupImageState(C.RBD_GROUP_IMAGE_STATE_ATTACHED)
|
||||
// GroupImageStateIncomplete is equivalent to RBD_GROUP_IMAGE_STATE_INCOMPLETE
|
||||
GroupImageStateIncomplete = GroupImageState(C.RBD_GROUP_IMAGE_STATE_INCOMPLETE)
|
||||
)
|
||||
|
||||
// GroupImageInfo reports on images within a group.
|
||||
type GroupImageInfo struct {
|
||||
Name string
|
||||
PoolID int64
|
||||
State GroupImageState
|
||||
}
|
||||
|
||||
// GroupImageList returns a slice of GroupImageInfo types based on the
|
||||
// images that are part of the named group.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_image_list(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// rbd_group_image_info_t *images,
|
||||
// size_t group_image_info_size,
|
||||
// size_t *num_entries);
|
||||
func GroupImageList(ioctx *rados.IOContext, name string) ([]GroupImageInfo, error) {
|
||||
cName := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cName))
|
||||
|
||||
var (
|
||||
cImages []C.rbd_group_image_info_t
|
||||
cSize C.size_t
|
||||
err error
|
||||
)
|
||||
retry.WithSizes(1024, 262144, func(size int) retry.Hint {
|
||||
cSize = C.size_t(size)
|
||||
cImages = make([]C.rbd_group_image_info_t, cSize)
|
||||
ret := C.rbd_group_image_list(
|
||||
cephIoctx(ioctx),
|
||||
cName,
|
||||
(*C.rbd_group_image_info_t)(unsafe.Pointer(&cImages[0])),
|
||||
C.sizeof_rbd_group_image_info_t,
|
||||
&cSize)
|
||||
err = getErrorIfNegative(ret)
|
||||
return retry.Size(int(cSize)).If(err == errRange)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
images := make([]GroupImageInfo, cSize)
|
||||
for i := range images {
|
||||
images[i].Name = C.GoString(cImages[i].name)
|
||||
images[i].PoolID = int64(cImages[i].pool)
|
||||
images[i].State = GroupImageState(cImages[i].state)
|
||||
}
|
||||
|
||||
// free C memory allocated by C.rbd_group_image_list call
|
||||
ret := C.rbd_group_image_list_cleanup(
|
||||
(*C.rbd_group_image_info_t)(unsafe.Pointer(&cImages[0])),
|
||||
C.sizeof_rbd_group_image_info_t,
|
||||
cSize)
|
||||
return images, getError(ret)
|
||||
}
|
||||
|
||||
// GroupInfo contains the name and pool id of a RBD group.
|
||||
type GroupInfo struct {
|
||||
Name string
|
||||
PoolID int64
|
||||
}
|
||||
|
||||
// GetGroup returns group info for the group this image is part of.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_get_group(rbd_image_t image, rbd_group_info_t *group_info,
|
||||
// size_t group_info_size);
|
||||
func (image *Image) GetGroup() (GroupInfo, error) {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return GroupInfo{}, err
|
||||
}
|
||||
|
||||
var cgi C.rbd_group_info_t
|
||||
ret := C.rbd_get_group(
|
||||
image.image,
|
||||
&cgi,
|
||||
C.sizeof_rbd_group_info_t)
|
||||
if err := getErrorIfNegative(ret); err != nil {
|
||||
return GroupInfo{}, err
|
||||
}
|
||||
|
||||
gi := GroupInfo{
|
||||
Name: C.GoString(cgi.name),
|
||||
PoolID: int64(cgi.pool),
|
||||
}
|
||||
ret = C.rbd_group_info_cleanup(&cgi, C.sizeof_rbd_group_info_t)
|
||||
return gi, getError(ret)
|
||||
}
|
223
vendor/github.com/ceph/go-ceph/rbd/group_snap.go
generated
vendored
Normal file
223
vendor/github.com/ceph/go-ceph/rbd/group_snap.go
generated
vendored
Normal file
@ -0,0 +1,223 @@
|
||||
package rbd
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -lrbd
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <rbd/librbd.h>
|
||||
|
||||
extern int snapRollbackCallback(uint64_t, uint64_t, uintptr_t);
|
||||
|
||||
// inline wrapper to cast uintptr_t to void*
|
||||
static inline int wrap_rbd_group_snap_rollback_with_progress(
|
||||
rados_ioctx_t group_p, const char *group_name,
|
||||
const char *snap_name, uintptr_t arg) {
|
||||
return rbd_group_snap_rollback_with_progress(
|
||||
group_p, group_name, snap_name, (librbd_progress_fn_t)snapRollbackCallback, (void*)arg);
|
||||
};
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/internal/callbacks"
|
||||
"github.com/ceph/go-ceph/internal/retry"
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
// GroupSnapCreate will create a group snapshot.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_snap_create(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// const char *snap_name);
|
||||
func GroupSnapCreate(ioctx *rados.IOContext, group, snap string) error {
|
||||
cGroupName := C.CString(group)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
cSnapName := C.CString(snap)
|
||||
defer C.free(unsafe.Pointer(cSnapName))
|
||||
|
||||
ret := C.rbd_group_snap_create(cephIoctx(ioctx), cGroupName, cSnapName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupSnapRemove removes an existing group snapshot.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_snap_remove(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// const char *snap_name);
|
||||
func GroupSnapRemove(ioctx *rados.IOContext, group, snap string) error {
|
||||
cGroupName := C.CString(group)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
cSnapName := C.CString(snap)
|
||||
defer C.free(unsafe.Pointer(cSnapName))
|
||||
|
||||
ret := C.rbd_group_snap_remove(cephIoctx(ioctx), cGroupName, cSnapName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupSnapRename will rename an existing group snapshot.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_snap_rename(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// const char *old_snap_name,
|
||||
// const char *new_snap_name);
|
||||
func GroupSnapRename(ioctx *rados.IOContext, group, src, dest string) error {
|
||||
cGroupName := C.CString(group)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
cOldSnapName := C.CString(src)
|
||||
defer C.free(unsafe.Pointer(cOldSnapName))
|
||||
cNewSnapName := C.CString(dest)
|
||||
defer C.free(unsafe.Pointer(cNewSnapName))
|
||||
|
||||
ret := C.rbd_group_snap_rename(
|
||||
cephIoctx(ioctx), cGroupName, cOldSnapName, cNewSnapName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupSnapState represents the state of a group snapshot in GroupSnapInfo.
|
||||
type GroupSnapState int
|
||||
|
||||
const (
|
||||
// GroupSnapStateIncomplete is equivalent to RBD_GROUP_SNAP_STATE_INCOMPLETE.
|
||||
GroupSnapStateIncomplete = GroupSnapState(C.RBD_GROUP_SNAP_STATE_INCOMPLETE)
|
||||
// GroupSnapStateComplete is equivalent to RBD_GROUP_SNAP_STATE_COMPLETE.
|
||||
GroupSnapStateComplete = GroupSnapState(C.RBD_GROUP_SNAP_STATE_COMPLETE)
|
||||
)
|
||||
|
||||
// GroupSnapInfo values are returned by GroupSnapList, representing the
|
||||
// snapshots that are part of an rbd group.
|
||||
type GroupSnapInfo struct {
|
||||
Name string
|
||||
State GroupSnapState
|
||||
}
|
||||
|
||||
// GroupSnapList returns a slice of snapshots in a group.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_snap_list(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// rbd_group_snap_info_t *snaps,
|
||||
// size_t group_snap_info_size,
|
||||
// size_t *num_entries);
|
||||
func GroupSnapList(ioctx *rados.IOContext, group string) ([]GroupSnapInfo, error) {
|
||||
cGroupName := C.CString(group)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
|
||||
var (
|
||||
cSnaps []C.rbd_group_snap_info_t
|
||||
cSize C.size_t
|
||||
err error
|
||||
)
|
||||
retry.WithSizes(1024, 262144, func(size int) retry.Hint {
|
||||
cSize = C.size_t(size)
|
||||
cSnaps = make([]C.rbd_group_snap_info_t, cSize)
|
||||
ret := C.rbd_group_snap_list(
|
||||
cephIoctx(ioctx),
|
||||
cGroupName,
|
||||
(*C.rbd_group_snap_info_t)(unsafe.Pointer(&cSnaps[0])),
|
||||
C.sizeof_rbd_group_snap_info_t,
|
||||
&cSize)
|
||||
err = getErrorIfNegative(ret)
|
||||
return retry.Size(int(cSize)).If(err == errRange)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
snaps := make([]GroupSnapInfo, cSize)
|
||||
for i := range snaps {
|
||||
snaps[i].Name = C.GoString(cSnaps[i].name)
|
||||
snaps[i].State = GroupSnapState(cSnaps[i].state)
|
||||
}
|
||||
|
||||
// free C memory allocated by C.rbd_group_snap_list call
|
||||
ret := C.rbd_group_snap_list_cleanup(
|
||||
(*C.rbd_group_snap_info_t)(unsafe.Pointer(&cSnaps[0])),
|
||||
C.sizeof_rbd_group_snap_info_t,
|
||||
cSize)
|
||||
return snaps, getError(ret)
|
||||
}
|
||||
|
||||
// GroupSnapRollback will roll back the images in the group to that of the
|
||||
// given snapshot.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_snap_rollback(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// const char *snap_name);
|
||||
func GroupSnapRollback(ioctx *rados.IOContext, group, snap string) error {
|
||||
cGroupName := C.CString(group)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
cSnapName := C.CString(snap)
|
||||
defer C.free(unsafe.Pointer(cSnapName))
|
||||
|
||||
ret := C.rbd_group_snap_rollback(cephIoctx(ioctx), cGroupName, cSnapName)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GroupSnapRollbackCallback defines the function signature needed for the
|
||||
// GroupSnapRollbackWithProgress callback.
|
||||
//
|
||||
// This callback will be called by GroupSnapRollbackWithProgress when it
|
||||
// wishes to report progress rolling back a group snapshot.
|
||||
type GroupSnapRollbackCallback func(uint64, uint64, interface{}) int
|
||||
|
||||
var groupSnapRollbackCallbacks = callbacks.New()
|
||||
|
||||
// GroupSnapRollbackWithProgress will roll back the images in the group
|
||||
// to that of given snapshot. The given progress callback will be called
|
||||
// to report on the progress of the snapshot rollback.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_group_snap_rollback_with_progress(rados_ioctx_t group_p,
|
||||
// const char *group_name,
|
||||
// const char *snap_name,
|
||||
// librbd_progress_fn_t cb,
|
||||
// void *cbdata);
|
||||
func GroupSnapRollbackWithProgress(
|
||||
ioctx *rados.IOContext, group, snap string,
|
||||
cb GroupSnapRollbackCallback, data interface{}) error {
|
||||
// the provided callback must be a real function
|
||||
if cb == nil {
|
||||
return rbdError(C.EINVAL)
|
||||
}
|
||||
|
||||
cGroupName := C.CString(group)
|
||||
defer C.free(unsafe.Pointer(cGroupName))
|
||||
cSnapName := C.CString(snap)
|
||||
defer C.free(unsafe.Pointer(cSnapName))
|
||||
|
||||
ctx := gsnapRollbackCallbackCtx{
|
||||
callback: cb,
|
||||
data: data,
|
||||
}
|
||||
cbIndex := groupSnapRollbackCallbacks.Add(ctx)
|
||||
defer diffIterateCallbacks.Remove(cbIndex)
|
||||
|
||||
ret := C.wrap_rbd_group_snap_rollback_with_progress(
|
||||
cephIoctx(ioctx),
|
||||
cGroupName,
|
||||
cSnapName,
|
||||
C.uintptr_t(cbIndex))
|
||||
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
type gsnapRollbackCallbackCtx struct {
|
||||
callback GroupSnapRollbackCallback
|
||||
data interface{}
|
||||
}
|
||||
|
||||
//export snapRollbackCallback
|
||||
func snapRollbackCallback(
|
||||
offset, total C.uint64_t, index uintptr) C.int {
|
||||
|
||||
v := groupSnapRollbackCallbacks.Lookup(index)
|
||||
ctx := v.(gsnapRollbackCallbackCtx)
|
||||
return C.int(ctx.callback(uint64(offset), uint64(total), ctx.data))
|
||||
}
|
235
vendor/github.com/ceph/go-ceph/rbd/mirror.go
generated
vendored
Normal file
235
vendor/github.com/ceph/go-ceph/rbd/mirror.go
generated
vendored
Normal file
@ -0,0 +1,235 @@
|
||||
// +build !nautilus
|
||||
|
||||
// Initially, we're only providing mirroring related functions for octopus as
|
||||
// that version of ceph deprecated a number of the functions in nautilus. If
|
||||
// you need mirroring on an earlier supported version of ceph please file an
|
||||
// issue in our tracker.
|
||||
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// #include <stdlib.h>
|
||||
// #include <rbd/librbd.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/internal/retry"
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
// MirrorMode is used to indicate an approach used for RBD mirroring.
|
||||
type MirrorMode int64
|
||||
|
||||
const (
|
||||
// MirrorModeDisabled disables mirroring.
|
||||
MirrorModeDisabled = MirrorMode(C.RBD_MIRROR_MODE_DISABLED)
|
||||
// MirrorModeImage enables mirroring on a per-image basis.
|
||||
MirrorModeImage = MirrorMode(C.RBD_MIRROR_MODE_IMAGE)
|
||||
// MirrorModePool enables mirroring on all journaled images.
|
||||
MirrorModePool = MirrorMode(C.RBD_MIRROR_MODE_POOL)
|
||||
)
|
||||
|
||||
// ImageMirrorMode is used to indicate the mirroring approach for an RBD image.
|
||||
type ImageMirrorMode int64
|
||||
|
||||
const (
|
||||
// ImageMirrorModeJournal uses journaling to propagate RBD images between
|
||||
// ceph clusters.
|
||||
ImageMirrorModeJournal = ImageMirrorMode(C.RBD_MIRROR_IMAGE_MODE_JOURNAL)
|
||||
// ImageMirrorModeSnapshot uses snapshots to propagate RBD images between
|
||||
// ceph clusters.
|
||||
ImageMirrorModeSnapshot = ImageMirrorMode(C.RBD_MIRROR_IMAGE_MODE_SNAPSHOT)
|
||||
)
|
||||
|
||||
// SetMirrorMode is used to enable or disable pool level mirroring with either
|
||||
// an automatic or per-image behavior.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_mode_set(rados_ioctx_t io_ctx,
|
||||
// rbd_mirror_mode_t mirror_mode);
|
||||
func SetMirrorMode(ioctx *rados.IOContext, mode MirrorMode) error {
|
||||
ret := C.rbd_mirror_mode_set(
|
||||
cephIoctx(ioctx),
|
||||
C.rbd_mirror_mode_t(mode))
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// GetMirrorMode is used to fetch the current mirroring mode for a pool.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_mode_get(rados_ioctx_t io_ctx,
|
||||
// rbd_mirror_mode_t *mirror_mode);
|
||||
func GetMirrorMode(ioctx *rados.IOContext) (MirrorMode, error) {
|
||||
var mode C.rbd_mirror_mode_t
|
||||
|
||||
ret := C.rbd_mirror_mode_get(
|
||||
cephIoctx(ioctx),
|
||||
&mode)
|
||||
if err := getError(ret); err != nil {
|
||||
return MirrorModeDisabled, err
|
||||
}
|
||||
return MirrorMode(mode), nil
|
||||
}
|
||||
|
||||
// MirrorEnable will enable mirroring for an image using the specified mode.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_enable2(rbd_image_t image,
|
||||
// rbd_mirror_image_mode_t mode);
|
||||
func (image *Image) MirrorEnable(mode ImageMirrorMode) error {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
ret := C.rbd_mirror_image_enable2(image.image, C.rbd_mirror_image_mode_t(mode))
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// MirrorDisable will disable mirroring for the image.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_disable(rbd_image_t image, bool force);
|
||||
func (image *Image) MirrorDisable(force bool) error {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
ret := C.rbd_mirror_image_disable(image.image, C.bool(force))
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// MirrorPromote will promote the image to primary status.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_promote(rbd_image_t image, bool force);
|
||||
func (image *Image) MirrorPromote(force bool) error {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
ret := C.rbd_mirror_image_promote(image.image, C.bool(force))
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// MirrorDemote will demote the image to secondary status.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_demote(rbd_image_t image);
|
||||
func (image *Image) MirrorDemote() error {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
ret := C.rbd_mirror_image_demote(image.image)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// MirrorResync is used to manually resolve split-brain status by triggering
|
||||
// resynchronization.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_resync(rbd_image_t image);
|
||||
func (image *Image) MirrorResync() error {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
ret := C.rbd_mirror_image_resync(image.image)
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// MirrorInstanceID returns a string naming the instance id for the image.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_get_instance_id(rbd_image_t image,
|
||||
// char *instance_id,
|
||||
// size_t *id_max_length);
|
||||
func (image *Image) MirrorInstanceID() (string, error) {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var (
|
||||
err error
|
||||
buf []byte
|
||||
cSize C.size_t
|
||||
)
|
||||
retry.WithSizes(1024, 1<<16, func(size int) retry.Hint {
|
||||
cSize = C.size_t(size)
|
||||
buf = make([]byte, cSize)
|
||||
ret := C.rbd_mirror_image_get_instance_id(
|
||||
image.image,
|
||||
(*C.char)(unsafe.Pointer(&buf[0])),
|
||||
&cSize)
|
||||
err = getErrorIfNegative(ret)
|
||||
return retry.Size(int(cSize)).If(err == errRange)
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(buf[:cSize]), nil
|
||||
}
|
||||
|
||||
// MirrorImageState represents the mirroring state of a RBD image.
|
||||
type MirrorImageState C.rbd_mirror_image_state_t
|
||||
|
||||
const (
|
||||
// MirrorImageDisabling is the representation of
|
||||
// RBD_MIRROR_IMAGE_DISABLING from librbd.
|
||||
MirrorImageDisabling = MirrorImageState(C.RBD_MIRROR_IMAGE_DISABLING)
|
||||
// MirrorImageEnabled is the representation of
|
||||
// RBD_MIRROR_IMAGE_ENABLED from librbd.
|
||||
MirrorImageEnabled = MirrorImageState(C.RBD_MIRROR_IMAGE_ENABLED)
|
||||
// MirrorImageDisabled is the representation of
|
||||
// RBD_MIRROR_IMAGE_DISABLED from librbd.
|
||||
MirrorImageDisabled = MirrorImageState(C.RBD_MIRROR_IMAGE_DISABLED)
|
||||
)
|
||||
|
||||
// MirrorImageInfo represents the mirroring status information of a RBD image.
|
||||
type MirrorImageInfo struct {
|
||||
GlobalID string
|
||||
State MirrorImageState
|
||||
Primary bool
|
||||
}
|
||||
|
||||
// GetMirrorImageInfo fetches the mirroring status information of a RBD image.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_get_info(rbd_image_t image,
|
||||
// rbd_mirror_image_info_t *mirror_image_info,
|
||||
// size_t info_size)
|
||||
func (image *Image) GetMirrorImageInfo() (*MirrorImageInfo, error) {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cInfo C.rbd_mirror_image_info_t
|
||||
|
||||
ret := C.rbd_mirror_image_get_info(
|
||||
image.image,
|
||||
&cInfo,
|
||||
C.sizeof_rbd_mirror_image_info_t)
|
||||
if ret < 0 {
|
||||
return nil, getError(ret)
|
||||
}
|
||||
|
||||
mii := MirrorImageInfo{
|
||||
GlobalID: C.GoString(cInfo.global_id),
|
||||
State: MirrorImageState(cInfo.state),
|
||||
Primary: bool(cInfo.primary),
|
||||
}
|
||||
|
||||
// free C memory allocated by C.rbd_mirror_image_get_info call
|
||||
C.rbd_mirror_image_get_info_cleanup(&cInfo)
|
||||
return &mii, nil
|
||||
}
|
||||
|
||||
// GetImageMirrorMode fetches the mirroring approach for an RBD image.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_get_mode(rbd_image_t image, rbd_mirror_image_mode_t *mode);
|
||||
func (image *Image) GetImageMirrorMode() (ImageMirrorMode, error) {
|
||||
var mode C.rbd_mirror_image_mode_t
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return ImageMirrorMode(mode), err
|
||||
}
|
||||
|
||||
ret := C.rbd_mirror_image_get_mode(image.image, &mode)
|
||||
return ImageMirrorMode(mode), getError(ret)
|
||||
}
|
6
vendor/github.com/ceph/go-ceph/rbd/rbd.go
generated
vendored
6
vendor/github.com/ceph/go-ceph/rbd/rbd.go
generated
vendored
@ -95,7 +95,11 @@ type TrashInfo struct {
|
||||
|
||||
// cephIoctx returns a ceph rados_ioctx_t given a go-ceph rados IOContext.
|
||||
func cephIoctx(radosIoctx *rados.IOContext) C.rados_ioctx_t {
|
||||
return C.rados_ioctx_t(radosIoctx.Pointer())
|
||||
p := radosIoctx.Pointer()
|
||||
if p == nil {
|
||||
panic("invalid IOContext pointer")
|
||||
}
|
||||
return C.rados_ioctx_t(p)
|
||||
}
|
||||
|
||||
// test if a bit is set in the given value
|
||||
|
Reference in New Issue
Block a user