]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/MDSDaemon.h
update source to Ceph Pacific 16.2.2
[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/ceph_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 36 /* cluster internal */
39
40 class Messenger;
41 class MonClient;
42
43 class MDSDaemon : public Dispatcher {
44 public:
45 MDSDaemon(std::string_view n, Messenger *m, MonClient *mc,
46 boost::asio::io_context& ioctx);
47
48 ~MDSDaemon() override;
49
50 mono_time get_starttime() const {
51 return starttime;
52 }
53 chrono::duration<double> get_uptime() const {
54 mono_time now = mono_clock::now();
55 return chrono::duration<double>(now-starttime);
56 }
57
58 // handle a signal (e.g., SIGTERM)
59 void handle_signal(int signum);
60
61 int init();
62
63 /**
64 * Hint at whether we were shutdown gracefully (i.e. we were only
65 * in standby, or our rank was stopped). Should be removed once
66 * we handle shutdown properly (e.g. clear out all message queues)
67 * such that deleting xlists doesn't assert.
68 */
69 bool is_clean_shutdown();
70
71 /* Global MDS lock: every time someone takes this, they must
72 * also check the `stopping` flag. If stopping is true, you
73 * must either do nothing and immediately drop the lock, or
74 * never drop the lock again (i.e. call respawn()) */
75 ceph::mutex mds_lock = ceph::make_mutex("MDSDaemon::mds_lock");
76 bool stopping = false;
77
78 SafeTimer timer;
79 std::string gss_ktfile_client{};
80
81 int orig_argc;
82 const char **orig_argv;
83
84
85 protected:
86 // admin socket handling
87 friend class MDSSocketHook;
88
89 // special message types
90 friend class C_MDS_Send_Command_Reply;
91
92 void reset_tick();
93 void wait_for_omap_osds();
94
95 void set_up_admin_socket();
96 void clean_up_admin_socket();
97 void check_ops_in_flight(); // send off any slow ops to monitor
98 void asok_command(
99 std::string_view command,
100 const cmdmap_t& cmdmap,
101 Formatter *f,
102 const bufferlist &inbl,
103 std::function<void(int,const std::string&,bufferlist&)> on_finish);
104
105 void dump_status(Formatter *f);
106
107 /**
108 * Terminate this daemon process.
109 *
110 * This function will return, but once it does so the calling thread
111 * must do no more work as all subsystems will have been shut down.
112 */
113 void suicide();
114
115 /**
116 * Start a new daemon process with the same command line parameters that
117 * this process was run with, then terminate this process
118 */
119 void respawn();
120
121 void tick();
122
123 bool handle_core_message(const cref_t<Message> &m);
124
125 void handle_command(const cref_t<MCommand> &m);
126 void handle_mds_map(const cref_t<MMDSMap> &m);
127
128 Beacon beacon;
129
130 std::string name;
131
132 Messenger *messenger;
133 MonClient *monc;
134 boost::asio::io_context& ioctx;
135 MgrClient mgrc;
136 std::unique_ptr<MDSMap> mdsmap;
137 LogClient log_client;
138 LogChannelRef clog;
139
140 MDSRankDispatcher *mds_rank = nullptr;
141
142 // tick and other timer fun
143 Context *tick_event = nullptr;
144 class MDSSocketHook *asok_hook = nullptr;
145
146 private:
147 bool ms_dispatch2(const ref_t<Message> &m) override;
148 int ms_handle_authentication(Connection *con) override;
149 void ms_handle_accept(Connection *con) override;
150 void ms_handle_connect(Connection *con) override;
151 bool ms_handle_reset(Connection *con) override;
152 void ms_handle_remote_reset(Connection *con) override;
153 bool ms_handle_refused(Connection *con) override;
154
155 bool parse_caps(const AuthCapsInfo&, MDSAuthCaps&);
156
157 mono_time starttime = mono_clock::zero();
158 };
159
160 #endif