From f06baa43e5fd150828b6fadc92803027007a0ec8 Mon Sep 17 00:00:00 2001 From: "Daniel M. Lambea" Date: Wed, 20 Jul 2022 12:25:04 +0100 Subject: [PATCH] rados: add support for retrieving the alignment (stripe size) for EC pools Add support for getting the alignment (stripe size) in bytes for pools that require/support it. Fixes #739 This commit adds two new API calls to IOContext, one to know if the pool requires alignment and the second one to get the stripe size in bytes: RequiresAlignment() (bool, error) Alignment() (uint64, error) Signed-off-by: Daniel M. Lambea --- rados/ioctx_pool_alignment.go | 27 +++++++++++++++++++++ rados/ioctx_pool_alignment_test.go | 15 ++++++++++++ rados/ioctx_pool_requires_alignment.go | 27 +++++++++++++++++++++ rados/ioctx_pool_requires_alignment_test.go | 15 ++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 rados/ioctx_pool_alignment.go create mode 100644 rados/ioctx_pool_alignment_test.go create mode 100644 rados/ioctx_pool_requires_alignment.go create mode 100644 rados/ioctx_pool_requires_alignment_test.go diff --git a/rados/ioctx_pool_alignment.go b/rados/ioctx_pool_alignment.go new file mode 100644 index 0000000..7ea47df --- /dev/null +++ b/rados/ioctx_pool_alignment.go @@ -0,0 +1,27 @@ +//go:build ceph_preview +// +build ceph_preview + +package rados + +// #cgo LDFLAGS: -lrados +// #include +// #include +// +import "C" + +// Alignment returns the required stripe size in bytes for pools supporting/requiring it, or an error if unsuccessful. +// For an EC pool, a buffer size multiple of its stripe size is required to call Append. To know if the pool requires +// alignment or not, use RequiresAlignment. +// +// Implements: +// int rados_ioctx_pool_required_alignment2(rados_ioctx_t io, uint64_t *alignment) +func (ioctx *IOContext) Alignment() (uint64, error) { + var alignSizeBytes C.uint64_t + ret := C.rados_ioctx_pool_required_alignment2( + ioctx.ioctx, + &alignSizeBytes) + if ret != 0 { + return 0, getError(ret) + } + return uint64(alignSizeBytes), nil +} diff --git a/rados/ioctx_pool_alignment_test.go b/rados/ioctx_pool_alignment_test.go new file mode 100644 index 0000000..4102dc1 --- /dev/null +++ b/rados/ioctx_pool_alignment_test.go @@ -0,0 +1,15 @@ +//go:build ceph_preview +// +build ceph_preview + +package rados + +import ( + "github.com/stretchr/testify/assert" +) + +func (suite *RadosTestSuite) TestAlignment() { + suite.SetupConnection() + + _, err := suite.ioctx.Alignment() + assert.NoError(suite.T(), err) +} diff --git a/rados/ioctx_pool_requires_alignment.go b/rados/ioctx_pool_requires_alignment.go new file mode 100644 index 0000000..0ec5fed --- /dev/null +++ b/rados/ioctx_pool_requires_alignment.go @@ -0,0 +1,27 @@ +//go:build ceph_preview +// +build ceph_preview + +package rados + +// #cgo LDFLAGS: -lrados +// #include +// #include +// +import "C" + +// RequiresAlignment returns true if the pool supports/requires alignment or an error if not successful. +// For an EC pool, a buffer size multiple of its stripe size is required to call Append. See +// Alignment to know how to get the stripe size for pools requiring it. +// +// Implements: +// int rados_ioctx_pool_requires_alignment2(rados_ioctx_t io, int *req) +func (ioctx *IOContext) RequiresAlignment() (bool, error) { + var alignRequired C.int + ret := C.rados_ioctx_pool_requires_alignment2( + ioctx.ioctx, + &alignRequired) + if ret != 0 { + return false, getError(ret) + } + return (alignRequired != 0), nil +} diff --git a/rados/ioctx_pool_requires_alignment_test.go b/rados/ioctx_pool_requires_alignment_test.go new file mode 100644 index 0000000..6b7424d --- /dev/null +++ b/rados/ioctx_pool_requires_alignment_test.go @@ -0,0 +1,15 @@ +//go:build ceph_preview +// +build ceph_preview + +package rados + +import ( + "github.com/stretchr/testify/assert" +) + +func (suite *RadosTestSuite) TestRequiresAlignment() { + suite.SetupConnection() + + _, err := suite.ioctx.RequiresAlignment() + assert.NoError(suite.T(), err) +}