]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) 2004-2006 Sage Weil <sage@newdream.net> | |
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 | ||
7c673cae FG |
15 | #ifndef CEPH_MDS_H |
16 | #define CEPH_MDS_H | |
17 | ||
94b18763 FG |
18 | #include <boost/utility/string_view.hpp> |
19 | ||
d2e6a577 | 20 | #include "common/LogClient.h" |
7c673cae | 21 | #include "common/Mutex.h" |
7c673cae | 22 | #include "common/Timer.h" |
d2e6a577 FG |
23 | #include "include/Context.h" |
24 | #include "include/types.h" | |
7c673cae | 25 | #include "mgr/MgrClient.h" |
d2e6a577 | 26 | #include "msg/Dispatcher.h" |
7c673cae FG |
27 | |
28 | #include "Beacon.h" | |
d2e6a577 FG |
29 | #include "MDSMap.h" |
30 | #include "MDSRank.h" | |
7c673cae | 31 | |
31f18b77 | 32 | #define CEPH_MDS_PROTOCOL 30 /* cluster internal */ |
7c673cae | 33 | |
7c673cae | 34 | class AuthAuthorizeHandlerRegistry; |
d2e6a577 FG |
35 | class Message; |
36 | class Messenger; | |
37 | class MonClient; | |
7c673cae FG |
38 | |
39 | class MDSDaemon : public Dispatcher, public md_config_obs_t { | |
40 | public: | |
41 | /* Global MDS lock: every time someone takes this, they must | |
42 | * also check the `stopping` flag. If stopping is true, you | |
43 | * must either do nothing and immediately drop the lock, or | |
44 | * never drop the lock again (i.e. call respawn()) */ | |
45 | Mutex mds_lock; | |
46 | bool stopping; | |
47 | ||
48 | SafeTimer timer; | |
49 | ||
94b18763 FG |
50 | |
51 | mono_time get_starttime() const { | |
52 | return starttime; | |
53 | } | |
54 | chrono::duration<double> get_uptime() const { | |
55 | mono_time now = mono_clock::now(); | |
56 | return chrono::duration<double>(now-starttime); | |
57 | } | |
58 | ||
7c673cae FG |
59 | protected: |
60 | Beacon beacon; | |
61 | ||
62 | AuthAuthorizeHandlerRegistry *authorize_handler_cluster_registry; | |
63 | AuthAuthorizeHandlerRegistry *authorize_handler_service_registry; | |
64 | ||
65 | std::string name; | |
66 | ||
67 | Messenger *messenger; | |
68 | MonClient *monc; | |
69 | MgrClient mgrc; | |
70 | MDSMap *mdsmap; | |
71 | LogClient log_client; | |
72 | LogChannelRef clog; | |
73 | ||
74 | MDSRankDispatcher *mds_rank; | |
75 | ||
76 | public: | |
94b18763 | 77 | MDSDaemon(boost::string_view n, Messenger *m, MonClient *mc); |
7c673cae FG |
78 | ~MDSDaemon() override; |
79 | int orig_argc; | |
80 | const char **orig_argv; | |
81 | ||
82 | // handle a signal (e.g., SIGTERM) | |
83 | void handle_signal(int signum); | |
84 | ||
85 | int init(); | |
86 | ||
87 | /** | |
88 | * Hint at whether we were shutdown gracefully (i.e. we were only | |
89 | * in standby, or our rank was stopped). Should be removed once | |
90 | * we handle shutdown properly (e.g. clear out all message queues) | |
91 | * such that deleting xlists doesn't assert. | |
92 | */ | |
93 | bool is_clean_shutdown(); | |
94 | ||
95 | // config observer bits | |
96 | const char** get_tracked_conf_keys() const override; | |
97 | void handle_conf_change(const struct md_config_t *conf, | |
98 | const std::set <std::string> &changed) override; | |
99 | protected: | |
100 | // tick and other timer fun | |
3efd9988 | 101 | Context *tick_event = nullptr; |
7c673cae FG |
102 | void reset_tick(); |
103 | ||
104 | void wait_for_omap_osds(); | |
105 | ||
106 | private: | |
107 | bool ms_dispatch(Message *m) override; | |
108 | bool ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer, bool force_new) override; | |
109 | bool ms_verify_authorizer(Connection *con, int peer_type, | |
110 | int protocol, bufferlist& authorizer_data, bufferlist& authorizer_reply, | |
28e407b8 AA |
111 | bool& isvalid, CryptoKey& session_key, |
112 | std::unique_ptr<AuthAuthorizerChallenge> *challenge) override; | |
7c673cae FG |
113 | void ms_handle_accept(Connection *con) override; |
114 | void ms_handle_connect(Connection *con) override; | |
115 | bool ms_handle_reset(Connection *con) override; | |
116 | void ms_handle_remote_reset(Connection *con) override; | |
117 | bool ms_handle_refused(Connection *con) override; | |
118 | ||
119 | protected: | |
120 | // admin socket handling | |
121 | friend class MDSSocketHook; | |
122 | class MDSSocketHook *asok_hook; | |
123 | void set_up_admin_socket(); | |
124 | void clean_up_admin_socket(); | |
125 | void check_ops_in_flight(); // send off any slow ops to monitor | |
126 | bool asok_command(string command, cmdmap_t& cmdmap, string format, | |
127 | ostream& ss); | |
128 | ||
129 | void dump_status(Formatter *f); | |
130 | ||
131 | /** | |
132 | * Terminate this daemon process. | |
133 | * | |
134 | * This function will return, but once it does so the calling thread | |
135 | * must do no more work as all subsystems will have been shut down. | |
136 | */ | |
137 | void suicide(); | |
138 | ||
139 | /** | |
140 | * Start a new daemon process with the same command line parameters that | |
141 | * this process was run with, then terminate this process | |
142 | */ | |
143 | void respawn(); | |
144 | ||
145 | void tick(); | |
146 | ||
147 | // messages | |
148 | bool _dispatch(Message *m, bool new_msg); | |
149 | ||
150 | protected: | |
151 | bool handle_core_message(Message *m); | |
152 | ||
153 | // special message types | |
154 | friend class C_MDS_Send_Command_Reply; | |
155 | static void send_command_reply(MCommand *m, MDSRank* mds_rank, int r, | |
94b18763 | 156 | bufferlist outbl, boost::string_view outs); |
7c673cae FG |
157 | int _handle_command( |
158 | const cmdmap_t &cmdmap, | |
159 | MCommand *m, | |
160 | bufferlist *outbl, | |
161 | std::string *outs, | |
162 | Context **run_later, | |
163 | bool *need_reply); | |
164 | void handle_command(class MCommand *m); | |
165 | void handle_mds_map(class MMDSMap *m); | |
166 | void _handle_mds_map(MDSMap *oldmap); | |
94b18763 FG |
167 | |
168 | private: | |
169 | mono_time starttime = mono_clock::zero(); | |
7c673cae FG |
170 | }; |
171 | ||
172 | ||
173 | #endif |