]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/MDSDaemon.h
86d116da291895a52c3bd7760eaf1aaa340ba2b7
[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 {
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 protected:
96 // tick and other timer fun
97 Context *tick_event = nullptr;
98 void reset_tick();
99
100 void wait_for_omap_osds();
101
102 private:
103 bool ms_dispatch2(const Message::ref &m) override;
104 bool ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer) override;
105 int ms_handle_authentication(Connection *con) override;
106 KeyStore *ms_get_auth1_authorizer_keystore() override;
107 void ms_handle_accept(Connection *con) override;
108 void ms_handle_connect(Connection *con) override;
109 bool ms_handle_reset(Connection *con) override;
110 void ms_handle_remote_reset(Connection *con) override;
111 bool ms_handle_refused(Connection *con) override;
112
113 protected:
114 // admin socket handling
115 friend class MDSSocketHook;
116 class MDSSocketHook *asok_hook;
117 void set_up_admin_socket();
118 void clean_up_admin_socket();
119 void check_ops_in_flight(); // send off any slow ops to monitor
120 bool asok_command(std::string_view command, const cmdmap_t& cmdmap,
121 std::string_view format, ostream& ss);
122
123 void dump_status(Formatter *f);
124
125 /**
126 * Terminate this daemon process.
127 *
128 * This function will return, but once it does so the calling thread
129 * must do no more work as all subsystems will have been shut down.
130 */
131 void suicide();
132
133 /**
134 * Start a new daemon process with the same command line parameters that
135 * this process was run with, then terminate this process
136 */
137 void respawn();
138
139 void tick();
140
141 protected:
142 bool handle_core_message(const Message::const_ref &m);
143
144 // special message types
145 friend class C_MDS_Send_Command_Reply;
146 static void send_command_reply(const MCommand::const_ref &m, MDSRank* mds_rank, int r,
147 bufferlist outbl, std::string_view outs);
148 int _handle_command(
149 const cmdmap_t &cmdmap,
150 const MCommand::const_ref &m,
151 bufferlist *outbl,
152 std::string *outs,
153 Context **run_later,
154 bool *need_reply);
155 void handle_command(const MCommand::const_ref &m);
156 void handle_mds_map(const MMDSMap::const_ref &m);
157 void _handle_mds_map(const MDSMap &oldmap);
158
159 private:
160 struct MDSCommand {
161 MDSCommand(std::string_view signature, std::string_view help)
162 : cmdstring(signature), helpstring(help)
163 {}
164
165 std::string cmdstring;
166 std::string helpstring;
167 std::string module = "mds";
168 };
169
170 static const std::vector<MDSCommand>& get_commands();
171
172 bool parse_caps(const AuthCapsInfo&, MDSAuthCaps&);
173
174 mono_time starttime = mono_clock::zero();
175 };
176
177 #endif