rbd: move features to its own file

By splitting up the features from the main rbd.go file, it becomes
easier to support new features added by newer versions of Ceph.

This also drops the Rbd-prefix from the constants, and adds backwards
compatible references.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2019-12-06 12:37:01 +01:00 committed by John Mulligan
parent fa5bb0fd69
commit 8b58ab92c4
3 changed files with 116 additions and 50 deletions

108
rbd/features.go Normal file
View File

@ -0,0 +1,108 @@
package rbd
// #cgo LDFLAGS: -lrbd
// #include <rbd/librbd.h>
import "C"
const (
// RBD features, bit values
// 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)
// RBD features, strings
// 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
// old names for backwards compatibility (unused?)
RbdFeatureLayering = FeatureLayering
RbdFeatureStripingV2 = FeatureStripingV2
RbdFeatureExclusiveLock = FeatureExclusiveLock
RbdFeatureObjectMap = FeatureObjectMap
RbdFeatureFastDiff = FeatureFastDiff
RbdFeatureDeepFlatten = FeatureDeepFlatten
RbdFeatureJournaling = FeatureJournaling
RbdFeatureDataPool = FeatureDataPool
// 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)
)
// GetFeatures returns the features bitmask for the rbd image.
//
// Implements:
// int rbd_get_features(rbd_image_t image, uint64_t *features);
func (image *Image) GetFeatures() (features uint64, err error) {
if err := image.validate(imageIsOpen); err != nil {
return 0, err
}
if ret := C.rbd_get_features(image.image, (*C.uint64_t)(&features)); ret < 0 {
return 0, RBDError(ret)
}
return features, nil
}

View File

@ -8,7 +8,6 @@ package rbd
// #include <stdlib.h>
// #include <rados/librados.h>
// #include <rbd/librbd.h>
// #include <rbd/features.h>
import "C"
import (
@ -24,31 +23,6 @@ import (
)
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)
@ -523,22 +497,6 @@ func (image *Image) GetSize() (size uint64, err error) {
return size, nil
}
// GetFeatures returns the features bitmask for the rbd image.
//
// Implements:
// int rbd_get_features(rbd_image_t image, uint64_t *features);
func (image *Image) GetFeatures() (features uint64, err error) {
if err := image.validate(imageIsOpen); err != nil {
return 0, err
}
if ret := C.rbd_get_features(image.image, (*C.uint64_t)(&features)); ret < 0 {
return 0, RBDError(ret)
}
return features, nil
}
// GetStripeUnit returns the stripe-unit value for the rbd image.
//
// Implements:

View File

@ -82,14 +82,14 @@ func TestImageCreate(t *testing.T) {
name = GetUUID()
image, err = Create(ioctx, name, testImageSize, testImageOrder,
RbdFeatureLayering|RbdFeatureStripingV2)
FeatureLayering|FeatureStripingV2)
assert.NoError(t, err)
err = image.Remove()
assert.NoError(t, err)
name = GetUUID()
image, err = Create(ioctx, name, testImageSize, testImageOrder,
RbdFeatureLayering|RbdFeatureStripingV2, 4096, 2)
FeatureLayering|FeatureStripingV2, 4096, 2)
assert.NoError(t, err)
err = image.Remove()
assert.NoError(t, err)
@ -101,7 +101,7 @@ func TestImageCreate(t *testing.T) {
// too many arguments
_, err = Create(ioctx, name, testImageSize, testImageOrder,
RbdFeatureLayering|RbdFeatureStripingV2, 4096, 2, 123)
FeatureLayering|FeatureStripingV2, 4096, 2, 123)
assert.Error(t, err)
ioctx.Destroy()
@ -121,7 +121,7 @@ func TestImageCreate2(t *testing.T) {
name := GetUUID()
image, err := Create2(ioctx, name, testImageSize,
RbdFeatureLayering|RbdFeatureStripingV2, testImageOrder)
FeatureLayering|FeatureStripingV2, testImageOrder)
assert.NoError(t, err)
err = image.Remove()
assert.NoError(t, err)
@ -143,7 +143,7 @@ func TestImageCreate3(t *testing.T) {
name := GetUUID()
image, err := Create3(ioctx, name, testImageSize,
RbdFeatureLayering|RbdFeatureStripingV2, testImageOrder, 4096, 2)
FeatureLayering|FeatureStripingV2, testImageOrder, 4096, 2)
assert.NoError(t, err)
err = image.Remove()
assert.NoError(t, err)
@ -343,7 +343,7 @@ func TestImageProperties(t *testing.T) {
name := GetUUID()
reqSize := uint64(1024 * 1024 * 4) // 4MB
_, err = Create3(ioctx, name, reqSize,
RbdFeatureLayering|RbdFeatureStripingV2, testImageOrder, 4096, 2)
FeatureLayering|FeatureStripingV2, testImageOrder, 4096, 2)
require.NoError(t, err)
img, err := OpenImage(ioctx, name, NoSnapshot)
@ -360,8 +360,8 @@ func TestImageProperties(t *testing.T) {
features, err := img.GetFeatures()
assert.NoError(t, err)
// compare features with the two requested ones
assert.Equal(t, features&(RbdFeatureLayering|RbdFeatureStripingV2),
RbdFeatureLayering|RbdFeatureStripingV2)
assert.Equal(t, features&(FeatureLayering|FeatureStripingV2),
FeatureLayering|FeatureStripingV2)
stripeUnit, err := img.GetStripeUnit()
assert.NoError(t, err)