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"
22 #include "common/Mutex.h"
23 #include "common/LogClient.h"
24 #include "common/Timer.h"
26 #include <msg/Messenger.h>
27 #include <mon/MonClient.h>
29 #include "ServiceMap.h"
30 #include "MgrSession.h"
31 #include "DaemonState.h"
32 #include "OSDPerfMetricCollector.h"
41 struct OSDPerfMetricQuery
;
45 * Server used in ceph-mgr to communicate with Ceph daemons like
48 class DaemonServer
: public Dispatcher
, public md_config_obs_t
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
;
63 DaemonStateIndex
&daemon_state
;
64 ClusterState
&cluster_state
;
65 PyModuleRegistry
&py_modules
;
66 LogChannelRef clog
, audit_clog
;
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
;
72 /// connections for osds
73 ceph::unordered_map
<int,set
<ConnectionRef
>> osd_cons
;
75 ServiceMap pending_service_map
; // uncommitted
77 epoch_t pending_service_map_dirty
= 0;
81 static void _generate_command_map(cmdmap_t
& cmdmap
,
82 map
<string
,string
> ¶m_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
);
92 friend class ReplyOnFinish
;
93 bool _reply(MCommand
* m
,
94 int ret
, const std::string
& s
, const bufferlist
& payload
);
96 void _prune_pending_service_map();
99 std::atomic
<bool> pgmap_ready
;
100 std::set
<int32_t> reported_osds
;
101 void maybe_ready(int32_t osd_id
);
107 void schedule_tick_locked(double delay_sec
);
109 class OSDPerfMetricCollectorListener
:
110 public OSDPerfMetricCollector::Listener
{
112 OSDPerfMetricCollectorListener(DaemonServer
*server
)
115 void handle_query_updated() override
{
116 server
->handle_osd_perf_metric_query_updated();
119 DaemonServer
*server
;
121 OSDPerfMetricCollectorListener osd_perf_metric_collector_listener
;
122 OSDPerfMetricCollector osd_perf_metric_collector
;
123 void handle_osd_perf_metric_query_updated();
126 int init(uint64_t gid
, entity_addrvec_t client_addrs
);
129 entity_addrvec_t
get_myaddrs() const;
131 DaemonServer(MonClient
*monc_
,
133 DaemonStateIndex
&daemon_state_
,
134 ClusterState
&cluster_state_
,
135 PyModuleRegistry
&py_modules_
,
137 LogChannelRef auditcl
);
138 ~DaemonServer() override
;
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
;
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
);
154 void got_service_map();
158 void _send_configure(ConnectionRef c
);
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
);
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
;
171 void schedule_tick(double delay_sec
);
173 void log_access_denied(std::shared_ptr
<CommandContext
>& cmdctx
,
174 MgrSession
* session
, std::stringstream
& ss
);