1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
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.
14 #ifndef DAEMON_SERVER_H_
15 #define DAEMON_SERVER_H_
17 #include "PyModuleRegistry.h"
21 #include <boost/variant.hpp>
23 #include "common/ceph_mutex.h"
24 #include "common/LogClient.h"
25 #include "common/Timer.h"
27 #include <msg/Messenger.h>
28 #include <mon/MonClient.h>
30 #include "ServiceMap.h"
31 #include "MgrSession.h"
32 #include "DaemonState.h"
33 #include "MetricCollector.h"
34 #include "OSDPerfMetricCollector.h"
44 struct OSDPerfMetricQuery
;
48 * Server used in ceph-mgr to communicate with Ceph daemons like
51 class DaemonServer
: public Dispatcher
, public md_config_obs_t
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
;
66 DaemonStateIndex
&daemon_state
;
67 ClusterState
&cluster_state
;
68 PyModuleRegistry
&py_modules
;
69 LogChannelRef clog
, audit_clog
;
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
;
75 /// connections for osds
76 ceph::unordered_map
<int,set
<ConnectionRef
>> osd_cons
;
78 ServiceMap pending_service_map
; // uncommitted
80 epoch_t pending_service_map_dirty
= 0;
82 ceph::mutex lock
= ceph::make_mutex("DaemonServer");
84 static void _generate_command_map(cmdmap_t
& cmdmap
,
85 map
<string
,string
> ¶m_str_map
);
86 static const MonCommand
*_get_mgrcommand(const string
&cmd_prefix
,
87 const std::vector
<MonCommand
> &commands
);
88 bool _allowed_command(
89 MgrSession
*s
, const string
&service
, const string
&module
,
90 const string
&prefix
, const cmdmap_t
& cmdmap
,
91 const map
<string
,string
>& param_str_map
,
92 const MonCommand
*this_cmd
);
95 friend class ReplyOnFinish
;
96 bool _reply(MCommand
* m
,
97 int ret
, const std::string
& s
, const bufferlist
& payload
);
99 void _prune_pending_service_map();
102 std::atomic
<bool> pgmap_ready
;
103 std::set
<int32_t> reported_osds
;
104 void maybe_ready(int32_t osd_id
);
110 void schedule_tick_locked(double delay_sec
);
112 class OSDPerfMetricCollectorListener
: public MetricListener
{
114 OSDPerfMetricCollectorListener(DaemonServer
*server
)
117 void handle_query_updated() override
{
118 server
->handle_osd_perf_metric_query_updated();
121 DaemonServer
*server
;
123 OSDPerfMetricCollectorListener osd_perf_metric_collector_listener
;
124 OSDPerfMetricCollector osd_perf_metric_collector
;
125 void handle_osd_perf_metric_query_updated();
127 void handle_metric_payload(const OSDMetricPayload
&payload
) {
128 osd_perf_metric_collector
.process_reports(payload
);
131 void handle_metric_payload(const UnknownMetricPayload
&payload
) {
135 struct HandlePayloadVisitor
: public boost::static_visitor
<void> {
136 DaemonServer
*server
;
138 HandlePayloadVisitor(DaemonServer
*server
)
142 template <typename MetricPayload
>
143 inline void operator()(const MetricPayload
&payload
) const {
144 server
->handle_metric_payload(payload
);
148 void update_task_status(DaemonKey key
,
149 const std::map
<std::string
,std::string
>& task_status
);
152 int init(uint64_t gid
, entity_addrvec_t client_addrs
);
155 entity_addrvec_t
get_myaddrs() const;
157 DaemonServer(MonClient
*monc_
,
159 DaemonStateIndex
&daemon_state_
,
160 ClusterState
&cluster_state_
,
161 PyModuleRegistry
&py_modules_
,
163 LogChannelRef auditcl
);
164 ~DaemonServer() override
;
166 bool ms_dispatch2(const ceph::ref_t
<Message
>& m
) override
;
167 int ms_handle_authentication(Connection
*con
) override
;
168 bool ms_handle_reset(Connection
*con
) override
;
169 void ms_handle_remote_reset(Connection
*con
) override
{}
170 bool ms_handle_refused(Connection
*con
) override
;
172 void fetch_missing_metadata(const DaemonKey
& key
, const entity_addr_t
& addr
);
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
);
180 void got_service_map();
184 void _send_configure(ConnectionRef c
);
186 MetricQueryID
add_osd_perf_query(
187 const OSDPerfMetricQuery
&query
,
188 const std::optional
<OSDPerfMetricLimit
> &limit
);
189 int remove_osd_perf_query(MetricQueryID query_id
);
190 int get_osd_perf_counters(MetricQueryID query_id
,
191 std::map
<OSDPerfMetricKey
, PerformanceCounters
> *c
);
193 virtual const char** get_tracked_conf_keys() const override
;
194 virtual void handle_conf_change(const ConfigProxy
& conf
,
195 const std::set
<std::string
> &changed
) override
;
197 void schedule_tick(double delay_sec
);
199 void log_access_denied(std::shared_ptr
<CommandContext
>& cmdctx
,
200 MgrSession
* session
, std::stringstream
& ss
);
201 void dump_pg_ready(ceph::Formatter
*f
);