]> git.proxmox.com Git - ceph.git/blame - ceph/src/mgr/DaemonServer.h
Import ceph 15.2.8
[ceph.git] / ceph / src / mgr / DaemonServer.h
CommitLineData
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
36class MMgrReport;
37class MMgrOpen;
11fdf7f2 38class MMgrClose;
31f18b77 39class MMonMgrReport;
7c673cae 40class MCommand;
9f95a23c 41class MMgrCommand;
c07f9fc5 42struct MonCommand;
11fdf7f2
TL
43class CommandContext;
44struct OSDPerfMetricQuery;
7c673cae
FG
45
46
47/**
48 * Server used in ceph-mgr to communicate with Ceph daemons like
49 * MDSs and OSDs.
50 */
3efd9988 51class DaemonServer : public Dispatcher, public md_config_obs_t
7c673cae
FG
52{
53protected:
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> &param_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
94private:
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
f91f0fd5
TL
148 void update_task_status(DaemonKey key,
149 const std::map<std::string,std::string>& task_status);
9f95a23c 150
7c673cae 151public:
11fdf7f2 152 int init(uint64_t gid, entity_addrvec_t client_addrs);
7c673cae
FG
153 void shutdown();
154
11fdf7f2 155 entity_addrvec_t get_myaddrs() const;
7c673cae
FG
156
157 DaemonServer(MonClient *monc_,
158 Finisher &finisher_,
159 DaemonStateIndex &daemon_state_,
160 ClusterState &cluster_state_,
3efd9988 161 PyModuleRegistry &py_modules_,
7c673cae
FG
162 LogChannelRef cl,
163 LogChannelRef auditcl);
164 ~DaemonServer() override;
165
9f95a23c 166 bool ms_dispatch2(const ceph::ref_t<Message>& m) override;
11fdf7f2 167 int ms_handle_authentication(Connection *con) override;
31f18b77 168 bool ms_handle_reset(Connection *con) override;
7c673cae
FG
169 void ms_handle_remote_reset(Connection *con) override {}
170 bool ms_handle_refused(Connection *con) override;
9f95a23c 171
1911f103 172 void fetch_missing_metadata(const DaemonKey& key, const entity_addr_t& addr);
9f95a23c
TL
173 bool handle_open(const ceph::ref_t<MMgrOpen>& m);
174 bool handle_close(const ceph::ref_t<MMgrClose>& m);
175 bool handle_report(const ceph::ref_t<MMgrReport>& m);
176 bool handle_command(const ceph::ref_t<MCommand>& m);
177 bool handle_command(const ceph::ref_t<MMgrCommand>& m);
178 bool _handle_command(std::shared_ptr<CommandContext>& cmdctx);
31f18b77 179 void send_report();
224ce89b 180 void got_service_map();
11fdf7f2
TL
181 void got_mgr_map();
182 void adjust_pgs();
3efd9988
FG
183
184 void _send_configure(ConnectionRef c);
185
9f95a23c 186 MetricQueryID add_osd_perf_query(
11fdf7f2
TL
187 const OSDPerfMetricQuery &query,
188 const std::optional<OSDPerfMetricLimit> &limit);
9f95a23c
TL
189 int remove_osd_perf_query(MetricQueryID query_id);
190 int get_osd_perf_counters(MetricQueryID query_id,
11fdf7f2
TL
191 std::map<OSDPerfMetricKey, PerformanceCounters> *c);
192
3efd9988 193 virtual const char** get_tracked_conf_keys() const override;
11fdf7f2 194 virtual void handle_conf_change(const ConfigProxy& conf,
3efd9988 195 const std::set <std::string> &changed) override;
11fdf7f2
TL
196
197 void schedule_tick(double delay_sec);
92f5a8d4
TL
198
199 void log_access_denied(std::shared_ptr<CommandContext>& cmdctx,
200 MgrSession* session, std::stringstream& ss);
9f95a23c 201 void dump_pg_ready(ceph::Formatter *f);
7c673cae
FG
202};
203
204#endif
205