mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
dep: add github.com/ceph/go-ceph for rbd API
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
3226b17d08
commit
ba99275f90
4
vendor/github.com/ceph/go-ceph/rbd/doc.go
generated
vendored
Normal file
4
vendor/github.com/ceph/go-ceph/rbd/doc.go
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/*
|
||||
Package rbd contains a set of wrappers around Ceph's librbd API.
|
||||
*/
|
||||
package rbd
|
169
vendor/github.com/ceph/go-ceph/rbd/options.go
generated
vendored
Normal file
169
vendor/github.com/ceph/go-ceph/rbd/options.go
generated
vendored
Normal file
@ -0,0 +1,169 @@
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// #include <stdlib.h>
|
||||
// #include <rbd/librbd.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
// RBD image options.
|
||||
RbdImageOptionFormat = C.RBD_IMAGE_OPTION_FORMAT
|
||||
RbdImageOptionFeatures = C.RBD_IMAGE_OPTION_FEATURES
|
||||
RbdImageOptionOrder = C.RBD_IMAGE_OPTION_ORDER
|
||||
RbdImageOptionStripeUnit = C.RBD_IMAGE_OPTION_STRIPE_UNIT
|
||||
RbdImageOptionStripeCount = C.RBD_IMAGE_OPTION_STRIPE_COUNT
|
||||
RbdImageOptionJournalOrder = C.RBD_IMAGE_OPTION_JOURNAL_ORDER
|
||||
RbdImageOptionJournalSplayWidth = C.RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH
|
||||
RbdImageOptionJournalPool = C.RBD_IMAGE_OPTION_JOURNAL_POOL
|
||||
RbdImageOptionFeaturesSet = C.RBD_IMAGE_OPTION_FEATURES_SET
|
||||
RbdImageOptionFeaturesClear = C.RBD_IMAGE_OPTION_FEATURES_CLEAR
|
||||
RbdImageOptionDataPool = C.RBD_IMAGE_OPTION_DATA_POOL
|
||||
// introduced with Ceph Mimic
|
||||
//RbdImageOptionFlatten = C.RBD_IMAGE_OPTION_FLATTEN
|
||||
)
|
||||
|
||||
type RbdImageOptions struct {
|
||||
options C.rbd_image_options_t
|
||||
}
|
||||
|
||||
type RbdImageOption C.int
|
||||
|
||||
// NewRbdImageOptions creates a new RbdImageOptions struct. Call
|
||||
// RbdImageOptions.Destroy() to free the resources.
|
||||
//
|
||||
// Implements:
|
||||
// void rbd_image_options_create(rbd_image_options_t* opts)
|
||||
func NewRbdImageOptions() *RbdImageOptions {
|
||||
rio := &RbdImageOptions{}
|
||||
C.rbd_image_options_create(&rio.options)
|
||||
return rio
|
||||
}
|
||||
|
||||
// Destroy a RbdImageOptions struct and free the associated resources.
|
||||
//
|
||||
// Implements:
|
||||
// void rbd_image_options_destroy(rbd_image_options_t opts);
|
||||
func (rio *RbdImageOptions) Destroy() {
|
||||
C.rbd_image_options_destroy(rio.options)
|
||||
}
|
||||
|
||||
// SetString sets the value of the RbdImageOption to the given string.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_image_options_set_string(rbd_image_options_t opts, int optname,
|
||||
// const char* optval);
|
||||
func (rio *RbdImageOptions) SetString(option RbdImageOption, value string) error {
|
||||
c_value := C.CString(value)
|
||||
defer C.free(unsafe.Pointer(c_value))
|
||||
|
||||
ret := C.rbd_image_options_set_string(rio.options, C.int(option), c_value)
|
||||
if ret != 0 {
|
||||
return fmt.Errorf("%v, could not set option %v to \"%v\"",
|
||||
getError(ret), option, value)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetString returns the string value of the RbdImageOption.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_image_options_get_string(rbd_image_options_t opts, int optname,
|
||||
// char* optval, size_t maxlen);
|
||||
func (rio *RbdImageOptions) GetString(option RbdImageOption) (string, error) {
|
||||
value := make([]byte, 4096)
|
||||
|
||||
ret := C.rbd_image_options_get_string(rio.options, C.int(option),
|
||||
(*C.char)(unsafe.Pointer(&value[0])),
|
||||
C.size_t(len(value)))
|
||||
if ret != 0 {
|
||||
return "", fmt.Errorf("%v, could not get option %v", getError(ret), option)
|
||||
}
|
||||
|
||||
return C.GoString((*C.char)(unsafe.Pointer(&value[0]))), nil
|
||||
}
|
||||
|
||||
// SetUint64 sets the value of the RbdImageOption to the given uint64.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_image_options_set_uint64(rbd_image_options_t opts, int optname,
|
||||
// const uint64_t optval);
|
||||
func (rio *RbdImageOptions) SetUint64(option RbdImageOption, value uint64) error {
|
||||
c_value := C.uint64_t(value)
|
||||
|
||||
ret := C.rbd_image_options_set_uint64(rio.options, C.int(option), c_value)
|
||||
if ret != 0 {
|
||||
return fmt.Errorf("%v, could not set option %v to \"%v\"",
|
||||
getError(ret), option, value)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUint64 returns the uint64 value of the RbdImageOption.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_image_options_get_uint64(rbd_image_options_t opts, int optname,
|
||||
// uint64_t* optval);
|
||||
func (rio *RbdImageOptions) GetUint64(option RbdImageOption) (uint64, error) {
|
||||
var c_value C.uint64_t
|
||||
|
||||
ret := C.rbd_image_options_get_uint64(rio.options, C.int(option), &c_value)
|
||||
if ret != 0 {
|
||||
return 0, fmt.Errorf("%v, could not get option %v", getError(ret), option)
|
||||
}
|
||||
|
||||
return uint64(c_value), nil
|
||||
}
|
||||
|
||||
// IsSet returns a true if the RbdImageOption is set, false otherwise.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_image_options_is_set(rbd_image_options_t opts, int optname,
|
||||
// bool* is_set);
|
||||
func (rio *RbdImageOptions) IsSet(option RbdImageOption) (bool, error) {
|
||||
var c_set C.bool
|
||||
|
||||
ret := C.rbd_image_options_is_set(rio.options, C.int(option), &c_set)
|
||||
if ret != 0 {
|
||||
return false, fmt.Errorf("%v, could not check option %v", getError(ret), option)
|
||||
}
|
||||
|
||||
return bool(c_set), nil
|
||||
}
|
||||
|
||||
// Unset a given RbdImageOption.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_image_options_unset(rbd_image_options_t opts, int optname)
|
||||
func (rio *RbdImageOptions) Unset(option RbdImageOption) error {
|
||||
ret := C.rbd_image_options_unset(rio.options, C.int(option))
|
||||
if ret != 0 {
|
||||
return fmt.Errorf("%v, could not unset option %v", getError(ret), option)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Clear all options in the RbdImageOptions.
|
||||
//
|
||||
// Implements:
|
||||
// void rbd_image_options_clear(rbd_image_options_t opts)
|
||||
func (rio *RbdImageOptions) Clear() {
|
||||
C.rbd_image_options_clear(rio.options)
|
||||
}
|
||||
|
||||
// IsEmpty returns true if there are no options set in the RbdImageOptions,
|
||||
// false otherwise.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_image_options_is_empty(rbd_image_options_t opts)
|
||||
func (rio *RbdImageOptions) IsEmpty() bool {
|
||||
ret := C.rbd_image_options_is_empty(rio.options)
|
||||
return ret != 0
|
||||
}
|
1403
vendor/github.com/ceph/go-ceph/rbd/rbd.go
generated
vendored
Normal file
1403
vendor/github.com/ceph/go-ceph/rbd/rbd.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
43
vendor/github.com/ceph/go-ceph/rbd/rbd_mimic.go
generated
vendored
Normal file
43
vendor/github.com/ceph/go-ceph/rbd/rbd_mimic.go
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// +build luminous mimic
|
||||
// +build !nautilus
|
||||
//
|
||||
// Ceph Nautilus includes rbd_list2() and marked rbd_list() deprecated.
|
||||
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// #include <rados/librados.h>
|
||||
// #include <rbd/librbd.h>
|
||||
// #include <errno.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
// GetImageNames returns the list of current RBD images.
|
||||
func GetImageNames(ioctx *rados.IOContext) (names []string, err error) {
|
||||
buf := make([]byte, 4096)
|
||||
for {
|
||||
size := C.size_t(len(buf))
|
||||
ret := C.rbd_list(C.rados_ioctx_t(ioctx.Pointer()),
|
||||
(*C.char)(unsafe.Pointer(&buf[0])), &size)
|
||||
if ret == -C.ERANGE {
|
||||
buf = make([]byte, size)
|
||||
continue
|
||||
} else if ret < 0 {
|
||||
return nil, RBDError(ret)
|
||||
}
|
||||
tmp := bytes.Split(buf[:size-1], []byte{0})
|
||||
for _, s := range tmp {
|
||||
if len(s) > 0 {
|
||||
name := C.GoString((*C.char)(unsafe.Pointer(&s[0])))
|
||||
names = append(names, name)
|
||||
}
|
||||
}
|
||||
return names, nil
|
||||
}
|
||||
}
|
45
vendor/github.com/ceph/go-ceph/rbd/rbd_nautilus.go
generated
vendored
Normal file
45
vendor/github.com/ceph/go-ceph/rbd/rbd_nautilus.go
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// +build !luminous,!mimic
|
||||
//
|
||||
// Ceph Nautilus is the first release that includes rbd_list2().
|
||||
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// #include <rados/librados.h>
|
||||
// #include <rbd/librbd.h>
|
||||
// #include <errno.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
// GetImageNames returns the list of current RBD images.
|
||||
func GetImageNames(ioctx *rados.IOContext) ([]string, error) {
|
||||
size := C.size_t(0)
|
||||
ret := C.rbd_list2(C.rados_ioctx_t(ioctx.Pointer()), nil, &size)
|
||||
if ret < 0 && ret != -C.ERANGE {
|
||||
return nil, RBDError(ret)
|
||||
} else if ret > 0 {
|
||||
return nil, fmt.Errorf("rbd_list2() returned %d names, expected 0", ret)
|
||||
} else if ret == 0 && size == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// expected: ret == -ERANGE, size contains number of image names
|
||||
images := make([]C.rbd_image_spec_t, size)
|
||||
ret = C.rbd_list2(C.rados_ioctx_t(ioctx.Pointer()), (*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])), &size)
|
||||
if ret < 0 {
|
||||
return nil, RBDError(ret)
|
||||
}
|
||||
defer C.rbd_image_spec_list_cleanup((*C.rbd_image_spec_t)(unsafe.Pointer(&images[0])), size)
|
||||
|
||||
names := make([]string, size)
|
||||
for i, image := range images {
|
||||
names[i] = C.GoString(image.name)
|
||||
}
|
||||
return names, nil
|
||||
}
|
101
vendor/github.com/ceph/go-ceph/rbd/snapshot_mimic.go
generated
vendored
Normal file
101
vendor/github.com/ceph/go-ceph/rbd/snapshot_mimic.go
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
// +build luminous mimic
|
||||
// +build !nautilus
|
||||
//
|
||||
// Ceph Nautilus introduced rbd_get_parent() and deprecated rbd_get_parent_info().
|
||||
// Ceph Nautilus introduced rbd_list_children3() and deprecated rbd_list_children().
|
||||
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// #include <rbd/librbd.h>
|
||||
// #include <errno.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// GetParentInfo looks for the parent of the image and stores the pool, name
|
||||
// and snapshot-name in the byte-arrays that are passed as arguments.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_get_parent_info(rbd_image_t image, char *parent_pool_name,
|
||||
// size_t ppool_namelen, char *parent_name,
|
||||
// size_t pnamelen, char *parent_snap_name,
|
||||
// size_t psnap_namelen)
|
||||
func (image *Image) GetParentInfo(p_pool, p_name, p_snapname []byte) error {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ret := C.rbd_get_parent_info(
|
||||
image.image,
|
||||
(*C.char)(unsafe.Pointer(&p_pool[0])),
|
||||
(C.size_t)(len(p_pool)),
|
||||
(*C.char)(unsafe.Pointer(&p_name[0])),
|
||||
(C.size_t)(len(p_name)),
|
||||
(*C.char)(unsafe.Pointer(&p_snapname[0])),
|
||||
(C.size_t)(len(p_snapname)))
|
||||
if ret == 0 {
|
||||
return nil
|
||||
} else {
|
||||
return RBDError(ret)
|
||||
}
|
||||
}
|
||||
|
||||
// ListChildren returns arrays with the pools and names of the images that are
|
||||
// children of the given image. The index of the pools and images arrays can be
|
||||
// used to link the two items together.
|
||||
//
|
||||
// Implements:
|
||||
// ssize_t rbd_list_children(rbd_image_t image, char *pools,
|
||||
// size_t *pools_len,
|
||||
// char *images, size_t *images_len);
|
||||
func (image *Image) ListChildren() (pools []string, images []string, err error) {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var c_pools_len, c_images_len C.size_t
|
||||
|
||||
ret := C.rbd_list_children(image.image,
|
||||
nil, &c_pools_len,
|
||||
nil, &c_images_len)
|
||||
if ret == 0 {
|
||||
return nil, nil, nil
|
||||
}
|
||||
if ret < 0 && ret != -C.ERANGE {
|
||||
return nil, nil, RBDError(ret)
|
||||
}
|
||||
|
||||
pools_buf := make([]byte, c_pools_len)
|
||||
images_buf := make([]byte, c_images_len)
|
||||
|
||||
ret = C.rbd_list_children(image.image,
|
||||
(*C.char)(unsafe.Pointer(&pools_buf[0])),
|
||||
&c_pools_len,
|
||||
(*C.char)(unsafe.Pointer(&images_buf[0])),
|
||||
&c_images_len)
|
||||
if ret < 0 {
|
||||
return nil, nil, RBDError(ret)
|
||||
}
|
||||
|
||||
tmp := bytes.Split(pools_buf[:c_pools_len-1], []byte{0})
|
||||
for _, s := range tmp {
|
||||
if len(s) > 0 {
|
||||
name := C.GoString((*C.char)(unsafe.Pointer(&s[0])))
|
||||
pools = append(pools, name)
|
||||
}
|
||||
}
|
||||
|
||||
tmp = bytes.Split(images_buf[:c_images_len-1], []byte{0})
|
||||
for _, s := range tmp {
|
||||
if len(s) > 0 {
|
||||
name := C.GoString((*C.char)(unsafe.Pointer(&s[0])))
|
||||
images = append(images, name)
|
||||
}
|
||||
}
|
||||
|
||||
return pools, images, nil
|
||||
}
|
104
vendor/github.com/ceph/go-ceph/rbd/snapshot_nautilus.go
generated
vendored
Normal file
104
vendor/github.com/ceph/go-ceph/rbd/snapshot_nautilus.go
generated
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
// +build !luminous,!mimic
|
||||
//
|
||||
// Ceph Nautilus introduced rbd_get_parent() and deprecated rbd_get_parent_info().
|
||||
// Ceph Nautilus introduced rbd_list_children3() and deprecated rbd_list_children().
|
||||
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// #include <rbd/librbd.h>
|
||||
// #include <errno.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// GetParentInfo looks for the parent of the image and stores the pool, name
|
||||
// and snapshot-name in the byte-arrays that are passed as arguments.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_get_parent(rbd_image_t image,
|
||||
// rbd_linked_image_spec_t *parent_image,
|
||||
// rbd_snap_spec_t *parent_snap)
|
||||
func (image *Image) GetParentInfo(pool, name, snapname []byte) error {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
parentImage := C.rbd_linked_image_spec_t{}
|
||||
parentSnap := C.rbd_snap_spec_t{}
|
||||
ret := C.rbd_get_parent(image.image, &parentImage, &parentSnap)
|
||||
if ret != 0 {
|
||||
return RBDError(ret)
|
||||
}
|
||||
|
||||
defer C.rbd_linked_image_spec_cleanup(&parentImage)
|
||||
defer C.rbd_snap_spec_cleanup(&parentSnap)
|
||||
|
||||
strlen := int(C.strlen(parentImage.pool_name))
|
||||
if len(pool) < strlen {
|
||||
return RBDError(C.ERANGE)
|
||||
}
|
||||
if copy(pool, C.GoString(parentImage.pool_name)) != strlen {
|
||||
return RBDError(C.ERANGE)
|
||||
}
|
||||
|
||||
strlen = int(C.strlen(parentImage.image_name))
|
||||
if len(name) < strlen {
|
||||
return RBDError(C.ERANGE)
|
||||
}
|
||||
if copy(name, C.GoString(parentImage.image_name)) != strlen {
|
||||
return RBDError(C.ERANGE)
|
||||
}
|
||||
|
||||
strlen = int(C.strlen(parentSnap.name))
|
||||
if len(snapname) < strlen {
|
||||
return RBDError(C.ERANGE)
|
||||
}
|
||||
if copy(snapname, C.GoString(parentSnap.name)) != strlen {
|
||||
return RBDError(C.ERANGE)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListChildren returns arrays with the pools and names of the images that are
|
||||
// children of the given image. The index of the pools and images arrays can be
|
||||
// used to link the two items together.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_list_children3(rbd_image_t image, rbd_linked_image_spec_t *images,
|
||||
// size_t *max_images);
|
||||
func (image *Image) ListChildren() (pools []string, images []string, err error) {
|
||||
if err := image.validate(imageIsOpen); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
size := C.size_t(0)
|
||||
ret := C.rbd_list_children3(image.image, nil, &size)
|
||||
if ret < 0 && ret != -C.ERANGE {
|
||||
return nil, nil, RBDError(ret)
|
||||
} else if ret > 0 {
|
||||
return nil, nil, fmt.Errorf("rbd_list_children3() returned %d, expected 0", ret)
|
||||
} else if ret == 0 && size == 0 {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
// expected: ret == -ERANGE, size contains number of image names
|
||||
children := make([]C.rbd_linked_image_spec_t, size)
|
||||
ret = C.rbd_list_children3(image.image, (*C.rbd_linked_image_spec_t)(unsafe.Pointer(&children[0])), &size)
|
||||
if ret < 0 {
|
||||
return nil, nil, RBDError(ret)
|
||||
}
|
||||
defer C.rbd_linked_image_spec_list_cleanup((*C.rbd_linked_image_spec_t)(unsafe.Pointer(&children[0])), size)
|
||||
|
||||
pools = make([]string, size)
|
||||
images = make([]string, size)
|
||||
for i, child := range children {
|
||||
pools[i] = C.GoString(child.pool_name)
|
||||
images[i] = C.GoString(child.image_name)
|
||||
}
|
||||
return pools, images, nil
|
||||
}
|
Reference in New Issue
Block a user