Whamcloud - gitweb
b=16777
[fs/lustre-release.git] / lustre / ldlm / ldlm_flock.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2003 Hewlett-Packard Development Company LP.
33  * Developed under the sponsorship of the US Government under
34  * Subcontract No. B514193
35  */
36 /*
37  * This file is part of Lustre, http://www.lustre.org/
38  * Lustre is a trademark of Sun Microsystems, Inc.
39  */
40
41 #define DEBUG_SUBSYSTEM S_LDLM
42
43 #ifdef __KERNEL__
44 #include <lustre_dlm.h>
45 #include <obd_support.h>
46 #include <obd_class.h>
47 #include <lustre_lib.h>
48 #include <libcfs/list.h>
49 #else
50 #include <liblustre.h>
51 #include <obd_class.h>
52 #endif
53
54 #include "ldlm_internal.h"
55
56 #define l_flock_waitq   l_lru
57
58 /**
59  * Wait queue for Posix lock deadlock detection, added with
60  * ldlm_lock::l_flock_waitq.
61  */
62 static CFS_LIST_HEAD(ldlm_flock_waitq);
63 /**
64  * Lock protecting access to ldlm_flock_waitq.
65  */
66 spinlock_t ldlm_flock_waitq_lock = SPIN_LOCK_UNLOCKED;
67
68 int ldlm_flock_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
69                             void *data, int flag);
70
71 /**
72  * list_for_remaining_safe - iterate over the remaining entries in a list
73  *              and safeguard against removal of a list entry.
74  * @pos:        the &struct list_head to use as a loop counter. pos MUST
75  *              have been initialized prior to using it in this macro.
76  * @n:          another &struct list_head to use as temporary storage
77  * @head:       the head for your list.
78  */
79 #define list_for_remaining_safe(pos, n, head) \
80         for (n = pos->next; pos != (head); pos = n, n = pos->next)
81
82 static inline int
83 ldlm_same_flock_owner(struct ldlm_lock *lock, struct ldlm_lock *new)
84 {
85         return((new->l_policy_data.l_flock.pid ==
86                 lock->l_policy_data.l_flock.pid) &&
87                (new->l_export == lock->l_export));
88 }
89
90 static inline int
91 ldlm_flocks_overlap(struct ldlm_lock *lock, struct ldlm_lock *new)
92 {
93         return((new->l_policy_data.l_flock.start <=
94                 lock->l_policy_data.l_flock.end) &&
95                (new->l_policy_data.l_flock.end >=
96                 lock->l_policy_data.l_flock.start));
97 }
98
99 static inline void
100 ldlm_flock_destroy(struct ldlm_lock *lock, ldlm_mode_t mode, int flags)
101 {
102         ENTRY;
103
104         LDLM_DEBUG(lock, "ldlm_flock_destroy(mode: %d, flags: 0x%x)",
105                    mode, flags);
106
107         /* Safe to not lock here, since it should be empty anyway */
108         LASSERT(list_empty(&lock->l_flock_waitq));
109
110         list_del_init(&lock->l_res_link);
111         if (flags == LDLM_FL_WAIT_NOREPROC) {
112                 /* client side - set a flag to prevent sending a CANCEL */
113                 lock->l_flags |= LDLM_FL_LOCAL_ONLY | LDLM_FL_CBPENDING;
114
115                 /* when reaching here, it is under lock_res_and_lock(). Thus, 
116                    need call the nolock version of ldlm_lock_decref_internal*/
117                 ldlm_lock_decref_internal_nolock(lock, mode);
118         }
119
120         ldlm_lock_destroy_nolock(lock);
121         EXIT;
122 }
123
124 static int
125 ldlm_flock_deadlock(struct ldlm_lock *req, struct ldlm_lock *blocking_lock)
126 {
127         struct obd_export *req_export = req->l_export;
128         struct obd_export *blocking_export = blocking_lock->l_export;
129         pid_t req_pid = req->l_policy_data.l_flock.pid;
130         pid_t blocking_pid = blocking_lock->l_policy_data.l_flock.pid;
131         struct ldlm_lock *lock;
132
133         spin_lock(&ldlm_flock_waitq_lock);
134 restart:
135         list_for_each_entry(lock, &ldlm_flock_waitq, l_flock_waitq) {
136                 if ((lock->l_policy_data.l_flock.pid != blocking_pid) ||
137                     (lock->l_export != blocking_export))
138                         continue;
139
140                 blocking_pid = lock->l_policy_data.l_flock.blocking_pid;
141                 blocking_export = (struct obd_export *)(long)
142                         lock->l_policy_data.l_flock.blocking_export;
143                 if (blocking_pid == req_pid && blocking_export == req_export) {
144                         spin_unlock(&ldlm_flock_waitq_lock);
145                         return 1;
146                 }
147
148                 goto restart;
149         }
150         spin_unlock(&ldlm_flock_waitq_lock);
151
152         return 0;
153 }
154
155 int
156 ldlm_process_flock_lock(struct ldlm_lock *req, int *flags, int first_enq,
157                         ldlm_error_t *err, struct list_head *work_list)
158 {
159         struct ldlm_resource *res = req->l_resource;
160         struct ldlm_namespace *ns = res->lr_namespace;
161         struct list_head *tmp;
162         struct list_head *ownlocks = NULL;
163         struct ldlm_lock *lock = NULL;
164         struct ldlm_lock *new = req;
165         struct ldlm_lock *new2 = NULL;
166         ldlm_mode_t mode = req->l_req_mode;
167         int local = ns_is_client(ns);
168         int added = (mode == LCK_NL);
169         int overlaps = 0;
170         int splitted = 0;
171         ENTRY;
172
173         CDEBUG(D_DLMTRACE, "flags %#x pid %u mode %u start "LPU64" end "LPU64
174                "\n", *flags, new->l_policy_data.l_flock.pid, mode,
175                req->l_policy_data.l_flock.start,
176                req->l_policy_data.l_flock.end);
177
178         *err = ELDLM_OK;
179
180         if (local) {
181                 /* No blocking ASTs are sent to the clients for
182                  * Posix file & record locks */
183                 req->l_blocking_ast = NULL;
184         } else {
185                 /* Called on the server for lock cancels. */
186                 req->l_blocking_ast = ldlm_flock_blocking_ast;
187         }
188
189 reprocess:
190         if ((*flags == LDLM_FL_WAIT_NOREPROC) || (mode == LCK_NL)) {
191                 /* This loop determines where this processes locks start
192                  * in the resource lr_granted list. */
193                 list_for_each(tmp, &res->lr_granted) {
194                         lock = list_entry(tmp, struct ldlm_lock, l_res_link);
195                         if (ldlm_same_flock_owner(lock, req)) {
196                                 ownlocks = tmp;
197                                 break;
198                         }
199                 }
200         } else {
201                 lockmode_verify(mode);
202
203                 /* This loop determines if there are existing locks
204                  * that conflict with the new lock request. */
205                 list_for_each(tmp, &res->lr_granted) {
206                         lock = list_entry(tmp, struct ldlm_lock, l_res_link);
207
208                         if (ldlm_same_flock_owner(lock, req)) {
209                                 if (!ownlocks)
210                                         ownlocks = tmp;
211                                 continue;
212                         }
213
214                         /* locks are compatible, overlap doesn't matter */
215                         if (lockmode_compat(lock->l_granted_mode, mode))
216                                 continue;
217
218                         if (!ldlm_flocks_overlap(lock, req))
219                                 continue;
220
221                         if (!first_enq)
222                                 RETURN(LDLM_ITER_CONTINUE);
223
224                         if (*flags & LDLM_FL_BLOCK_NOWAIT) {
225                                 ldlm_flock_destroy(req, mode, *flags);
226                                 *err = -EAGAIN;
227                                 RETURN(LDLM_ITER_STOP);
228                         }
229
230                         if (*flags & LDLM_FL_TEST_LOCK) {
231                                 ldlm_flock_destroy(req, mode, *flags);
232                                 req->l_req_mode = lock->l_granted_mode;
233                                 req->l_policy_data.l_flock.pid =
234                                         lock->l_policy_data.l_flock.pid;
235                                 req->l_policy_data.l_flock.start =
236                                         lock->l_policy_data.l_flock.start;
237                                 req->l_policy_data.l_flock.end =
238                                         lock->l_policy_data.l_flock.end;
239                                 *flags |= LDLM_FL_LOCK_CHANGED;
240                                 RETURN(LDLM_ITER_STOP);
241                         }
242
243                         if (ldlm_flock_deadlock(req, lock)) {
244                                 ldlm_flock_destroy(req, mode, *flags);
245                                 *err = -EDEADLK;
246                                 RETURN(LDLM_ITER_STOP);
247                         }
248
249                         req->l_policy_data.l_flock.blocking_pid =
250                                 lock->l_policy_data.l_flock.pid;
251                         req->l_policy_data.l_flock.blocking_export =
252                                 (long)(void *)lock->l_export;
253
254                         LASSERT(list_empty(&req->l_flock_waitq));
255                         spin_lock(&ldlm_flock_waitq_lock);
256                         list_add_tail(&req->l_flock_waitq, &ldlm_flock_waitq);
257                         spin_unlock(&ldlm_flock_waitq_lock);
258
259                         ldlm_resource_add_lock(res, &res->lr_waiting, req);
260                         *flags |= LDLM_FL_BLOCK_GRANTED;
261                         RETURN(LDLM_ITER_STOP);
262                 }
263         }
264
265         if (*flags & LDLM_FL_TEST_LOCK) {
266                 ldlm_flock_destroy(req, mode, *flags);
267                 req->l_req_mode = LCK_NL;
268                 *flags |= LDLM_FL_LOCK_CHANGED;
269                 RETURN(LDLM_ITER_STOP);
270         }
271
272         /* In case we had slept on this lock request take it off of the
273          * deadlock detection waitq. */
274         spin_lock(&ldlm_flock_waitq_lock);
275         list_del_init(&req->l_flock_waitq);
276         spin_unlock(&ldlm_flock_waitq_lock);
277
278         /* Scan the locks owned by this process that overlap this request.
279          * We may have to merge or split existing locks. */
280
281         if (!ownlocks)
282                 ownlocks = &res->lr_granted;
283
284         list_for_remaining_safe(ownlocks, tmp, &res->lr_granted) {
285                 lock = list_entry(ownlocks, struct ldlm_lock, l_res_link);
286
287                 if (!ldlm_same_flock_owner(lock, new))
288                         break;
289
290                 if (lock->l_granted_mode == mode) {
291                         /* If the modes are the same then we need to process
292                          * locks that overlap OR adjoin the new lock. The extra
293                          * logic condition is necessary to deal with arithmetic
294                          * overflow and underflow. */
295                         if ((new->l_policy_data.l_flock.start >
296                              (lock->l_policy_data.l_flock.end + 1))
297                             && (lock->l_policy_data.l_flock.end !=
298                                 OBD_OBJECT_EOF))
299                                 continue;
300
301                         if ((new->l_policy_data.l_flock.end <
302                              (lock->l_policy_data.l_flock.start - 1))
303                             && (lock->l_policy_data.l_flock.start != 0))
304                                 break;
305
306                         if (new->l_policy_data.l_flock.start <
307                             lock->l_policy_data.l_flock.start) {
308                                 lock->l_policy_data.l_flock.start =
309                                         new->l_policy_data.l_flock.start;
310                         } else {
311                                 new->l_policy_data.l_flock.start =
312                                         lock->l_policy_data.l_flock.start;
313                         }
314
315                         if (new->l_policy_data.l_flock.end >
316                             lock->l_policy_data.l_flock.end) {
317                                 lock->l_policy_data.l_flock.end =
318                                         new->l_policy_data.l_flock.end;
319                         } else {
320                                 new->l_policy_data.l_flock.end =
321                                         lock->l_policy_data.l_flock.end;
322                         }
323
324                         if (added) {
325                                 ldlm_flock_destroy(lock, mode, *flags);
326                         } else {
327                                 new = lock;
328                                 added = 1;
329                         }
330                         continue;
331                 }
332
333                 if (new->l_policy_data.l_flock.start >
334                     lock->l_policy_data.l_flock.end)
335                         continue;
336
337                 if (new->l_policy_data.l_flock.end <
338                     lock->l_policy_data.l_flock.start)
339                         break;
340
341                 ++overlaps;
342
343                 if (new->l_policy_data.l_flock.start <=
344                     lock->l_policy_data.l_flock.start) {
345                         if (new->l_policy_data.l_flock.end <
346                             lock->l_policy_data.l_flock.end) {
347                                 lock->l_policy_data.l_flock.start =
348                                         new->l_policy_data.l_flock.end + 1;
349                                 break;
350                         }
351                         ldlm_flock_destroy(lock, lock->l_req_mode, *flags);
352                         continue;
353                 }
354                 if (new->l_policy_data.l_flock.end >=
355                     lock->l_policy_data.l_flock.end) {
356                         lock->l_policy_data.l_flock.end =
357                                 new->l_policy_data.l_flock.start - 1;
358                         continue;
359                 }
360
361                 /* split the existing lock into two locks */
362
363                 /* if this is an F_UNLCK operation then we could avoid
364                  * allocating a new lock and use the req lock passed in
365                  * with the request but this would complicate the reply
366                  * processing since updates to req get reflected in the
367                  * reply. The client side replays the lock request so
368                  * it must see the original lock data in the reply. */
369
370                 /* XXX - if ldlm_lock_new() can sleep we should
371                  * release the ns_lock, allocate the new lock,
372                  * and restart processing this lock. */
373                 if (!new2) {
374                         unlock_res_and_lock(req);
375                          new2 = ldlm_lock_create(ns, &res->lr_name, LDLM_FLOCK,
376                                         lock->l_granted_mode, NULL, NULL, NULL,
377                                         NULL, 0);
378                         lock_res_and_lock(req);
379                         if (!new2) {
380                                 ldlm_flock_destroy(req, lock->l_granted_mode, *flags);
381                                 *err = -ENOLCK;
382                                 RETURN(LDLM_ITER_STOP);
383                         }
384                         goto reprocess;
385                 }
386
387                 splitted = 1;
388
389                 new2->l_granted_mode = lock->l_granted_mode;
390                 new2->l_policy_data.l_flock.pid =
391                         new->l_policy_data.l_flock.pid;
392                 new2->l_policy_data.l_flock.start =
393                         lock->l_policy_data.l_flock.start;
394                 new2->l_policy_data.l_flock.end =
395                         new->l_policy_data.l_flock.start - 1;
396                 lock->l_policy_data.l_flock.start =
397                         new->l_policy_data.l_flock.end + 1;
398                 new2->l_conn_export = lock->l_conn_export;
399                 if (lock->l_export != NULL) {
400                         new2->l_export = class_export_get(lock->l_export);
401                         if (new2->l_export->exp_lock_hash && 
402                             hlist_unhashed(&new2->l_exp_hash))
403                                 lustre_hash_add(new2->l_export->exp_lock_hash,
404                                                 &new2->l_remote_handle,
405                                                 &new2->l_exp_hash);
406                 }
407                 if (*flags == LDLM_FL_WAIT_NOREPROC) {
408                         ldlm_lock_addref_internal_nolock(new2, lock->l_granted_mode);
409                 }
410
411                 /* insert new2 at lock */
412                 ldlm_resource_add_lock(res, ownlocks, new2);
413                 LDLM_LOCK_PUT(new2);
414                 break;
415         }
416
417         /* if new2 is created but never used, destroy it*/
418         if (splitted == 0 && new2 != NULL)
419                 ldlm_lock_destroy_nolock(new2);
420
421         /* At this point we're granting the lock request. */
422         req->l_granted_mode = req->l_req_mode;
423
424         /* Add req to the granted queue before calling ldlm_reprocess_all(). */
425         if (!added) {
426                 list_del_init(&req->l_res_link);
427                 /* insert new lock before ownlocks in list. */
428                 ldlm_resource_add_lock(res, ownlocks, req);
429         }
430
431         if (*flags != LDLM_FL_WAIT_NOREPROC) {
432                 if (first_enq) {
433                         /* If this is an unlock, reprocess the waitq and
434                          * send completions ASTs for locks that can now be
435                          * granted. The only problem with doing this
436                          * reprocessing here is that the completion ASTs for
437                          * newly granted locks will be sent before the unlock
438                          * completion is sent. It shouldn't be an issue. Also
439                          * note that ldlm_process_flock_lock() will recurse,
440                          * but only once because first_enq will be false from
441                          * ldlm_reprocess_queue. */
442                         if ((mode == LCK_NL) && overlaps) {
443                                 CFS_LIST_HEAD(rpc_list);
444                                 int rc;
445 restart:
446                                 ldlm_reprocess_queue(res, &res->lr_waiting,
447                                                      &rpc_list);
448
449                                 unlock_res_and_lock(req);
450                                 rc = ldlm_run_ast_work(&rpc_list,
451                                                        LDLM_WORK_CP_AST);
452                                 lock_res_and_lock(req);
453                                 if (rc == -ERESTART)
454                                         GOTO(restart, -ERESTART);
455                        }
456                 } else {
457                         LASSERT(req->l_completion_ast);
458                         ldlm_add_ast_work_item(req, NULL, work_list);
459                 }
460         }
461
462         /* In case we're reprocessing the requested lock we can't destroy
463          * it until after calling ldlm_ast_work_item() above so that lawi()
464          * can bump the reference count on req. Otherwise req could be freed
465          * before the completion AST can be sent.  */
466         if (added)
467                 ldlm_flock_destroy(req, mode, *flags);
468
469         ldlm_resource_dump(D_INFO, res);
470         RETURN(LDLM_ITER_CONTINUE);
471 }
472
473 struct ldlm_flock_wait_data {
474         struct ldlm_lock *fwd_lock;
475         int               fwd_generation;
476 };
477
478 static void
479 ldlm_flock_interrupted_wait(void *data)
480 {
481         struct ldlm_lock *lock;
482         struct lustre_handle lockh;
483         int rc;
484         ENTRY;
485
486         lock = ((struct ldlm_flock_wait_data *)data)->fwd_lock;
487
488         /* take lock off the deadlock detection waitq. */
489         spin_lock(&ldlm_flock_waitq_lock);
490         list_del_init(&lock->l_flock_waitq);
491         spin_unlock(&ldlm_flock_waitq_lock);
492
493         /* client side - set flag to prevent lock from being put on lru list */
494         lock->l_flags |= LDLM_FL_CBPENDING;
495
496         ldlm_lock_decref_internal(lock, lock->l_req_mode);
497         ldlm_lock2handle(lock, &lockh);
498         rc = ldlm_cli_cancel(&lockh);
499         if (rc != ELDLM_OK)
500                 CERROR("ldlm_cli_cancel: %d\n", rc);
501
502         EXIT;
503 }
504
505 int
506 ldlm_flock_completion_ast(struct ldlm_lock *lock, int flags, void *data)
507 {
508         struct ldlm_namespace *ns;
509         cfs_flock_t *getlk = lock->l_ast_data;
510         struct ldlm_flock_wait_data fwd;
511         struct obd_device *obd;
512         struct obd_import *imp = NULL;
513         ldlm_error_t err;
514         int rc = 0;
515         struct l_wait_info lwi;
516         ENTRY;
517
518         CDEBUG(D_DLMTRACE, "flags: 0x%x data: %p getlk: %p\n",
519                flags, data, getlk);
520
521         /* Import invalidation. We need to actually release the lock
522          * references being held, so that it can go away. No point in
523          * holding the lock even if app still believes it has it, since
524          * server already dropped it anyway. Only for granted locks too. */
525         lock_res_and_lock(lock);
526         if ((lock->l_flags & (LDLM_FL_FAILED|LDLM_FL_LOCAL_ONLY)) == 
527             (LDLM_FL_FAILED|LDLM_FL_LOCAL_ONLY)) {
528                 unlock_res_and_lock(lock);
529                 if (lock->l_req_mode == lock->l_granted_mode &&
530                     lock->l_granted_mode != LCK_NL)
531                         ldlm_lock_decref_internal(lock, lock->l_req_mode);
532                 RETURN(0);
533         }
534         unlock_res_and_lock(lock);
535
536         LASSERT(flags != LDLM_FL_WAIT_NOREPROC);
537
538         if (!(flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED |
539                        LDLM_FL_BLOCK_CONV)))
540                 goto  granted;
541
542         LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, "
543                    "sleeping");
544
545         fwd.fwd_lock = lock;
546         obd = class_exp2obd(lock->l_conn_export);
547
548         /* if this is a local lock, then there is no import */
549         if (obd != NULL)
550                 imp = obd->u.cli.cl_import;
551
552         if (imp != NULL) {
553                 spin_lock(&imp->imp_lock);
554                 fwd.fwd_generation = imp->imp_generation;
555                 spin_unlock(&imp->imp_lock);
556         }
557
558         lwi = LWI_TIMEOUT_INTR(0, NULL, ldlm_flock_interrupted_wait, &fwd);
559
560         /* Go to sleep until the lock is granted. */
561         rc = l_wait_event(lock->l_waitq,
562                           ((lock->l_req_mode == lock->l_granted_mode) ||
563                            lock->l_destroyed), &lwi);
564
565         LDLM_DEBUG(lock, "client-side enqueue waking up: rc = %d", rc);
566         RETURN(rc);
567
568 granted:
569         OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CP_CB_WAIT, 10);
570         LDLM_DEBUG(lock, "client-side enqueue granted");
571         ns = lock->l_resource->lr_namespace;
572         lock_res_and_lock(lock);
573
574         /* before flock's complete ast gets here, the flock
575          * can possibly be freed by another thread
576          */
577         if (lock->l_destroyed) {
578                 LDLM_DEBUG(lock, "already destroyed by another thread");
579                 unlock_res(lock->l_resource);
580                 RETURN(0);
581         }
582
583         /* take lock off the deadlock detection waitq. */
584         spin_lock(&ldlm_flock_waitq_lock);
585         list_del_init(&lock->l_flock_waitq);
586         spin_unlock(&ldlm_flock_waitq_lock);
587
588         /* ldlm_lock_enqueue() has already placed lock on the granted list. */
589         list_del_init(&lock->l_res_link);
590
591         if (flags & LDLM_FL_TEST_LOCK) {
592                 /* fcntl(F_GETLK) request */
593                 /* The old mode was saved in getlk->fl_type so that if the mode
594                  * in the lock changes we can decref the approprate refcount. */
595                 ldlm_flock_destroy(lock, cfs_flock_type(getlk), LDLM_FL_WAIT_NOREPROC);
596                 switch (lock->l_granted_mode) {
597                 case LCK_PR:
598                         cfs_flock_set_type(getlk, F_RDLCK);
599                         break;
600                 case LCK_PW:
601                         cfs_flock_set_type(getlk, F_WRLCK);
602                         break;
603                 default:
604                         cfs_flock_set_type(getlk, F_UNLCK);
605                 }
606                 cfs_flock_set_pid(getlk, (pid_t)lock->l_policy_data.l_flock.pid);
607                 cfs_flock_set_start(getlk, (loff_t)lock->l_policy_data.l_flock.start);
608                 cfs_flock_set_end(getlk, (loff_t)lock->l_policy_data.l_flock.end);
609         } else {
610                 int noreproc = LDLM_FL_WAIT_NOREPROC;
611
612                 /* We need to reprocess the lock to do merges or splits
613                  * with existing locks owned by this process. */
614                 ldlm_process_flock_lock(lock, &noreproc, 1, &err, NULL);
615                 if (flags == 0)
616                         cfs_waitq_signal(&lock->l_waitq);
617         }
618         unlock_res_and_lock(lock);
619         RETURN(0);
620 }
621 EXPORT_SYMBOL(ldlm_flock_completion_ast);
622
623 int ldlm_flock_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
624                             void *data, int flag)
625 {
626         struct ldlm_namespace *ns;
627         ENTRY;
628
629         LASSERT(lock);
630         LASSERT(flag == LDLM_CB_CANCELING);
631
632         ns = lock->l_resource->lr_namespace;
633
634         /* take lock off the deadlock detection waitq. */
635         spin_lock(&ldlm_flock_waitq_lock);
636         list_del_init(&lock->l_flock_waitq);
637         spin_unlock(&ldlm_flock_waitq_lock);
638         RETURN(0);
639 }