From ae76420eccc76b4f12750fa89941a585e90b5bc5 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 13 Dec 2022 18:23:43 +0800 Subject: [PATCH] crimson/os: define device_spec_t as packed per C++ standard 20, alignas cannot be applied to scoped enum. despite that there is a resolution to address this, see https://cplusplus.github.io/CWG/issues/2354.html, it's not included in C++20. so we have to use a different way to address > runtime error: reference binding to misaligned address 0x610000008395 > for type 'device_type_t', which requires 4 byte alignment otherwise the code would fail to compile with Clang-15, like: > :3:13: error: 'alignas' attribute cannot be applied to an enumeration Signed-off-by: Kefu Chai --- src/crimson/os/seastore/device.h | 4 ++-- src/crimson/os/seastore/seastore_types.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/crimson/os/seastore/device.h b/src/crimson/os/seastore/device.h index 24a3d4bac2b..3b479d7b9b7 100644 --- a/src/crimson/os/seastore/device.h +++ b/src/crimson/os/seastore/device.h @@ -14,7 +14,7 @@ namespace crimson::os::seastore { using magic_t = uint64_t; -struct device_spec_t{ +struct device_spec_t { magic_t magic = 0; device_type_t dtype = device_type_t::NONE; device_id_t id = DEVICE_ID_NULL; @@ -25,7 +25,7 @@ struct device_spec_t{ denc(v.id, p); DENC_FINISH(p); } -}; +} __attribute__ ((packed)); std::ostream& operator<<(std::ostream&, const device_spec_t&); diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index 761577ec85c..f98f800ffc8 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -871,7 +871,7 @@ constexpr auto PLACEMENT_HINT_NULL = placement_hint_t::NUM_HINTS; std::ostream& operator<<(std::ostream& out, placement_hint_t h); -enum class alignas(4) device_type_t : uint_fast8_t { +enum class device_type_t : uint8_t { NONE = 0, HDD, SSD, -- 2.39.5