]>
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); |
7c673cae FG |
91 | |
92 | void eval_gather(SimpleLock *lock, bool first=false, bool *need_issue=0, list<MDSInternalContextBase*> *pfinishers=0); | |
93 | void eval(SimpleLock *lock, bool *need_issue); | |
94 | void eval_any(SimpleLock *lock, bool *need_issue, list<MDSInternalContextBase*> *pfinishers=0, bool first=false) { | |
95 | if (!lock->is_stable()) | |
96 | eval_gather(lock, first, need_issue, pfinishers); | |
97 | else if (lock->get_parent()->is_auth()) | |
98 | eval(lock, need_issue); | |
99 | } | |
100 | ||
101 | void eval_scatter_gathers(CInode *in); | |
102 | ||
103 | void eval_cap_gather(CInode *in, set<CInode*> *issue_set=0); | |
104 | ||
105 | bool eval(CInode *in, int mask, bool caps_imported=false); | |
106 | void try_eval(MDSCacheObject *p, int mask); | |
107 | void try_eval(SimpleLock *lock, bool *pneed_issue); | |
108 | ||
109 | bool _rdlock_kick(SimpleLock *lock, bool as_anon); | |
110 | bool rdlock_try(SimpleLock *lock, client_t client, MDSInternalContextBase *c); | |
111 | bool rdlock_start(SimpleLock *lock, MDRequestRef& mut, bool as_anon=false); | |
112 | void rdlock_finish(SimpleLock *lock, MutationImpl *mut, bool *pneed_issue); | |
113 | bool can_rdlock_set(set<SimpleLock*>& locks); | |
114 | bool rdlock_try_set(set<SimpleLock*>& locks); | |
115 | void rdlock_take_set(set<SimpleLock*>& locks, MutationRef& mut); | |
116 | ||
117 | void wrlock_force(SimpleLock *lock, MutationRef& mut); | |
118 | bool wrlock_start(SimpleLock *lock, MDRequestRef& mut, bool nowait=false); | |
119 | void wrlock_finish(SimpleLock *lock, MutationImpl *mut, bool *pneed_issue); | |
120 | ||
121 | void remote_wrlock_start(SimpleLock *lock, mds_rank_t target, MDRequestRef& mut); | |
122 | void remote_wrlock_finish(SimpleLock *lock, mds_rank_t target, MutationImpl *mut); | |
123 | ||
124 | bool xlock_start(SimpleLock *lock, MDRequestRef& mut); | |
125 | void _finish_xlock(SimpleLock *lock, client_t xlocker, bool *pneed_issue); | |
126 | void xlock_finish(SimpleLock *lock, MutationImpl *mut, bool *pneed_issue); | |
127 | ||
128 | void xlock_export(SimpleLock *lock, MutationImpl *mut); | |
129 | void xlock_import(SimpleLock *lock); | |
130 | ||
131 | ||
132 | // simple | |
133 | public: | |
134 | void try_simple_eval(SimpleLock *lock); | |
135 | bool simple_rdlock_try(SimpleLock *lock, MDSInternalContextBase *con); | |
136 | protected: | |
137 | void simple_eval(SimpleLock *lock, bool *need_issue); | |
138 | void handle_simple_lock(SimpleLock *lock, MLock *m); | |
139 | ||
140 | public: | |
141 | bool simple_sync(SimpleLock *lock, bool *need_issue=0); | |
142 | protected: | |
143 | void simple_lock(SimpleLock *lock, bool *need_issue=0); | |
144 | void simple_excl(SimpleLock *lock, bool *need_issue=0); | |
145 | void simple_xlock(SimpleLock *lock); | |
146 | ||
147 | ||
148 | // scatter | |
149 | public: | |
150 | void scatter_eval(ScatterLock *lock, bool *need_issue); // public for MDCache::adjust_subtree_auth() | |
151 | ||
152 | void scatter_tick(); | |
153 | void scatter_nudge(ScatterLock *lock, MDSInternalContextBase *c, bool forcelockchange=false); | |
154 | ||
155 | protected: | |
156 | void handle_scatter_lock(ScatterLock *lock, MLock *m); | |
157 | bool scatter_scatter_fastpath(ScatterLock *lock); | |
158 | void scatter_scatter(ScatterLock *lock, bool nowait=false); | |
159 | void scatter_tempsync(ScatterLock *lock, bool *need_issue=0); | |
160 | ||
161 | void scatter_writebehind(ScatterLock *lock); | |
162 | ||
163 | void scatter_writebehind_finish(ScatterLock *lock, MutationRef& mut); | |
164 | ||
165 | xlist<ScatterLock*> updated_scatterlocks; | |
166 | public: | |
167 | void mark_updated_scatterlock(ScatterLock *lock); | |
168 | ||
169 | ||
170 | void handle_reqrdlock(SimpleLock *lock, MLock *m); | |
171 | ||
172 | ||
173 | ||
174 | // caps | |
175 | ||
176 | // when to defer processing client cap release or writeback due to being | |
177 | // frozen. the condition must be consistent across handle_client_caps and | |
178 | // process_request_cap_release to preserve ordering. | |
179 | bool should_defer_client_cap_frozen(CInode *in); | |
180 | ||
181 | void process_request_cap_release(MDRequestRef& mdr, client_t client, const ceph_mds_request_release& r, | |
94b18763 | 182 | boost::string_view dname); |
7c673cae FG |
183 | |
184 | void kick_cap_releases(MDRequestRef& mdr); | |
185 | void kick_issue_caps(CInode *in, client_t client, ceph_seq_t seq); | |
186 | ||
187 | void remove_client_cap(CInode *in, client_t client); | |
188 | ||
189 | void get_late_revoking_clients(std::list<client_t> *result) const; | |
190 | bool any_late_revoking_caps(xlist<Capability*> const &revoking) const; | |
191 | ||
192 | protected: | |
193 | bool _need_flush_mdlog(CInode *in, int wanted_caps); | |
194 | void adjust_cap_wanted(Capability *cap, int wanted, int issue_seq); | |
195 | void handle_client_caps(class MClientCaps *m); | |
94b18763 | 196 | void _update_cap_fields(CInode *in, int dirty, MClientCaps *m, CInode::mempool_inode *pi); |
7c673cae | 197 | void _do_snap_update(CInode *in, snapid_t snap, int dirty, snapid_t follows, client_t client, MClientCaps *m, MClientCaps *ack); |
c07f9fc5 | 198 | void _do_null_snapflush(CInode *head_in, client_t client, snapid_t last=CEPH_NOSNAP); |
7c673cae FG |
199 | bool _do_cap_update(CInode *in, Capability *cap, int dirty, snapid_t follows, MClientCaps *m, |
200 | MClientCaps *ack=0, bool *need_flush=NULL); | |
201 | void handle_client_cap_release(class MClientCapRelease *m); | |
202 | void _do_cap_release(client_t client, inodeno_t ino, uint64_t cap_id, ceph_seq_t mseq, ceph_seq_t seq); | |
203 | void caps_tick(); | |
204 | ||
205 | // Maintain a global list to quickly find if any caps are late revoking | |
206 | xlist<Capability*> revoking_caps; | |
207 | // Maintain a per-client list to find clients responsible for late ones quickly | |
208 | std::map<client_t, xlist<Capability*> > revoking_caps_by_client; | |
209 | ||
210 | // local | |
211 | public: | |
212 | void local_wrlock_grab(LocalLock *lock, MutationRef& mut); | |
213 | protected: | |
214 | bool local_wrlock_start(LocalLock *lock, MDRequestRef& mut); | |
215 | void local_wrlock_finish(LocalLock *lock, MutationImpl *mut); | |
216 | bool local_xlock_start(LocalLock *lock, MDRequestRef& mut); | |
217 | void local_xlock_finish(LocalLock *lock, MutationImpl *mut); | |
218 | ||
219 | ||
220 | // file | |
221 | public: | |
222 | void file_eval(ScatterLock *lock, bool *need_issue); | |
223 | protected: | |
224 | void handle_file_lock(ScatterLock *lock, MLock *m); | |
225 | void scatter_mix(ScatterLock *lock, bool *need_issue=0); | |
226 | void file_excl(ScatterLock *lock, bool *need_issue=0); | |
227 | void file_xsyn(SimpleLock *lock, bool *need_issue=0); | |
228 | ||
229 | public: | |
230 | void file_recover(ScatterLock *lock); | |
231 | ||
232 | private: | |
233 | xlist<ScatterLock*> updated_filelocks; | |
234 | public: | |
235 | void mark_updated_Filelock(ScatterLock *lock); | |
236 | ||
237 | // -- file i/o -- | |
238 | public: | |
239 | version_t issue_file_data_version(CInode *in); | |
240 | Capability* issue_new_caps(CInode *in, int mode, Session *session, SnapRealm *conrealm, bool is_replay); | |
241 | bool issue_caps(CInode *in, Capability *only_cap=0); | |
242 | void issue_caps_set(set<CInode*>& inset); | |
243 | void issue_truncate(CInode *in); | |
244 | void revoke_stale_caps(Session *session); | |
245 | void revoke_stale_caps(Capability *cap); | |
246 | void resume_stale_caps(Session *session); | |
247 | void remove_stale_leases(Session *session); | |
248 | ||
249 | public: | |
250 | void request_inode_file_caps(CInode *in); | |
251 | protected: | |
252 | void handle_inode_file_caps(class MInodeFileCaps *m); | |
253 | ||
254 | void file_update_finish(CInode *in, MutationRef& mut, bool share_max, bool issue_client_cap, | |
255 | client_t client, MClientCaps *ack); | |
31f18b77 | 256 | private: |
94b18763 | 257 | uint64_t calc_new_max_size(CInode::mempool_inode *pi, uint64_t size); |
7c673cae FG |
258 | public: |
259 | void calc_new_client_ranges(CInode *in, uint64_t size, | |
94b18763 | 260 | CInode::mempool_inode::client_range_map* new_ranges, |
7c673cae FG |
261 | bool *max_increased); |
262 | bool check_inode_max_size(CInode *in, bool force_wrlock=false, | |
263 | uint64_t newmax=0, uint64_t newsize=0, | |
264 | utime_t mtime=utime_t()); | |
265 | void share_inode_max_size(CInode *in, Capability *only_cap=0); | |
266 | ||
267 | private: | |
268 | friend class C_MDL_CheckMaxSize; | |
269 | friend class C_MDL_RequestInodeFileCaps; | |
270 | friend class C_Locker_FileUpdate_finish; | |
271 | friend class C_Locker_RetryCapRelease; | |
272 | friend class C_Locker_Eval; | |
273 | friend class C_Locker_ScatterWB; | |
274 | friend class LockerContext; | |
275 | friend class LockerLogContext; | |
276 | ||
277 | ||
278 | // -- client leases -- | |
279 | public: | |
280 | void handle_client_lease(struct MClientLease *m); | |
281 | ||
282 | void issue_client_lease(CDentry *dn, client_t client, bufferlist &bl, utime_t now, Session *session); | |
283 | void revoke_client_leases(SimpleLock *lock); | |
284 | }; | |
285 | ||
286 | ||
287 | #endif |