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"
25 #include <msg/Messenger.h>
26 #include <mon/MonClient.h>
28 #include "auth/AuthAuthorizeHandler.h"
30 #include "ServiceMap.h"
31 #include "MgrSession.h"
32 #include "DaemonState.h"
42 * Server used in ceph-mgr to communicate with Ceph daemons like
45 class DaemonServer
: public Dispatcher
, public md_config_obs_t
48 boost::scoped_ptr
<Throttle
> client_byte_throttler
;
49 boost::scoped_ptr
<Throttle
> client_msg_throttler
;
50 boost::scoped_ptr
<Throttle
> osd_byte_throttler
;
51 boost::scoped_ptr
<Throttle
> osd_msg_throttler
;
52 boost::scoped_ptr
<Throttle
> mds_byte_throttler
;
53 boost::scoped_ptr
<Throttle
> mds_msg_throttler
;
54 boost::scoped_ptr
<Throttle
> mon_byte_throttler
;
55 boost::scoped_ptr
<Throttle
> mon_msg_throttler
;
60 DaemonStateIndex
&daemon_state
;
61 ClusterState
&cluster_state
;
62 PyModuleRegistry
&py_modules
;
63 LogChannelRef clog
, audit_clog
;
65 AuthAuthorizeHandlerRegistry auth_registry
;
67 // Connections for daemons, and clients with service names set
68 // (i.e. those MgrClients that are allowed to send MMgrReports)
69 std::set
<ConnectionRef
> daemon_connections
;
71 /// connections for osds
72 ceph::unordered_map
<int,set
<ConnectionRef
>> osd_cons
;
74 ServiceMap pending_service_map
; // uncommitted
76 epoch_t pending_service_map_dirty
= 0;
80 static void _generate_command_map(map
<string
,cmd_vartype
>& cmdmap
,
81 map
<string
,string
> ¶m_str_map
);
82 static const MonCommand
*_get_mgrcommand(const string
&cmd_prefix
,
83 const std::vector
<MonCommand
> &commands
);
84 bool _allowed_command(
85 MgrSession
*s
, const string
&module
, const string
&prefix
,
86 const map
<string
,cmd_vartype
>& cmdmap
,
87 const map
<string
,string
>& param_str_map
,
88 const MonCommand
*this_cmd
);
91 friend class ReplyOnFinish
;
92 bool _reply(MCommand
* m
,
93 int ret
, const std::string
& s
, const bufferlist
& payload
);
95 void _prune_pending_service_map();
98 std::atomic
<bool> pgmap_ready
;
99 std::set
<int32_t> reported_osds
;
100 void maybe_ready(int32_t osd_id
);
103 int init(uint64_t gid
, entity_addr_t client_addr
);
106 entity_addr_t
get_myaddr() const;
108 DaemonServer(MonClient
*monc_
,
110 DaemonStateIndex
&daemon_state_
,
111 ClusterState
&cluster_state_
,
112 PyModuleRegistry
&py_modules_
,
114 LogChannelRef auditcl
);
115 ~DaemonServer() override
;
117 bool ms_dispatch(Message
*m
) override
;
118 bool ms_handle_reset(Connection
*con
) override
;
119 void ms_handle_remote_reset(Connection
*con
) override
{}
120 bool ms_handle_refused(Connection
*con
) override
;
121 bool ms_get_authorizer(int dest_type
, AuthAuthorizer
**authorizer
,
122 bool force_new
) override
;
123 bool ms_verify_authorizer(Connection
*con
,
126 ceph::bufferlist
& authorizer
,
127 ceph::bufferlist
& authorizer_reply
,
129 CryptoKey
& session_key
) override
;
131 bool handle_open(MMgrOpen
*m
);
132 bool handle_report(MMgrReport
*m
);
133 bool handle_command(MCommand
*m
);
135 void got_service_map();
137 void _send_configure(ConnectionRef c
);
139 virtual const char** get_tracked_conf_keys() const override
;
140 virtual void handle_conf_change(const struct md_config_t
*conf
,
141 const std::set
<std::string
> &changed
) override
;