rbd

package
v1.0.1-0...-e84a606 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package rbd contains a set of wrappers around Ceph's librbd API.

Index

Constants

View Source
const (
	// ExcludeParent will exclude the parent from the diff.
	ExcludeParent = DiffIncludeParent(0)
	// IncludeParent will include the parent in the diff.
	IncludeParent = DiffIncludeParent(1)

	// DisableWholeObject will not use the whole object in the diff.
	DisableWholeObject = DiffWholeObject(0)
	// EnableWholeObject will use the whole object in the diff.
	EnableWholeObject = DiffWholeObject(1)
)
View Source
const (

	// FeatureLayering is the representation of RBD_FEATURE_LAYERING from
	// librbd
	FeatureLayering = uint64(C.RBD_FEATURE_LAYERING)

	// FeatureStripingV2 is the representation of RBD_FEATURE_STRIPINGV2
	// from librbd
	FeatureStripingV2 = uint64(C.RBD_FEATURE_STRIPINGV2)

	// FeatureExclusiveLock is the representation of
	// RBD_FEATURE_EXCLUSIVE_LOCK from librbd
	FeatureExclusiveLock = uint64(C.RBD_FEATURE_EXCLUSIVE_LOCK)

	// FeatureObjectMap is the representation of RBD_FEATURE_OBJECT_MAP
	// from librbd
	FeatureObjectMap = uint64(C.RBD_FEATURE_OBJECT_MAP)

	// FeatureFastDiff is the representation of RBD_FEATURE_FAST_DIFF from
	// librbd
	FeatureFastDiff = uint64(C.RBD_FEATURE_FAST_DIFF)

	// FeatureDeepFlatten is the representation of RBD_FEATURE_DEEP_FLATTEN
	// from librbd
	FeatureDeepFlatten = uint64(C.RBD_FEATURE_DEEP_FLATTEN)

	// FeatureJournaling is the representation of RBD_FEATURE_JOURNALING
	// from librbd
	FeatureJournaling = uint64(C.RBD_FEATURE_JOURNALING)

	// FeatureDataPool is the representation of RBD_FEATURE_DATA_POOL from
	// librbd
	FeatureDataPool = uint64(C.RBD_FEATURE_DATA_POOL)

	// FeatureNameLayering is the representation of
	// RBD_FEATURE_NAME_LAYERING from librbd
	FeatureNameLayering = C.RBD_FEATURE_NAME_LAYERING

	// FeatureNameStripingV2 is the representation of
	// RBD_FEATURE_NAME_STRIPINGV2 from librbd
	FeatureNameStripingV2 = C.RBD_FEATURE_NAME_STRIPINGV2

	// FeatureNameExclusiveLock is the representation of
	// RBD_FEATURE_NAME_EXCLUSIVE_LOCK from librbd
	FeatureNameExclusiveLock = C.RBD_FEATURE_NAME_EXCLUSIVE_LOCK

	// FeatureNameObjectMap is the representation of
	// RBD_FEATURE_NAME_OBJECT_MAP from librbd
	FeatureNameObjectMap = C.RBD_FEATURE_NAME_OBJECT_MAP

	// FeatureNameFastDiff is the representation of
	// RBD_FEATURE_NAME_FAST_DIFF from librbd
	FeatureNameFastDiff = C.RBD_FEATURE_NAME_FAST_DIFF

	// FeatureNameDeepFlatten is the representation of
	// RBD_FEATURE_NAME_DEEP_FLATTEN from librbd
	FeatureNameDeepFlatten = C.RBD_FEATURE_NAME_DEEP_FLATTEN

	// FeatureNameJournaling is the representation of
	// RBD_FEATURE_NAME_JOURNALING from librbd
	FeatureNameJournaling = C.RBD_FEATURE_NAME_JOURNALING

	// FeatureNameDataPool is the representation of
	// RBD_FEATURE_NAME_DATA_POOL from librbd
	FeatureNameDataPool = C.RBD_FEATURE_NAME_DATA_POOL

	// RbdFeatureLayering deprecated alias for FeatureLayering
	RbdFeatureLayering = FeatureLayering
	// RbdFeatureStripingV2 deprecated alias for FeatureStripingV2
	RbdFeatureStripingV2 = FeatureStripingV2
	// RbdFeatureExclusiveLock deprecated alias for FeatureExclusiveLock
	RbdFeatureExclusiveLock = FeatureExclusiveLock
	// RbdFeatureObjectMap deprecated alias for FeatureObjectMap
	RbdFeatureObjectMap = FeatureObjectMap
	// RbdFeatureFastDiff deprecated alias for FeatureFastDiff
	RbdFeatureFastDiff = FeatureFastDiff
	// RbdFeatureDeepFlatten deprecated alias for FeatureDeepFlatten
	RbdFeatureDeepFlatten = FeatureDeepFlatten
	// RbdFeatureJournaling deprecated alias for FeatureJournaling
	RbdFeatureJournaling = FeatureJournaling
	// RbdFeatureDataPool deprecated alias for FeatureDataPool
	RbdFeatureDataPool = FeatureDataPool

	// revive:disable:exported Maybe unused
	// the following are probably really unused?
	RbdFeaturesDefault        = uint64(C.RBD_FEATURES_DEFAULT)
	RbdFeaturesIncompatible   = uint64(C.RBD_FEATURES_INCOMPATIBLE)
	RbdFeaturesRwIncompatible = uint64(C.RBD_FEATURES_RW_INCOMPATIBLE)
	RbdFeaturesMutable        = uint64(C.RBD_FEATURES_MUTABLE)
	RbdFeaturesSingleClient   = uint64(C.RBD_FEATURES_SINGLE_CLIENT)
)
View Source
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
)
View Source
const (
	// FeatureMigrating is the representation of RBD_FEATURE_MIGRATING from
	// librbd
	FeatureMigrating = uint64(C.RBD_FEATURE_MIGRATING)

	// FeatureNameMigrating is the representation of
	// RBD_FEATURE_NAME_MIGRATING from librbd
	FeatureNameMigrating = C.RBD_FEATURE_NAME_MIGRATING
)
View Source
const (

	// ImageOptionFormat is the representation of RBD_IMAGE_OPTION_FORMAT from
	// librbd
	ImageOptionFormat = C.RBD_IMAGE_OPTION_FORMAT
	// ImageOptionFeatures is the representation of RBD_IMAGE_OPTION_FEATURES
	// from librbd
	ImageOptionFeatures = C.RBD_IMAGE_OPTION_FEATURES
	// ImageOptionOrder is the representation of RBD_IMAGE_OPTION_ORDER from
	// librbd
	ImageOptionOrder = C.RBD_IMAGE_OPTION_ORDER
	// ImageOptionStripeUnit is the representation of
	// RBD_IMAGE_OPTION_STRIPE_UNIT from librbd
	ImageOptionStripeUnit = C.RBD_IMAGE_OPTION_STRIPE_UNIT
	// ImageOptionStripeCount is the representation of
	// RBD_IMAGE_OPTION_STRIPE_COUNT from librbd
	ImageOptionStripeCount = C.RBD_IMAGE_OPTION_STRIPE_COUNT
	// ImageOptionJournalOrder is the representation of
	// RBD_IMAGE_OPTION_JOURNAL_ORDER from librbd
	ImageOptionJournalOrder = C.RBD_IMAGE_OPTION_JOURNAL_ORDER
	// ImageOptionJournalSplayWidth is the representation of
	// RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH from librbd
	ImageOptionJournalSplayWidth = C.RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH
	// ImageOptionJournalPool is the representation of
	// RBD_IMAGE_OPTION_JOURNAL_POOL from librbd
	ImageOptionJournalPool = C.RBD_IMAGE_OPTION_JOURNAL_POOL
	// ImageOptionFeaturesSet is the representation of
	// RBD_IMAGE_OPTION_FEATURES_SET from librbd
	ImageOptionFeaturesSet = C.RBD_IMAGE_OPTION_FEATURES_SET
	// ImageOptionFeaturesClear is the representation of
	// RBD_IMAGE_OPTION_FEATURES_CLEAR from librbd
	ImageOptionFeaturesClear = C.RBD_IMAGE_OPTION_FEATURES_CLEAR
	// ImageOptionDataPool is the representation of RBD_IMAGE_OPTION_DATA_POOL
	// from librbd
	ImageOptionDataPool = C.RBD_IMAGE_OPTION_DATA_POOL

	// RbdImageOptionFormat deprecated alias for ImageOptionFormat
	RbdImageOptionFormat = ImageOptionFormat
	// RbdImageOptionFeatures deprecated alias for ImageOptionFeatures
	RbdImageOptionFeatures = ImageOptionFeatures
	// RbdImageOptionOrder deprecated alias for ImageOptionOrder
	RbdImageOptionOrder = ImageOptionOrder
	// RbdImageOptionStripeUnit deprecated alias for ImageOptionStripeUnit
	RbdImageOptionStripeUnit = ImageOptionStripeUnit
	// RbdImageOptionStripeCount deprecated alias for ImageOptionStripeCount
	RbdImageOptionStripeCount = ImageOptionStripeCount
	// RbdImageOptionJournalOrder deprecated alias for ImageOptionJournalOrder
	RbdImageOptionJournalOrder = ImageOptionJournalOrder
	// RbdImageOptionJournalSplayWidth deprecated alias for
	RbdImageOptionJournalSplayWidth = ImageOptionJournalSplayWidth
	// RbdImageOptionJournalPool deprecated alias for ImageOptionJournalPool
	RbdImageOptionJournalPool = ImageOptionJournalPool
	// RbdImageOptionFeaturesSet deprecated alias for ImageOptionFeaturesSet
	RbdImageOptionFeaturesSet = ImageOptionFeaturesSet
	// RbdImageOptionFeaturesClear deprecated alias for ImageOptionFeaturesClear
	RbdImageOptionFeaturesClear = ImageOptionFeaturesClear
	// RbdImageOptionDataPool deprecated alias for ImageOptionDataPool
	RbdImageOptionDataPool = ImageOptionDataPool
)
View Source
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
)
View Source
const (
	// PoolStatOptionImages is the representation of
	// RBD_POOL_STAT_OPTION_IMAGES from librbd.
	PoolStatOptionImages = PoolStatOption(C.RBD_POOL_STAT_OPTION_IMAGES)
	// PoolStatOptionImageProvisionedBytes is the representation of
	// RBD_POOL_STAT_OPTION_IMAGE_PROVISIONED_BYTES from librbd.
	PoolStatOptionImageProvisionedBytes = PoolStatOption(C.RBD_POOL_STAT_OPTION_IMAGE_PROVISIONED_BYTES)
	// PoolStatOptionImageMaxProvisionedBytes is the representation of
	// RBD_POOL_STAT_OPTION_IMAGE_MAX_PROVISIONED_BYTES from librbd.
	PoolStatOptionImageMaxProvisionedBytes = PoolStatOption(C.RBD_POOL_STAT_OPTION_IMAGE_MAX_PROVISIONED_BYTES)
	// PoolStatOptionImageSnapshots is the representation of
	// RBD_POOL_STAT_OPTION_IMAGE_SNAPSHOTS from librbd.
	PoolStatOptionImageSnapshots = PoolStatOption(C.RBD_POOL_STAT_OPTION_IMAGE_SNAPSHOTS)
	// PoolStatOptionTrashImages is the representation of
	// RBD_POOL_STAT_OPTION_TRASH_IMAGES from librbd.
	PoolStatOptionTrashImages = PoolStatOption(C.RBD_POOL_STAT_OPTION_TRASH_IMAGES)
	// PoolStatOptionTrashProvisionedBytes is the representation of
	// RBD_POOL_STAT_OPTION_TRASH_PROVISIONED_BYTES from librbd.
	PoolStatOptionTrashProvisionedBytes = PoolStatOption(C.RBD_POOL_STAT_OPTION_TRASH_PROVISIONED_BYTES)
	// PoolStatOptionTrashMaxProvisionedBytes is the representation of
	// RBD_POOL_STAT_OPTION_TRASH_MAX_PROVISIONED_BYTES from librbd.
	PoolStatOptionTrashMaxProvisionedBytes = PoolStatOption(C.RBD_POOL_STAT_OPTION_TRASH_MAX_PROVISIONED_BYTES)
	// PoolStatOptionTrashSnapshots is the representation of
	// RBD_POOL_STAT_OPTION_TRASH_SNAPSHOTS from librbd.
	PoolStatOptionTrashSnapshots = PoolStatOption(C.RBD_POOL_STAT_OPTION_TRASH_SNAPSHOTS)
)
View Source
const (

	// SeekSet is used with Seek to absolutely position the file.
	SeekSet = int(C.SEEK_SET)
	// SeekCur is used with Seek to position the file relatively to the current
	// position.
	SeekCur = int(C.SEEK_CUR)
	// SeekEnd is used with Seek to position the file relatively to the end.
	SeekEnd = int(C.SEEK_END)
)
View Source
const (
	// SnapNamespaceTypeUser indicates that the snapshot belongs to user namespace.
	SnapNamespaceTypeUser = SnapNamespaceType(C.RBD_SNAP_NAMESPACE_TYPE_USER)

	// SnapNamespaceTypeGroup indicates that the snapshot belongs to group namespace.
	// Such snapshots will have associated group information.
	SnapNamespaceTypeGroup = SnapNamespaceType(C.RBD_SNAP_NAMESPACE_TYPE_GROUP)

	// SnapNamespaceTypeTrash indicates that the snapshot belongs to trash namespace.
	SnapNamespaceTypeTrash = SnapNamespaceType(C.RBD_SNAP_NAMESPACE_TYPE_TRASH)
)
View Source
const (
	// ImageOptionMirrorImageMode is the representation of
	// RBD_IMAGE_OPTION_MIRROR_IMAGE_MODE from librbd
	ImageOptionMirrorImageMode = C.RBD_IMAGE_OPTION_MIRROR_IMAGE_MODE
)
View Source
const (

	// NoSnapshot indicates that no snapshot name is in use (see OpenImage)
	NoSnapshot = ""
)

bits for Image.validate() and Snapshot.validate()

Variables

View Source
var (
	// ErrNoIOContext may be returned if an api call requires an IOContext and
	// it is not provided.
	ErrNoIOContext = errors.New("IOContext is missing")
	// ErrNoName may be returned if an api call requires a name and it is
	// not provided.
	ErrNoName = errors.New("RBD image does not have a name")
	// ErrSnapshotNoName may be returned if an api call requires a snapshot
	// name and it is not provided.
	ErrSnapshotNoName = errors.New("RBD snapshot does not have a name")
	// ErrImageNotOpen may be returned if an api call requires an open image handle and one is not provided.
	ErrImageNotOpen = errors.New("RBD image not open")
	// ErrImageIsOpen may be returned if an api call requires a closed image handle and one is not provided.
	ErrImageIsOpen = errors.New("RBD image is open")
	// ErrNotFound may be returned from an api call when the requested item is
	// missing.
	ErrNotFound = errors.New("RBD image not found")
	// ErrNoNamespaceName maye be returned if an api call requires a namespace
	// name and it is not provided.
	ErrNoNamespaceName = errors.New("Namespace value is missing")

	// revive:disable:exported for compatibility with old versions
	RbdErrorImageNotOpen = ErrImageNotOpen
	RbdErrorNotFound     = ErrNotFound
)

Functions

func CloneFromImage

func CloneFromImage(parent *Image, snapName string,
	destctx *rados.IOContext, name string, rio *ImageOptions) error

CloneFromImage creates a clone of the image from the named snapshot in the provided io-context with the given name and image options. This function is a convenience wrapper around CloneImage to support cloning from an existing Image.

func CloneImage

func CloneImage(ioctx *rados.IOContext, parentName, snapName string,
	destctx *rados.IOContext, name string, rio *ImageOptions) error

CloneImage creates a clone of the image from the named snapshot in the provided io-context with the given name and image options.

Implements:

int rbd_clone3(rados_ioctx_t p_ioctx, const char *p_name,
               const char *p_snapname, rados_ioctx_t c_ioctx,
               const char *c_name, rbd_image_options_t c_opts);

func CreateImage

func CreateImage(ioctx *rados.IOContext, name string, size uint64, rio *ImageOptions) error

CreateImage creates a new rbd image using provided image options.

Implements:

int rbd_create4(rados_ioctx_t io, const char *name, uint64_t size,
               rbd_image_options_t opts);

func GetAllPoolStats

func GetAllPoolStats(ioctx *rados.IOContext) (map[PoolStatOption]uint64, error)

GetAllPoolStats returns a map of all PoolStatOption(s) to their respective values.

Implements:

int rbd_pool_stats_get(rados_ioctx_t io, rbd_pool_stats_t stats);

func GetImageNames

func GetImageNames(ioctx *rados.IOContext) ([]string, error)

GetImageNames returns the list of current RBD images.

func GetPoolMetadata

func GetPoolMetadata(ioctx *rados.IOContext, key string) (string, error)

GetPoolMetadata returns pool metadata associated with the given key.

Implements:

int rbd_pool_metadata_get(rados_ioctx_t io_ctx, const char *key, char *value, size_t *val_len);

func NamespaceCreate

func NamespaceCreate(ioctx *rados.IOContext, namespaceName string) error

NamespaceCreate creates the namespace for a given Rados IOContext.

Implements:

int rbd_namespace_create(rados_ioctx_t io, const char *namespace_name);

func NamespaceExists

func NamespaceExists(ioctx *rados.IOContext, namespaceName string) (bool, error)

NamespaceExists checks whether a given namespace exists or not.

Implements:

int rbd_namespace_exists(rados_ioctx_t io, const char *namespace_name, bool *exists);

func NamespaceList

func NamespaceList(ioctx *rados.IOContext) (names []string, err error)

NamespaceList returns a slice containing the names of existing rbd namespaces.

Implements:

int rbd_namespace_list(rados_ioctx_t io, char *namespace_names, size_t *size);

func NamespaceRemove

func NamespaceRemove(ioctx *rados.IOContext, namespaceName string) error

NamespaceRemove removes a given namespace.

Implements:

int rbd_namespace_remove(rados_ioctx_t io, const char *namespace_name);

func PoolInit

func PoolInit(ioctx *rados.IOContext, force bool) error

PoolInit initializes a pool for use by rbd. This function does not create new pools, rather it prepares the pool to host rbd images.

Implements:

int rbd_pool_init(rados_ioctx_t io, bool force)

func RemoveImage

func RemoveImage(ioctx *rados.IOContext, name string) error

RemoveImage removes the specified rbd image.

Implements:

int rbd_remove(rados_ioctx_t io, const char *name);

func RemovePoolMetadata

func RemovePoolMetadata(ioctx *rados.IOContext, key string) error

RemovePoolMetadata removes the pool metadata value for a given pool metadata key.

Implements:

int rbd_pool_metadata_remove(rados_ioctx_t io_ctx, const char *key)

func SetPoolMetadata

func SetPoolMetadata(ioctx *rados.IOContext, key, value string) error

SetPoolMetadata updates the pool metadata string associated with the given key.

Implements:

int rbd_pool_metadata_set(rados_ioctx_t io_ctx, const char *key, const char *value);

func TrashRemove

func TrashRemove(ioctx *rados.IOContext, id string, force bool) error

TrashRemove permanently deletes the trashed RBD with the specified id.

func TrashRestore

func TrashRestore(ioctx *rados.IOContext, id, name string) error

TrashRestore restores the trashed RBD with the specified id back to the pool from whence it came, with the specified new name.

func Version

func Version() (int, int, int)

Version returns the major, minor, and patch level of the librbd library.

Types

type DiffIncludeParent

type DiffIncludeParent uint8

DiffIncludeParent values control if the difference should include the parent image.

type DiffIterateCallback

type DiffIterateCallback func(uint64, uint64, int, interface{}) int

DiffIterateCallback defines the function signature needed for the DiffIterate callback.

The function will be called with the arguments: offset, length, exists, and data. The offset and length correspond to the changed region of the image. The exists value is set to zero if the region is known to be zeros, otherwise it is set to 1. The data value is the extra data parameter that was set on the DiffIterateConfig and is meant to be used for passing arbitrary user-defined items to the callback function.

The callback can trigger the iteration to terminate early by returning a non-zero error code.

type DiffIterateConfig

type DiffIterateConfig struct {
	SnapName      string
	Offset        uint64
	Length        uint64
	IncludeParent DiffIncludeParent
	WholeObject   DiffWholeObject
	Callback      DiffIterateCallback
	Data          interface{}
}

DiffIterateConfig is used to define the parameters of a DiffIterate call. Callback, Offset, and Length should always be specified when passed to DiffIterate. The other values are optional.

type DiffWholeObject

type DiffWholeObject uint8

DiffWholeObject values control if the diff extents should cover the whole object.

type FeatureSet

type FeatureSet uint64

FeatureSet is a combination of the bit value for multiple features.

func FeatureSetFromNames

func FeatureSetFromNames(names []string) FeatureSet

FeatureSetFromNames returns a FeatureSet built from flag bits corresponding to the provided feature names.

func (*FeatureSet) Names

func (fs *FeatureSet) Names() []string

Names converts all of the enabled feature bits in the FeatureSet to a slice of strings corresponding to the names for each feature.

type Image

type Image struct {
	io.Reader
	io.Writer
	io.Seeker
	io.ReaderAt
	io.WriterAt
	// contains filtered or unexported fields
}

Image is a handle for an RBD image.

func Create

func Create(ioctx *rados.IOContext, name string, size uint64, order int,
	args ...uint64) (image *Image, err error)

Create a new rbd image.

Implements:

int rbd_create(rados_ioctx_t io, const char *name, uint64_t size, int *order);

Also implements (for backward compatibility):

int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size,
        uint64_t features, int *order);
int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size,
      uint64_t features, int *order,
      uint64_t stripe_unit, uint64_t stripe_count);

func Create2

func Create2(ioctx *rados.IOContext, name string, size uint64, features uint64,
	order int) (image *Image, err error)

Create2 creates a new rbd image using provided features.

Implements:

int rbd_create2(rados_ioctx_t io, const char *name, uint64_t size,
        uint64_t features, int *order);

func Create3

func Create3(ioctx *rados.IOContext, name string, size uint64, features uint64,
	order int, stripe_unit uint64, stripe_count uint64) (image *Image, err error)

Create3 creates a new rbd image using provided features and stripe parameters.

Implements:

int rbd_create3(rados_ioctx_t io, const char *name, uint64_t size,
      uint64_t features, int *order,
      uint64_t stripe_unit, uint64_t stripe_count);

func GetImage

func GetImage(ioctx *rados.IOContext, name string) *Image

GetImage gets a reference to a previously created rbd image.

func OpenImage

func OpenImage(ioctx *rados.IOContext, name, snapName string) (*Image, error)

OpenImage will open an existing rbd image by name and snapshot name, returning a new opened image. Pass the NoSnapshot sentinel value as the snapName to explicitly indicate that no snapshot name is being provided.

Implements:

int rbd_open(rados_ioctx_t io, const char *name,
             rbd_image_t *image, const char *snap_name);

func OpenImageById

func OpenImageById(ioctx *rados.IOContext, id, snapName string) (*Image, error)

OpenImageById will open an existing rbd image by ID and snapshot name, returning a new opened image. Pass the NoSnapshot sentinel value as the snapName to explicitly indicate that no snapshot name is being provided. Error handling will fail & segfault unless compiled with a version of ceph that fixes https://tracker.ceph.com/issues/43178

Implements:

int rbd_open_by_id(rados_ioctx_t io, const char *id,
                   rbd_image_t *image, const char *snap_name);

func OpenImageByIdReadOnly

func OpenImageByIdReadOnly(ioctx *rados.IOContext, id, snapName string) (*Image, error)

OpenImageByIdReadOnly will open an existing rbd image by ID and snapshot name, returning a new opened-for-read image. Pass the NoSnapshot sentinel value as the snapName to explicitly indicate that no snapshot name is being provided. Error handling will fail & segfault unless compiled with a version of ceph that fixes https://tracker.ceph.com/issues/43178

Implements:

int rbd_open_by_id_read_only(rados_ioctx_t io, const char *id,
                             rbd_image_t *image, const char *snap_name);

func OpenImageReadOnly

func OpenImageReadOnly(ioctx *rados.IOContext, name, snapName string) (*Image, error)

OpenImageReadOnly will open an existing rbd image by name and snapshot name, returning a new opened-for-read image. Pass the NoSnapshot sentinel value as the snapName to explicitly indicate that no snapshot name is being provided.

Implements:

int rbd_open_read_only(rados_ioctx_t io, const char *name,
                       rbd_image_t *image, const char *snap_name);

func (*Image) BreakLock

func (image *Image) BreakLock(client string, cookie string) error

BreakLock forces the release of a lock held by another client.

Implements:

int rbd_break_lock(rbd_image_t image, const char *client, const char *cookie);

func (*Image) Clone

func (image *Image) Clone(snapname string, c_ioctx *rados.IOContext, c_name string, features uint64, order int) (*Image, error)

Clone a new rbd image from a snapshot.

Implements:

int rbd_clone(rados_ioctx_t p_ioctx, const char *p_name,
         const char *p_snapname, rados_ioctx_t c_ioctx,
         const char *c_name, uint64_t features, int *c_order);

func (*Image) Close

func (image *Image) Close() error

Close an open rbd image.

Implements:

int rbd_close(rbd_image_t image);

func (*Image) Copy

func (image *Image) Copy(ioctx *rados.IOContext, destname string) error

Copy one rbd image to another.

Implements:

int rbd_copy(rbd_image_t image, rados_ioctx_t dest_io_ctx, const char *destname);

func (*Image) Copy2

func (image *Image) Copy2(dest *Image) error

Copy2 copies one rbd image to another, using an image handle.

Implements:

int rbd_copy2(rbd_image_t src, rbd_image_t dest);

func (*Image) CreateSnapshot

func (image *Image) CreateSnapshot(snapname string) (*Snapshot, error)

CreateSnapshot returns a new Snapshot objects after creating a snapshot of the rbd image.

Implements:

int rbd_snap_create(rbd_image_t image, const char *snapname);

func (*Image) DiffIterate

func (image *Image) DiffIterate(config DiffIterateConfig) error

DiffIterate calls a callback on changed extents of an image.

Calling DiffIterate will cause the callback specified in the DiffIterateConfig to be called as many times as there are changed regions in the image (controlled by the parameters as passed to librbd).

See the documentation of DiffIterateCallback for a description of the arguments to the callback and the return behavior.

Implements:

int rbd_diff_iterate2(rbd_image_t image,
                      const char *fromsnapname,
                      uint64_t ofs, uint64_t len,
                      uint8_t include_parent, uint8_t whole_object,
                      int (*cb)(uint64_t, size_t, int, void *),
                      void *arg);

func (*Image) Discard

func (image *Image) Discard(ofs uint64, length uint64) (int, error)

Discard the supplied range from the image. The supplied range will be read as zeros once Discard returns. The discarded range will no longer take up space.

Implements:

int rbd_discard(rbd_image_t image, uint64_t ofs, uint64_t len);

func (*Image) Flatten

func (image *Image) Flatten() error

Flatten removes snapshot references from the image.

Implements:

int rbd_flatten(rbd_image_t image);

func (*Image) Flush

func (image *Image) Flush() error

Flush all cached writes to storage.

Implements:

int rbd_flush(rbd_image_t image);

func (*Image) GetAccessTimestamp

func (image *Image) GetAccessTimestamp() (Timespec, error)

GetAccessTimestamp returns the time the rbd image was last accessed.

Implements:

int rbd_get_access_timestamp(rbd_image_t image, struct timespec *timestamp);

func (*Image) GetCreateTimestamp

func (image *Image) GetCreateTimestamp() (Timespec, error)

GetCreateTimestamp returns the time the rbd image was created.

Implements:

int rbd_get_create_timestamp(rbd_image_t image, struct timespec *timestamp);

func (*Image) GetFeatures

func (image *Image) GetFeatures() (features uint64, err error)

GetFeatures returns the features bitmask for the rbd image.

Implements:

int rbd_get_features(rbd_image_t image, uint64_t *features);

func (*Image) GetId

func (image *Image) GetId() (string, error)

GetId returns the internal image ID string.

Implements:

int rbd_get_id(rbd_image_t image, char *id, size_t id_len);

func (*Image) GetMetadata

func (image *Image) GetMetadata(key string) (string, error)

GetMetadata returns the metadata string associated with the given key.

Implements:

int rbd_metadata_get(rbd_image_t image, const char *key, char *value, size_t *vallen)

func (*Image) GetModifyTimestamp

func (image *Image) GetModifyTimestamp() (Timespec, error)

GetModifyTimestamp returns the time the rbd image was last modified.

Implements:

int rbd_get_modify_timestamp(rbd_image_t image, struct timespec *timestamp);

func (*Image) GetOverlap

func (image *Image) GetOverlap() (overlap uint64, err error)

GetOverlap returns the overlapping bytes between the rbd image and its parent.

Implements:

int rbd_get_overlap(rbd_image_t image, uint64_t *overlap);

func (*Image) GetParent

func (image *Image) GetParent() (*ParentInfo, error)

GetParent looks for the parent of the image and returns the parent image information which includes the image name, the pool name and the snapshot information.

Implements: int rbd_get_parent(rbd_image_t image, rbd_linked_image_spec_t *parent_image, rbd_snap_spec_t *parent_snap)

func (*Image) GetParentInfo

func (image *Image) GetParentInfo(pool, name, snapname []byte) error

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) GetSize

func (image *Image) GetSize() (size uint64, err error)

GetSize returns the size of the rbd image.

Implements:

int rbd_size(rbd_image_t image, uint64_t *size);

func (*Image) GetSnapNamespaceType

func (image *Image) GetSnapNamespaceType(snapID uint64) (SnapNamespaceType, error)

GetSnapNamespaceType gets the type of namespace to which the snapshot belongs to, returns error on failure.

Implements:

int rbd_snap_get_namespace_type(rbd_image_t image, uint64_t snap_id, rbd_snap_namespace_type_t *namespace_type)

func (*Image) GetSnapTimestamp

func (image *Image) GetSnapTimestamp(snapID uint64) (Timespec, error)

GetSnapTimestamp returns the timestamp of a snapshot for an image. For a non-existing snap ID, GetSnapTimestamp() may trigger an assertion and crash in the ceph library. Check https://tracker.ceph.com/issues/47287 for details.

Implements:

int rbd_snap_get_timestamp(rbd_image_t image, uint64_t snap_id, struct timespec *timestamp)

func (*Image) GetSnapTrashNamespace

func (image *Image) GetSnapTrashNamespace(snapID uint64) (string, error)

GetSnapTrashNamespace returns the original name of the snapshot which was moved to the Trash. The caller should make sure that the snapshot ID passed in this function belongs to a snapshot already in the Trash.

Implements:

int rbd_snap_get_trash_namespace(rbd_image_t image, uint64_t snap_id, char *original_name, size_t max_length)

func (*Image) GetSnapshot

func (image *Image) GetSnapshot(snapname string) *Snapshot

GetSnapshot constructs a snapshot object for the image given the snap name. It does not validate that this snapshot exists.

func (*Image) GetSnapshotNames

func (image *Image) GetSnapshotNames() (snaps []SnapInfo, err error)

GetSnapshotNames returns more than just the names of snapshots associated with the rbd image.

Implements:

int rbd_snap_list(rbd_image_t image, rbd_snap_info_t *snaps, int *max_snaps);

func (*Image) GetStripeCount

func (image *Image) GetStripeCount() (stripe_count uint64, err error)

GetStripeCount returns the stripe-count value for the rbd image.

Implements:

int rbd_get_stripe_count(rbd_image_t image, uint64_t *stripe_count);

func (*Image) GetStripeUnit

func (image *Image) GetStripeUnit() (stripe_unit uint64, err error)

GetStripeUnit returns the stripe-unit value for the rbd image.

Implements:

int rbd_get_stripe_unit(rbd_image_t image, uint64_t *stripe_unit);

func (*Image) IsOldFormat

func (image *Image) IsOldFormat() (old_format bool, err error)

IsOldFormat returns true if the rbd image uses the old format.

Implements:

int rbd_get_old_format(rbd_image_t image, uint8_t *old);

func (*Image) ListChildren

func (image *Image) ListChildren() (pools []string, images []string, err error)

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) ListLockers

func (image *Image) ListLockers() (tag string, lockers []Locker, err error)

ListLockers returns a list of clients that have locks on the image.

Impelemnts:

ssize_t rbd_list_lockers(rbd_image_t image, int *exclusive,
            char *tag, size_t *tag_len,
            char *clients, size_t *clients_len,
            char *cookies, size_t *cookies_len,
            char *addrs, size_t *addrs_len);

func (*Image) ListMetadata

func (image *Image) ListMetadata() (map[string]string, error)

ListMetadata returns a map containing all metadata assigned to the RBD image.

Implements:

int rbd_metadata_list(rbd_image_t image, const char *start, uint64_t max,
                      char *keys, size_t *key_len, char *values, size_t *vals_len);

func (*Image) ListWatchers

func (image *Image) ListWatchers() ([]ImageWatcher, error)

ListWatchers returns the watchers on an RBD image. In case of an error, nil and an error are returned.

Note:

Only supported in Ceph Mimic and newer.

Implements:

int rbd_watchers_list(rbd_image_t image,
                      rbd_image_watcher_t *watchers, size_t *max_watchers)

func (*Image) LockExclusive

func (image *Image) LockExclusive(cookie string) error

LockExclusive acquires an exclusive lock on the rbd image.

Implements:

int rbd_lock_exclusive(rbd_image_t image, const char *cookie);

func (*Image) LockShared

func (image *Image) LockShared(cookie string, tag string) error

LockShared acquires a shared lock on the rbd image.

Implements:

int rbd_lock_shared(rbd_image_t image, const char *cookie, const char *tag);

func (*Image) Open deprecated

func (image *Image) Open(args ...interface{}) error

Open the rbd image.

Deprecated: The Open function was provided in earlier versions of the API and now exists to support older code. The use of OpenImage and OpenImageReadOnly is preferred.

func (*Image) Read

func (image *Image) Read(data []byte) (int, error)

ssize_t rbd_read(rbd_image_t image, uint64_t ofs, size_t len, char *buf); TODO: int64_t rbd_read_iterate(rbd_image_t image, uint64_t ofs, size_t len,

int (*cb)(uint64_t, size_t, const char *, void *), void *arg);

TODO: int rbd_read_iterate2(rbd_image_t image, uint64_t ofs, uint64_t len,

int (*cb)(uint64_t, size_t, const char *, void *), void *arg);

TODO: int rbd_diff_iterate(rbd_image_t image,

const char *fromsnapname,
uint64_t ofs, uint64_t len,
int (*cb)(uint64_t, size_t, int, void *), void *arg);

func (*Image) ReadAt

func (image *Image) ReadAt(data []byte, off int64) (int, error)

ReadAt copies data from the image into the supplied buffer.

func (*Image) Remove

func (image *Image) Remove() error

Remove the specified rbd image.

Implements:

int rbd_remove(rados_ioctx_t io, const char *name);

func (*Image) RemoveMetadata

func (image *Image) RemoveMetadata(key string) error

RemoveMetadata clears the metadata associated with the given key.

Implements:

int rbd_metadata_remove(rbd_image_t image, const char *key)

func (*Image) Rename

func (image *Image) Rename(destname string) error

Rename an rbd image.

Implements:

int rbd_rename(rados_ioctx_t src_io_ctx, const char *srcname, const char *destname);

func (*Image) Resize

func (image *Image) Resize(size uint64) error

Resize an rbd image.

Implements:

int rbd_resize(rbd_image_t image, uint64_t size);

func (*Image) Seek

func (image *Image) Seek(offset int64, whence int) (int64, error)

Seek updates the internal file position for the current image.

func (*Image) SetMetadata

func (image *Image) SetMetadata(key string, value string) error

SetMetadata updates the metadata string associated with the given key.

Implements:

int rbd_metadata_set(rbd_image_t image, const char *key, const char *value)

func (*Image) SetSnapByID

func (image *Image) SetSnapByID(snapID uint64) error

SetSnapByID updates the rbd image (not the Snapshot) such that the snapshot is the source of readable data.

Implements:

int rbd_snap_set_by_id(rbd_image_t image, uint64_t snap_id);

func (*Image) Sparsify

func (image *Image) Sparsify(sparseSize uint) error

Sparsify makes an image sparse by deallocating runs of zeros. The sparseSize value will be used to find runs of zeros and must be a power of two no less than 4096 and no larger than the image size.

Implements:

int rbd_sparsify(rbd_image_t image, size_t sparse_size);

func (*Image) Stat

func (image *Image) Stat() (info *ImageInfo, err error)

Stat an rbd image.

Implements:

int rbd_stat(rbd_image_t image, rbd_image_info_t *info, size_t infosize);

func (*Image) Trash

func (image *Image) Trash(delay time.Duration) error

Trash will move an image into the RBD trash, where it will be protected (i.e., salvageable) for at least the specified delay.

func (*Image) Unlock

func (image *Image) Unlock(cookie string) error

Unlock releases a lock on the image.

Implements:

int rbd_lock_shared(rbd_image_t image, const char *cookie, const char *tag);

func (*Image) UpdateFeatures

func (image *Image) UpdateFeatures(features uint64, enabled bool) error

UpdateFeatures updates the features on the Image.

Implements:

int rbd_update_features(rbd_image_t image, uint64_t features,
                        uint8_t enabled);

func (*Image) UpdateWatch

func (image *Image) UpdateWatch(cb WatchCallback, data interface{}) (*Watch, error)

UpdateWatch updates the image object to watch metadata changes to the image, returning a Watch object.

Implements:

int rbd_update_watch(rbd_image_t image, uint64_t *handle,
                     rbd_update_callback_t watch_cb, void *arg);

func (*Image) Write

func (image *Image) Write(data []byte) (n int, err error)

ssize_t rbd_write(rbd_image_t image, uint64_t ofs, size_t len, const char *buf);

func (*Image) WriteAt

func (image *Image) WriteAt(data []byte, off int64) (n int, err error)

WriteAt copies data from the supplied buffer to the image.

func (*Image) WriteSame

func (image *Image) WriteSame(ofs, n uint64, data []byte, flags rados.OpFlags) (int64, error)

WriteSame repeats writing data from starting point ofs until n bytes have been written.

Implements:

ssize_t rbd_writesame(rbd_image_t image, uint64_t ofs, size_t len,
                      const char *buf, size_t data_len, int op_flags);

type ImageInfo

type ImageInfo struct {
	Size              uint64
	Obj_size          uint64
	Num_objs          uint64
	Order             int
	Block_name_prefix string
}

ImageInfo represents the status information for an image.

type ImageOption

type ImageOption C.int

ImageOption values are unique keys for configurable options.

type ImageOptions

type ImageOptions struct {
	// contains filtered or unexported fields
}

ImageOptions represents a group of configurable image options.

func NewRbdImageOptions

func NewRbdImageOptions() *ImageOptions

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 (*ImageOptions) Clear

func (rio *ImageOptions) Clear()

Clear all options in the RbdImageOptions.

Implements:

void rbd_image_options_clear(rbd_image_options_t opts)

func (*ImageOptions) Destroy

func (rio *ImageOptions) Destroy()

Destroy a RbdImageOptions struct and free the associated resources.

Implements:

void rbd_image_options_destroy(rbd_image_options_t opts);

func (*ImageOptions) GetString

func (rio *ImageOptions) GetString(option ImageOption) (string, error)

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 (*ImageOptions) GetUint64

func (rio *ImageOptions) GetUint64(option ImageOption) (uint64, error)

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 (*ImageOptions) IsEmpty

func (rio *ImageOptions) IsEmpty() bool

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 (*ImageOptions) IsSet

func (rio *ImageOptions) IsSet(option ImageOption) (bool, error)

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 (*ImageOptions) SetString

func (rio *ImageOptions) SetString(option ImageOption, value string) error

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 (*ImageOptions) SetUint64

func (rio *ImageOptions) SetUint64(option ImageOption, value uint64) error

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 (*ImageOptions) Unset

func (rio *ImageOptions) Unset(option ImageOption) error

Unset a given RbdImageOption.

Implements:

int rbd_image_options_unset(rbd_image_options_t opts, int optname)

type ImageSpec

type ImageSpec struct {
	ImageName string
	PoolName  string
}

ImageSpec represents the image information.

type ImageWatcher

type ImageWatcher struct {
	Addr   string
	Id     int64
	Cookie uint64
}

ImageWatcher is a representation of the rbd_image_watcher_t from librbd.h

type Locker

type Locker struct {
	Client string
	Cookie string
	Addr   string
}

Locker provides info about a client that is locking an image.

type ParentInfo

type ParentInfo struct {
	Image ImageSpec
	Snap  SnapSpec
}

ParentInfo represents the parent image and the parent snapshot information.

type PoolStatOption

type PoolStatOption C.rbd_pool_stat_option_t

PoolStatOption represents a group of configurable pool stat options.

type RbdImageOption

type RbdImageOption = ImageOption

RbdImageOption is a deprecated alias for ImageOption

type RbdImageOptions

type RbdImageOptions = ImageOptions

RbdImageOptions deprecated alias for ImageOptions

type SnapInfo

type SnapInfo struct {
	Id   uint64
	Size uint64
	Name string
}

SnapInfo represents the status information for a snapshot.

type SnapNamespaceType

type SnapNamespaceType C.rbd_snap_namespace_type_t

SnapNamespaceType indicates the namespace to which the snapshot belongs to.

type SnapSpec

type SnapSpec struct {
	ID       uint64
	SnapName string
}

SnapSpec represents the snapshot infomation.

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot represents a snapshot on a particular rbd image.

func (*Snapshot) IsProtected

func (snapshot *Snapshot) IsProtected() (bool, error)

IsProtected returns true if the snapshot is currently protected.

Implements:

int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,
             int *is_protected);

func (*Snapshot) Protect

func (snapshot *Snapshot) Protect() error

Protect a snapshot from unwanted deletion.

Implements:

int rbd_snap_protect(rbd_image_t image, const char *snap_name);

func (*Snapshot) Remove

func (snapshot *Snapshot) Remove() error

Remove the snapshot from the connected rbd image.

Implements:

int rbd_snap_remove(rbd_image_t image, const char *snapname);

func (*Snapshot) Rollback

func (snapshot *Snapshot) Rollback() error

Rollback the image to the snapshot.

Implements:

int rbd_snap_rollback(rbd_image_t image, const char *snapname);

func (*Snapshot) Set

func (snapshot *Snapshot) Set() error

Set updates the rbd image (not the Snapshot) such that the snapshot is the source of readable data.

Implements:

int rbd_snap_set(rbd_image_t image, const char *snapname);

func (*Snapshot) Unprotect

func (snapshot *Snapshot) Unprotect() error

Unprotect stops protecting the snapshot.

Implements:

int rbd_snap_unprotect(rbd_image_t image, const char *snap_name);

type Timespec

type Timespec ts.Timespec

Timespec is a public type for the internal C 'struct timespec'

type TrashInfo

type TrashInfo struct {
	Id               string    // Id string, required to remove / restore trashed RBDs.
	Name             string    // Original name of trashed RBD.
	DeletionTime     time.Time // Date / time at which the RBD was moved to the trash.
	DefermentEndTime time.Time // Date / time after which the trashed RBD may be permanently deleted.
}

TrashInfo contains information about trashed RBDs.

func GetTrashList

func GetTrashList(ioctx *rados.IOContext) ([]TrashInfo, error)

GetTrashList returns a slice of TrashInfo structs, containing information about all RBD images currently residing in the trash.

type Watch

type Watch struct {
	// contains filtered or unexported fields
}

Watch represents an ongoing image metadata watch.

func (*Watch) Unwatch

func (w *Watch) Unwatch() error

Unwatch un-registers the image watch.

Implements:

int rbd_update_unwatch(rbd_image_t image, uint64_t handle);

type WatchCallback

type WatchCallback func(interface{})

WatchCallback defines the function signature needed for the UpdateWatch callback.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL