]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_LOCKER_H | |
16 | #define CEPH_MDS_LOCKER_H | |
17 | ||
94b18763 FG |
18 | #include <boost/utility/string_view.hpp> |
19 | ||
7c673cae FG |
20 | #include "include/types.h" |
21 | ||
22 | #include <map> | |
23 | #include <list> | |
24 | #include <set> | |
25 | using std::map; | |
26 | using std::list; | |
27 | using std::set; | |
28 | ||
29 | class MDSRank; | |
30 | class Session; | |
7c673cae FG |
31 | class CDentry; |
32 | struct SnapRealm; | |
33 | ||
34 | class Message; | |
35 | ||
36 | class MLock; | |
37 | ||
38 | class Capability; | |
39 | ||
40 | class SimpleLock; | |
41 | class ScatterLock; | |
42 | class LocalLock; | |
43 | ||
94b18763 | 44 | #include "CInode.h" |
7c673cae FG |
45 | #include "SimpleLock.h" |
46 | #include "Mutation.h" | |
47 | ||
48 | class Locker { | |
49 | private: | |
50 | MDSRank *mds; | |
51 | MDCache *mdcache; | |
52 | ||
53 | public: | |
54 | Locker(MDSRank *m, MDCache *c) : mds(m), mdcache(c) {} | |
55 | ||
56 | SimpleLock *get_lock(int lock_type, MDSCacheObjectInfo &info); | |
57 | ||
58 | void dispatch(Message *m); | |
59 | void handle_lock(MLock *m); | |
60 | ||
61 | void tick(); | |
62 | ||
63 | void nudge_log(SimpleLock *lock); | |
64 | ||
65 | protected: | |
66 | void send_lock_message(SimpleLock *lock, int msg); | |
67 | void send_lock_message(SimpleLock *lock, int msg, const bufferlist &data); | |
68 | ||
69 | // -- locks -- | |
70 | void _drop_rdlocks(MutationImpl *mut, set<CInode*> *pneed_issue); | |
71 | void _drop_non_rdlocks(MutationImpl *mut, set<CInode*> *pneed_issue); | |
72 | public: | |
73 | void include_snap_rdlocks(set<SimpleLock*>& rdlocks, CInode *in); | |
74 | void include_snap_rdlocks_wlayout(set<SimpleLock*>& rdlocks, CInode *in, | |
75 | file_layout_t **layout); | |
76 | ||
77 | bool acquire_locks(MDRequestRef& mdr, | |
78 | set<SimpleLock*> &rdlocks, | |
79 | set<SimpleLock*> &wrlocks, | |
80 | set<SimpleLock*> &xlocks, | |
81 | map<SimpleLock*,mds_rank_t> *remote_wrlocks=NULL, | |
82 | CInode *auth_pin_freeze=NULL, | |
83 | bool auth_pin_nonblock=false); | |
84 | ||
224ce89b | 85 | void notify_freeze_waiter(MDSCacheObject *o); |
7c673cae FG |
86 | void cancel_locking(MutationImpl *mut, set<CInode*> *pneed_issue); |
87 | void drop_locks(MutationImpl *mut, set<CInode*> *pneed_issue=0); | |
88 | void set_xlocks_done(MutationImpl *mut, bool skip_dentry=false); | |
89 | void drop_non_rdlocks(MutationImpl *mut, set<CInode*> *pneed_issue=0); | |
b32b8144 | 90 | void drop_rdlocks_for_early_reply(MutationImpl *mut); |
a8e16298 | 91 | void drop_locks_for_fragment_unfreeze(MutationImpl *mut); |
7c673cae FG |
92 | |
93 | void eval_gather(SimpleLock *lock, bool first=false, bool *need_issue=0, list<MDSInternalContextBase*> *pfinishers=0); | |
94 | void eval(SimpleLock *lock, bool *need_issue); | |
95 | void eval_any(SimpleLock *lock, bool *need_issue, list<MDSInternalContextBase*> *pfinishers=0, bool first=false) { | |
96 | if (!lock->is_stable()) | |
97 | eval_gather(lock, first, need_issue, pfinishers); | |
98 | else if (lock->get_parent()->is_auth()) | |
99 | eval(lock, need_issue); | |
100 | } | |
101 | ||
102 | void eval_scatter_gathers(CInode *in); | |
103 | ||
104 | void eval_cap_gather(CInode *in, set<CInode*> *issue_set=0); | |
105 | ||
106 | bool eval(CInode *in, int mask, bool caps_imported=false); | |
107 | void try_eval(MDSCacheObject *p, int mask); | |
108 | void try_eval(SimpleLock *lock, bool *pneed_issue); | |
109 | ||
110 | bool _rdlock_kick(SimpleLock *lock, bool as_anon); | |
111 | bool rdlock_try(SimpleLock *lock, client_t client, MDSInternalContextBase *c); | |
112 | bool rdlock_start(SimpleLock *lock, MDRequestRef& mut, bool as_anon=false); | |
113 | void rdlock_finish(SimpleLock *lock, MutationImpl *mut, bool *pneed_issue); | |
114 | bool can_rdlock_set(set<SimpleLock*>& locks); | |
115 | bool rdlock_try_set(set<SimpleLock*>& locks); | |
116 | void rdlock_take_set(set<SimpleLock*>& locks, MutationRef& mut); | |
117 | ||
118 | void wrlock_force(SimpleLock *lock, MutationRef& mut); | |
119 | bool wrlock_start(SimpleLock *lock, MDRequestRef& mut, bool nowait=false); | |
120 | void wrlock_finish(SimpleLock *lock, MutationImpl *mut, bool *pneed_issue); | |
121 | ||
122 | void remote_wrlock_start(SimpleLock *lock, mds_rank_t target, MDRequestRef& mut); | |
123 | void remote_wrlock_finish(SimpleLock *lock, mds_rank_t target, MutationImpl *mut); | |
124 | ||
125 | bool xlock_start(SimpleLock *lock, MDRequestRef& mut); | |
126 | void _finish_xlock(SimpleLock *lock, client_t xlocker, bool *pneed_issue); | |
127 | void xlock_finish(SimpleLock *lock, MutationImpl *mut, bool *pneed_issue); | |
128 | ||
129 | void xlock_export(SimpleLock *lock, MutationImpl *mut); | |
130 | void xlock_import(SimpleLock *lock); | |
131 | ||
132 | ||
133 | // simple | |
134 | public: | |
135 | void try_simple_eval(SimpleLock *lock); | |
136 | bool simple_rdlock_try(SimpleLock *lock, MDSInternalContextBase *con); | |
137 | protected: | |
138 | void simple_eval(SimpleLock *lock, bool *need_issue); | |
139 | void handle_simple_lock(SimpleLock *lock, MLock *m); | |
140 | ||
141 | public: | |
142 | bool simple_sync(SimpleLock *lock, bool *need_issue=0); | |
143 | protected: | |
144 | void simple_lock(SimpleLock *lock, bool *need_issue=0); | |
145 | void simple_excl(SimpleLock *lock, bool *need_issue=0); | |
146 | void simple_xlock(SimpleLock *lock); | |
147 | ||
148 | ||
149 | // scatter | |
150 | public: | |
151 | void scatter_eval(ScatterLock *lock, bool *need_issue); // public for MDCache::adjust_subtree_auth() | |
152 | ||
153 | void scatter_tick(); | |
154 | void scatter_nudge(ScatterLock *lock, MDSInternalContextBase *c, bool forcelockchange=false); | |
155 | ||
156 | protected: | |
157 | void handle_scatter_lock(ScatterLock *lock, MLock *m); | |
158 | bool scatter_scatter_fastpath(ScatterLock *lock); | |
159 | void scatter_scatter(ScatterLock *lock, bool nowait=false); | |
160 | void scatter_tempsync(ScatterLock *lock, bool *need_issue=0); | |
161 | ||
162 | void scatter_writebehind(ScatterLock *lock); | |
163 | ||
164 | void scatter_writebehind_finish(ScatterLock *lock, MutationRef& mut); | |
165 | ||
166 | xlist<ScatterLock*> updated_scatterlocks; | |
167 | public: | |
168 | void mark_updated_scatterlock(ScatterLock *lock); | |
169 | ||
170 | ||
171 | void handle_reqrdlock(SimpleLock *lock, MLock *m); | |
172 | ||
173 | ||
174 | ||
175 | // caps | |
176 | ||
177 | // when to defer processing client cap release or writeback due to being | |
178 | // frozen. the condition must be consistent across handle_client_caps and | |
179 | // process_request_cap_release to preserve ordering. | |
180 | bool should_defer_client_cap_frozen(CInode *in); | |
181 | ||
182 | void process_request_cap_release(MDRequestRef& mdr, client_t client, const ceph_mds_request_release& r, | |
94b18763 | 183 | boost::string_view dname); |
7c673cae FG |
184 | |
185 | void kick_cap_releases(MDRequestRef& mdr); | |
186 | void kick_issue_caps(CInode *in, client_t client, ceph_seq_t seq); | |
187 | ||
a8e16298 | 188 | void remove_client_cap(CInode *in, Capability *cap); |
7c673cae | 189 | |
91327a77 AA |
190 | void get_late_revoking_clients(std::list<client_t> *result, double timeout) const; |
191 | ||
192 | private: | |
193 | bool any_late_revoking_caps(xlist<Capability*> const &revoking, double timeout) const; | |
7c673cae FG |
194 | |
195 | protected: | |
196 | bool _need_flush_mdlog(CInode *in, int wanted_caps); | |
197 | void adjust_cap_wanted(Capability *cap, int wanted, int issue_seq); | |
198 | void handle_client_caps(class MClientCaps *m); | |
94b18763 | 199 | void _update_cap_fields(CInode *in, int dirty, MClientCaps *m, CInode::mempool_inode *pi); |
7c673cae | 200 | void _do_snap_update(CInode *in, snapid_t snap, int dirty, snapid_t follows, client_t client, MClientCaps *m, MClientCaps *ack); |
c07f9fc5 | 201 | void _do_null_snapflush(CInode *head_in, client_t client, snapid_t last=CEPH_NOSNAP); |
7c673cae FG |
202 | bool _do_cap_update(CInode *in, Capability *cap, int dirty, snapid_t follows, MClientCaps *m, |
203 | MClientCaps *ack=0, bool *need_flush=NULL); | |
204 | void handle_client_cap_release(class MClientCapRelease *m); | |
205 | void _do_cap_release(client_t client, inodeno_t ino, uint64_t cap_id, ceph_seq_t mseq, ceph_seq_t seq); | |
206 | void caps_tick(); | |
207 | ||
208 | // Maintain a global list to quickly find if any caps are late revoking | |
209 | xlist<Capability*> revoking_caps; | |
210 | // Maintain a per-client list to find clients responsible for late ones quickly | |
211 | std::map<client_t, xlist<Capability*> > revoking_caps_by_client; | |
212 | ||
213 | // local | |
214 | public: | |
215 | void local_wrlock_grab(LocalLock *lock, MutationRef& mut); | |
216 | protected: | |
217 | bool local_wrlock_start(LocalLock *lock, MDRequestRef& mut); | |
218 | void local_wrlock_finish(LocalLock *lock, MutationImpl *mut); | |
219 | bool local_xlock_start(LocalLock *lock, MDRequestRef& mut); | |
220 | void local_xlock_finish(LocalLock *lock, MutationImpl *mut); | |
221 | ||
222 | ||
223 | // file | |
224 | public: | |
225 | void file_eval(ScatterLock *lock, bool *need_issue); | |
226 | protected: | |
227 | void handle_file_lock(ScatterLock *lock, MLock *m); | |
228 | void scatter_mix(ScatterLock *lock, bool *need_issue=0); | |
229 | void file_excl(ScatterLock *lock, bool *need_issue=0); | |
230 | void file_xsyn(SimpleLock *lock, bool *need_issue=0); | |
231 | ||
232 | public: | |
233 | void file_recover(ScatterLock *lock); | |
234 | ||
235 | private: | |
236 | xlist<ScatterLock*> updated_filelocks; | |
237 | public: | |
238 | void mark_updated_Filelock(ScatterLock *lock); | |
239 | ||
240 | // -- file i/o -- | |
241 | public: | |
242 | version_t issue_file_data_version(CInode *in); | |
243 | Capability* issue_new_caps(CInode *in, int mode, Session *session, SnapRealm *conrealm, bool is_replay); | |
244 | bool issue_caps(CInode *in, Capability *only_cap=0); | |
245 | void issue_caps_set(set<CInode*>& inset); | |
246 | void issue_truncate(CInode *in); | |
247 | void revoke_stale_caps(Session *session); | |
7c673cae FG |
248 | void resume_stale_caps(Session *session); |
249 | void remove_stale_leases(Session *session); | |
250 | ||
251 | public: | |
252 | void request_inode_file_caps(CInode *in); | |
253 | protected: | |
254 | void handle_inode_file_caps(class MInodeFileCaps *m); | |
255 | ||
256 | void file_update_finish(CInode *in, MutationRef& mut, bool share_max, bool issue_client_cap, | |
257 | client_t client, MClientCaps *ack); | |
31f18b77 | 258 | private: |
94b18763 | 259 | uint64_t calc_new_max_size(CInode::mempool_inode *pi, uint64_t size); |
7c673cae | 260 | public: |
a8e16298 | 261 | void calc_new_client_ranges(CInode *in, uint64_t size, bool update, |
94b18763 | 262 | CInode::mempool_inode::client_range_map* new_ranges, |
7c673cae FG |
263 | bool *max_increased); |
264 | bool check_inode_max_size(CInode *in, bool force_wrlock=false, | |
265 | uint64_t newmax=0, uint64_t newsize=0, | |
266 | utime_t mtime=utime_t()); | |
267 | void share_inode_max_size(CInode *in, Capability *only_cap=0); | |
268 | ||
269 | private: | |
270 | friend class C_MDL_CheckMaxSize; | |
271 | friend class C_MDL_RequestInodeFileCaps; | |
272 | friend class C_Locker_FileUpdate_finish; | |
273 | friend class C_Locker_RetryCapRelease; | |
274 | friend class C_Locker_Eval; | |
275 | friend class C_Locker_ScatterWB; | |
276 | friend class LockerContext; | |
277 | friend class LockerLogContext; | |
278 | ||
279 | ||
280 | // -- client leases -- | |
281 | public: | |
282 | void handle_client_lease(struct MClientLease *m); | |
283 | ||
284 | void issue_client_lease(CDentry *dn, client_t client, bufferlist &bl, utime_t now, Session *session); | |
285 | void revoke_client_leases(SimpleLock *lock); | |
286 | }; | |
287 | ||
288 | ||
289 | #endif |