1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef CEPH_MDS_SERVER_H
16 #define CEPH_MDS_SERVER_H
18 #include <boost/utility/string_view.hpp>
28 class MMDSSlaveRequest
;
36 l_mdss_dispatch_client_request
,
37 l_mdss_dispatch_slave_request
,
38 l_mdss_handle_client_request
,
39 l_mdss_handle_client_session
,
40 l_mdss_handle_slave_request
,
41 l_mdss_req_create_latency
,
42 l_mdss_req_getattr_latency
,
43 l_mdss_req_getfilelock_latency
,
44 l_mdss_req_link_latency
,
45 l_mdss_req_lookup_latency
,
46 l_mdss_req_lookuphash_latency
,
47 l_mdss_req_lookupino_latency
,
48 l_mdss_req_lookupname_latency
,
49 l_mdss_req_lookupparent_latency
,
50 l_mdss_req_lookupsnap_latency
,
51 l_mdss_req_lssnap_latency
,
52 l_mdss_req_mkdir_latency
,
53 l_mdss_req_mknod_latency
,
54 l_mdss_req_mksnap_latency
,
55 l_mdss_req_open_latency
,
56 l_mdss_req_readdir_latency
,
57 l_mdss_req_rename_latency
,
58 l_mdss_req_renamesnap_latency
,
59 l_mdss_req_rmdir_latency
,
60 l_mdss_req_rmsnap_latency
,
61 l_mdss_req_rmxattr_latency
,
62 l_mdss_req_setattr_latency
,
63 l_mdss_req_setdirlayout_latency
,
64 l_mdss_req_setfilelock_latency
,
65 l_mdss_req_setlayout_latency
,
66 l_mdss_req_setxattr_latency
,
67 l_mdss_req_symlink_latency
,
68 l_mdss_req_unlink_latency
,
69 l_mdss_cap_revoke_eviction
,
75 using clock
= ceph::coarse_mono_clock
;
76 using time
= ceph::coarse_mono_time
;
84 // OSDMap full status, used to generate ENOSPC on some operations
87 // State for while in reconnect
88 MDSInternalContext
*reconnect_done
;
89 int failed_reconnects
;
90 bool reconnect_evicting
; // true if I am waiting for evictions to complete
91 // before proceeding to reconnect_gather_finish
92 time reconnect_start
= time::min();
93 time reconnect_last_seen
= time::min();
94 set
<client_t
> client_reconnect_gather
; // clients i need a reconnect msg from.
96 double cap_revoke_eviction_timeout
= 0;
98 friend class MDSContinuation
;
99 friend class ServerContext
;
100 friend class ServerLogContext
;
103 bool terminating_sessions
;
105 explicit Server(MDSRank
*m
);
107 g_ceph_context
->get_perfcounters_collection()->remove(logger
);
109 delete reconnect_done
;
112 void create_logger();
115 void dispatch(Message
*m
);
117 void handle_osd_map();
119 // -- sessions and recovery --
120 bool waiting_for_reconnect(client_t c
) const;
121 void dump_reconnect_status(Formatter
*f
) const;
123 void handle_client_session(class MClientSession
*m
);
124 void _session_logged(Session
*session
, uint64_t state_seq
,
125 bool open
, version_t pv
, interval_set
<inodeno_t
>& inos
,version_t piv
);
126 version_t
prepare_force_open_sessions(map
<client_t
,entity_inst_t
> &cm
,
127 map
<client_t
,pair
<Session
*,uint64_t> >& smap
);
128 void finish_force_open_sessions(const map
<client_t
,pair
<Session
*,uint64_t> >& smap
,
129 bool dec_import
=true);
130 void flush_client_sessions(set
<client_t
>& client_set
, MDSGatherBuilder
& gather
);
131 void finish_flush_session(Session
*session
, version_t seq
);
132 void terminate_sessions();
133 void find_idle_sessions();
134 void kill_session(Session
*session
, Context
*on_safe
);
135 size_t apply_blacklist(const std::set
<entity_addr_t
> &blacklist
);
136 void journal_close_session(Session
*session
, int state
, Context
*on_safe
);
137 void reconnect_clients(MDSInternalContext
*reconnect_done_
);
138 void handle_client_reconnect(class MClientReconnect
*m
);
139 //void process_reconnect_cap(CInode *in, int from, ceph_mds_cap_reconnect& capinfo);
140 void reconnect_gather_finish();
141 void reconnect_tick();
142 void recover_filelocks(CInode
*in
, bufferlist locks
, int64_t client
);
144 void recall_client_state(double ratio
, bool flush_client_session
,
145 MDSGatherBuilder
*gather
);
146 void force_clients_readonly();
149 void handle_client_request(MClientRequest
*m
);
151 void journal_and_reply(MDRequestRef
& mdr
, CInode
*tracei
, CDentry
*tracedn
,
152 LogEvent
*le
, MDSLogContextBase
*fin
);
153 void submit_mdlog_entry(LogEvent
*le
, MDSLogContextBase
*fin
,
154 MDRequestRef
& mdr
, const char *evt
);
155 void dispatch_client_request(MDRequestRef
& mdr
);
156 void perf_gather_op_latency(const MClientRequest
* req
, utime_t lat
);
157 void early_reply(MDRequestRef
& mdr
, CInode
*tracei
, CDentry
*tracedn
);
158 void respond_to_request(MDRequestRef
& mdr
, int r
= 0);
159 void set_trace_dist(Session
*session
, MClientReply
*reply
, CInode
*in
, CDentry
*dn
,
161 int num_dentries_wanted
,
164 void encode_empty_dirstat(bufferlist
& bl
);
165 void encode_infinite_lease(bufferlist
& bl
);
166 void encode_null_lease(bufferlist
& bl
);
168 void handle_slave_request(MMDSSlaveRequest
*m
);
169 void handle_slave_request_reply(MMDSSlaveRequest
*m
);
170 void dispatch_slave_request(MDRequestRef
& mdr
);
171 void handle_slave_auth_pin(MDRequestRef
& mdr
);
172 void handle_slave_auth_pin_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*ack
);
175 bool check_fragment_space(MDRequestRef
& mdr
, CDir
*in
);
176 bool check_access(MDRequestRef
& mdr
, CInode
*in
, unsigned mask
);
177 bool _check_access(Session
*session
, CInode
*in
, unsigned mask
, int caller_uid
, int caller_gid
, int setattr_uid
, int setattr_gid
);
178 CDir
*validate_dentry_dir(MDRequestRef
& mdr
, CInode
*diri
, boost::string_view dname
);
179 CDir
*traverse_to_auth_dir(MDRequestRef
& mdr
, vector
<CDentry
*> &trace
, filepath refpath
);
180 CDentry
*prepare_null_dentry(MDRequestRef
& mdr
, CDir
*dir
, boost::string_view dname
, bool okexist
=false);
181 CDentry
*prepare_stray_dentry(MDRequestRef
& mdr
, CInode
*in
);
182 CInode
* prepare_new_inode(MDRequestRef
& mdr
, CDir
*dir
, inodeno_t useino
, unsigned mode
,
183 file_layout_t
*layout
=NULL
);
184 void journal_allocated_inos(MDRequestRef
& mdr
, EMetaBlob
*blob
);
185 void apply_allocated_inos(MDRequestRef
& mdr
, Session
*session
);
187 CInode
* rdlock_path_pin_ref(MDRequestRef
& mdr
, int n
, set
<SimpleLock
*>& rdlocks
, bool want_auth
,
188 bool no_want_auth
=false,
189 file_layout_t
**layout
=NULL
,
190 bool no_lookup
=false);
191 CDentry
* rdlock_path_xlock_dentry(MDRequestRef
& mdr
, int n
,
192 set
<SimpleLock
*>& rdlocks
,
193 set
<SimpleLock
*>& wrlocks
,
194 set
<SimpleLock
*>& xlocks
, bool okexist
,
195 bool mustexist
, bool alwaysxlock
,
196 file_layout_t
**layout
=NULL
);
198 CDir
* try_open_auth_dirfrag(CInode
*diri
, frag_t fg
, MDRequestRef
& mdr
);
201 // requests on existing inodes.
202 void handle_client_getattr(MDRequestRef
& mdr
, bool is_lookup
);
203 void handle_client_lookup_ino(MDRequestRef
& mdr
,
204 bool want_parent
, bool want_dentry
);
205 void _lookup_ino_2(MDRequestRef
& mdr
, int r
);
206 void handle_client_readdir(MDRequestRef
& mdr
);
207 void handle_client_file_setlock(MDRequestRef
& mdr
);
208 void handle_client_file_readlock(MDRequestRef
& mdr
);
210 void handle_client_setattr(MDRequestRef
& mdr
);
211 void handle_client_setlayout(MDRequestRef
& mdr
);
212 void handle_client_setdirlayout(MDRequestRef
& mdr
);
214 int parse_layout_vxattr(string name
, string value
, const OSDMap
& osdmap
,
215 file_layout_t
*layout
, bool validate
=true);
216 int parse_quota_vxattr(string name
, string value
, quota_info_t
*quota
);
217 int check_layout_vxattr(MDRequestRef
& mdr
,
220 file_layout_t
*layout
);
221 void handle_set_vxattr(MDRequestRef
& mdr
, CInode
*cur
,
222 file_layout_t
*dir_layout
,
223 set
<SimpleLock
*> rdlocks
,
224 set
<SimpleLock
*> wrlocks
,
225 set
<SimpleLock
*> xlocks
);
226 void handle_remove_vxattr(MDRequestRef
& mdr
, CInode
*cur
,
227 file_layout_t
*dir_layout
,
228 set
<SimpleLock
*> rdlocks
,
229 set
<SimpleLock
*> wrlocks
,
230 set
<SimpleLock
*> xlocks
);
231 void handle_client_setxattr(MDRequestRef
& mdr
);
232 void handle_client_removexattr(MDRequestRef
& mdr
);
234 void handle_client_fsync(MDRequestRef
& mdr
);
237 void handle_client_open(MDRequestRef
& mdr
);
238 void handle_client_openc(MDRequestRef
& mdr
); // O_CREAT variant.
239 void do_open_truncate(MDRequestRef
& mdr
, int cmode
); // O_TRUNC variant.
242 void handle_client_mknod(MDRequestRef
& mdr
);
243 void handle_client_mkdir(MDRequestRef
& mdr
);
244 void handle_client_symlink(MDRequestRef
& mdr
);
247 void handle_client_link(MDRequestRef
& mdr
);
248 void _link_local(MDRequestRef
& mdr
, CDentry
*dn
, CInode
*targeti
);
249 void _link_local_finish(MDRequestRef
& mdr
,
250 CDentry
*dn
, CInode
*targeti
,
251 version_t
, version_t
);
253 void _link_remote(MDRequestRef
& mdr
, bool inc
, CDentry
*dn
, CInode
*targeti
);
254 void _link_remote_finish(MDRequestRef
& mdr
, bool inc
, CDentry
*dn
, CInode
*targeti
,
257 void handle_slave_link_prep(MDRequestRef
& mdr
);
258 void _logged_slave_link(MDRequestRef
& mdr
, CInode
*targeti
);
259 void _commit_slave_link(MDRequestRef
& mdr
, int r
, CInode
*targeti
);
260 void _committed_slave(MDRequestRef
& mdr
); // use for rename, too
261 void handle_slave_link_prep_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*m
);
262 void do_link_rollback(bufferlist
&rbl
, mds_rank_t master
, MDRequestRef
& mdr
);
263 void _link_rollback_finish(MutationRef
& mut
, MDRequestRef
& mdr
);
266 void handle_client_unlink(MDRequestRef
& mdr
);
267 bool _dir_is_nonempty_unlocked(MDRequestRef
& mdr
, CInode
*rmdiri
);
268 bool _dir_is_nonempty(MDRequestRef
& mdr
, CInode
*rmdiri
);
269 void _unlink_local(MDRequestRef
& mdr
, CDentry
*dn
, CDentry
*straydn
);
270 void _unlink_local_finish(MDRequestRef
& mdr
,
271 CDentry
*dn
, CDentry
*straydn
,
273 bool _rmdir_prepare_witness(MDRequestRef
& mdr
, mds_rank_t who
, vector
<CDentry
*>& trace
, CDentry
*straydn
);
274 void handle_slave_rmdir_prep(MDRequestRef
& mdr
);
275 void _logged_slave_rmdir(MDRequestRef
& mdr
, CDentry
*srcdn
, CDentry
*straydn
);
276 void _commit_slave_rmdir(MDRequestRef
& mdr
, int r
, CDentry
*straydn
);
277 void handle_slave_rmdir_prep_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*ack
);
278 void do_rmdir_rollback(bufferlist
&rbl
, mds_rank_t master
, MDRequestRef
& mdr
);
279 void _rmdir_rollback_finish(MDRequestRef
& mdr
, metareqid_t reqid
, CDentry
*dn
, CDentry
*straydn
);
282 void handle_client_rename(MDRequestRef
& mdr
);
283 void _rename_finish(MDRequestRef
& mdr
,
284 CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
286 void handle_client_lssnap(MDRequestRef
& mdr
);
287 void handle_client_mksnap(MDRequestRef
& mdr
);
288 void _mksnap_finish(MDRequestRef
& mdr
, CInode
*diri
, SnapInfo
&info
);
289 void handle_client_rmsnap(MDRequestRef
& mdr
);
290 void _rmsnap_finish(MDRequestRef
& mdr
, CInode
*diri
, snapid_t snapid
);
291 void handle_client_renamesnap(MDRequestRef
& mdr
);
292 void _renamesnap_finish(MDRequestRef
& mdr
, CInode
*diri
, snapid_t snapid
);
296 bool _rename_prepare_witness(MDRequestRef
& mdr
, mds_rank_t who
, set
<mds_rank_t
> &witnesse
,
297 vector
<CDentry
*>& srctrace
, vector
<CDentry
*>& dsttrace
, CDentry
*straydn
);
298 version_t
_rename_prepare_import(MDRequestRef
& mdr
, CDentry
*srcdn
, bufferlist
*client_map_bl
);
299 bool _need_force_journal(CInode
*diri
, bool empty
);
300 void _rename_prepare(MDRequestRef
& mdr
,
301 EMetaBlob
*metablob
, bufferlist
*client_map_bl
,
302 CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
303 /* set not_journaling=true if you're going to discard the results --
304 * this bypasses the asserts to make sure we're journaling the right
305 * things on the right nodes */
306 void _rename_apply(MDRequestRef
& mdr
, CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
309 void handle_slave_rename_prep(MDRequestRef
& mdr
);
310 void handle_slave_rename_prep_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*m
);
311 void handle_slave_rename_notify_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*m
);
312 void _slave_rename_sessions_flushed(MDRequestRef
& mdr
);
313 void _logged_slave_rename(MDRequestRef
& mdr
, CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
314 void _commit_slave_rename(MDRequestRef
& mdr
, int r
, CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
315 void do_rename_rollback(bufferlist
&rbl
, mds_rank_t master
, MDRequestRef
& mdr
, bool finish_mdr
=false);
316 void _rename_rollback_finish(MutationRef
& mut
, MDRequestRef
& mdr
, CDentry
*srcdn
, version_t srcdnpv
,
317 CDentry
*destdn
, CDentry
*staydn
, bool finish_mdr
);
319 void evict_cap_revoke_non_responders();
320 void handle_conf_change(const struct md_config_t
*,
321 const std::set
<std::string
> &changed
);
324 void reply_client_request(MDRequestRef
& mdr
, MClientReply
*reply
);
325 void flush_session(Session
*session
, MDSGatherBuilder
*gather
);