]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) 2016 John Spray <john.spray@redhat.com> | |
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 DAEMON_SERVER_H_ | |
15 | #define DAEMON_SERVER_H_ | |
16 | ||
3efd9988 | 17 | #include "PyModuleRegistry.h" |
7c673cae FG |
18 | |
19 | #include <set> | |
20 | #include <string> | |
9f95a23c | 21 | #include <boost/variant.hpp> |
7c673cae | 22 | |
9f95a23c | 23 | #include "common/ceph_mutex.h" |
7c673cae | 24 | #include "common/LogClient.h" |
11fdf7f2 | 25 | #include "common/Timer.h" |
7c673cae FG |
26 | |
27 | #include <msg/Messenger.h> | |
28 | #include <mon/MonClient.h> | |
29 | ||
224ce89b | 30 | #include "ServiceMap.h" |
7c673cae FG |
31 | #include "MgrSession.h" |
32 | #include "DaemonState.h" | |
9f95a23c | 33 | #include "MetricCollector.h" |
11fdf7f2 | 34 | #include "OSDPerfMetricCollector.h" |
7c673cae FG |
35 | |
36 | class MMgrReport; | |
37 | class MMgrOpen; | |
11fdf7f2 | 38 | class MMgrClose; |
31f18b77 | 39 | class MMonMgrReport; |
7c673cae | 40 | class MCommand; |
9f95a23c | 41 | class MMgrCommand; |
c07f9fc5 | 42 | struct MonCommand; |
11fdf7f2 TL |
43 | class CommandContext; |
44 | struct OSDPerfMetricQuery; | |
7c673cae FG |
45 | |
46 | ||
47 | /** | |
48 | * Server used in ceph-mgr to communicate with Ceph daemons like | |
49 | * MDSs and OSDs. | |
50 | */ | |
3efd9988 | 51 | class DaemonServer : public Dispatcher, public md_config_obs_t |
7c673cae FG |
52 | { |
53 | protected: | |
54 | boost::scoped_ptr<Throttle> client_byte_throttler; | |
55 | boost::scoped_ptr<Throttle> client_msg_throttler; | |
56 | boost::scoped_ptr<Throttle> osd_byte_throttler; | |
57 | boost::scoped_ptr<Throttle> osd_msg_throttler; | |
58 | boost::scoped_ptr<Throttle> mds_byte_throttler; | |
59 | boost::scoped_ptr<Throttle> mds_msg_throttler; | |
60 | boost::scoped_ptr<Throttle> mon_byte_throttler; | |
61 | boost::scoped_ptr<Throttle> mon_msg_throttler; | |
62 | ||
63 | Messenger *msgr; | |
64 | MonClient *monc; | |
65 | Finisher &finisher; | |
66 | DaemonStateIndex &daemon_state; | |
67 | ClusterState &cluster_state; | |
3efd9988 | 68 | PyModuleRegistry &py_modules; |
7c673cae FG |
69 | LogChannelRef clog, audit_clog; |
70 | ||
3efd9988 FG |
71 | // Connections for daemons, and clients with service names set |
72 | // (i.e. those MgrClients that are allowed to send MMgrReports) | |
73 | std::set<ConnectionRef> daemon_connections; | |
74 | ||
31f18b77 FG |
75 | /// connections for osds |
76 | ceph::unordered_map<int,set<ConnectionRef>> osd_cons; | |
77 | ||
224ce89b | 78 | ServiceMap pending_service_map; // uncommitted |
3efd9988 | 79 | |
224ce89b WB |
80 | epoch_t pending_service_map_dirty = 0; |
81 | ||
9f95a23c | 82 | ceph::mutex lock = ceph::make_mutex("DaemonServer"); |
7c673cae | 83 | |
11fdf7f2 | 84 | static void _generate_command_map(cmdmap_t& cmdmap, |
7c673cae | 85 | map<string,string> ¶m_str_map); |
c07f9fc5 FG |
86 | static const MonCommand *_get_mgrcommand(const string &cmd_prefix, |
87 | const std::vector<MonCommand> &commands); | |
7c673cae | 88 | bool _allowed_command( |
92f5a8d4 TL |
89 | MgrSession *s, const string &service, const string &module, |
90 | const string &prefix, const cmdmap_t& cmdmap, | |
7c673cae | 91 | const map<string,string>& param_str_map, |
c07f9fc5 | 92 | const MonCommand *this_cmd); |
7c673cae FG |
93 | |
94 | private: | |
95 | friend class ReplyOnFinish; | |
96 | bool _reply(MCommand* m, | |
97 | int ret, const std::string& s, const bufferlist& payload); | |
98 | ||
224ce89b WB |
99 | void _prune_pending_service_map(); |
100 | ||
101 | utime_t started_at; | |
3efd9988 | 102 | std::atomic<bool> pgmap_ready; |
224ce89b WB |
103 | std::set<int32_t> reported_osds; |
104 | void maybe_ready(int32_t osd_id); | |
105 | ||
11fdf7f2 TL |
106 | SafeTimer timer; |
107 | bool shutting_down; | |
108 | Context *tick_event; | |
109 | void tick(); | |
110 | void schedule_tick_locked(double delay_sec); | |
111 | ||
9f95a23c | 112 | class OSDPerfMetricCollectorListener : public MetricListener { |
11fdf7f2 TL |
113 | public: |
114 | OSDPerfMetricCollectorListener(DaemonServer *server) | |
115 | : server(server) { | |
116 | } | |
117 | void handle_query_updated() override { | |
118 | server->handle_osd_perf_metric_query_updated(); | |
119 | } | |
120 | private: | |
121 | DaemonServer *server; | |
122 | }; | |
123 | OSDPerfMetricCollectorListener osd_perf_metric_collector_listener; | |
124 | OSDPerfMetricCollector osd_perf_metric_collector; | |
125 | void handle_osd_perf_metric_query_updated(); | |
126 | ||
9f95a23c TL |
127 | void handle_metric_payload(const OSDMetricPayload &payload) { |
128 | osd_perf_metric_collector.process_reports(payload); | |
129 | } | |
130 | ||
131 | void handle_metric_payload(const UnknownMetricPayload &payload) { | |
132 | ceph_abort(); | |
133 | } | |
134 | ||
135 | struct HandlePayloadVisitor : public boost::static_visitor<void> { | |
136 | DaemonServer *server; | |
137 | ||
138 | HandlePayloadVisitor(DaemonServer *server) | |
139 | : server(server) { | |
140 | } | |
141 | ||
142 | template <typename MetricPayload> | |
143 | inline void operator()(const MetricPayload &payload) const { | |
144 | server->handle_metric_payload(payload); | |
145 | } | |
146 | }; | |
147 | ||
148 | void update_task_status(DaemonKey key, const ref_t<MMgrReport>& m); | |
149 | ||
7c673cae | 150 | public: |
11fdf7f2 | 151 | int init(uint64_t gid, entity_addrvec_t client_addrs); |
7c673cae FG |
152 | void shutdown(); |
153 | ||
11fdf7f2 | 154 | entity_addrvec_t get_myaddrs() const; |
7c673cae FG |
155 | |
156 | DaemonServer(MonClient *monc_, | |
157 | Finisher &finisher_, | |
158 | DaemonStateIndex &daemon_state_, | |
159 | ClusterState &cluster_state_, | |
3efd9988 | 160 | PyModuleRegistry &py_modules_, |
7c673cae FG |
161 | LogChannelRef cl, |
162 | LogChannelRef auditcl); | |
163 | ~DaemonServer() override; | |
164 | ||
9f95a23c | 165 | bool ms_dispatch2(const ceph::ref_t<Message>& m) override; |
11fdf7f2 | 166 | int ms_handle_authentication(Connection *con) override; |
31f18b77 | 167 | bool ms_handle_reset(Connection *con) override; |
7c673cae FG |
168 | void ms_handle_remote_reset(Connection *con) override {} |
169 | bool ms_handle_refused(Connection *con) override; | |
9f95a23c TL |
170 | |
171 | bool handle_open(const ceph::ref_t<MMgrOpen>& m); | |
172 | bool handle_close(const ceph::ref_t<MMgrClose>& m); | |
173 | bool handle_report(const ceph::ref_t<MMgrReport>& m); | |
174 | bool handle_command(const ceph::ref_t<MCommand>& m); | |
175 | bool handle_command(const ceph::ref_t<MMgrCommand>& m); | |
176 | bool _handle_command(std::shared_ptr<CommandContext>& cmdctx); | |
31f18b77 | 177 | void send_report(); |
224ce89b | 178 | void got_service_map(); |
11fdf7f2 TL |
179 | void got_mgr_map(); |
180 | void adjust_pgs(); | |
3efd9988 FG |
181 | |
182 | void _send_configure(ConnectionRef c); | |
183 | ||
9f95a23c | 184 | MetricQueryID add_osd_perf_query( |
11fdf7f2 TL |
185 | const OSDPerfMetricQuery &query, |
186 | const std::optional<OSDPerfMetricLimit> &limit); | |
9f95a23c TL |
187 | int remove_osd_perf_query(MetricQueryID query_id); |
188 | int get_osd_perf_counters(MetricQueryID query_id, | |
11fdf7f2 TL |
189 | std::map<OSDPerfMetricKey, PerformanceCounters> *c); |
190 | ||
3efd9988 | 191 | virtual const char** get_tracked_conf_keys() const override; |
11fdf7f2 | 192 | virtual void handle_conf_change(const ConfigProxy& conf, |
3efd9988 | 193 | const std::set <std::string> &changed) override; |
11fdf7f2 TL |
194 | |
195 | void schedule_tick(double delay_sec); | |
92f5a8d4 TL |
196 | |
197 | void log_access_denied(std::shared_ptr<CommandContext>& cmdctx, | |
198 | MgrSession* session, std::stringstream& ss); | |
9f95a23c | 199 | void dump_pg_ready(ceph::Formatter *f); |
7c673cae FG |
200 | }; |
201 | ||
202 | #endif | |
203 |