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