rbd

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: MIT Imports: 9 Imported by: 36

Documentation

Overview

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

Index

Constants

View Source
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
)
View Source
const (
	// RBD features.
	RbdFeatureLayering      = uint64(C.RBD_FEATURE_LAYERING)
	RbdFeatureStripingV2    = uint64(C.RBD_FEATURE_STRIPINGV2)
	RbdFeatureExclusiveLock = uint64(C.RBD_FEATURE_EXCLUSIVE_LOCK)
	RbdFeatureObjectMap     = uint64(C.RBD_FEATURE_OBJECT_MAP)
	RbdFeatureFastDiff      = uint64(C.RBD_FEATURE_FAST_DIFF)
	RbdFeatureDeepFlatten   = uint64(C.RBD_FEATURE_DEEP_FLATTEN)
	RbdFeatureJournaling    = uint64(C.RBD_FEATURE_JOURNALING)
	RbdFeatureDataPool      = uint64(C.RBD_FEATURE_DATA_POOL)

	RbdFeaturesDefault = uint64(C.RBD_FEATURES_DEFAULT)

	// Features that make an image inaccessible for read or write by clients that don't understand
	// them.
	RbdFeaturesIncompatible = uint64(C.RBD_FEATURES_INCOMPATIBLE)

	// Features that make an image unwritable by clients that don't understand them.
	RbdFeaturesRwIncompatible = uint64(C.RBD_FEATURES_RW_INCOMPATIBLE)

	// Features that may be dynamically enabled or disabled.
	RbdFeaturesMutable = uint64(C.RBD_FEATURES_MUTABLE)

	// Features that only work when used with a single client using the image for writes.
	RbdFeaturesSingleClient = uint64(C.RBD_FEATURES_SINGLE_CLIENT)

	// Image.Seek() constants
	SeekSet = int(C.SEEK_SET)
	SeekCur = int(C.SEEK_CUR)
	SeekEnd = int(C.SEEK_END)
)
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    = errors.New("RBD image does not have an IOContext")
	ErrNoName         = errors.New("RBD image does not have a name")
	ErrSnapshotNoName = errors.New("RBD snapshot does not have a name")
	ErrImageNotOpen   = errors.New("RBD image not open")
	ErrNotFound       = errors.New("RBD image not found")

	// retained for compatibility with old versions
	RbdErrorImageNotOpen = ErrImageNotOpen
	RbdErrorNotFound     = ErrNotFound
)

Functions

func CloneFromImage

func CloneFromImage(parent *Image, snapName string,
	destctx *rados.IOContext, name string, rio *RbdImageOptions) 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 *RbdImageOptions) 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 *RbdImageOptions) 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 GetImageNames

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

GetImageNames returns the list of current RBD images.

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 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 Image

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

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

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

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

func (*Image) Discard

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

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

int rbd_flush(rbd_image_t image);

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)

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

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

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

func (*Image) GetSnapshotNames

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

int rbd_snap_list(rbd_image_t image, rbd_snap_info_t *snaps, int *max_snaps); void rbd_snap_list_end(rbd_snap_info_t *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) 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)

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

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)

func (*Image) SetMetadata

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

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

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

type ImageInfo

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

type Locker

type Locker struct {
	Client string
	Cookie string
	Addr   string
}

type RBDError

type RBDError int

func (RBDError) Error

func (e RBDError) Error() string

type RbdImageOption

type RbdImageOption C.int

type RbdImageOptions

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

func NewRbdImageOptions

func NewRbdImageOptions() *RbdImageOptions

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

func (rio *RbdImageOptions) Clear()

Clear all options in the RbdImageOptions.

Implements:

void rbd_image_options_clear(rbd_image_options_t opts)

func (*RbdImageOptions) Destroy

func (rio *RbdImageOptions) Destroy()

Destroy a RbdImageOptions struct and free the associated resources.

Implements:

void rbd_image_options_destroy(rbd_image_options_t opts);

func (*RbdImageOptions) GetString

func (rio *RbdImageOptions) GetString(option RbdImageOption) (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 (*RbdImageOptions) GetUint64

func (rio *RbdImageOptions) GetUint64(option RbdImageOption) (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 (*RbdImageOptions) IsEmpty

func (rio *RbdImageOptions) 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 (*RbdImageOptions) IsSet

func (rio *RbdImageOptions) IsSet(option RbdImageOption) (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 (*RbdImageOptions) SetString

func (rio *RbdImageOptions) SetString(option RbdImageOption, 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 (*RbdImageOptions) SetUint64

func (rio *RbdImageOptions) SetUint64(option RbdImageOption, 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 (*RbdImageOptions) Unset

func (rio *RbdImageOptions) Unset(option RbdImageOption) error

Unset a given RbdImageOption.

Implements:

int rbd_image_options_unset(rbd_image_options_t opts, int optname)

type SnapInfo

type SnapInfo struct {
	Id   uint64
	Size uint64
	Name string
}

type Snapshot

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

func (*Snapshot) IsProtected

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

int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,

int *is_protected);

func (*Snapshot) Protect

func (snapshot *Snapshot) Protect() error

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

func (*Snapshot) Remove

func (snapshot *Snapshot) Remove() error

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

func (*Snapshot) Rollback

func (snapshot *Snapshot) Rollback() error

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

librbd_progress_fn_t cb, void *cbdata);

func (*Snapshot) Set

func (snapshot *Snapshot) Set() error

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

func (*Snapshot) Unprotect

func (snapshot *Snapshot) Unprotect() error

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

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.

Jump to

Keyboard shortcuts

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