From: Alexander Indenbaum Date: Mon, 6 Oct 2025 08:41:40 +0000 (+0300) Subject: mon: centralize beacon version constants to eliminate duplication X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fheads%2Fwip-baum-beacon-diff-20251006-00;p=ceph-ci.git mon: centralize beacon version constants to eliminate duplication Signed-off-by: Alexander Indenbaum --- diff --git a/src/messages/MNVMeofGwBeacon.h b/src/messages/MNVMeofGwBeacon.h index a26d6d09f07..2ac395390e7 100644 --- a/src/messages/MNVMeofGwBeacon.h +++ b/src/messages/MNVMeofGwBeacon.h @@ -21,12 +21,10 @@ #include "mon/MonCommand.h" #include "mon/NVMeofGwMap.h" #include "include/types.h" +#include "mon/NVMeofGwBeaconConstants.h" class MNVMeofGwBeacon final : public PaxosServiceMessage { private: - static constexpr int BEACON_VERSION_LEGACY = 1; // legacy beacon format (no diff support) - static constexpr int BEACON_VERSION_ENHANCED = 2; // enhanced beacon format (with diff support) - static constexpr int COMPAT_VERSION = BEACON_VERSION_LEGACY; // minimum version to decode enhanced format protected: std::string gw_id; @@ -41,7 +39,7 @@ protected: public: MNVMeofGwBeacon() : PaxosServiceMessage{MSG_MNVMEOF_GW_BEACON, 0, BEACON_VERSION_ENHANCED, - COMPAT_VERSION}, sequence(0) + BEACON_VERSION_LEGACY}, sequence(0) { set_priority(CEPH_MSG_PRIO_HIGH); } @@ -57,8 +55,8 @@ public: bool enable_diff = false) // default to legacy behavior for backward compatibility : PaxosServiceMessage{MSG_MNVMEOF_GW_BEACON, static_cast(enable_diff ? 1 : 0), // user_version: 1=enhanced, 0=legacy - enable_diff ? BEACON_VERSION_ENHANCED : - BEACON_VERSION_LEGACY, COMPAT_VERSION},// Minimum compatible version + enable_diff ? BEACON_VERSION_ENHANCED : + BEACON_VERSION_LEGACY, BEACON_VERSION_LEGACY},// Minimum compatible version gw_id(gw_id_), gw_pool(gw_pool_), gw_group(gw_group_), subsystems(subsystems_), availability(availability_), last_osd_epoch(last_osd_epoch_), last_gwmap_epoch(last_gwmap_epoch_), sequence(sequence_) diff --git a/src/mon/NVMeofGwBeaconConstants.h b/src/mon/NVMeofGwBeaconConstants.h new file mode 100644 index 00000000000..7453905012f --- /dev/null +++ b/src/mon/NVMeofGwBeaconConstants.h @@ -0,0 +1,24 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2025 IBM, Inc. + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#ifndef CEPH_NVMEOFGWBEACONCONSTANTS_H +#define CEPH_NVMEOFGWBEACONCONSTANTS_H + +// This header contains version constants used across multiple files +// to avoid duplication and maintain consistency. + +// Beacon version constants +#define BEACON_VERSION_LEGACY 1 // Legacy beacon format (no diff support) +#define BEACON_VERSION_ENHANCED 2 // Enhanced beacon format (with diff support) + +#endif /* CEPH_NVMEOFGWBEACONCONSTANTS_H */ diff --git a/src/mon/NVMeofGwSerialize.h b/src/mon/NVMeofGwSerialize.h index 39fc7aaf4b7..d293504f216 100755 --- a/src/mon/NVMeofGwSerialize.h +++ b/src/mon/NVMeofGwSerialize.h @@ -13,6 +13,8 @@ #ifndef MON_NVMEOFGWSERIALIZE_H_ #define MON_NVMEOFGWSERIALIZE_H_ +#include "mon/NVMeofGwBeaconConstants.h" + #define dout_context g_ceph_context #define dout_subsys ceph_subsys_mon #undef dout_prefix @@ -20,11 +22,6 @@ #define dout_prefix *_dout << MODULE_PREFFIX << __PRETTY_FUNCTION__ << " " #define MAX_SUPPORTED_ANA_GROUPS 16 -// Local version constants that match MNVMeofGwBeacon.h -// We can't include that header here due to circular dependencies -#define BEACON_SUBSYS_VERSION_LEGACY 1 // Legacy beacon format (no diff support) -#define BEACON_SUBSYS_VERSION_ENHANCED 2 // Enhanced beacon format (with diff support) - inline std::ostream& operator<<( std::ostream& os, const gw_exported_states_per_group_t value) { switch (value) { @@ -318,7 +315,7 @@ inline void decode( inline void encode(const NvmeGwClientState& state, ceph::bufferlist &bl, uint64_t features) { uint8_t version = 1; if (HAVE_FEATURE(features, NVMEOF_BEACON_DIFF)) { - version = BEACON_SUBSYS_VERSION_ENHANCED; + version = BEACON_VERSION_ENHANCED; } ENCODE_START(version, version, bl); encode(state.group_id, bl); @@ -823,7 +820,7 @@ inline void decode(NvmeGwTimers& md, ceph::buffer::list::const_iterator &bl) { } inline void encode(const BeaconNamespace& ns, ceph::bufferlist &bl) { - ENCODE_START(BEACON_SUBSYS_VERSION_LEGACY, BEACON_SUBSYS_VERSION_LEGACY, bl); + ENCODE_START(BEACON_VERSION_LEGACY, BEACON_VERSION_LEGACY, bl); encode(ns.anagrpid, bl); encode(ns.nonce, bl); ENCODE_FINISH(bl); @@ -837,7 +834,7 @@ inline void decode(BeaconNamespace& ns, ceph::buffer::list::const_iterator &bl) } inline void encode(const BeaconListener& ls, ceph::bufferlist &bl) { - ENCODE_START(BEACON_SUBSYS_VERSION_LEGACY, BEACON_SUBSYS_VERSION_LEGACY, bl); + ENCODE_START(BEACON_VERSION_LEGACY, BEACON_VERSION_LEGACY, bl); encode(ls.address_family, bl); encode(ls.address, bl); encode(ls.svcid, bl); @@ -853,12 +850,12 @@ inline void decode(BeaconListener& ls, ceph::buffer::list::const_iterator &bl) { } inline void encode(const BeaconSubsystem& sub, ceph::bufferlist &bl, uint64_t features) { - uint8_t version = BEACON_SUBSYS_VERSION_LEGACY; // Default to legacy version + uint8_t version = BEACON_VERSION_LEGACY; // Default to legacy version if (HAVE_FEATURE(features, NVMEOF_BEACON_DIFF)) { - version = BEACON_SUBSYS_VERSION_ENHANCED; // Use enhanced version if feature supported + version = BEACON_VERSION_ENHANCED; // Use enhanced version if feature supported } // For legacy encoding, skip deleted subsystems to maintain compatibility - if (version == BEACON_SUBSYS_VERSION_LEGACY && + if (version == BEACON_VERSION_LEGACY && sub.change_descriptor != subsystem_change_t::SUBSYSTEM_ADDED) { dout(4) << "encode BeaconSubsystem: skipping subsystem " << sub.nqn << " with change_descriptor " << (int)sub.change_descriptor @@ -876,7 +873,7 @@ inline void encode(const BeaconSubsystem& sub, ceph::bufferlist &bl, uint64_t f encode((uint32_t)sub.namespaces.size(), bl); for (const auto& ns: sub.namespaces) encode(ns, bl); - if (version >= BEACON_SUBSYS_VERSION_ENHANCED) { + if (version >= BEACON_VERSION_ENHANCED) { encode((uint32_t)sub.change_descriptor, bl); dout(20) << "encode BeaconSubsystems change-descr: " << (uint32_t)sub.change_descriptor << dendl; } @@ -884,7 +881,7 @@ inline void encode(const BeaconSubsystem& sub, ceph::bufferlist &bl, uint64_t f } inline void decode(BeaconSubsystem& sub, ceph::buffer::list::const_iterator &bl) { - DECODE_START(BEACON_SUBSYS_VERSION_ENHANCED, bl); // Always decode with enhanced version support + DECODE_START(BEACON_VERSION_ENHANCED, bl); // Always decode with enhanced version support decode(sub.nqn, bl); dout(20) << "decode BeaconSubsystems " << sub.nqn << dendl; uint32_t s; @@ -903,11 +900,11 @@ inline void decode(BeaconSubsystem& sub, ceph::buffer::list::const_iterator &bl) decode(ns, bl); sub.namespaces.push_back(ns); } - if (struct_v >= BEACON_SUBSYS_VERSION_ENHANCED) { + if (struct_v >= BEACON_VERSION_ENHANCED) { uint32_t change_desc; decode(change_desc, bl); sub.change_descriptor = static_cast(change_desc); - dout(20) << "decode BeaconSubsystems version >= " << BEACON_SUBSYS_VERSION_ENHANCED << dendl; + dout(20) << "decode BeaconSubsystems version >= " << BEACON_VERSION_ENHANCED << dendl; } DECODE_FINISH(bl); }