]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
neorados: specify alignments for aligned_storage 67512/head
authorCasey Bodley <cbodley@redhat.com>
Mon, 24 Nov 2025 21:35:07 +0000 (16:35 -0500)
committerNitzanMordhai <nmordech@ibm.com>
Wed, 25 Feb 2026 08:59:44 +0000 (08:59 +0000)
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 <cbodley@redhat.com>
(cherry picked from commit 7f388199b5a20cd5507f3d7208731026f324b6fd)

Conflicts:
  - src/include/neorados/RADOS.hpp
    struct alignas was missing in tentacle and been used, adding it

src/include/neorados/RADOS.hpp
src/neorados/RADOS.cc

index a3ff6f8abefb0b4fef82940089dc820440330c13..8fb2c35458394b22bf8779f3da01c9f10577cded 100644 (file)
@@ -77,6 +77,10 @@ struct hash<neorados::IOContext>;
 namespace neorados {
 namespace detail {
 class Client;
+template<std::size_t S, std::size_t Alignment = alignof(std::max_align_t)>
+struct alignas(Alignment) aligned_storage {
+  std::byte data[S];
+};
 }
 
 class RADOS;
index 4dcba611907fb5e67e9295794665d50b475c6610..4ec1f9cf3efdd94a9a71cf2bec9a240d52ce05ba 100644 (file)
@@ -73,26 +73,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);
 }
 
@@ -102,6 +107,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<const object_t*>(&o.impl));
 }
 Object& Object::operator =(const Object& o) {
@@ -111,6 +117,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<object_t*>(&o.impl)));
 }
 Object& Object::operator =(Object&& o) {
@@ -164,6 +171,7 @@ struct IOContextImpl {
 
 IOContext::IOContext() {
   static_assert(impl_size >= sizeof(IOContextImpl));
+  static_assert(alignof(decltype(impl)) >= alignof(IOContextImpl));
   new (&impl) IOContextImpl();
 }
 
@@ -184,6 +192,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<const IOContextImpl*>(&rhs.impl));
 }
 
@@ -195,6 +204,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<IOContextImpl*>(&rhs.impl)));
 }
@@ -413,6 +423,7 @@ struct OpImpl {
 
 Op::Op() {
   static_assert(Op::impl_size >= sizeof(OpImpl));
+  static_assert(alignof(decltype(impl)) >= alignof(OpImpl));
   new (&impl) OpImpl;
 }
 
@@ -1751,16 +1762,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<hobject_t*>(p)));
 }
 
@@ -1776,11 +1790,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<const hobject_t*>(&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<hobject_t*>(&impl)->~hobject_t();
   new (&impl) hobject_t(*reinterpret_cast<const hobject_t*>(&rhs.impl));
   return *this;
@@ -1788,11 +1804,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<hobject_t*>(&rhs.impl)));
 }
 
 Cursor& Cursor::operator =(Cursor&& rhs) {
   static_assert(impl_size >= sizeof(hobject_t));
+  static_assert(alignof(decltype(impl)) >= alignof(hobject_t));
   reinterpret_cast<hobject_t*>(&impl)->~hobject_t();
   new (&impl) hobject_t(std::move(*reinterpret_cast<hobject_t*>(&rhs.impl)));
   return *this;