]> err.no Git - linux-2.6/blob - fs/ocfs2/dlm/dlmlock.c
0ff934874942a423e19478331423408017db0dc3
[linux-2.6] / fs / ocfs2 / dlm / dlmlock.c
1 /* -*- mode: c; c-basic-offset: 8; -*-
2  * vim: noexpandtab sw=8 ts=8 sts=0:
3  *
4  * dlmlock.c
5  *
6  * underlying calls for lock creation
7  *
8  * Copyright (C) 2004 Oracle.  All rights reserved.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public
21  * License along with this program; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 021110-1307, USA.
24  *
25  */
26
27
28 #include <linux/module.h>
29 #include <linux/fs.h>
30 #include <linux/types.h>
31 #include <linux/slab.h>
32 #include <linux/highmem.h>
33 #include <linux/utsname.h>
34 #include <linux/init.h>
35 #include <linux/sysctl.h>
36 #include <linux/random.h>
37 #include <linux/blkdev.h>
38 #include <linux/socket.h>
39 #include <linux/inet.h>
40 #include <linux/spinlock.h>
41 #include <linux/delay.h>
42
43
44 #include "cluster/heartbeat.h"
45 #include "cluster/nodemanager.h"
46 #include "cluster/tcp.h"
47
48 #include "dlmapi.h"
49 #include "dlmcommon.h"
50
51 #include "dlmconvert.h"
52
53 #define MLOG_MASK_PREFIX ML_DLM
54 #include "cluster/masklog.h"
55
56 static spinlock_t dlm_cookie_lock = SPIN_LOCK_UNLOCKED;
57 static u64 dlm_next_cookie = 1;
58
59 static enum dlm_status dlm_send_remote_lock_request(struct dlm_ctxt *dlm,
60                                                struct dlm_lock_resource *res,
61                                                struct dlm_lock *lock, int flags);
62 static void dlm_init_lock(struct dlm_lock *newlock, int type,
63                           u8 node, u64 cookie);
64 static void dlm_lock_release(struct kref *kref);
65 static void dlm_lock_detach_lockres(struct dlm_lock *lock);
66
67 /* Tell us whether we can grant a new lock request.
68  * locking:
69  *   caller needs:  res->spinlock
70  *   taken:         none
71  *   held on exit:  none
72  * returns: 1 if the lock can be granted, 0 otherwise.
73  */
74 static int dlm_can_grant_new_lock(struct dlm_lock_resource *res,
75                                   struct dlm_lock *lock)
76 {
77         struct list_head *iter;
78         struct dlm_lock *tmplock;
79
80         list_for_each(iter, &res->granted) {
81                 tmplock = list_entry(iter, struct dlm_lock, list);
82
83                 if (!dlm_lock_compatible(tmplock->ml.type, lock->ml.type))
84                         return 0;
85         }
86
87         list_for_each(iter, &res->converting) {
88                 tmplock = list_entry(iter, struct dlm_lock, list);
89
90                 if (!dlm_lock_compatible(tmplock->ml.type, lock->ml.type))
91                         return 0;
92         }
93
94         return 1;
95 }
96
97 /* performs lock creation at the lockres master site
98  * locking:
99  *   caller needs:  none
100  *   taken:         takes and drops res->spinlock
101  *   held on exit:  none
102  * returns: DLM_NORMAL, DLM_NOTQUEUED
103  */
104 static enum dlm_status dlmlock_master(struct dlm_ctxt *dlm,
105                                       struct dlm_lock_resource *res,
106                                       struct dlm_lock *lock, int flags)
107 {
108         int call_ast = 0, kick_thread = 0;
109         enum dlm_status status = DLM_NORMAL;
110
111         mlog_entry("type=%d\n", lock->ml.type);
112
113         spin_lock(&res->spinlock);
114         /* if called from dlm_create_lock_handler, need to
115          * ensure it will not sleep in dlm_wait_on_lockres */
116         status = __dlm_lockres_state_to_status(res);
117         if (status != DLM_NORMAL &&
118             lock->ml.node != dlm->node_num) {
119                 /* erf.  state changed after lock was dropped. */
120                 spin_unlock(&res->spinlock);
121                 dlm_error(status);
122                 return status;
123         }
124         __dlm_wait_on_lockres(res);
125         __dlm_lockres_reserve_ast(res);
126
127         if (dlm_can_grant_new_lock(res, lock)) {
128                 mlog(0, "I can grant this lock right away\n");
129                 /* got it right away */
130                 lock->lksb->status = DLM_NORMAL;
131                 status = DLM_NORMAL;
132                 dlm_lock_get(lock);
133                 list_add_tail(&lock->list, &res->granted);
134
135                 /* for the recovery lock, we can't allow the ast
136                  * to be queued since the dlmthread is already
137                  * frozen.  but the recovery lock is always locked
138                  * with LKM_NOQUEUE so we do not need the ast in
139                  * this special case */
140                 if (!dlm_is_recovery_lock(res->lockname.name,
141                                           res->lockname.len)) {
142                         kick_thread = 1;
143                         call_ast = 1;
144                 } else {
145                         mlog(0, "%s: returning DLM_NORMAL to "
146                              "node %u for reco lock\n", dlm->name,
147                              lock->ml.node);
148                 }
149         } else {
150                 /* for NOQUEUE request, unless we get the
151                  * lock right away, return DLM_NOTQUEUED */
152                 if (flags & LKM_NOQUEUE) {
153                         status = DLM_NOTQUEUED;
154                         if (dlm_is_recovery_lock(res->lockname.name,
155                                                  res->lockname.len)) {
156                                 mlog(0, "%s: returning NOTQUEUED to "
157                                      "node %u for reco lock\n", dlm->name,
158                                      lock->ml.node);
159                         }
160                 } else {
161                         dlm_lock_get(lock);
162                         list_add_tail(&lock->list, &res->blocked);
163                         kick_thread = 1;
164                 }
165         }
166
167         spin_unlock(&res->spinlock);
168         wake_up(&res->wq);
169
170         /* either queue the ast or release it */
171         if (call_ast)
172                 dlm_queue_ast(dlm, lock);
173         else
174                 dlm_lockres_release_ast(dlm, res);
175
176         dlm_lockres_calc_usage(dlm, res);
177         if (kick_thread)
178                 dlm_kick_thread(dlm, res);
179
180         return status;
181 }
182
183 void dlm_revert_pending_lock(struct dlm_lock_resource *res,
184                              struct dlm_lock *lock)
185 {
186         /* remove from local queue if it failed */
187         list_del_init(&lock->list);
188         lock->lksb->flags &= ~DLM_LKSB_GET_LVB;
189 }
190
191
192 /*
193  * locking:
194  *   caller needs:  none
195  *   taken:         takes and drops res->spinlock
196  *   held on exit:  none
197  * returns: DLM_DENIED, DLM_RECOVERING, or net status
198  */
199 static enum dlm_status dlmlock_remote(struct dlm_ctxt *dlm,
200                                       struct dlm_lock_resource *res,
201                                       struct dlm_lock *lock, int flags)
202 {
203         enum dlm_status status = DLM_DENIED;
204         int lockres_changed = 1;
205
206         mlog_entry("type=%d\n", lock->ml.type);
207         mlog(0, "lockres %.*s, flags = 0x%x\n", res->lockname.len,
208              res->lockname.name, flags);
209
210         spin_lock(&res->spinlock);
211
212         /* will exit this call with spinlock held */
213         __dlm_wait_on_lockres(res);
214         res->state |= DLM_LOCK_RES_IN_PROGRESS;
215
216         /* add lock to local (secondary) queue */
217         dlm_lock_get(lock);
218         list_add_tail(&lock->list, &res->blocked);
219         lock->lock_pending = 1;
220         spin_unlock(&res->spinlock);
221
222         /* spec seems to say that you will get DLM_NORMAL when the lock
223          * has been queued, meaning we need to wait for a reply here. */
224         status = dlm_send_remote_lock_request(dlm, res, lock, flags);
225
226         spin_lock(&res->spinlock);
227         res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
228         lock->lock_pending = 0;
229         if (status != DLM_NORMAL) {
230                 if (status != DLM_NOTQUEUED) {
231                         /*
232                          * DO NOT call calc_usage, as this would unhash
233                          * the remote lockres before we ever get to use
234                          * it.  treat as if we never made any change to
235                          * the lockres.
236                          */
237                         lockres_changed = 0;
238                         dlm_error(status);
239                 }
240                 dlm_revert_pending_lock(res, lock);
241                 dlm_lock_put(lock);
242         } else if (dlm_is_recovery_lock(res->lockname.name, 
243                                         res->lockname.len)) {
244                 /* special case for the $RECOVERY lock.
245                  * there will never be an AST delivered to put
246                  * this lock on the proper secondary queue
247                  * (granted), so do it manually. */
248                 mlog(0, "%s: $RECOVERY lock for this node (%u) is "
249                      "mastered by %u; got lock, manually granting (no ast)\n",
250                      dlm->name, dlm->node_num, res->owner);
251                 list_move_tail(&lock->list, &res->granted);
252         }
253         spin_unlock(&res->spinlock);
254
255         if (lockres_changed)
256                 dlm_lockres_calc_usage(dlm, res);
257
258         wake_up(&res->wq);
259         return status;
260 }
261
262
263 /* for remote lock creation.
264  * locking:
265  *   caller needs:  none, but need res->state & DLM_LOCK_RES_IN_PROGRESS
266  *   taken:         none
267  *   held on exit:  none
268  * returns: DLM_NOLOCKMGR, or net status
269  */
270 static enum dlm_status dlm_send_remote_lock_request(struct dlm_ctxt *dlm,
271                                                struct dlm_lock_resource *res,
272                                                struct dlm_lock *lock, int flags)
273 {
274         struct dlm_create_lock create;
275         int tmpret, status = 0;
276         enum dlm_status ret;
277
278         mlog_entry_void();
279
280         memset(&create, 0, sizeof(create));
281         create.node_idx = dlm->node_num;
282         create.requested_type = lock->ml.type;
283         create.cookie = lock->ml.cookie;
284         create.namelen = res->lockname.len;
285         create.flags = cpu_to_be32(flags);
286         memcpy(create.name, res->lockname.name, create.namelen);
287
288         tmpret = o2net_send_message(DLM_CREATE_LOCK_MSG, dlm->key, &create,
289                                     sizeof(create), res->owner, &status);
290         if (tmpret >= 0) {
291                 // successfully sent and received
292                 ret = status;  // this is already a dlm_status
293                 if (ret == DLM_RECOVERING) {
294                         mlog(ML_ERROR, "%s:%.*s: BUG.  this is a stale lockres "
295                              "no longer owned by %u.  that node is coming back "
296                              "up currently.\n", dlm->name, create.namelen,
297                              create.name, res->owner);
298                         dlm_print_one_lock_resource(res);
299                         BUG();
300                 }
301         } else {
302                 mlog_errno(tmpret);
303                 if (dlm_is_host_down(tmpret)) {
304                         ret = DLM_RECOVERING;
305                         mlog(0, "node %u died so returning DLM_RECOVERING "
306                              "from lock message!\n", res->owner);
307                 } else {
308                         ret = dlm_err_to_dlm_status(tmpret);
309                 }
310         }
311
312         return ret;
313 }
314
315 void dlm_lock_get(struct dlm_lock *lock)
316 {
317         kref_get(&lock->lock_refs);
318 }
319
320 void dlm_lock_put(struct dlm_lock *lock)
321 {
322         kref_put(&lock->lock_refs, dlm_lock_release);
323 }
324
325 static void dlm_lock_release(struct kref *kref)
326 {
327         struct dlm_lock *lock;
328
329         lock = container_of(kref, struct dlm_lock, lock_refs);
330
331         BUG_ON(!list_empty(&lock->list));
332         BUG_ON(!list_empty(&lock->ast_list));
333         BUG_ON(!list_empty(&lock->bast_list));
334         BUG_ON(lock->ast_pending);
335         BUG_ON(lock->bast_pending);
336
337         dlm_lock_detach_lockres(lock);
338
339         if (lock->lksb_kernel_allocated) {
340                 mlog(0, "freeing kernel-allocated lksb\n");
341                 kfree(lock->lksb);
342         }
343         kfree(lock);
344 }
345
346 /* associate a lock with it's lockres, getting a ref on the lockres */
347 void dlm_lock_attach_lockres(struct dlm_lock *lock,
348                              struct dlm_lock_resource *res)
349 {
350         dlm_lockres_get(res);
351         lock->lockres = res;
352 }
353
354 /* drop ref on lockres, if there is still one associated with lock */
355 static void dlm_lock_detach_lockres(struct dlm_lock *lock)
356 {
357         struct dlm_lock_resource *res;
358
359         res = lock->lockres;
360         if (res) {
361                 lock->lockres = NULL;
362                 mlog(0, "removing lock's lockres reference\n");
363                 dlm_lockres_put(res);
364         }
365 }
366
367 static void dlm_init_lock(struct dlm_lock *newlock, int type,
368                           u8 node, u64 cookie)
369 {
370         INIT_LIST_HEAD(&newlock->list);
371         INIT_LIST_HEAD(&newlock->ast_list);
372         INIT_LIST_HEAD(&newlock->bast_list);
373         spin_lock_init(&newlock->spinlock);
374         newlock->ml.type = type;
375         newlock->ml.convert_type = LKM_IVMODE;
376         newlock->ml.highest_blocked = LKM_IVMODE;
377         newlock->ml.node = node;
378         newlock->ml.pad1 = 0;
379         newlock->ml.list = 0;
380         newlock->ml.flags = 0;
381         newlock->ast = NULL;
382         newlock->bast = NULL;
383         newlock->astdata = NULL;
384         newlock->ml.cookie = cpu_to_be64(cookie);
385         newlock->ast_pending = 0;
386         newlock->bast_pending = 0;
387         newlock->convert_pending = 0;
388         newlock->lock_pending = 0;
389         newlock->unlock_pending = 0;
390         newlock->cancel_pending = 0;
391         newlock->lksb_kernel_allocated = 0;
392
393         kref_init(&newlock->lock_refs);
394 }
395
396 struct dlm_lock * dlm_new_lock(int type, u8 node, u64 cookie,
397                                struct dlm_lockstatus *lksb)
398 {
399         struct dlm_lock *lock;
400         int kernel_allocated = 0;
401
402         lock = kcalloc(1, sizeof(*lock), GFP_KERNEL);
403         if (!lock)
404                 return NULL;
405
406         if (!lksb) {
407                 /* zero memory only if kernel-allocated */
408                 lksb = kcalloc(1, sizeof(*lksb), GFP_KERNEL);
409                 if (!lksb) {
410                         kfree(lock);
411                         return NULL;
412                 }
413                 kernel_allocated = 1;
414         }
415
416         dlm_init_lock(lock, type, node, cookie);
417         if (kernel_allocated)
418                 lock->lksb_kernel_allocated = 1;
419         lock->lksb = lksb;
420         lksb->lockid = lock;
421         return lock;
422 }
423
424 /* handler for lock creation net message
425  * locking:
426  *   caller needs:  none
427  *   taken:         takes and drops res->spinlock
428  *   held on exit:  none
429  * returns: DLM_NORMAL, DLM_SYSERR, DLM_IVLOCKID, DLM_NOTQUEUED
430  */
431 int dlm_create_lock_handler(struct o2net_msg *msg, u32 len, void *data)
432 {
433         struct dlm_ctxt *dlm = data;
434         struct dlm_create_lock *create = (struct dlm_create_lock *)msg->buf;
435         struct dlm_lock_resource *res = NULL;
436         struct dlm_lock *newlock = NULL;
437         struct dlm_lockstatus *lksb = NULL;
438         enum dlm_status status = DLM_NORMAL;
439         char *name;
440         unsigned int namelen;
441
442         BUG_ON(!dlm);
443
444         mlog_entry_void();
445
446         if (!dlm_grab(dlm))
447                 return DLM_REJECTED;
448
449         name = create->name;
450         namelen = create->namelen;
451         status = DLM_RECOVERING;
452         if (!dlm_domain_fully_joined(dlm)) {
453                 mlog(ML_ERROR, "Domain %s not fully joined, but node %u is "
454                      "sending a create_lock message for lock %.*s!\n",
455                      dlm->name, create->node_idx, namelen, name);
456                 dlm_error(status);
457                 goto leave;
458         }
459
460         status = DLM_IVBUFLEN;
461         if (namelen > DLM_LOCKID_NAME_MAX) {
462                 dlm_error(status);
463                 goto leave;
464         }
465
466         status = DLM_SYSERR;
467         newlock = dlm_new_lock(create->requested_type,
468                                create->node_idx,
469                                be64_to_cpu(create->cookie), NULL);
470         if (!newlock) {
471                 dlm_error(status);
472                 goto leave;
473         }
474
475         lksb = newlock->lksb;
476
477         if (be32_to_cpu(create->flags) & LKM_GET_LVB) {
478                 lksb->flags |= DLM_LKSB_GET_LVB;
479                 mlog(0, "set DLM_LKSB_GET_LVB flag\n");
480         }
481
482         status = DLM_IVLOCKID;
483         res = dlm_lookup_lockres(dlm, name, namelen);
484         if (!res) {
485                 dlm_error(status);
486                 goto leave;
487         }
488
489         spin_lock(&res->spinlock);
490         status = __dlm_lockres_state_to_status(res);
491         spin_unlock(&res->spinlock);
492
493         if (status != DLM_NORMAL) {
494                 mlog(0, "lockres recovering/migrating/in-progress\n");
495                 goto leave;
496         }
497
498         dlm_lock_attach_lockres(newlock, res);
499
500         status = dlmlock_master(dlm, res, newlock, be32_to_cpu(create->flags));
501 leave:
502         if (status != DLM_NORMAL)
503                 if (newlock)
504                         dlm_lock_put(newlock);
505
506         if (res)
507                 dlm_lockres_put(res);
508
509         dlm_put(dlm);
510
511         return status;
512 }
513
514
515 /* fetch next node-local (u8 nodenum + u56 cookie) into u64 */
516 static inline void dlm_get_next_cookie(u8 node_num, u64 *cookie)
517 {
518         u64 tmpnode = node_num;
519
520         /* shift single byte of node num into top 8 bits */
521         tmpnode <<= 56;
522
523         spin_lock(&dlm_cookie_lock);
524         *cookie = (dlm_next_cookie | tmpnode);
525         if (++dlm_next_cookie & 0xff00000000000000ull) {
526                 mlog(0, "This node's cookie will now wrap!\n");
527                 dlm_next_cookie = 1;
528         }
529         spin_unlock(&dlm_cookie_lock);
530 }
531
532 enum dlm_status dlmlock(struct dlm_ctxt *dlm, int mode,
533                         struct dlm_lockstatus *lksb, int flags,
534                         const char *name, dlm_astlockfunc_t *ast, void *data,
535                         dlm_bastlockfunc_t *bast)
536 {
537         enum dlm_status status;
538         struct dlm_lock_resource *res = NULL;
539         struct dlm_lock *lock = NULL;
540         int convert = 0, recovery = 0;
541
542         /* yes this function is a mess.
543          * TODO: clean this up.  lots of common code in the
544          *       lock and convert paths, especially in the retry blocks */
545         if (!lksb) {
546                 dlm_error(DLM_BADARGS);
547                 return DLM_BADARGS;
548         }
549
550         status = DLM_BADPARAM;
551         if (mode != LKM_EXMODE && mode != LKM_PRMODE && mode != LKM_NLMODE) {
552                 dlm_error(status);
553                 goto error;
554         }
555
556         if (flags & ~LKM_VALID_FLAGS) {
557                 dlm_error(status);
558                 goto error;
559         }
560
561         convert = (flags & LKM_CONVERT);
562         recovery = (flags & LKM_RECOVERY);
563
564         if (recovery &&
565             (!dlm_is_recovery_lock(name, strlen(name)) || convert) ) {
566                 dlm_error(status);
567                 goto error;
568         }
569         if (convert && (flags & LKM_LOCAL)) {
570                 mlog(ML_ERROR, "strange LOCAL convert request!\n");
571                 goto error;
572         }
573
574         if (convert) {
575                 /* CONVERT request */
576
577                 /* if converting, must pass in a valid dlm_lock */
578                 lock = lksb->lockid;
579                 if (!lock) {
580                         mlog(ML_ERROR, "NULL lock pointer in convert "
581                              "request\n");
582                         goto error;
583                 }
584
585                 res = lock->lockres;
586                 if (!res) {
587                         mlog(ML_ERROR, "NULL lockres pointer in convert "
588                              "request\n");
589                         goto error;
590                 }
591                 dlm_lockres_get(res);
592
593                 /* XXX: for ocfs2 purposes, the ast/bast/astdata/lksb are
594                  * static after the original lock call.  convert requests will
595                  * ensure that everything is the same, or return DLM_BADARGS.
596                  * this means that DLM_DENIED_NOASTS will never be returned.
597                  */
598                 if (lock->lksb != lksb || lock->ast != ast ||
599                     lock->bast != bast || lock->astdata != data) {
600                         status = DLM_BADARGS;
601                         mlog(ML_ERROR, "new args:  lksb=%p, ast=%p, bast=%p, "
602                              "astdata=%p\n", lksb, ast, bast, data);
603                         mlog(ML_ERROR, "orig args: lksb=%p, ast=%p, bast=%p, "
604                              "astdata=%p\n", lock->lksb, lock->ast,
605                              lock->bast, lock->astdata);
606                         goto error;
607                 }
608 retry_convert:
609                 dlm_wait_for_recovery(dlm);
610
611                 if (res->owner == dlm->node_num)
612                         status = dlmconvert_master(dlm, res, lock, flags, mode);
613                 else
614                         status = dlmconvert_remote(dlm, res, lock, flags, mode);
615                 if (status == DLM_RECOVERING || status == DLM_MIGRATING ||
616                     status == DLM_FORWARD) {
617                         /* for now, see how this works without sleeping
618                          * and just retry right away.  I suspect the reco
619                          * or migration will complete fast enough that
620                          * no waiting will be necessary */
621                         mlog(0, "retrying convert with migration/recovery/"
622                              "in-progress\n");
623                         msleep(100);
624                         goto retry_convert;
625                 }
626         } else {
627                 u64 tmpcookie;
628
629                 /* LOCK request */
630                 status = DLM_BADARGS;
631                 if (!name) {
632                         dlm_error(status);
633                         goto error;
634                 }
635
636                 status = DLM_IVBUFLEN;
637                 if (strlen(name) > DLM_LOCKID_NAME_MAX || strlen(name) < 1) {
638                         dlm_error(status);
639                         goto error;
640                 }
641
642                 dlm_get_next_cookie(dlm->node_num, &tmpcookie);
643                 lock = dlm_new_lock(mode, dlm->node_num, tmpcookie, lksb);
644                 if (!lock) {
645                         dlm_error(status);
646                         goto error;
647                 }
648
649                 if (!recovery)
650                         dlm_wait_for_recovery(dlm);
651
652                 /* find or create the lock resource */
653                 res = dlm_get_lock_resource(dlm, name, flags);
654                 if (!res) {
655                         status = DLM_IVLOCKID;
656                         dlm_error(status);
657                         goto error;
658                 }
659
660                 mlog(0, "type=%d, flags = 0x%x\n", mode, flags);
661                 mlog(0, "creating lock: lock=%p res=%p\n", lock, res);
662
663                 dlm_lock_attach_lockres(lock, res);
664                 lock->ast = ast;
665                 lock->bast = bast;
666                 lock->astdata = data;
667
668 retry_lock:
669                 if (flags & LKM_VALBLK) {
670                         mlog(0, "LKM_VALBLK passed by caller\n");
671
672                         /* LVB requests for non PR, PW or EX locks are
673                          * ignored. */
674                         if (mode < LKM_PRMODE)
675                                 flags &= ~LKM_VALBLK;
676                         else {
677                                 flags |= LKM_GET_LVB;
678                                 lock->lksb->flags |= DLM_LKSB_GET_LVB;
679                         }
680                 }
681
682                 if (res->owner == dlm->node_num)
683                         status = dlmlock_master(dlm, res, lock, flags);
684                 else
685                         status = dlmlock_remote(dlm, res, lock, flags);
686
687                 if (status == DLM_RECOVERING || status == DLM_MIGRATING ||
688                     status == DLM_FORWARD) {
689                         mlog(0, "retrying lock with migration/"
690                              "recovery/in progress\n");
691                         msleep(100);
692                         /* no waiting for dlm_reco_thread */
693                         if (recovery) {
694                                 if (status == DLM_RECOVERING) {
695                                         mlog(0, "%s: got RECOVERING "
696                                              "for $REOCVERY lock, master "
697                                              "was %u\n", dlm->name, 
698                                              res->owner);
699                                         dlm_wait_for_node_death(dlm, res->owner, 
700                                                         DLM_NODE_DEATH_WAIT_MAX);
701                                 }
702                         } else {
703                                 dlm_wait_for_recovery(dlm);
704                         }
705                         goto retry_lock;
706                 }
707
708                 if (status != DLM_NORMAL) {
709                         lock->lksb->flags &= ~DLM_LKSB_GET_LVB;
710                         if (status != DLM_NOTQUEUED)
711                                 dlm_error(status);
712                         goto error;
713                 }
714         }
715
716 error:
717         if (status != DLM_NORMAL) {
718                 if (lock && !convert)
719                         dlm_lock_put(lock);
720                 // this is kind of unnecessary
721                 lksb->status = status;
722         }
723
724         /* put lockres ref from the convert path
725          * or from dlm_get_lock_resource */
726         if (res)
727                 dlm_lockres_put(res);
728
729         return status;
730 }
731 EXPORT_SYMBOL_GPL(dlmlock);