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
93 double cap_revoke_eviction_timeout
= 0;
95 friend class MDSContinuation
;
96 friend class ServerContext
;
97 friend class ServerLogContext
;
100 bool terminating_sessions
;
102 explicit Server(MDSRank
*m
);
104 g_ceph_context
->get_perfcounters_collection()->remove(logger
);
106 delete reconnect_done
;
109 void create_logger();
112 void dispatch(Message
*m
);
114 void handle_osd_map();
116 // -- sessions and recovery --
117 utime_t reconnect_start
;
118 set
<client_t
> client_reconnect_gather
; // clients i need a reconnect msg from.
119 bool waiting_for_reconnect(client_t c
) const;
120 void dump_reconnect_status(Formatter
*f
) const;
122 void handle_client_session(class MClientSession
*m
);
123 void _session_logged(Session
*session
, uint64_t state_seq
,
124 bool open
, version_t pv
, interval_set
<inodeno_t
>& inos
,version_t piv
);
125 version_t
prepare_force_open_sessions(map
<client_t
,entity_inst_t
> &cm
,
126 map
<client_t
,pair
<Session
*,uint64_t> >& smap
);
127 void finish_force_open_sessions(const map
<client_t
,pair
<Session
*,uint64_t> >& smap
,
128 bool dec_import
=true);
129 void flush_client_sessions(set
<client_t
>& client_set
, MDSGatherBuilder
& gather
);
130 void finish_flush_session(Session
*session
, version_t seq
);
131 void terminate_sessions();
132 void find_idle_sessions();
133 void kill_session(Session
*session
, Context
*on_safe
);
134 size_t apply_blacklist(const std::set
<entity_addr_t
> &blacklist
);
135 void journal_close_session(Session
*session
, int state
, Context
*on_safe
);
136 void reconnect_clients(MDSInternalContext
*reconnect_done_
);
137 void handle_client_reconnect(class MClientReconnect
*m
);
138 //void process_reconnect_cap(CInode *in, int from, ceph_mds_cap_reconnect& capinfo);
139 void reconnect_gather_finish();
140 void reconnect_tick();
141 void recover_filelocks(CInode
*in
, bufferlist locks
, int64_t client
);
143 void recall_client_state(void);
144 void force_clients_readonly();
147 void handle_client_request(MClientRequest
*m
);
149 void journal_and_reply(MDRequestRef
& mdr
, CInode
*tracei
, CDentry
*tracedn
,
150 LogEvent
*le
, MDSLogContextBase
*fin
);
151 void submit_mdlog_entry(LogEvent
*le
, MDSLogContextBase
*fin
,
152 MDRequestRef
& mdr
, const char *evt
);
153 void dispatch_client_request(MDRequestRef
& mdr
);
154 void perf_gather_op_latency(const MClientRequest
* req
, utime_t lat
);
155 void early_reply(MDRequestRef
& mdr
, CInode
*tracei
, CDentry
*tracedn
);
156 void respond_to_request(MDRequestRef
& mdr
, int r
= 0);
157 void set_trace_dist(Session
*session
, MClientReply
*reply
, CInode
*in
, CDentry
*dn
,
159 int num_dentries_wanted
,
162 void encode_empty_dirstat(bufferlist
& bl
);
163 void encode_infinite_lease(bufferlist
& bl
);
164 void encode_null_lease(bufferlist
& bl
);
166 void handle_slave_request(MMDSSlaveRequest
*m
);
167 void handle_slave_request_reply(MMDSSlaveRequest
*m
);
168 void dispatch_slave_request(MDRequestRef
& mdr
);
169 void handle_slave_auth_pin(MDRequestRef
& mdr
);
170 void handle_slave_auth_pin_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*ack
);
173 bool check_fragment_space(MDRequestRef
& mdr
, CDir
*in
);
174 bool check_access(MDRequestRef
& mdr
, CInode
*in
, unsigned mask
);
175 bool _check_access(Session
*session
, CInode
*in
, unsigned mask
, int caller_uid
, int caller_gid
, int setattr_uid
, int setattr_gid
);
176 CDir
*validate_dentry_dir(MDRequestRef
& mdr
, CInode
*diri
, boost::string_view dname
);
177 CDir
*traverse_to_auth_dir(MDRequestRef
& mdr
, vector
<CDentry
*> &trace
, filepath refpath
);
178 CDentry
*prepare_null_dentry(MDRequestRef
& mdr
, CDir
*dir
, boost::string_view dname
, bool okexist
=false);
179 CDentry
*prepare_stray_dentry(MDRequestRef
& mdr
, CInode
*in
);
180 CInode
* prepare_new_inode(MDRequestRef
& mdr
, CDir
*dir
, inodeno_t useino
, unsigned mode
,
181 file_layout_t
*layout
=NULL
);
182 void journal_allocated_inos(MDRequestRef
& mdr
, EMetaBlob
*blob
);
183 void apply_allocated_inos(MDRequestRef
& mdr
, Session
*session
);
185 CInode
* rdlock_path_pin_ref(MDRequestRef
& mdr
, int n
, set
<SimpleLock
*>& rdlocks
, bool want_auth
,
186 bool no_want_auth
=false,
187 file_layout_t
**layout
=NULL
,
188 bool no_lookup
=false);
189 CDentry
* rdlock_path_xlock_dentry(MDRequestRef
& mdr
, int n
,
190 set
<SimpleLock
*>& rdlocks
,
191 set
<SimpleLock
*>& wrlocks
,
192 set
<SimpleLock
*>& xlocks
, bool okexist
,
193 bool mustexist
, bool alwaysxlock
,
194 file_layout_t
**layout
=NULL
);
196 CDir
* try_open_auth_dirfrag(CInode
*diri
, frag_t fg
, MDRequestRef
& mdr
);
199 // requests on existing inodes.
200 void handle_client_getattr(MDRequestRef
& mdr
, bool is_lookup
);
201 void handle_client_lookup_ino(MDRequestRef
& mdr
,
202 bool want_parent
, bool want_dentry
);
203 void _lookup_ino_2(MDRequestRef
& mdr
, int r
);
204 void handle_client_readdir(MDRequestRef
& mdr
);
205 void handle_client_file_setlock(MDRequestRef
& mdr
);
206 void handle_client_file_readlock(MDRequestRef
& mdr
);
208 void handle_client_setattr(MDRequestRef
& mdr
);
209 void handle_client_setlayout(MDRequestRef
& mdr
);
210 void handle_client_setdirlayout(MDRequestRef
& mdr
);
212 int parse_layout_vxattr(string name
, string value
, const OSDMap
& osdmap
,
213 file_layout_t
*layout
, bool validate
=true);
214 int parse_quota_vxattr(string name
, string value
, quota_info_t
*quota
);
215 int check_layout_vxattr(MDRequestRef
& mdr
,
218 file_layout_t
*layout
);
219 void handle_set_vxattr(MDRequestRef
& mdr
, CInode
*cur
,
220 file_layout_t
*dir_layout
,
221 set
<SimpleLock
*> rdlocks
,
222 set
<SimpleLock
*> wrlocks
,
223 set
<SimpleLock
*> xlocks
);
224 void handle_remove_vxattr(MDRequestRef
& mdr
, CInode
*cur
,
225 file_layout_t
*dir_layout
,
226 set
<SimpleLock
*> rdlocks
,
227 set
<SimpleLock
*> wrlocks
,
228 set
<SimpleLock
*> xlocks
);
229 void handle_client_setxattr(MDRequestRef
& mdr
);
230 void handle_client_removexattr(MDRequestRef
& mdr
);
232 void handle_client_fsync(MDRequestRef
& mdr
);
235 void handle_client_open(MDRequestRef
& mdr
);
236 void handle_client_openc(MDRequestRef
& mdr
); // O_CREAT variant.
237 void do_open_truncate(MDRequestRef
& mdr
, int cmode
); // O_TRUNC variant.
240 void handle_client_mknod(MDRequestRef
& mdr
);
241 void handle_client_mkdir(MDRequestRef
& mdr
);
242 void handle_client_symlink(MDRequestRef
& mdr
);
245 void handle_client_link(MDRequestRef
& mdr
);
246 void _link_local(MDRequestRef
& mdr
, CDentry
*dn
, CInode
*targeti
);
247 void _link_local_finish(MDRequestRef
& mdr
,
248 CDentry
*dn
, CInode
*targeti
,
249 version_t
, version_t
);
251 void _link_remote(MDRequestRef
& mdr
, bool inc
, CDentry
*dn
, CInode
*targeti
);
252 void _link_remote_finish(MDRequestRef
& mdr
, bool inc
, CDentry
*dn
, CInode
*targeti
,
255 void handle_slave_link_prep(MDRequestRef
& mdr
);
256 void _logged_slave_link(MDRequestRef
& mdr
, CInode
*targeti
);
257 void _commit_slave_link(MDRequestRef
& mdr
, int r
, CInode
*targeti
);
258 void _committed_slave(MDRequestRef
& mdr
); // use for rename, too
259 void handle_slave_link_prep_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*m
);
260 void do_link_rollback(bufferlist
&rbl
, mds_rank_t master
, MDRequestRef
& mdr
);
261 void _link_rollback_finish(MutationRef
& mut
, MDRequestRef
& mdr
);
264 void handle_client_unlink(MDRequestRef
& mdr
);
265 bool _dir_is_nonempty_unlocked(MDRequestRef
& mdr
, CInode
*rmdiri
);
266 bool _dir_is_nonempty(MDRequestRef
& mdr
, CInode
*rmdiri
);
267 void _unlink_local(MDRequestRef
& mdr
, CDentry
*dn
, CDentry
*straydn
);
268 void _unlink_local_finish(MDRequestRef
& mdr
,
269 CDentry
*dn
, CDentry
*straydn
,
271 bool _rmdir_prepare_witness(MDRequestRef
& mdr
, mds_rank_t who
, vector
<CDentry
*>& trace
, CDentry
*straydn
);
272 void handle_slave_rmdir_prep(MDRequestRef
& mdr
);
273 void _logged_slave_rmdir(MDRequestRef
& mdr
, CDentry
*srcdn
, CDentry
*straydn
);
274 void _commit_slave_rmdir(MDRequestRef
& mdr
, int r
, CDentry
*straydn
);
275 void handle_slave_rmdir_prep_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*ack
);
276 void do_rmdir_rollback(bufferlist
&rbl
, mds_rank_t master
, MDRequestRef
& mdr
);
277 void _rmdir_rollback_finish(MDRequestRef
& mdr
, metareqid_t reqid
, CDentry
*dn
, CDentry
*straydn
);
280 void handle_client_rename(MDRequestRef
& mdr
);
281 void _rename_finish(MDRequestRef
& mdr
,
282 CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
284 void handle_client_lssnap(MDRequestRef
& mdr
);
285 void handle_client_mksnap(MDRequestRef
& mdr
);
286 void _mksnap_finish(MDRequestRef
& mdr
, CInode
*diri
, SnapInfo
&info
);
287 void handle_client_rmsnap(MDRequestRef
& mdr
);
288 void _rmsnap_finish(MDRequestRef
& mdr
, CInode
*diri
, snapid_t snapid
);
289 void handle_client_renamesnap(MDRequestRef
& mdr
);
290 void _renamesnap_finish(MDRequestRef
& mdr
, CInode
*diri
, snapid_t snapid
);
294 bool _rename_prepare_witness(MDRequestRef
& mdr
, mds_rank_t who
, set
<mds_rank_t
> &witnesse
,
295 vector
<CDentry
*>& srctrace
, vector
<CDentry
*>& dsttrace
, CDentry
*straydn
);
296 version_t
_rename_prepare_import(MDRequestRef
& mdr
, CDentry
*srcdn
, bufferlist
*client_map_bl
);
297 bool _need_force_journal(CInode
*diri
, bool empty
);
298 void _rename_prepare(MDRequestRef
& mdr
,
299 EMetaBlob
*metablob
, bufferlist
*client_map_bl
,
300 CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
301 /* set not_journaling=true if you're going to discard the results --
302 * this bypasses the asserts to make sure we're journaling the right
303 * things on the right nodes */
304 void _rename_apply(MDRequestRef
& mdr
, CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
307 void handle_slave_rename_prep(MDRequestRef
& mdr
);
308 void handle_slave_rename_prep_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*m
);
309 void handle_slave_rename_notify_ack(MDRequestRef
& mdr
, MMDSSlaveRequest
*m
);
310 void _slave_rename_sessions_flushed(MDRequestRef
& mdr
);
311 void _logged_slave_rename(MDRequestRef
& mdr
, CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
312 void _commit_slave_rename(MDRequestRef
& mdr
, int r
, CDentry
*srcdn
, CDentry
*destdn
, CDentry
*straydn
);
313 void do_rename_rollback(bufferlist
&rbl
, mds_rank_t master
, MDRequestRef
& mdr
, bool finish_mdr
=false);
314 void _rename_rollback_finish(MutationRef
& mut
, MDRequestRef
& mdr
, CDentry
*srcdn
, version_t srcdnpv
,
315 CDentry
*destdn
, CDentry
*staydn
, bool finish_mdr
);
317 void evict_cap_revoke_non_responders();
318 void handle_conf_change(const struct md_config_t
*,
319 const std::set
<std::string
> &changed
);
322 void reply_client_request(MDRequestRef
& mdr
, MClientReply
*reply
);