From: Casey Bodley Date: Mon, 24 Nov 2025 21:35:07 +0000 (-0500) Subject: neorados: specify alignments for aligned_storage X-Git-Tag: testing/wip-pdonnell-testing-20260306.175013~3^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7f388199b5a20cd5507f3d7208731026f324b6fd;p=ceph-ci.git neorados: specify alignments for aligned_storage the default alignment of `Alignment = std::bit_ceil(S)` was a very conservative estimate. reduce that to `alignof(std::max_align_t)` to match the old behavior, then assert on construction that the given alignment is large enough for the implementation's type Fixes: https://tracker.ceph.com/issues/73750 Signed-off-by: Casey Bodley --- diff --git a/src/include/neorados/RADOS.hpp b/src/include/neorados/RADOS.hpp index 5dfc51a33b1..d2183dc95b4 100644 --- a/src/include/neorados/RADOS.hpp +++ b/src/include/neorados/RADOS.hpp @@ -78,7 +78,7 @@ struct hash; namespace neorados { namespace detail { class Client; -template +template struct alignas(Alignment) aligned_storage { std::byte data[S]; }; diff --git a/src/neorados/RADOS.cc b/src/neorados/RADOS.cc index 3824e3fe6c3..7f64d828ee6 100644 --- a/src/neorados/RADOS.cc +++ b/src/neorados/RADOS.cc @@ -74,26 +74,31 @@ namespace neorados { Object::Object() { static_assert(impl_size >= sizeof(object_t)); + static_assert(alignof(decltype(impl)) >= alignof(object_t)); new (&impl) object_t(); } Object::Object(const char* s) { static_assert(impl_size >= sizeof(object_t)); + static_assert(alignof(decltype(impl)) >= alignof(object_t)); new (&impl) object_t(s); } Object::Object(std::string_view s) { static_assert(impl_size >= sizeof(object_t)); + static_assert(alignof(decltype(impl)) >= alignof(object_t)); new (&impl) object_t(s); } Object::Object(std::string&& s) { static_assert(impl_size >= sizeof(object_t)); + static_assert(alignof(decltype(impl)) >= alignof(object_t)); new (&impl) object_t(std::move(s)); } Object::Object(const std::string& s) { static_assert(impl_size >= sizeof(object_t)); + static_assert(alignof(decltype(impl)) >= alignof(object_t)); new (&impl) object_t(s); } @@ -103,6 +108,7 @@ Object::~Object() { Object::Object(const Object& o) { static_assert(impl_size >= sizeof(object_t)); + static_assert(alignof(decltype(impl)) >= alignof(object_t)); new (&impl) object_t(*reinterpret_cast(&o.impl)); } Object& Object::operator =(const Object& o) { @@ -112,6 +118,7 @@ Object& Object::operator =(const Object& o) { } Object::Object(Object&& o) { static_assert(impl_size >= sizeof(object_t)); + static_assert(alignof(decltype(impl)) >= alignof(object_t)); new (&impl) object_t(std::move(*reinterpret_cast(&o.impl))); } Object& Object::operator =(Object&& o) { @@ -165,6 +172,7 @@ struct IOContextImpl { IOContext::IOContext() { static_assert(impl_size >= sizeof(IOContextImpl)); + static_assert(alignof(decltype(impl)) >= alignof(IOContextImpl)); new (&impl) IOContextImpl(); } @@ -185,6 +193,7 @@ IOContext::~IOContext() { IOContext::IOContext(const IOContext& rhs) { static_assert(impl_size >= sizeof(IOContextImpl)); + static_assert(alignof(decltype(impl)) >= alignof(IOContextImpl)); new (&impl) IOContextImpl(*reinterpret_cast(&rhs.impl)); } @@ -196,6 +205,7 @@ IOContext& IOContext::operator =(const IOContext& rhs) { IOContext::IOContext(IOContext&& rhs) { static_assert(impl_size >= sizeof(IOContextImpl)); + static_assert(alignof(decltype(impl)) >= alignof(IOContextImpl)); new (&impl) IOContextImpl( std::move(*reinterpret_cast(&rhs.impl))); } @@ -414,6 +424,7 @@ struct OpImpl { Op::Op() { static_assert(Op::impl_size >= sizeof(OpImpl)); + static_assert(alignof(decltype(impl)) >= alignof(OpImpl)); new (&impl) OpImpl; } @@ -1757,16 +1768,19 @@ void RADOS::notify_(Object o, IOContext _ioc, bufferlist bl, Cursor::Cursor() { static_assert(impl_size >= sizeof(hobject_t)); + static_assert(alignof(decltype(impl)) >= alignof(hobject_t)); new (&impl) hobject_t(); }; Cursor::Cursor(end_magic_t) { static_assert(impl_size >= sizeof(hobject_t)); + static_assert(alignof(decltype(impl)) >= alignof(hobject_t)); new (&impl) hobject_t(hobject_t::get_max()); } Cursor::Cursor(void* p) { static_assert(impl_size >= sizeof(hobject_t)); + static_assert(alignof(decltype(impl)) >= alignof(hobject_t)); new (&impl) hobject_t(std::move(*reinterpret_cast(p))); } @@ -1782,11 +1796,13 @@ Cursor Cursor::end() { Cursor::Cursor(const Cursor& rhs) { static_assert(impl_size >= sizeof(hobject_t)); + static_assert(alignof(decltype(impl)) >= alignof(hobject_t)); new (&impl) hobject_t(*reinterpret_cast(&rhs.impl)); } Cursor& Cursor::operator =(const Cursor& rhs) { static_assert(impl_size >= sizeof(hobject_t)); + static_assert(alignof(decltype(impl)) >= alignof(hobject_t)); reinterpret_cast(&impl)->~hobject_t(); new (&impl) hobject_t(*reinterpret_cast(&rhs.impl)); return *this; @@ -1794,11 +1810,13 @@ Cursor& Cursor::operator =(const Cursor& rhs) { Cursor::Cursor(Cursor&& rhs) { static_assert(impl_size >= sizeof(hobject_t)); + static_assert(alignof(decltype(impl)) >= alignof(hobject_t)); new (&impl) hobject_t(std::move(*reinterpret_cast(&rhs.impl))); } Cursor& Cursor::operator =(Cursor&& rhs) { static_assert(impl_size >= sizeof(hobject_t)); + static_assert(alignof(decltype(impl)) >= alignof(hobject_t)); reinterpret_cast(&impl)->~hobject_t(); new (&impl) hobject_t(std::move(*reinterpret_cast(&rhs.impl))); return *this;