From: Kefu Chai Date: Wed, 25 Feb 2026 07:55:25 +0000 (+0800) Subject: osd: fix ASAN ODR violations in denc-mod-osd X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=aa859508bd8a912475fc78a3287ae7c1ad46f285;p=ceph.git osd: fix ASAN ODR violations in denc-mod-osd When building ceph-dencoder with ASAN (-DWITH_ASAN=ON), loading denc-mod-osd.so triggered ODR (One Definition Rule) violations because several static class members were defined both in libceph-common.so and denc-mod-osd.so. Fix each case appropriately: - pg_pool_t::APPLICATION_NAME_{CEPHFS,RBD,RGW}: used across many translation units; convert to inline static constexpr in the header and remove the out-of-line definitions from osd_types.cc. - ObjectCleanRegions::max_num_intervals: used in osd_types.cc and OSD.cc; convert to inline static in the header and remove the out-of-line definition from osd_types.cc. - SnapMapper::{MAPPING_PREFIX,OBJECT_PREFIX,PURGED_SNAP_PREFIX}: only used within SnapMapper.cc; remove from the class entirely and move to file-local static constants in SnapMapper.cc. - SnapMapper::{LEGACY_MAPPING_PREFIX,PURGED_SNAP_EPOCH_PREFIX}: never used anywhere; remove the dead declarations from SnapMapper.h. Signed-off-by: Kefu Chai --- diff --git a/src/osd/SnapMapper.cc b/src/osd/SnapMapper.cc index df2da64b3e49..6496b05d04f0 100644 --- a/src/osd/SnapMapper.cc +++ b/src/osd/SnapMapper.cc @@ -42,11 +42,9 @@ using ceph::timespan_str; using result_t = Scrub::SnapMapReaderI::result_t; using code_t = Scrub::SnapMapReaderI::result_t::code_t; - -const string SnapMapper::MAPPING_PREFIX = "SNA_"; -const string SnapMapper::OBJECT_PREFIX = "OBJ_"; - -const char *SnapMapper::PURGED_SNAP_PREFIX = "PSN_"; +static const std::string MAPPING_PREFIX = "SNA_"; +static const std::string OBJECT_PREFIX = "OBJ_"; +static const char *PURGED_SNAP_PREFIX = "PSN_"; /* diff --git a/src/osd/SnapMapper.h b/src/osd/SnapMapper.h index c7cab0c34401..f3d4f58ec573 100644 --- a/src/osd/SnapMapper.h +++ b/src/osd/SnapMapper.h @@ -181,12 +181,6 @@ public: } }; - static const std::string LEGACY_MAPPING_PREFIX; - static const std::string MAPPING_PREFIX; - static const std::string OBJECT_PREFIX; - static const char *PURGED_SNAP_EPOCH_PREFIX; - static const char *PURGED_SNAP_PREFIX; - #ifndef WITH_CRIMSON struct Scrubber { CephContext *cct; diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 7c7e87b65492..21baa09aaef8 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -1584,10 +1584,6 @@ ostream& operator<<(ostream& out, const pool_opts_t& opts) // -- pg_pool_t -- -const char *pg_pool_t::APPLICATION_NAME_CEPHFS("cephfs"); -const char *pg_pool_t::APPLICATION_NAME_RBD("rbd"); -const char *pg_pool_t::APPLICATION_NAME_RGW("rgw"); - void pg_pool_t::dump(Formatter *f) const { f->dump_stream("create_time") << get_create_time(); @@ -4875,8 +4871,6 @@ void ObjectModDesc::decode(ceph::buffer::list::const_iterator &_bl) DECODE_FINISH(_bl); } -std::atomic ObjectCleanRegions::max_num_intervals = {10}; - void ObjectCleanRegions::set_max_num_intervals(uint32_t num) { max_num_intervals = num; diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 5377ffac182e..f876dc20ee62 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -1278,9 +1278,9 @@ class OSDMap; * pg_pool */ struct pg_pool_t { - static const char *APPLICATION_NAME_CEPHFS; - static const char *APPLICATION_NAME_RBD; - static const char *APPLICATION_NAME_RGW; + inline static constexpr const char *APPLICATION_NAME_CEPHFS = "cephfs"; + inline static constexpr const char *APPLICATION_NAME_RBD = "rbd"; + inline static constexpr const char *APPLICATION_NAME_RGW = "rgw"; enum { TYPE_REPLICATED = 1, // replication @@ -4270,7 +4270,7 @@ private: bool new_object; bool clean_omap; interval_set clean_offsets; - static std::atomic max_num_intervals; + inline static std::atomic max_num_intervals{10}; /** * trim the number of intervals if clean_offsets.num_intervals()