diff options
Diffstat (limited to 'fs/gfs2/locking/dlm/lock.c')
-rw-r--r-- | fs/gfs2/locking/dlm/lock.c | 368 |
1 files changed, 274 insertions, 94 deletions
diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index cf7ea8abec87..2482c9047505 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c | |||
@@ -11,46 +11,60 @@ | |||
11 | 11 | ||
12 | static char junk_lvb[GDLM_LVB_SIZE]; | 12 | static char junk_lvb[GDLM_LVB_SIZE]; |
13 | 13 | ||
14 | static void queue_complete(struct gdlm_lock *lp) | 14 | |
15 | /* convert dlm lock-mode to gfs lock-state */ | ||
16 | |||
17 | static s16 gdlm_make_lmstate(s16 dlmmode) | ||
15 | { | 18 | { |
16 | struct gdlm_ls *ls = lp->ls; | 19 | switch (dlmmode) { |
20 | case DLM_LOCK_IV: | ||
21 | case DLM_LOCK_NL: | ||
22 | return LM_ST_UNLOCKED; | ||
23 | case DLM_LOCK_EX: | ||
24 | return LM_ST_EXCLUSIVE; | ||
25 | case DLM_LOCK_CW: | ||
26 | return LM_ST_DEFERRED; | ||
27 | case DLM_LOCK_PR: | ||
28 | return LM_ST_SHARED; | ||
29 | } | ||
30 | gdlm_assert(0, "unknown DLM mode %d", dlmmode); | ||
31 | return -1; | ||
32 | } | ||
17 | 33 | ||
18 | clear_bit(LFL_ACTIVE, &lp->flags); | 34 | /* A lock placed on this queue is re-submitted to DLM as soon as the lock_dlm |
35 | thread gets to it. */ | ||
36 | |||
37 | static void queue_submit(struct gdlm_lock *lp) | ||
38 | { | ||
39 | struct gdlm_ls *ls = lp->ls; | ||
19 | 40 | ||
20 | spin_lock(&ls->async_lock); | 41 | spin_lock(&ls->async_lock); |
21 | list_add_tail(&lp->clist, &ls->complete); | 42 | list_add_tail(&lp->delay_list, &ls->submit); |
22 | spin_unlock(&ls->async_lock); | 43 | spin_unlock(&ls->async_lock); |
23 | wake_up(&ls->thread_wait); | 44 | wake_up(&ls->thread_wait); |
24 | } | 45 | } |
25 | 46 | ||
26 | static inline void gdlm_ast(void *astarg) | 47 | static void wake_up_ast(struct gdlm_lock *lp) |
27 | { | 48 | { |
28 | queue_complete(astarg); | 49 | clear_bit(LFL_AST_WAIT, &lp->flags); |
50 | smp_mb__after_clear_bit(); | ||
51 | wake_up_bit(&lp->flags, LFL_AST_WAIT); | ||
29 | } | 52 | } |
30 | 53 | ||
31 | static inline void gdlm_bast(void *astarg, int mode) | 54 | static void gdlm_delete_lp(struct gdlm_lock *lp) |
32 | { | 55 | { |
33 | struct gdlm_lock *lp = astarg; | ||
34 | struct gdlm_ls *ls = lp->ls; | 56 | struct gdlm_ls *ls = lp->ls; |
35 | 57 | ||
36 | if (!mode) { | ||
37 | printk(KERN_INFO "lock_dlm: bast mode zero %x,%llx\n", | ||
38 | lp->lockname.ln_type, | ||
39 | (unsigned long long)lp->lockname.ln_number); | ||
40 | return; | ||
41 | } | ||
42 | |||
43 | spin_lock(&ls->async_lock); | 58 | spin_lock(&ls->async_lock); |
44 | if (!lp->bast_mode) { | 59 | if (!list_empty(&lp->delay_list)) |
45 | list_add_tail(&lp->blist, &ls->blocking); | 60 | list_del_init(&lp->delay_list); |
46 | lp->bast_mode = mode; | 61 | ls->all_locks_count--; |
47 | } else if (lp->bast_mode < mode) | ||
48 | lp->bast_mode = mode; | ||
49 | spin_unlock(&ls->async_lock); | 62 | spin_unlock(&ls->async_lock); |
50 | wake_up(&ls->thread_wait); | 63 | |
64 | kfree(lp); | ||
51 | } | 65 | } |
52 | 66 | ||
53 | void gdlm_queue_delayed(struct gdlm_lock *lp) | 67 | static void gdlm_queue_delayed(struct gdlm_lock *lp) |
54 | { | 68 | { |
55 | struct gdlm_ls *ls = lp->ls; | 69 | struct gdlm_ls *ls = lp->ls; |
56 | 70 | ||
@@ -59,6 +73,236 @@ void gdlm_queue_delayed(struct gdlm_lock *lp) | |||
59 | spin_unlock(&ls->async_lock); | 73 | spin_unlock(&ls->async_lock); |
60 | } | 74 | } |
61 | 75 | ||
76 | static void process_complete(struct gdlm_lock *lp) | ||
77 | { | ||
78 | struct gdlm_ls *ls = lp->ls; | ||
79 | struct lm_async_cb acb; | ||
80 | |||
81 | memset(&acb, 0, sizeof(acb)); | ||
82 | |||
83 | if (lp->lksb.sb_status == -DLM_ECANCEL) { | ||
84 | log_info("complete dlm cancel %x,%llx flags %lx", | ||
85 | lp->lockname.ln_type, | ||
86 | (unsigned long long)lp->lockname.ln_number, | ||
87 | lp->flags); | ||
88 | |||
89 | lp->req = lp->cur; | ||
90 | acb.lc_ret |= LM_OUT_CANCELED; | ||
91 | if (lp->cur == DLM_LOCK_IV) | ||
92 | lp->lksb.sb_lkid = 0; | ||
93 | goto out; | ||
94 | } | ||
95 | |||
96 | if (test_and_clear_bit(LFL_DLM_UNLOCK, &lp->flags)) { | ||
97 | if (lp->lksb.sb_status != -DLM_EUNLOCK) { | ||
98 | log_info("unlock sb_status %d %x,%llx flags %lx", | ||
99 | lp->lksb.sb_status, lp->lockname.ln_type, | ||
100 | (unsigned long long)lp->lockname.ln_number, | ||
101 | lp->flags); | ||
102 | return; | ||
103 | } | ||
104 | |||
105 | lp->cur = DLM_LOCK_IV; | ||
106 | lp->req = DLM_LOCK_IV; | ||
107 | lp->lksb.sb_lkid = 0; | ||
108 | |||
109 | if (test_and_clear_bit(LFL_UNLOCK_DELETE, &lp->flags)) { | ||
110 | gdlm_delete_lp(lp); | ||
111 | return; | ||
112 | } | ||
113 | goto out; | ||
114 | } | ||
115 | |||
116 | if (lp->lksb.sb_flags & DLM_SBF_VALNOTVALID) | ||
117 | memset(lp->lksb.sb_lvbptr, 0, GDLM_LVB_SIZE); | ||
118 | |||
119 | if (lp->lksb.sb_flags & DLM_SBF_ALTMODE) { | ||
120 | if (lp->req == DLM_LOCK_PR) | ||
121 | lp->req = DLM_LOCK_CW; | ||
122 | else if (lp->req == DLM_LOCK_CW) | ||
123 | lp->req = DLM_LOCK_PR; | ||
124 | } | ||
125 | |||
126 | /* | ||
127 | * A canceled lock request. The lock was just taken off the delayed | ||
128 | * list and was never even submitted to dlm. | ||
129 | */ | ||
130 | |||
131 | if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) { | ||
132 | log_info("complete internal cancel %x,%llx", | ||
133 | lp->lockname.ln_type, | ||
134 | (unsigned long long)lp->lockname.ln_number); | ||
135 | lp->req = lp->cur; | ||
136 | acb.lc_ret |= LM_OUT_CANCELED; | ||
137 | goto out; | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * An error occured. | ||
142 | */ | ||
143 | |||
144 | if (lp->lksb.sb_status) { | ||
145 | /* a "normal" error */ | ||
146 | if ((lp->lksb.sb_status == -EAGAIN) && | ||
147 | (lp->lkf & DLM_LKF_NOQUEUE)) { | ||
148 | lp->req = lp->cur; | ||
149 | if (lp->cur == DLM_LOCK_IV) | ||
150 | lp->lksb.sb_lkid = 0; | ||
151 | goto out; | ||
152 | } | ||
153 | |||
154 | /* this could only happen with cancels I think */ | ||
155 | log_info("ast sb_status %d %x,%llx flags %lx", | ||
156 | lp->lksb.sb_status, lp->lockname.ln_type, | ||
157 | (unsigned long long)lp->lockname.ln_number, | ||
158 | lp->flags); | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | /* | ||
163 | * This is an AST for an EX->EX conversion for sync_lvb from GFS. | ||
164 | */ | ||
165 | |||
166 | if (test_and_clear_bit(LFL_SYNC_LVB, &lp->flags)) { | ||
167 | wake_up_ast(lp); | ||
168 | return; | ||
169 | } | ||
170 | |||
171 | /* | ||
172 | * A lock has been demoted to NL because it initially completed during | ||
173 | * BLOCK_LOCKS. Now it must be requested in the originally requested | ||
174 | * mode. | ||
175 | */ | ||
176 | |||
177 | if (test_and_clear_bit(LFL_REREQUEST, &lp->flags)) { | ||
178 | gdlm_assert(lp->req == DLM_LOCK_NL, "%x,%llx", | ||
179 | lp->lockname.ln_type, | ||
180 | (unsigned long long)lp->lockname.ln_number); | ||
181 | gdlm_assert(lp->prev_req > DLM_LOCK_NL, "%x,%llx", | ||
182 | lp->lockname.ln_type, | ||
183 | (unsigned long long)lp->lockname.ln_number); | ||
184 | |||
185 | lp->cur = DLM_LOCK_NL; | ||
186 | lp->req = lp->prev_req; | ||
187 | lp->prev_req = DLM_LOCK_IV; | ||
188 | lp->lkf &= ~DLM_LKF_CONVDEADLK; | ||
189 | |||
190 | set_bit(LFL_NOCACHE, &lp->flags); | ||
191 | |||
192 | if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) && | ||
193 | !test_bit(LFL_NOBLOCK, &lp->flags)) | ||
194 | gdlm_queue_delayed(lp); | ||
195 | else | ||
196 | queue_submit(lp); | ||
197 | return; | ||
198 | } | ||
199 | |||
200 | /* | ||
201 | * A request is granted during dlm recovery. It may be granted | ||
202 | * because the locks of a failed node were cleared. In that case, | ||
203 | * there may be inconsistent data beneath this lock and we must wait | ||
204 | * for recovery to complete to use it. When gfs recovery is done this | ||
205 | * granted lock will be converted to NL and then reacquired in this | ||
206 | * granted state. | ||
207 | */ | ||
208 | |||
209 | if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) && | ||
210 | !test_bit(LFL_NOBLOCK, &lp->flags) && | ||
211 | lp->req != DLM_LOCK_NL) { | ||
212 | |||
213 | lp->cur = lp->req; | ||
214 | lp->prev_req = lp->req; | ||
215 | lp->req = DLM_LOCK_NL; | ||
216 | lp->lkf |= DLM_LKF_CONVERT; | ||
217 | lp->lkf &= ~DLM_LKF_CONVDEADLK; | ||
218 | |||
219 | log_debug("rereq %x,%llx id %x %d,%d", | ||
220 | lp->lockname.ln_type, | ||
221 | (unsigned long long)lp->lockname.ln_number, | ||
222 | lp->lksb.sb_lkid, lp->cur, lp->req); | ||
223 | |||
224 | set_bit(LFL_REREQUEST, &lp->flags); | ||
225 | queue_submit(lp); | ||
226 | return; | ||
227 | } | ||
228 | |||
229 | /* | ||
230 | * DLM demoted the lock to NL before it was granted so GFS must be | ||
231 | * told it cannot cache data for this lock. | ||
232 | */ | ||
233 | |||
234 | if (lp->lksb.sb_flags & DLM_SBF_DEMOTED) | ||
235 | set_bit(LFL_NOCACHE, &lp->flags); | ||
236 | |||
237 | out: | ||
238 | /* | ||
239 | * This is an internal lock_dlm lock | ||
240 | */ | ||
241 | |||
242 | if (test_bit(LFL_INLOCK, &lp->flags)) { | ||
243 | clear_bit(LFL_NOBLOCK, &lp->flags); | ||
244 | lp->cur = lp->req; | ||
245 | wake_up_ast(lp); | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | /* | ||
250 | * Normal completion of a lock request. Tell GFS it now has the lock. | ||
251 | */ | ||
252 | |||
253 | clear_bit(LFL_NOBLOCK, &lp->flags); | ||
254 | lp->cur = lp->req; | ||
255 | |||
256 | acb.lc_name = lp->lockname; | ||
257 | acb.lc_ret |= gdlm_make_lmstate(lp->cur); | ||
258 | |||
259 | ls->fscb(ls->sdp, LM_CB_ASYNC, &acb); | ||
260 | } | ||
261 | |||
262 | static void gdlm_ast(void *astarg) | ||
263 | { | ||
264 | struct gdlm_lock *lp = astarg; | ||
265 | clear_bit(LFL_ACTIVE, &lp->flags); | ||
266 | process_complete(lp); | ||
267 | } | ||
268 | |||
269 | static void process_blocking(struct gdlm_lock *lp, int bast_mode) | ||
270 | { | ||
271 | struct gdlm_ls *ls = lp->ls; | ||
272 | unsigned int cb = 0; | ||
273 | |||
274 | switch (gdlm_make_lmstate(bast_mode)) { | ||
275 | case LM_ST_EXCLUSIVE: | ||
276 | cb = LM_CB_NEED_E; | ||
277 | break; | ||
278 | case LM_ST_DEFERRED: | ||
279 | cb = LM_CB_NEED_D; | ||
280 | break; | ||
281 | case LM_ST_SHARED: | ||
282 | cb = LM_CB_NEED_S; | ||
283 | break; | ||
284 | default: | ||
285 | gdlm_assert(0, "unknown bast mode %u", bast_mode); | ||
286 | } | ||
287 | |||
288 | ls->fscb(ls->sdp, cb, &lp->lockname); | ||
289 | } | ||
290 | |||
291 | |||
292 | static void gdlm_bast(void *astarg, int mode) | ||
293 | { | ||
294 | struct gdlm_lock *lp = astarg; | ||
295 | |||
296 | if (!mode) { | ||
297 | printk(KERN_INFO "lock_dlm: bast mode zero %x,%llx\n", | ||
298 | lp->lockname.ln_type, | ||
299 | (unsigned long long)lp->lockname.ln_number); | ||
300 | return; | ||
301 | } | ||
302 | |||
303 | process_blocking(lp, mode); | ||
304 | } | ||
305 | |||
62 | /* convert gfs lock-state to dlm lock-mode */ | 306 | /* convert gfs lock-state to dlm lock-mode */ |
63 | 307 | ||
64 | static s16 make_mode(s16 lmstate) | 308 | static s16 make_mode(s16 lmstate) |
@@ -77,24 +321,6 @@ static s16 make_mode(s16 lmstate) | |||
77 | return -1; | 321 | return -1; |
78 | } | 322 | } |
79 | 323 | ||
80 | /* convert dlm lock-mode to gfs lock-state */ | ||
81 | |||
82 | s16 gdlm_make_lmstate(s16 dlmmode) | ||
83 | { | ||
84 | switch (dlmmode) { | ||
85 | case DLM_LOCK_IV: | ||
86 | case DLM_LOCK_NL: | ||
87 | return LM_ST_UNLOCKED; | ||
88 | case DLM_LOCK_EX: | ||
89 | return LM_ST_EXCLUSIVE; | ||
90 | case DLM_LOCK_CW: | ||
91 | return LM_ST_DEFERRED; | ||
92 | case DLM_LOCK_PR: | ||
93 | return LM_ST_SHARED; | ||
94 | } | ||
95 | gdlm_assert(0, "unknown DLM mode %d", dlmmode); | ||
96 | return -1; | ||
97 | } | ||
98 | 324 | ||
99 | /* verify agreement with GFS on the current lock state, NB: DLM_LOCK_NL and | 325 | /* verify agreement with GFS on the current lock state, NB: DLM_LOCK_NL and |
100 | DLM_LOCK_IV are both considered LM_ST_UNLOCKED by GFS. */ | 326 | DLM_LOCK_IV are both considered LM_ST_UNLOCKED by GFS. */ |
@@ -134,14 +360,6 @@ static inline unsigned int make_flags(struct gdlm_lock *lp, | |||
134 | 360 | ||
135 | if (lp->lksb.sb_lkid != 0) { | 361 | if (lp->lksb.sb_lkid != 0) { |
136 | lkf |= DLM_LKF_CONVERT; | 362 | lkf |= DLM_LKF_CONVERT; |
137 | |||
138 | /* Conversion deadlock avoidance by DLM */ | ||
139 | |||
140 | if (!(lp->ls->fsflags & LM_MFLAG_CONV_NODROP) && | ||
141 | !test_bit(LFL_FORCE_PROMOTE, &lp->flags) && | ||
142 | !(lkf & DLM_LKF_NOQUEUE) && | ||
143 | cur > DLM_LOCK_NL && req > DLM_LOCK_NL && cur != req) | ||
144 | lkf |= DLM_LKF_CONVDEADLK; | ||
145 | } | 363 | } |
146 | 364 | ||
147 | if (lp->lvb) | 365 | if (lp->lvb) |
@@ -173,14 +391,9 @@ static int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name, | |||
173 | make_strname(name, &lp->strname); | 391 | make_strname(name, &lp->strname); |
174 | lp->ls = ls; | 392 | lp->ls = ls; |
175 | lp->cur = DLM_LOCK_IV; | 393 | lp->cur = DLM_LOCK_IV; |
176 | lp->lvb = NULL; | ||
177 | lp->hold_null = NULL; | ||
178 | INIT_LIST_HEAD(&lp->clist); | ||
179 | INIT_LIST_HEAD(&lp->blist); | ||
180 | INIT_LIST_HEAD(&lp->delay_list); | 394 | INIT_LIST_HEAD(&lp->delay_list); |
181 | 395 | ||
182 | spin_lock(&ls->async_lock); | 396 | spin_lock(&ls->async_lock); |
183 | list_add(&lp->all_list, &ls->all_locks); | ||
184 | ls->all_locks_count++; | 397 | ls->all_locks_count++; |
185 | spin_unlock(&ls->async_lock); | 398 | spin_unlock(&ls->async_lock); |
186 | 399 | ||
@@ -188,26 +401,6 @@ static int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name, | |||
188 | return 0; | 401 | return 0; |
189 | } | 402 | } |
190 | 403 | ||
191 | void gdlm_delete_lp(struct gdlm_lock *lp) | ||
192 | { | ||
193 | struct gdlm_ls *ls = lp->ls; | ||
194 | |||
195 | spin_lock(&ls->async_lock); | ||
196 | if (!list_empty(&lp->clist)) | ||
197 | list_del_init(&lp->clist); | ||
198 | if (!list_empty(&lp->blist)) | ||
199 | list_del_init(&lp->blist); | ||
200 | if (!list_empty(&lp->delay_list)) | ||
201 | list_del_init(&lp->delay_list); | ||
202 | gdlm_assert(!list_empty(&lp->all_list), "%x,%llx", lp->lockname.ln_type, | ||
203 | (unsigned long long)lp->lockname.ln_number); | ||
204 | list_del_init(&lp->all_list); | ||
205 | ls->all_locks_count--; | ||
206 | spin_unlock(&ls->async_lock); | ||
207 | |||
208 | kfree(lp); | ||
209 | } | ||
210 | |||
211 | int gdlm_get_lock(void *lockspace, struct lm_lockname *name, | 404 | int gdlm_get_lock(void *lockspace, struct lm_lockname *name, |
212 | void **lockp) | 405 | void **lockp) |
213 | { | 406 | { |
@@ -261,7 +454,7 @@ unsigned int gdlm_do_lock(struct gdlm_lock *lp) | |||
261 | 454 | ||
262 | if ((error == -EAGAIN) && (lp->lkf & DLM_LKF_NOQUEUE)) { | 455 | if ((error == -EAGAIN) && (lp->lkf & DLM_LKF_NOQUEUE)) { |
263 | lp->lksb.sb_status = -EAGAIN; | 456 | lp->lksb.sb_status = -EAGAIN; |
264 | queue_complete(lp); | 457 | gdlm_ast(lp); |
265 | error = 0; | 458 | error = 0; |
266 | } | 459 | } |
267 | 460 | ||
@@ -308,6 +501,12 @@ unsigned int gdlm_lock(void *lock, unsigned int cur_state, | |||
308 | { | 501 | { |
309 | struct gdlm_lock *lp = lock; | 502 | struct gdlm_lock *lp = lock; |
310 | 503 | ||
504 | if (req_state == LM_ST_UNLOCKED) | ||
505 | return gdlm_unlock(lock, cur_state); | ||
506 | |||
507 | if (req_state == LM_ST_UNLOCKED) | ||
508 | return gdlm_unlock(lock, cur_state); | ||
509 | |||
311 | clear_bit(LFL_DLM_CANCEL, &lp->flags); | 510 | clear_bit(LFL_DLM_CANCEL, &lp->flags); |
312 | if (flags & LM_FLAG_NOEXP) | 511 | if (flags & LM_FLAG_NOEXP) |
313 | set_bit(LFL_NOBLOCK, &lp->flags); | 512 | set_bit(LFL_NOBLOCK, &lp->flags); |
@@ -351,7 +550,7 @@ void gdlm_cancel(void *lock) | |||
351 | if (delay_list) { | 550 | if (delay_list) { |
352 | set_bit(LFL_CANCEL, &lp->flags); | 551 | set_bit(LFL_CANCEL, &lp->flags); |
353 | set_bit(LFL_ACTIVE, &lp->flags); | 552 | set_bit(LFL_ACTIVE, &lp->flags); |
354 | queue_complete(lp); | 553 | gdlm_ast(lp); |
355 | return; | 554 | return; |
356 | } | 555 | } |
357 | 556 | ||
@@ -507,22 +706,3 @@ void gdlm_submit_delayed(struct gdlm_ls *ls) | |||
507 | wake_up(&ls->thread_wait); | 706 | wake_up(&ls->thread_wait); |
508 | } | 707 | } |
509 | 708 | ||
510 | int gdlm_release_all_locks(struct gdlm_ls *ls) | ||
511 | { | ||
512 | struct gdlm_lock *lp, *safe; | ||
513 | int count = 0; | ||
514 | |||
515 | spin_lock(&ls->async_lock); | ||
516 | list_for_each_entry_safe(lp, safe, &ls->all_locks, all_list) { | ||
517 | list_del_init(&lp->all_list); | ||
518 | |||
519 | if (lp->lvb && lp->lvb != junk_lvb) | ||
520 | kfree(lp->lvb); | ||
521 | kfree(lp); | ||
522 | count++; | ||
523 | } | ||
524 | spin_unlock(&ls->async_lock); | ||
525 | |||
526 | return count; | ||
527 | } | ||
528 | |||