]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/DaemonServer.h
a1ed292e1a0c1a15cf5b7a52641c70da22fd58db
[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 "PyModules.h"
18
19 #include <set>
20 #include <string>
21
22 #include "common/Mutex.h"
23 #include "common/LogClient.h"
24
25 #include <msg/Messenger.h>
26 #include <mon/MonClient.h>
27
28 #include "auth/AuthAuthorizeHandler.h"
29
30 #include "MgrSession.h"
31 #include "DaemonState.h"
32
33 class MMgrReport;
34 class MMgrOpen;
35 class MMonMgrReport;
36 class MCommand;
37 struct MgrCommand;
38
39
40 /**
41 * Server used in ceph-mgr to communicate with Ceph daemons like
42 * MDSs and OSDs.
43 */
44 class DaemonServer : public Dispatcher
45 {
46 protected:
47 boost::scoped_ptr<Throttle> client_byte_throttler;
48 boost::scoped_ptr<Throttle> client_msg_throttler;
49 boost::scoped_ptr<Throttle> osd_byte_throttler;
50 boost::scoped_ptr<Throttle> osd_msg_throttler;
51 boost::scoped_ptr<Throttle> mds_byte_throttler;
52 boost::scoped_ptr<Throttle> mds_msg_throttler;
53 boost::scoped_ptr<Throttle> mon_byte_throttler;
54 boost::scoped_ptr<Throttle> mon_msg_throttler;
55
56 Messenger *msgr;
57 MonClient *monc;
58 Finisher &finisher;
59 DaemonStateIndex &daemon_state;
60 ClusterState &cluster_state;
61 PyModules &py_modules;
62 LogChannelRef clog, audit_clog;
63
64 AuthAuthorizeHandlerRegistry auth_registry;
65
66 /// connections for osds
67 ceph::unordered_map<int,set<ConnectionRef>> osd_cons;
68
69 Mutex lock;
70
71 static void _generate_command_map(map<string,cmd_vartype>& cmdmap,
72 map<string,string> &param_str_map);
73 static const MgrCommand *_get_mgrcommand(const string &cmd_prefix,
74 MgrCommand *cmds, int cmds_size);
75 bool _allowed_command(
76 MgrSession *s, const string &module, const string &prefix,
77 const map<string,cmd_vartype>& cmdmap,
78 const map<string,string>& param_str_map,
79 const MgrCommand *this_cmd);
80
81 private:
82 friend class ReplyOnFinish;
83 bool _reply(MCommand* m,
84 int ret, const std::string& s, const bufferlist& payload);
85
86 public:
87 int init(uint64_t gid, entity_addr_t client_addr);
88 void shutdown();
89
90 entity_addr_t get_myaddr() const;
91
92 DaemonServer(MonClient *monc_,
93 Finisher &finisher_,
94 DaemonStateIndex &daemon_state_,
95 ClusterState &cluster_state_,
96 PyModules &py_modules_,
97 LogChannelRef cl,
98 LogChannelRef auditcl);
99 ~DaemonServer() override;
100
101 bool ms_dispatch(Message *m) override;
102 bool ms_handle_reset(Connection *con) override;
103 void ms_handle_remote_reset(Connection *con) override {}
104 bool ms_handle_refused(Connection *con) override;
105 bool ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer,
106 bool force_new) override;
107 bool ms_verify_authorizer(Connection *con,
108 int peer_type,
109 int protocol,
110 ceph::bufferlist& authorizer,
111 ceph::bufferlist& authorizer_reply,
112 bool& isvalid,
113 CryptoKey& session_key) override;
114
115 bool handle_open(MMgrOpen *m);
116 bool handle_report(MMgrReport *m);
117 bool handle_command(MCommand *m);
118 void send_report();
119 };
120
121 #endif
122