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