|
| 1 | +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
| 2 | +// vim: ts=8 sw=2 smarttab |
| 3 | +/* |
| 4 | + * Ceph - scalable distributed file system |
| 5 | + * |
| 6 | + * Copyright (C) 2023 IBM, Inc. |
| 7 | + * |
| 8 | + * This is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU Lesser General Public |
| 10 | + * License version 2.1, as published by the Free Software |
| 11 | + * Foundation. See file COPYING. |
| 12 | + */ |
| 13 | + |
| 14 | +#ifndef MON_NVMEOFGWMAP_H_ |
| 15 | +#define MON_NVMEOFGWMAP_H_ |
| 16 | +#include <map> |
| 17 | +#include <iostream> |
| 18 | +#include "include/encoding.h" |
| 19 | +#include "include/utime.h" |
| 20 | +#include "common/Formatter.h" |
| 21 | +#include "common/ceph_releases.h" |
| 22 | +#include "common/version.h" |
| 23 | +#include "common/options.h" |
| 24 | +#include "common/Clock.h" |
| 25 | +#include "msg/Message.h" |
| 26 | +#include "common/ceph_time.h" |
| 27 | +#include "NVMeofGwTypes.h" |
| 28 | +#define dout_context g_ceph_context |
| 29 | +#define dout_subsys ceph_subsys_mon |
| 30 | +#undef dout_prefix |
| 31 | +#define MODULE_PREFFIX "nvmeofgw " |
| 32 | +#define dout_prefix *_dout << MODULE_PREFFIX << __PRETTY_FUNCTION__ << " " |
| 33 | + |
| 34 | + |
| 35 | +static const version_t STRUCT_VERSION = 2; |
| 36 | +static const version_t OLD_STRUCT_VERSION = 1; |
| 37 | + |
| 38 | +using ceph::coarse_mono_clock; |
| 39 | +class Monitor; |
| 40 | +/*-------------------*/ |
| 41 | +class NVMeofGwMap |
| 42 | +{ |
| 43 | +public: |
| 44 | + Monitor* mon = NULL; |
| 45 | + epoch_t epoch = 0; // epoch is for Paxos synchronization mechanizm |
| 46 | + bool delay_propose = false; |
| 47 | + std::map<entity_addrvec_t , uint32_t> peer_addr_2_version; |
| 48 | + std::map<NvmeGroupKey, NvmeGwMonStates> created_gws; |
| 49 | + std::map<NvmeGroupKey, NvmeGwTimers> fsm_timers;// map that handles timers started by all Gateway FSMs |
| 50 | + void to_gmap(std::map<NvmeGroupKey, NvmeGwMonClientStates>& Gmap) const; |
| 51 | + |
| 52 | + int cfg_add_gw (const NvmeGwId &gw_id, const NvmeGroupKey& group_key); |
| 53 | + int cfg_delete_gw (const NvmeGwId &gw_id, const NvmeGroupKey& group_key); |
| 54 | + void process_gw_map_ka (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, epoch_t& last_osd_epoch, bool &propose_pending); |
| 55 | + int process_gw_map_gw_down (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, bool &propose_pending); |
| 56 | + void update_active_timers (bool &propose_pending); |
| 57 | + void handle_abandoned_ana_groups (bool &propose_pending); |
| 58 | + void handle_removed_subsystems (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, const std::vector<NvmeNqnId> ¤t_subsystems, bool &propose_pending); |
| 59 | + void start_timer (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, NvmeAnaGrpId anagrpid, uint8_t value); |
| 60 | +private: |
| 61 | + void add_grp_id (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, const NvmeAnaGrpId grpid); |
| 62 | + void remove_grp_id(const NvmeGwId &gw_id, const NvmeGroupKey& group_key, const NvmeAnaGrpId grpid); |
| 63 | + void fsm_handle_gw_down (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, gw_states_per_group_t state, NvmeAnaGrpId grpid, bool &map_modified); |
| 64 | + void fsm_handle_gw_delete (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, gw_states_per_group_t state, NvmeAnaGrpId grpid, bool &map_modified); |
| 65 | + void fsm_handle_gw_alive (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, NvmeGwMonState & gw_state, gw_states_per_group_t state, |
| 66 | + NvmeAnaGrpId grpid, epoch_t& last_osd_epoch, bool &map_modified); |
| 67 | + void fsm_handle_to_expired (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, NvmeAnaGrpId grpid, bool &map_modified); |
| 68 | + |
| 69 | + void find_failover_candidate(const NvmeGwId &gw_id, const NvmeGroupKey& group_key, NvmeAnaGrpId grpid, bool &propose_pending); |
| 70 | + void find_failback_gw (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, bool &propose_pending); |
| 71 | + void set_failover_gw_for_ANA_group (const NvmeGwId &failed_gw_id, const NvmeGroupKey& group_key, const NvmeGwId &gw_id, |
| 72 | + NvmeAnaGrpId groupid); |
| 73 | + |
| 74 | + |
| 75 | + int get_timer (const NvmeGwId &gw_id, const NvmeGroupKey& group_key, NvmeAnaGrpId anagrpid); |
| 76 | + void cancel_timer(const NvmeGwId &gw_id, const NvmeGroupKey& group_key, NvmeAnaGrpId anagrpid); |
| 77 | + void validate_gw_map(const NvmeGroupKey& group_key); |
| 78 | + |
| 79 | +public: |
| 80 | + int blocklist_gw(const NvmeGwId &gw_id, const NvmeGroupKey& group_key, NvmeAnaGrpId ANA_groupid, epoch_t &epoch, bool failover); |
| 81 | + |
| 82 | + void encode(ceph::buffer::list &bl, uint64_t features) const { |
| 83 | + uint8_t version; |
| 84 | + if (HAVE_FEATURE(features, SERVER_SQUID)) version = STRUCT_VERSION; |
| 85 | + else version = OLD_STRUCT_VERSION; |
| 86 | + ENCODE_START(version, 1, bl); |
| 87 | + dout(4) << "encode1 version " << (uint64_t)version << version << " features " << features << dendl; |
| 88 | + using ceph::encode; |
| 89 | + encode(epoch, bl);// global map epoch |
| 90 | + if (version == STRUCT_VERSION) { |
| 91 | + //encode(peer_addr_2_version, bl); |
| 92 | + } |
| 93 | + encode(created_gws, bl, features); //Encode created GWs |
| 94 | + encode(fsm_timers, bl, features); |
| 95 | + ENCODE_FINISH(bl); |
| 96 | + } |
| 97 | + |
| 98 | + void decode(ceph::buffer::list::const_iterator &bl) { |
| 99 | + using ceph::decode; |
| 100 | + epoch_t struct_version = 0; |
| 101 | + DECODE_START(STRUCT_VERSION, bl); |
| 102 | + DECODE_OLDEST(1); |
| 103 | + struct_version = struct_v; |
| 104 | + dout(4) << "decode version " << struct_version << dendl; |
| 105 | + decode(epoch, bl); |
| 106 | + if (struct_version == STRUCT_VERSION) { |
| 107 | + //dout(4) << "Decode peer_2_addr " << dendl; |
| 108 | + //decode(peer_addr_2_version, bl); |
| 109 | + } |
| 110 | + decode(created_gws, bl); |
| 111 | + decode(fsm_timers, bl); |
| 112 | + DECODE_FINISH(bl); |
| 113 | + } |
| 114 | +}; |
| 115 | + |
| 116 | +#include "NVMeofGwSerialize.h" |
| 117 | + |
| 118 | +#endif /* SRC_MON_NVMEOFGWMAP_H_ */ |
0 commit comments