mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: update go-ceph version to v0.11.0
Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
87beaac25b
commit
56ac143450
139
vendor/github.com/ceph/go-ceph/rbd/encryption.go
generated
vendored
Normal file
139
vendor/github.com/ceph/go-ceph/rbd/encryption.go
generated
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
// +build !octopus,!nautilus
|
||||
|
||||
package rbd
|
||||
|
||||
// #cgo LDFLAGS: -lrbd
|
||||
// /* force XSI-complaint strerror_r() */
|
||||
// #define _POSIX_C_SOURCE 200112L
|
||||
// #undef _GNU_SOURCE
|
||||
// #include <errno.h>
|
||||
// #include <stdlib.h>
|
||||
// #include <rados/librados.h>
|
||||
// #include <rbd/librbd.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// cEncryptionData contains the data needed by the encryption functions
|
||||
type cEncryptionData struct {
|
||||
format C.rbd_encryption_format_t
|
||||
opts C.rbd_encryption_options_t
|
||||
optsSize C.size_t
|
||||
free func()
|
||||
}
|
||||
|
||||
// EncryptionAlgorithm is the encryption algorithm
|
||||
type EncryptionAlgorithm C.rbd_encryption_algorithm_t
|
||||
|
||||
// Possible values for EncryptionAlgorithm:
|
||||
// EncryptionAlgorithmAES128: AES 128bits
|
||||
// EncryptionAlgorithmAES256: AES 256bits
|
||||
const (
|
||||
EncryptionAlgorithmAES128 = EncryptionAlgorithm(C.RBD_ENCRYPTION_ALGORITHM_AES128)
|
||||
EncryptionAlgorithmAES256 = EncryptionAlgorithm(C.RBD_ENCRYPTION_ALGORITHM_AES256)
|
||||
)
|
||||
|
||||
// EncryptionOptionsLUKS1 and EncryptionOptionsLUKS2 are identical
|
||||
// structures at the moment, just as they are in the librbd api.
|
||||
// The purpose behind creating different identical structures, is to facilitate
|
||||
// future modifications of one of the formats, while maintaining backwards
|
||||
// compatibility with the other.
|
||||
|
||||
// EncryptionOptionsLUKS1 options required for LUKS v1
|
||||
type EncryptionOptionsLUKS1 struct {
|
||||
Alg EncryptionAlgorithm
|
||||
Passphrase []byte
|
||||
}
|
||||
|
||||
// EncryptionOptionsLUKS2 options required for LUKS v2
|
||||
type EncryptionOptionsLUKS2 struct {
|
||||
Alg EncryptionAlgorithm
|
||||
Passphrase []byte
|
||||
}
|
||||
|
||||
// EncryptionOptions interface is used to encapsulate the different encryption
|
||||
// formats options and enable converting them from go to C structures.
|
||||
type EncryptionOptions interface {
|
||||
allocateEncryptionOptions() cEncryptionData
|
||||
}
|
||||
|
||||
func (opts EncryptionOptionsLUKS1) allocateEncryptionOptions() cEncryptionData {
|
||||
var cOpts C.rbd_encryption_luks1_format_options_t
|
||||
var retData cEncryptionData
|
||||
cOpts.alg = C.rbd_encryption_algorithm_t(opts.Alg)
|
||||
//CBytes allocates memory which we'll free by calling cOptsFree()
|
||||
cOpts.passphrase = (*C.char)(C.CBytes(opts.Passphrase))
|
||||
cOpts.passphrase_size = C.size_t(len(opts.Passphrase))
|
||||
retData.opts = C.rbd_encryption_options_t(&cOpts)
|
||||
retData.optsSize = C.size_t(C.sizeof_rbd_encryption_luks1_format_options_t)
|
||||
retData.free = func() { C.free(unsafe.Pointer(cOpts.passphrase)) }
|
||||
retData.format = C.RBD_ENCRYPTION_FORMAT_LUKS1
|
||||
return retData
|
||||
}
|
||||
|
||||
func (opts EncryptionOptionsLUKS2) allocateEncryptionOptions() cEncryptionData {
|
||||
var cOpts C.rbd_encryption_luks2_format_options_t
|
||||
var retData cEncryptionData
|
||||
cOpts.alg = C.rbd_encryption_algorithm_t(opts.Alg)
|
||||
//CBytes allocates memory which we'll free by calling cOptsFree()
|
||||
cOpts.passphrase = (*C.char)(C.CBytes(opts.Passphrase))
|
||||
cOpts.passphrase_size = C.size_t(len(opts.Passphrase))
|
||||
retData.opts = C.rbd_encryption_options_t(&cOpts)
|
||||
retData.optsSize = C.size_t(C.sizeof_rbd_encryption_luks2_format_options_t)
|
||||
retData.free = func() { C.free(unsafe.Pointer(cOpts.passphrase)) }
|
||||
retData.format = C.RBD_ENCRYPTION_FORMAT_LUKS2
|
||||
return retData
|
||||
}
|
||||
|
||||
// EncryptionFormat creates an encryption format header
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_encryption_format(rbd_image_t image,
|
||||
// rbd_encryption_format_t format,
|
||||
// rbd_encryption_options_t opts,
|
||||
// size_t opts_size);
|
||||
//
|
||||
// To issue an IO against the image, you need to mount the image
|
||||
// with libvirt/qemu using the LUKS format, or make a call to
|
||||
// rbd_encryption_load().
|
||||
func (image *Image) EncryptionFormat(opts EncryptionOptions) error {
|
||||
if image.image == nil {
|
||||
return ErrImageNotOpen
|
||||
}
|
||||
|
||||
encryptionOpts := opts.allocateEncryptionOptions()
|
||||
defer encryptionOpts.free()
|
||||
|
||||
ret := C.rbd_encryption_format(
|
||||
image.image,
|
||||
encryptionOpts.format,
|
||||
encryptionOpts.opts,
|
||||
encryptionOpts.optsSize)
|
||||
|
||||
return getError(ret)
|
||||
}
|
||||
|
||||
// EncryptionLoad enables IO on an open encrypted image
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_encryption_load(rbd_image_t image,
|
||||
// rbd_encryption_format_t format,
|
||||
// rbd_encryption_options_t opts,
|
||||
// size_t opts_size);
|
||||
func (image *Image) EncryptionLoad(opts EncryptionOptions) error {
|
||||
if image.image == nil {
|
||||
return ErrImageNotOpen
|
||||
}
|
||||
|
||||
encryptionOpts := opts.allocateEncryptionOptions()
|
||||
defer encryptionOpts.free()
|
||||
|
||||
ret := C.rbd_encryption_load(
|
||||
image.image,
|
||||
encryptionOpts.format,
|
||||
encryptionOpts.opts,
|
||||
encryptionOpts.optsSize)
|
||||
return getError(ret)
|
||||
}
|
9
vendor/github.com/ceph/go-ceph/rbd/features.go
generated
vendored
9
vendor/github.com/ceph/go-ceph/rbd/features.go
generated
vendored
@ -39,6 +39,10 @@ const (
|
||||
// librbd
|
||||
FeatureDataPool = uint64(C.RBD_FEATURE_DATA_POOL)
|
||||
|
||||
// FeatureOperations is the representation of RBD_FEATURE_OPERATIONS
|
||||
// from librbd
|
||||
FeatureOperations = uint64(C.RBD_FEATURE_OPERATIONS)
|
||||
|
||||
// RBD features, strings
|
||||
|
||||
// FeatureNameLayering is the representation of
|
||||
@ -73,6 +77,10 @@ const (
|
||||
// RBD_FEATURE_NAME_DATA_POOL from librbd
|
||||
FeatureNameDataPool = C.RBD_FEATURE_NAME_DATA_POOL
|
||||
|
||||
// FeatureNameOperations is the representation of
|
||||
// RBD_FEATURE_NAME_OPERATIONS from librbd
|
||||
FeatureNameOperations = C.RBD_FEATURE_NAME_OPERATIONS
|
||||
|
||||
// old names for backwards compatibility (unused?)
|
||||
|
||||
// RbdFeatureLayering deprecated alias for FeatureLayering
|
||||
@ -115,6 +123,7 @@ var (
|
||||
FeatureNameDeepFlatten: FeatureDeepFlatten,
|
||||
FeatureNameJournaling: FeatureJournaling,
|
||||
FeatureNameDataPool: FeatureDataPool,
|
||||
FeatureNameOperations: FeatureOperations,
|
||||
}
|
||||
)
|
||||
|
||||
|
20
vendor/github.com/ceph/go-ceph/rbd/features_mimic.go
generated
vendored
20
vendor/github.com/ceph/go-ceph/rbd/features_mimic.go
generated
vendored
@ -1,20 +0,0 @@
|
||||
// +build !luminous
|
||||
|
||||
package rbd
|
||||
|
||||
// #include <rbd/librbd.h>
|
||||
import "C"
|
||||
|
||||
const (
|
||||
// FeatureOperations is the representation of RBD_FEATURE_OPERATIONS
|
||||
// from librbd
|
||||
FeatureOperations = uint64(C.RBD_FEATURE_OPERATIONS)
|
||||
|
||||
// FeatureNameOperations is the representation of
|
||||
// RBD_FEATURE_NAME_OPERATIONS from librbd
|
||||
FeatureNameOperations = C.RBD_FEATURE_NAME_OPERATIONS
|
||||
)
|
||||
|
||||
func init() {
|
||||
featureNameToBit[FeatureNameOperations] = FeatureOperations
|
||||
}
|
226
vendor/github.com/ceph/go-ceph/rbd/mirror.go
generated
vendored
226
vendor/github.com/ceph/go-ceph/rbd/mirror.go
generated
vendored
@ -50,6 +50,16 @@ func (m MirrorMode) String() string {
|
||||
// ImageMirrorMode is used to indicate the mirroring approach for an RBD image.
|
||||
type ImageMirrorMode int64
|
||||
|
||||
// ImageMirrorModeFilter is a ImageMirrorMode or nil for no filtering
|
||||
type ImageMirrorModeFilter interface {
|
||||
mode() ImageMirrorMode
|
||||
}
|
||||
|
||||
// Mode returns the ImageMirrorMode
|
||||
func (imm ImageMirrorMode) mode() ImageMirrorMode {
|
||||
return imm
|
||||
}
|
||||
|
||||
const (
|
||||
// ImageMirrorModeJournal uses journaling to propagate RBD images between
|
||||
// ceph clusters.
|
||||
@ -71,12 +81,12 @@ func (imm ImageMirrorMode) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
// GetMirrorUUID returns a string naming the mirroring uuid for the pool
|
||||
// associated with the ioctx.
|
||||
// GetMirrorUUID returns a string naming the mirroring uuid for the pool
|
||||
// associated with the ioctx.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_uuid_get(rados_ioctx_t io_ctx,
|
||||
// char *uuid, size_t *max_len);
|
||||
// Implements:
|
||||
// int rbd_mirror_uuid_get(rados_ioctx_t io_ctx, char *uuid, size_t
|
||||
// *max_len);
|
||||
func GetMirrorUUID(ioctx *rados.IOContext) (string, error) {
|
||||
var (
|
||||
err error
|
||||
@ -626,6 +636,45 @@ type GlobalMirrorImageIDAndStatus struct {
|
||||
Status GlobalMirrorImageStatus
|
||||
}
|
||||
|
||||
// iterBufSize is intentionally not a constant. The unit tests alter
|
||||
// this value in order to get more code coverage w/o needing to create
|
||||
// very many images.
|
||||
var iterBufSize = 64
|
||||
|
||||
// MirrorImageGlobalStatusList returns a slice of GlobalMirrorImageIDAndStatus.
|
||||
// If the length of the returned slice equals max, the next chunk of the list
|
||||
// can be obtained by setting start to the ID of the last item of the returned
|
||||
// slice. If max is 0 a slice of all items is returned.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_status_list(rados_ioctx_t p,
|
||||
// const char *start_id, size_t max, char **image_ids,
|
||||
// rbd_mirror_image_status_t *images, size_t *len)
|
||||
func MirrorImageGlobalStatusList(
|
||||
ioctx *rados.IOContext, start string, max int) ([]GlobalMirrorImageIDAndStatus, error) {
|
||||
var (
|
||||
result []GlobalMirrorImageIDAndStatus
|
||||
fetchAll bool
|
||||
)
|
||||
if max <= 0 {
|
||||
max = iterBufSize
|
||||
fetchAll = true
|
||||
}
|
||||
chunk := make([]GlobalMirrorImageIDAndStatus, max)
|
||||
for {
|
||||
length, err := mirrorImageGlobalStatusList(ioctx, start, chunk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, chunk[:length]...)
|
||||
if !fetchAll || length < max {
|
||||
break
|
||||
}
|
||||
start = chunk[length-1].ID
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func mirrorImageGlobalStatusList(
|
||||
ioctx *rados.IOContext, start string,
|
||||
results []GlobalMirrorImageIDAndStatus) (int, error) {
|
||||
@ -645,26 +694,23 @@ func mirrorImageGlobalStatusList(
|
||||
cephIoctx(ioctx),
|
||||
cStart,
|
||||
max,
|
||||
(**C.char)(unsafe.Pointer(&ids[0])),
|
||||
(*C.rbd_mirror_image_global_status_t)(unsafe.Pointer(&images[0])),
|
||||
&ids[0],
|
||||
&images[0],
|
||||
&length)
|
||||
|
||||
if err := getError(ret); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for i := 0; i < int(length); i++ {
|
||||
results[i].ID = C.GoString(ids[i])
|
||||
results[i].Status = newGlobalMirrorImageStatus(&images[0])
|
||||
}
|
||||
C.rbd_mirror_image_global_status_list_cleanup(
|
||||
(**C.char)(unsafe.Pointer(&ids[0])),
|
||||
(*C.rbd_mirror_image_global_status_t)(unsafe.Pointer(&images[0])),
|
||||
&ids[0],
|
||||
&images[0],
|
||||
length)
|
||||
return int(length), getError(ret)
|
||||
}
|
||||
|
||||
// statusIterBufSize is intentionally not a constant. The unit tests alter
|
||||
// this value in order to get more code coverage w/o needing to create
|
||||
// very many images.
|
||||
var statusIterBufSize = 64
|
||||
|
||||
// MirrorImageGlobalStatusIter provide methods for iterating over all
|
||||
// the GlobalMirrorImageIdAndStatus values in a pool.
|
||||
type MirrorImageGlobalStatusIter struct {
|
||||
@ -700,16 +746,14 @@ func (iter *MirrorImageGlobalStatusIter) Next() (*GlobalMirrorImageIDAndStatus,
|
||||
}
|
||||
|
||||
// Close terminates iteration regardless if iteration was completed and
|
||||
// frees any associated resources.
|
||||
func (iter *MirrorImageGlobalStatusIter) Close() error {
|
||||
iter.buf = nil
|
||||
iter.lastID = ""
|
||||
// frees any associated resources. (DEPRECATED)
|
||||
func (*MirrorImageGlobalStatusIter) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (iter *MirrorImageGlobalStatusIter) fetch() error {
|
||||
iter.buf = nil
|
||||
items := make([]GlobalMirrorImageIDAndStatus, statusIterBufSize)
|
||||
items := make([]GlobalMirrorImageIDAndStatus, iterBufSize)
|
||||
n, err := mirrorImageGlobalStatusList(
|
||||
iter.ioctx,
|
||||
iter.lastID,
|
||||
@ -722,3 +766,145 @@ func (iter *MirrorImageGlobalStatusIter) fetch() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MirrorImageInfoItem contains an ID string for a RBD image and that image's
|
||||
// ImageMirrorMode and MirrorImageInfo.
|
||||
type MirrorImageInfoItem struct {
|
||||
ID string
|
||||
Mode ImageMirrorMode
|
||||
Info MirrorImageInfo
|
||||
}
|
||||
|
||||
// MirrorImageInfoList returns a slice of MirrorImageInfoItem. If the length of
|
||||
// the returned slice equals max, the next chunk of the list can be obtained by
|
||||
// setting start to the ID of the last item of the returned slice. The returned
|
||||
// items are filtered by the mirror mode specified with modeFilter. If max is 0
|
||||
// a slice of all items is returned.
|
||||
//
|
||||
// Implements:
|
||||
// int rbd_mirror_image_info_list(
|
||||
// rados_ioctx_t p, rbd_mirror_image_mode_t *mode_filter,
|
||||
// const char *start_id, size_t max, char **image_ids,
|
||||
// rbd_mirror_image_mode_t *mode_entries,
|
||||
// rbd_mirror_image_info_t *info_entries, size_t *num_entries)
|
||||
func MirrorImageInfoList(
|
||||
ioctx *rados.IOContext, modeFilter ImageMirrorModeFilter, start string,
|
||||
max int) ([]MirrorImageInfoItem, error) {
|
||||
var (
|
||||
result []MirrorImageInfoItem
|
||||
fetchAll bool
|
||||
)
|
||||
if max <= 0 {
|
||||
max = iterBufSize
|
||||
fetchAll = true
|
||||
}
|
||||
chunk := make([]MirrorImageInfoItem, max)
|
||||
for {
|
||||
length, err := mirrorImageInfoList(ioctx, start, modeFilter, chunk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, chunk[:length]...)
|
||||
if !fetchAll || length < max {
|
||||
break
|
||||
}
|
||||
start = chunk[length-1].ID
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func mirrorImageInfoList(ioctx *rados.IOContext, start string,
|
||||
modeFilter ImageMirrorModeFilter, results []MirrorImageInfoItem) (int, error) {
|
||||
|
||||
cStart := C.CString(start)
|
||||
defer C.free(unsafe.Pointer(cStart))
|
||||
|
||||
var (
|
||||
max = C.size_t(len(results))
|
||||
length = C.size_t(0)
|
||||
ids = make([]*C.char, len(results))
|
||||
modes = make([]C.rbd_mirror_image_mode_t, len(results))
|
||||
infos = make([]C.rbd_mirror_image_info_t, len(results))
|
||||
modeFilterPtr *C.rbd_mirror_image_mode_t
|
||||
)
|
||||
if modeFilter != nil {
|
||||
cMode := C.rbd_mirror_image_mode_t(modeFilter.mode())
|
||||
modeFilterPtr = &cMode
|
||||
}
|
||||
ret := C.rbd_mirror_image_info_list(
|
||||
cephIoctx(ioctx),
|
||||
modeFilterPtr,
|
||||
cStart,
|
||||
max,
|
||||
&ids[0],
|
||||
&modes[0],
|
||||
&infos[0],
|
||||
&length,
|
||||
)
|
||||
if err := getError(ret); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for i := 0; i < int(length); i++ {
|
||||
results[i].ID = C.GoString(ids[i])
|
||||
results[i].Mode = ImageMirrorMode(modes[i])
|
||||
results[i].Info = convertMirrorImageInfo(&infos[i])
|
||||
}
|
||||
C.rbd_mirror_image_info_list_cleanup(
|
||||
&ids[0],
|
||||
&infos[0],
|
||||
length)
|
||||
return int(length), getError(ret)
|
||||
}
|
||||
|
||||
// MirrorImageInfoIter provide methods for iterating over all
|
||||
// the MirrorImageInfoItem values in a pool.
|
||||
type MirrorImageInfoIter struct {
|
||||
ioctx *rados.IOContext
|
||||
|
||||
modeFilter ImageMirrorModeFilter
|
||||
buf []MirrorImageInfoItem
|
||||
lastID string
|
||||
}
|
||||
|
||||
// NewMirrorImageInfoIter creates a new iterator ready for use.
|
||||
func NewMirrorImageInfoIter(ioctx *rados.IOContext, modeFilter ImageMirrorModeFilter) *MirrorImageInfoIter {
|
||||
return &MirrorImageInfoIter{
|
||||
ioctx: ioctx,
|
||||
modeFilter: modeFilter,
|
||||
}
|
||||
}
|
||||
|
||||
// Next fetches one MirrorImageInfoItem value or a nil value if iteration is
|
||||
// exhausted. The error return will be non-nil if an underlying error fetching
|
||||
// more values occurred.
|
||||
func (iter *MirrorImageInfoIter) Next() (*MirrorImageInfoItem, error) {
|
||||
if len(iter.buf) == 0 {
|
||||
if err := iter.fetch(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(iter.buf) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
iter.lastID = iter.buf[len(iter.buf)-1].ID
|
||||
}
|
||||
item := iter.buf[0]
|
||||
iter.buf = iter.buf[1:]
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
func (iter *MirrorImageInfoIter) fetch() error {
|
||||
iter.buf = nil
|
||||
items := make([]MirrorImageInfoItem, iterBufSize)
|
||||
n, err := mirrorImageInfoList(
|
||||
iter.ioctx,
|
||||
iter.lastID,
|
||||
iter.modeFilter,
|
||||
items)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n > 0 {
|
||||
iter.buf = items[:n]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
6
vendor/github.com/ceph/go-ceph/rbd/options.go
generated
vendored
6
vendor/github.com/ceph/go-ceph/rbd/options.go
generated
vendored
@ -46,6 +46,12 @@ const (
|
||||
// ImageOptionDataPool is the representation of RBD_IMAGE_OPTION_DATA_POOL
|
||||
// from librbd
|
||||
ImageOptionDataPool = C.RBD_IMAGE_OPTION_DATA_POOL
|
||||
// ImageOptionFlatten is the representation of RBD_IMAGE_OPTION_FLATTEN
|
||||
// from librbd
|
||||
ImageOptionFlatten = C.RBD_IMAGE_OPTION_FLATTEN
|
||||
// ImageOptionCloneFormat is the representation of
|
||||
// RBD_IMAGE_OPTION_CLONE_FORMAT from librbd
|
||||
ImageOptionCloneFormat = C.RBD_IMAGE_OPTION_CLONE_FORMAT
|
||||
|
||||
// RbdImageOptionFormat deprecated alias for ImageOptionFormat
|
||||
RbdImageOptionFormat = ImageOptionFormat
|
||||
|
16
vendor/github.com/ceph/go-ceph/rbd/options_mimic.go
generated
vendored
16
vendor/github.com/ceph/go-ceph/rbd/options_mimic.go
generated
vendored
@ -1,16 +0,0 @@
|
||||
// +build !luminous
|
||||
|
||||
package rbd
|
||||
|
||||
// #include <rbd/librbd.h>
|
||||
import "C"
|
||||
|
||||
const (
|
||||
// ImageOptionFlatten is the representation of RBD_IMAGE_OPTION_FLATTEN
|
||||
// from librbd
|
||||
ImageOptionFlatten = C.RBD_IMAGE_OPTION_FLATTEN
|
||||
|
||||
// ImageOptionCloneFormat is the representation of
|
||||
// RBD_IMAGE_OPTION_CLONE_FORMAT from librbd
|
||||
ImageOptionCloneFormat = C.RBD_IMAGE_OPTION_CLONE_FORMAT
|
||||
)
|
2
vendor/github.com/ceph/go-ceph/rbd/options_octopus.go
generated
vendored
2
vendor/github.com/ceph/go-ceph/rbd/options_octopus.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// +build !luminous,!mimic,!nautilus
|
||||
// +build !nautilus
|
||||
|
||||
package rbd
|
||||
|
||||
|
42
vendor/github.com/ceph/go-ceph/rbd/rbd_mimic.go
generated
vendored
42
vendor/github.com/ceph/go-ceph/rbd/rbd_mimic.go
generated
vendored
@ -1,42 +0,0 @@
|
||||
// +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 (
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/internal/cutil"
|
||||
"github.com/ceph/go-ceph/internal/retry"
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
// GetImageNames returns the list of current RBD images.
|
||||
func GetImageNames(ioctx *rados.IOContext) (names []string, err error) {
|
||||
var (
|
||||
buf []byte
|
||||
csize C.size_t
|
||||
)
|
||||
// from 4KiB to 32KiB
|
||||
retry.WithSizes(4096, 1<<15, func(size int) retry.Hint {
|
||||
csize = C.size_t(size)
|
||||
buf = make([]byte, csize)
|
||||
ret := C.rbd_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
|
||||
}
|
||||
names = cutil.SplitSparseBuffer(buf[:csize])
|
||||
return names, nil
|
||||
}
|
88
vendor/github.com/ceph/go-ceph/rbd/snapshot_mimic.go
generated
vendored
88
vendor/github.com/ceph/go-ceph/rbd/snapshot_mimic.go
generated
vendored
@ -1,88 +0,0 @@
|
||||
// +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 (
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/internal/cutil"
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
pools = cutil.SplitSparseBuffer(pools_buf[:c_pools_len])
|
||||
images = cutil.SplitSparseBuffer(images_buf[:c_images_len])
|
||||
return pools, images, nil
|
||||
}
|
@ -1,7 +1,3 @@
|
||||
// +build !luminous
|
||||
//
|
||||
// Ceph Mimic is the first version that supports watchers through librbd.
|
||||
|
||||
package rbd
|
||||
|
||||
/*
|
Reference in New Issue
Block a user