]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/Locker.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / mds / Locker.h
CommitLineData
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
31struct SnapRealm;
7c673cae
FG
32
33class MDSRank;
34class Session;
7c673cae 35class CDentry;
7c673cae 36class Capability;
7c673cae
FG
37class SimpleLock;
38class ScatterLock;
f67539c2 39class LocalLockC;
7c673cae 40
7c673cae 41class Locker {
9f95a23c 42public:
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);
81eedcae 167 int issue_caps(CInode *in, Capability *only_cap=0);
11fdf7f2 168 void issue_caps_set(std::set<CInode*>& inset);
7c673cae 169 void issue_truncate(CInode *in);
494da23a
TL
170 void revoke_stale_cap(CInode *in, client_t client);
171 bool revoke_stale_caps(Session *session);
7c673cae
FG
172 void resume_stale_caps(Session *session);
173 void remove_stale_leases(Session *session);
174
7c673cae 175 void request_inode_file_caps(CInode *in);
7c673cae 176
f91f0fd5
TL
177 bool check_client_ranges(CInode *in, uint64_t size);
178 bool calc_new_client_ranges(CInode *in, uint64_t size,
179 bool *max_increased=nullptr);
7c673cae
FG
180 bool check_inode_max_size(CInode *in, bool force_wrlock=false,
181 uint64_t newmax=0, uint64_t newsize=0,
182 utime_t mtime=utime_t());
183 void share_inode_max_size(CInode *in, Capability *only_cap=0);
184
9f95a23c
TL
185 // -- client leases --
186 void handle_client_lease(const cref_t<MClientLease> &m);
187
188 void issue_client_lease(CDentry *dn, MDRequestRef &mdr, int mask, utime_t now, bufferlist &bl);
189 void revoke_client_leases(SimpleLock *lock);
190 static void encode_lease(bufferlist& bl, const session_info_t& info, const LeaseStat& ls);
191
192protected:
193 void send_lock_message(SimpleLock *lock, int msg);
194 void send_lock_message(SimpleLock *lock, int msg, const bufferlist &data);
195
196 // -- locks --
197 void _drop_locks(MutationImpl *mut, std::set<CInode*> *pneed_issue, bool drop_rdlocks);
198
199 void simple_eval(SimpleLock *lock, bool *need_issue);
200 void handle_simple_lock(SimpleLock *lock, const cref_t<MLock> &m);
201
202 void simple_lock(SimpleLock *lock, bool *need_issue=0);
203 void simple_excl(SimpleLock *lock, bool *need_issue=0);
204 void simple_xlock(SimpleLock *lock);
205
206 void handle_scatter_lock(ScatterLock *lock, const cref_t<MLock> &m);
207 bool scatter_scatter_fastpath(ScatterLock *lock);
208 void scatter_scatter(ScatterLock *lock, bool nowait=false);
209 void scatter_tempsync(ScatterLock *lock, bool *need_issue=0);
210
211 void scatter_writebehind(ScatterLock *lock);
212
213 void scatter_writebehind_finish(ScatterLock *lock, MutationRef& mut);
214
215 bool _need_flush_mdlog(CInode *in, int wanted_caps);
216 void adjust_cap_wanted(Capability *cap, int wanted, int issue_seq);
217 void handle_client_caps(const cref_t<MClientCaps> &m);
218 void _update_cap_fields(CInode *in, int dirty, const cref_t<MClientCaps> &m, CInode::mempool_inode *pi);
219 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);
220 void _do_null_snapflush(CInode *head_in, client_t client, snapid_t last=CEPH_NOSNAP);
221 bool _do_cap_update(CInode *in, Capability *cap, int dirty, snapid_t follows, const cref_t<MClientCaps> &m,
222 const ref_t<MClientCaps> &ack, bool *need_flush=NULL);
223 void handle_client_cap_release(const cref_t<MClientCapRelease> &m);
224 void _do_cap_release(client_t client, inodeno_t ino, uint64_t cap_id, ceph_seq_t mseq, ceph_seq_t seq);
225 void caps_tick();
226
f67539c2 227 bool local_wrlock_start(LocalLockC *lock, MDRequestRef& mut);
9f95a23c 228 void local_wrlock_finish(const MutationImpl::lock_iterator& it, MutationImpl *mut);
f67539c2 229 bool local_xlock_start(LocalLockC *lock, MDRequestRef& mut);
9f95a23c
TL
230 void local_xlock_finish(const MutationImpl::lock_iterator& it, MutationImpl *mut);
231
232 void handle_file_lock(ScatterLock *lock, const cref_t<MLock> &m);
233 void scatter_mix(ScatterLock *lock, bool *need_issue=0);
234 void file_excl(ScatterLock *lock, bool *need_issue=0);
235 void file_xsyn(SimpleLock *lock, bool *need_issue=0);
236
237 void handle_inode_file_caps(const cref_t<MInodeFileCaps> &m);
238
239 void file_update_finish(CInode *in, MutationRef& mut, unsigned flags,
240 client_t client, const ref_t<MClientCaps> &ack);
241
242 xlist<ScatterLock*> updated_scatterlocks;
243
244 // Maintain a global list to quickly find if any caps are late revoking
245 xlist<Capability*> revoking_caps;
246 // Maintain a per-client list to find clients responsible for late ones quickly
247 std::map<client_t, xlist<Capability*> > revoking_caps_by_client;
248
249 elist<CInode*> need_snapflush_inodes;
250
7c673cae
FG
251private:
252 friend class C_MDL_CheckMaxSize;
253 friend class C_MDL_RequestInodeFileCaps;
254 friend class C_Locker_FileUpdate_finish;
255 friend class C_Locker_RetryCapRelease;
256 friend class C_Locker_Eval;
257 friend class C_Locker_ScatterWB;
258 friend class LockerContext;
259 friend class LockerLogContext;
260
9f95a23c 261 bool any_late_revoking_caps(xlist<Capability*> const &revoking, double timeout) const;
f67539c2 262 uint64_t calc_new_max_size(const CInode::inode_const_ptr& pi, uint64_t size);
7c673cae 263
9f95a23c
TL
264 MDSRank *mds;
265 MDCache *mdcache;
266 xlist<ScatterLock*> updated_filelocks;
7c673cae 267};
7c673cae 268#endif