]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/DaemonServer.h
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / mgr / DaemonServer.h
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
17 #include "PyModuleRegistry.h"
18
19 #include <set>
20 #include <string>
21
22 #include "common/Mutex.h"
23 #include "common/LogClient.h"
24 #include "common/Timer.h"
25
26 #include <msg/Messenger.h>
27 #include <mon/MonClient.h>
28
29 #include "ServiceMap.h"
30 #include "MgrSession.h"
31 #include "DaemonState.h"
32 #include "OSDPerfMetricCollector.h"
33
34 class MMgrReport;
35 class MMgrOpen;
36 class MMgrClose;
37 class MMonMgrReport;
38 class MCommand;
39 struct MonCommand;
40 class CommandContext;
41 struct OSDPerfMetricQuery;
42
43
44 /**
45 * Server used in ceph-mgr to communicate with Ceph daemons like
46 * MDSs and OSDs.
47 */
48 class DaemonServer : public Dispatcher, public md_config_obs_t
49 {
50 protected:
51 boost::scoped_ptr<Throttle> client_byte_throttler;
52 boost::scoped_ptr<Throttle> client_msg_throttler;
53 boost::scoped_ptr<Throttle> osd_byte_throttler;
54 boost::scoped_ptr<Throttle> osd_msg_throttler;
55 boost::scoped_ptr<Throttle> mds_byte_throttler;
56 boost::scoped_ptr<Throttle> mds_msg_throttler;
57 boost::scoped_ptr<Throttle> mon_byte_throttler;
58 boost::scoped_ptr<Throttle> mon_msg_throttler;
59
60 Messenger *msgr;
61 MonClient *monc;
62 Finisher &finisher;
63 DaemonStateIndex &daemon_state;
64 ClusterState &cluster_state;
65 PyModuleRegistry &py_modules;
66 LogChannelRef clog, audit_clog;
67
68 // Connections for daemons, and clients with service names set
69 // (i.e. those MgrClients that are allowed to send MMgrReports)
70 std::set<ConnectionRef> daemon_connections;
71
72 /// connections for osds
73 ceph::unordered_map<int,set<ConnectionRef>> osd_cons;
74
75 ServiceMap pending_service_map; // uncommitted
76
77 epoch_t pending_service_map_dirty = 0;
78
79 Mutex lock;
80
81 static void _generate_command_map(cmdmap_t& cmdmap,
82 map<string,string> &param_str_map);
83 static const MonCommand *_get_mgrcommand(const string &cmd_prefix,
84 const std::vector<MonCommand> &commands);
85 bool _allowed_command(
86 MgrSession *s, const string &service, const string &module,
87 const string &prefix, const cmdmap_t& cmdmap,
88 const map<string,string>& param_str_map,
89 const MonCommand *this_cmd);
90
91 private:
92 friend class ReplyOnFinish;
93 bool _reply(MCommand* m,
94 int ret, const std::string& s, const bufferlist& payload);
95
96 void _prune_pending_service_map();
97
98 utime_t started_at;
99 std::atomic<bool> pgmap_ready;
100 std::set<int32_t> reported_osds;
101 void maybe_ready(int32_t osd_id);
102
103 SafeTimer timer;
104 bool shutting_down;
105 Context *tick_event;
106 void tick();
107 void schedule_tick_locked(double delay_sec);
108
109 class OSDPerfMetricCollectorListener :
110 public OSDPerfMetricCollector::Listener {
111 public:
112 OSDPerfMetricCollectorListener(DaemonServer *server)
113 : server(server) {
114 }
115 void handle_query_updated() override {
116 server->handle_osd_perf_metric_query_updated();
117 }
118 private:
119 DaemonServer *server;
120 };
121 OSDPerfMetricCollectorListener osd_perf_metric_collector_listener;
122 OSDPerfMetricCollector osd_perf_metric_collector;
123 void handle_osd_perf_metric_query_updated();
124
125 public:
126 int init(uint64_t gid, entity_addrvec_t client_addrs);
127 void shutdown();
128
129 entity_addrvec_t get_myaddrs() const;
130
131 DaemonServer(MonClient *monc_,
132 Finisher &finisher_,
133 DaemonStateIndex &daemon_state_,
134 ClusterState &cluster_state_,
135 PyModuleRegistry &py_modules_,
136 LogChannelRef cl,
137 LogChannelRef auditcl);
138 ~DaemonServer() override;
139
140 bool ms_dispatch(Message *m) override;
141 int ms_handle_authentication(Connection *con) override;
142 bool ms_handle_reset(Connection *con) override;
143 void ms_handle_remote_reset(Connection *con) override {}
144 bool ms_handle_refused(Connection *con) override;
145 bool ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer) override;
146 KeyStore *ms_get_auth1_authorizer_keystore() override;
147
148 bool handle_open(MMgrOpen *m);
149 bool handle_close(MMgrClose *m);
150 bool handle_report(MMgrReport *m);
151 bool handle_command(MCommand *m);
152 bool _handle_command(MCommand *m, std::shared_ptr<CommandContext>& cmdctx);
153 void send_report();
154 void got_service_map();
155 void got_mgr_map();
156 void adjust_pgs();
157
158 void _send_configure(ConnectionRef c);
159
160 OSDPerfMetricQueryID add_osd_perf_query(
161 const OSDPerfMetricQuery &query,
162 const std::optional<OSDPerfMetricLimit> &limit);
163 int remove_osd_perf_query(OSDPerfMetricQueryID query_id);
164 int get_osd_perf_counters(OSDPerfMetricQueryID query_id,
165 std::map<OSDPerfMetricKey, PerformanceCounters> *c);
166
167 virtual const char** get_tracked_conf_keys() const override;
168 virtual void handle_conf_change(const ConfigProxy& conf,
169 const std::set <std::string> &changed) override;
170
171 void schedule_tick(double delay_sec);
172
173 void log_access_denied(std::shared_ptr<CommandContext>& cmdctx,
174 MgrSession* session, std::stringstream& ss);
175 };
176
177 #endif
178