4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ldlm/ldlm_lockd.c
38 * Author: Peter Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
42 #define DEBUG_SUBSYSTEM S_LDLM
45 # include <libcfs/libcfs.h>
47 # include <liblustre.h>
50 #include <lustre_dlm.h>
51 #include <obd_class.h>
52 #include <libcfs/list.h>
53 #include "ldlm_internal.h"
55 static int ldlm_num_threads;
56 CFS_MODULE_PARM(ldlm_num_threads, "i", int, 0444,
57 "number of DLM service threads to start");
59 extern cfs_mem_cache_t *ldlm_resource_slab;
60 extern cfs_mem_cache_t *ldlm_lock_slab;
61 static cfs_mutex_t ldlm_ref_mutex;
62 static int ldlm_refcount;
64 struct ldlm_cb_async_args {
65 struct ldlm_cb_set_arg *ca_set_arg;
66 struct ldlm_lock *ca_lock;
71 static struct ldlm_state *ldlm_state;
73 inline cfs_time_t round_timeout(cfs_time_t timeout)
75 return cfs_time_seconds((int)cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1);
78 /* timeout for initial callback (AST) reply (bz10399) */
79 static inline unsigned int ldlm_get_rq_timeout(void)
82 unsigned int timeout = min(ldlm_timeout, obd_timeout / 3);
84 return timeout < 1 ? 1 : timeout;
88 /* w_l_spinlock protects both waiting_locks_list and expired_lock_thread */
89 static cfs_spinlock_t waiting_locks_spinlock; /* BH lock (timer) */
90 static cfs_list_t waiting_locks_list;
91 static cfs_timer_t waiting_locks_timer;
93 static struct expired_lock_thread {
94 cfs_waitq_t elt_waitq;
97 cfs_list_t elt_expired_locks;
98 } expired_lock_thread;
101 #define ELT_STOPPED 0
103 #define ELT_TERMINATE 2
105 struct ldlm_bl_pool {
106 cfs_spinlock_t blp_lock;
109 * blp_prio_list is used for callbacks that should be handled
110 * as a priority. It is used for LDLM_FL_DISCARD_DATA requests.
113 cfs_list_t blp_prio_list;
116 * blp_list is used for all other callbacks which are likely
117 * to take longer to process.
121 cfs_waitq_t blp_waitq;
122 cfs_completion_t blp_comp;
123 cfs_atomic_t blp_num_threads;
124 cfs_atomic_t blp_busy_threads;
129 struct ldlm_bl_work_item {
130 cfs_list_t blwi_entry;
131 struct ldlm_namespace *blwi_ns;
132 struct ldlm_lock_desc blwi_ld;
133 struct ldlm_lock *blwi_lock;
134 cfs_list_t blwi_head;
136 cfs_completion_t blwi_comp;
138 int blwi_mem_pressure;
143 static inline int have_expired_locks(void)
148 cfs_spin_lock_bh(&waiting_locks_spinlock);
149 need_to_run = !cfs_list_empty(&expired_lock_thread.elt_expired_locks);
150 cfs_spin_unlock_bh(&waiting_locks_spinlock);
155 static int expired_lock_main(void *arg)
157 cfs_list_t *expired = &expired_lock_thread.elt_expired_locks;
158 struct l_wait_info lwi = { 0 };
162 cfs_daemonize("ldlm_elt");
164 expired_lock_thread.elt_state = ELT_READY;
165 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
168 l_wait_event(expired_lock_thread.elt_waitq,
169 have_expired_locks() ||
170 expired_lock_thread.elt_state == ELT_TERMINATE,
173 cfs_spin_lock_bh(&waiting_locks_spinlock);
174 if (expired_lock_thread.elt_dump) {
175 struct libcfs_debug_msg_data msgdata = {
176 .msg_file = __FILE__,
177 .msg_fn = "waiting_locks_callback",
178 .msg_line = expired_lock_thread.elt_dump };
179 cfs_spin_unlock_bh(&waiting_locks_spinlock);
181 /* from waiting_locks_callback, but not in timer */
182 libcfs_debug_dumplog();
183 libcfs_run_lbug_upcall(&msgdata);
185 cfs_spin_lock_bh(&waiting_locks_spinlock);
186 expired_lock_thread.elt_dump = 0;
191 while (!cfs_list_empty(expired)) {
192 struct obd_export *export;
193 struct ldlm_lock *lock;
195 lock = cfs_list_entry(expired->next, struct ldlm_lock,
197 if ((void *)lock < LP_POISON + CFS_PAGE_SIZE &&
198 (void *)lock >= LP_POISON) {
199 cfs_spin_unlock_bh(&waiting_locks_spinlock);
200 CERROR("free lock on elt list %p\n", lock);
203 cfs_list_del_init(&lock->l_pending_chain);
204 if ((void *)lock->l_export < LP_POISON + CFS_PAGE_SIZE &&
205 (void *)lock->l_export >= LP_POISON) {
206 CERROR("lock with free export on elt list %p\n",
208 lock->l_export = NULL;
209 LDLM_ERROR(lock, "free export");
210 /* release extra ref grabbed by
211 * ldlm_add_waiting_lock() or
212 * ldlm_failed_ast() */
213 LDLM_LOCK_RELEASE(lock);
216 export = class_export_lock_get(lock->l_export, lock);
217 cfs_spin_unlock_bh(&waiting_locks_spinlock);
220 class_fail_export(export);
221 class_export_lock_put(export, lock);
223 /* release extra ref grabbed by ldlm_add_waiting_lock()
224 * or ldlm_failed_ast() */
225 LDLM_LOCK_RELEASE(lock);
227 cfs_spin_lock_bh(&waiting_locks_spinlock);
229 cfs_spin_unlock_bh(&waiting_locks_spinlock);
231 if (do_dump && obd_dump_on_eviction) {
232 CERROR("dump the log upon eviction\n");
233 libcfs_debug_dumplog();
236 if (expired_lock_thread.elt_state == ELT_TERMINATE)
240 expired_lock_thread.elt_state = ELT_STOPPED;
241 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
245 static int ldlm_add_waiting_lock(struct ldlm_lock *lock);
248 * Check if there is a request in the export request list
249 * which prevents the lock canceling.
251 static int ldlm_lock_busy(struct ldlm_lock *lock)
253 struct ptlrpc_request *req;
257 if (lock->l_export == NULL)
260 cfs_spin_lock_bh(&lock->l_export->exp_rpc_lock);
261 cfs_list_for_each_entry(req, &lock->l_export->exp_hp_rpcs,
263 if (req->rq_ops->hpreq_lock_match) {
264 match = req->rq_ops->hpreq_lock_match(req, lock);
269 cfs_spin_unlock_bh(&lock->l_export->exp_rpc_lock);
273 /* This is called from within a timer interrupt and cannot schedule */
274 static void waiting_locks_callback(unsigned long unused)
276 struct ldlm_lock *lock;
279 cfs_spin_lock_bh(&waiting_locks_spinlock);
280 while (!cfs_list_empty(&waiting_locks_list)) {
281 lock = cfs_list_entry(waiting_locks_list.next, struct ldlm_lock,
283 if (cfs_time_after(lock->l_callback_timeout,
284 cfs_time_current()) ||
285 (lock->l_req_mode == LCK_GROUP))
288 if (ptlrpc_check_suspend()) {
289 /* there is a case when we talk to one mds, holding
290 * lock from another mds. this way we easily can get
291 * here, if second mds is being recovered. so, we
292 * suspend timeouts. bug 6019 */
294 LDLM_ERROR(lock, "recharge timeout: %s@%s nid %s ",
295 lock->l_export->exp_client_uuid.uuid,
296 lock->l_export->exp_connection->c_remote_uuid.uuid,
297 libcfs_nid2str(lock->l_export->exp_connection->c_peer.nid));
299 cfs_list_del_init(&lock->l_pending_chain);
300 cfs_spin_unlock_bh(&waiting_locks_spinlock);
301 ldlm_add_waiting_lock(lock);
305 /* if timeout overlaps the activation time of suspended timeouts
306 * then extend it to give a chance for client to reconnect */
307 if (cfs_time_before(cfs_time_sub(lock->l_callback_timeout,
308 cfs_time_seconds(obd_timeout)/2),
309 ptlrpc_suspend_wakeup_time())) {
310 LDLM_ERROR(lock, "extend timeout due to recovery: %s@%s nid %s ",
311 lock->l_export->exp_client_uuid.uuid,
312 lock->l_export->exp_connection->c_remote_uuid.uuid,
313 libcfs_nid2str(lock->l_export->exp_connection->c_peer.nid));
315 cfs_list_del_init(&lock->l_pending_chain);
316 cfs_spin_unlock_bh(&waiting_locks_spinlock);
317 ldlm_add_waiting_lock(lock);
321 /* Check if we need to prolong timeout */
322 if (!OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT) &&
323 ldlm_lock_busy(lock)) {
326 if (lock->l_pending_chain.next == &waiting_locks_list)
331 cfs_spin_unlock_bh(&waiting_locks_spinlock);
332 LDLM_DEBUG(lock, "prolong the busy lock");
333 ldlm_refresh_waiting_lock(lock,
334 ldlm_get_enq_timeout(lock));
335 cfs_spin_lock_bh(&waiting_locks_spinlock);
338 LDLM_LOCK_RELEASE(lock);
342 LDLM_LOCK_RELEASE(lock);
345 ldlm_lock_to_ns(lock)->ns_timeouts++;
346 LDLM_ERROR(lock, "lock callback timer expired after %lds: "
347 "evicting client at %s ",
348 cfs_time_current_sec()- lock->l_last_activity,
350 lock->l_export->exp_connection->c_peer.nid));
352 /* no needs to take an extra ref on the lock since it was in
353 * the waiting_locks_list and ldlm_add_waiting_lock()
354 * already grabbed a ref */
355 cfs_list_del(&lock->l_pending_chain);
356 cfs_list_add(&lock->l_pending_chain,
357 &expired_lock_thread.elt_expired_locks);
360 if (!cfs_list_empty(&expired_lock_thread.elt_expired_locks)) {
361 if (obd_dump_on_timeout)
362 expired_lock_thread.elt_dump = __LINE__;
364 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
368 * Make sure the timer will fire again if we have any locks
371 if (!cfs_list_empty(&waiting_locks_list)) {
372 cfs_time_t timeout_rounded;
373 lock = cfs_list_entry(waiting_locks_list.next, struct ldlm_lock,
375 timeout_rounded = (cfs_time_t)round_timeout(lock->l_callback_timeout);
376 cfs_timer_arm(&waiting_locks_timer, timeout_rounded);
378 cfs_spin_unlock_bh(&waiting_locks_spinlock);
382 * Indicate that we're waiting for a client to call us back cancelling a given
383 * lock. We add it to the pending-callback chain, and schedule the lock-timeout
384 * timer to fire appropriately. (We round up to the next second, to avoid
385 * floods of timer firings during periods of high lock contention and traffic).
386 * As done by ldlm_add_waiting_lock(), the caller must grab a lock reference
387 * if it has been added to the waiting list (1 is returned).
389 * Called with the namespace lock held.
391 static int __ldlm_add_waiting_lock(struct ldlm_lock *lock, int seconds)
394 cfs_time_t timeout_rounded;
396 if (!cfs_list_empty(&lock->l_pending_chain))
399 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT) ||
400 OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT))
403 timeout = cfs_time_shift(seconds);
404 if (likely(cfs_time_after(timeout, lock->l_callback_timeout)))
405 lock->l_callback_timeout = timeout;
407 timeout_rounded = round_timeout(lock->l_callback_timeout);
409 if (cfs_time_before(timeout_rounded,
410 cfs_timer_deadline(&waiting_locks_timer)) ||
411 !cfs_timer_is_armed(&waiting_locks_timer)) {
412 cfs_timer_arm(&waiting_locks_timer, timeout_rounded);
414 /* if the new lock has a shorter timeout than something earlier on
415 the list, we'll wait the longer amount of time; no big deal. */
417 cfs_list_add_tail(&lock->l_pending_chain, &waiting_locks_list);
421 static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
424 int timeout = ldlm_get_enq_timeout(lock);
426 LASSERT(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK));
428 cfs_spin_lock_bh(&waiting_locks_spinlock);
429 if (lock->l_destroyed) {
430 static cfs_time_t next;
431 cfs_spin_unlock_bh(&waiting_locks_spinlock);
432 LDLM_ERROR(lock, "not waiting on destroyed lock (bug 5653)");
433 if (cfs_time_after(cfs_time_current(), next)) {
434 next = cfs_time_shift(14400);
435 libcfs_debug_dumpstack(NULL);
440 ret = __ldlm_add_waiting_lock(lock, timeout);
442 /* grab ref on the lock if it has been added to the
446 cfs_spin_unlock_bh(&waiting_locks_spinlock);
449 cfs_spin_lock_bh(&lock->l_export->exp_bl_list_lock);
450 if (cfs_list_empty(&lock->l_exp_list))
451 cfs_list_add(&lock->l_exp_list,
452 &lock->l_export->exp_bl_list);
453 cfs_spin_unlock_bh(&lock->l_export->exp_bl_list_lock);
456 LDLM_DEBUG(lock, "%sadding to wait list(timeout: %d, AT: %s)",
457 ret == 0 ? "not re-" : "", timeout,
458 AT_OFF ? "off" : "on");
463 * Remove a lock from the pending list, likely because it had its cancellation
464 * callback arrive without incident. This adjusts the lock-timeout timer if
465 * needed. Returns 0 if the lock wasn't pending after all, 1 if it was.
466 * As done by ldlm_del_waiting_lock(), the caller must release the lock
467 * reference when the lock is removed from any list (1 is returned).
469 * Called with namespace lock held.
471 static int __ldlm_del_waiting_lock(struct ldlm_lock *lock)
473 cfs_list_t *list_next;
475 if (cfs_list_empty(&lock->l_pending_chain))
478 list_next = lock->l_pending_chain.next;
479 if (lock->l_pending_chain.prev == &waiting_locks_list) {
480 /* Removing the head of the list, adjust timer. */
481 if (list_next == &waiting_locks_list) {
482 /* No more, just cancel. */
483 cfs_timer_disarm(&waiting_locks_timer);
485 struct ldlm_lock *next;
486 next = cfs_list_entry(list_next, struct ldlm_lock,
488 cfs_timer_arm(&waiting_locks_timer,
489 round_timeout(next->l_callback_timeout));
492 cfs_list_del_init(&lock->l_pending_chain);
497 int ldlm_del_waiting_lock(struct ldlm_lock *lock)
501 if (lock->l_export == NULL) {
502 /* We don't have a "waiting locks list" on clients. */
503 CDEBUG(D_DLMTRACE, "Client lock %p : no-op\n", lock);
507 cfs_spin_lock_bh(&waiting_locks_spinlock);
508 ret = __ldlm_del_waiting_lock(lock);
509 cfs_spin_unlock_bh(&waiting_locks_spinlock);
511 /* remove the lock out of export blocking list */
512 cfs_spin_lock_bh(&lock->l_export->exp_bl_list_lock);
513 cfs_list_del_init(&lock->l_exp_list);
514 cfs_spin_unlock_bh(&lock->l_export->exp_bl_list_lock);
517 /* release lock ref if it has indeed been removed
519 LDLM_LOCK_RELEASE(lock);
522 LDLM_DEBUG(lock, "%s", ret == 0 ? "wasn't waiting" : "removed");
529 * Called with namespace lock held.
531 int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout)
533 if (lock->l_export == NULL) {
534 /* We don't have a "waiting locks list" on clients. */
535 LDLM_DEBUG(lock, "client lock: no-op");
539 cfs_spin_lock_bh(&waiting_locks_spinlock);
541 if (cfs_list_empty(&lock->l_pending_chain)) {
542 cfs_spin_unlock_bh(&waiting_locks_spinlock);
543 LDLM_DEBUG(lock, "wasn't waiting");
547 /* we remove/add the lock to the waiting list, so no needs to
548 * release/take a lock reference */
549 __ldlm_del_waiting_lock(lock);
550 __ldlm_add_waiting_lock(lock, timeout);
551 cfs_spin_unlock_bh(&waiting_locks_spinlock);
553 LDLM_DEBUG(lock, "refreshed");
556 #else /* !__KERNEL__ */
558 int ldlm_del_waiting_lock(struct ldlm_lock *lock)
563 int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout)
567 #endif /* __KERNEL__ */
569 #ifdef HAVE_SERVER_SUPPORT
571 static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
573 LASSERT(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK));
578 static void ldlm_failed_ast(struct ldlm_lock *lock, int rc,
579 const char *ast_type)
581 LCONSOLE_ERROR_MSG(0x138, "%s: A client on nid %s was evicted due "
582 "to a lock %s callback time out: rc %d\n",
583 lock->l_export->exp_obd->obd_name,
584 obd_export_nid2str(lock->l_export), ast_type, rc);
586 if (obd_dump_on_timeout)
587 libcfs_debug_dumplog();
589 cfs_spin_lock_bh(&waiting_locks_spinlock);
590 if (__ldlm_del_waiting_lock(lock) == 0)
591 /* the lock was not in any list, grab an extra ref before adding
592 * the lock to the expired list */
594 cfs_list_add(&lock->l_pending_chain,
595 &expired_lock_thread.elt_expired_locks);
596 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
597 cfs_spin_unlock_bh(&waiting_locks_spinlock);
599 class_fail_export(lock->l_export);
603 static int ldlm_handle_ast_error(struct ldlm_lock *lock,
604 struct ptlrpc_request *req, int rc,
605 const char *ast_type)
607 lnet_process_id_t peer = req->rq_import->imp_connection->c_peer;
609 if (rc == -ETIMEDOUT || rc == -EINTR || rc == -ENOTCONN) {
610 LASSERT(lock->l_export);
611 if (lock->l_export->exp_libclient) {
612 LDLM_DEBUG(lock, "%s AST to liblustre client (nid %s)"
613 " timeout, just cancelling lock", ast_type,
614 libcfs_nid2str(peer.nid));
615 ldlm_lock_cancel(lock);
617 } else if (lock->l_flags & LDLM_FL_CANCEL) {
618 LDLM_DEBUG(lock, "%s AST timeout from nid %s, but "
619 "cancel was received (AST reply lost?)",
620 ast_type, libcfs_nid2str(peer.nid));
621 ldlm_lock_cancel(lock);
624 ldlm_del_waiting_lock(lock);
625 ldlm_failed_ast(lock, rc, ast_type);
629 struct ldlm_resource *res = lock->l_resource;
630 LDLM_DEBUG(lock, "client (nid %s) returned %d"
631 " from %s AST - normal race",
632 libcfs_nid2str(peer.nid),
634 lustre_msg_get_status(req->rq_repmsg) : -1,
637 /* update lvbo to return proper attributes.
639 ldlm_resource_getref(res);
640 ldlm_res_lvbo_update(res, NULL, 1);
641 ldlm_resource_putref(res);
645 LDLM_ERROR(lock, "client (nid %s) returned %d "
646 "from %s AST", libcfs_nid2str(peer.nid),
647 (req->rq_repmsg != NULL) ?
648 lustre_msg_get_status(req->rq_repmsg) : 0,
651 ldlm_lock_cancel(lock);
652 /* Server-side AST functions are called from ldlm_reprocess_all,
653 * which needs to be told to please restart its reprocessing. */
660 static int ldlm_cb_interpret(const struct lu_env *env,
661 struct ptlrpc_request *req, void *data, int rc)
663 struct ldlm_cb_async_args *ca = data;
664 struct ldlm_lock *lock = ca->ca_lock;
665 struct ldlm_cb_set_arg *arg = ca->ca_set_arg;
668 LASSERT(lock != NULL);
670 rc = ldlm_handle_ast_error(lock, req, rc,
671 arg->type == LDLM_BL_CALLBACK
672 ? "blocking" : "completion");
674 cfs_atomic_inc(&arg->restart);
676 LDLM_LOCK_RELEASE(lock);
681 static inline int ldlm_bl_and_cp_ast_tail(struct ptlrpc_request *req,
682 struct ldlm_cb_set_arg *arg,
683 struct ldlm_lock *lock,
689 if (unlikely(instant_cancel)) {
690 rc = ptl_send_rpc(req, 1);
691 ptlrpc_req_finished(req);
693 cfs_atomic_inc(&arg->restart);
696 ptlrpc_set_add_req(arg->set, req);
703 * Check if there are requests in the export request list which prevent
704 * the lock canceling and make these requests high priority ones.
706 static void ldlm_lock_reorder_req(struct ldlm_lock *lock)
708 struct ptlrpc_request *req;
711 if (lock->l_export == NULL) {
712 LDLM_DEBUG(lock, "client lock: no-op");
716 cfs_spin_lock_bh(&lock->l_export->exp_rpc_lock);
717 cfs_list_for_each_entry(req, &lock->l_export->exp_hp_rpcs,
719 /* Do not process requests that were not yet added to there
720 * incoming queue or were already removed from there for
722 if (!req->rq_hp && !cfs_list_empty(&req->rq_list) &&
723 req->rq_ops->hpreq_lock_match &&
724 req->rq_ops->hpreq_lock_match(req, lock))
725 ptlrpc_hpreq_reorder(req);
727 cfs_spin_unlock_bh(&lock->l_export->exp_rpc_lock);
732 * ->l_blocking_ast() method for server-side locks. This is invoked when newly
733 * enqueued server lock conflicts with given one.
735 * Sends blocking ast rpc to the client owning that lock; arms timeout timer
736 * to wait for client response.
738 int ldlm_server_blocking_ast(struct ldlm_lock *lock,
739 struct ldlm_lock_desc *desc,
740 void *data, int flag)
742 struct ldlm_cb_async_args *ca;
743 struct ldlm_cb_set_arg *arg = data;
744 struct ldlm_request *body;
745 struct ptlrpc_request *req;
746 int instant_cancel = 0;
750 if (flag == LDLM_CB_CANCELING)
751 /* Don't need to do anything here. */
755 LASSERT(data != NULL);
756 if (lock->l_export->exp_obd->obd_recovering != 0)
757 LDLM_ERROR(lock, "BUG 6063: lock collide during recovery");
759 ldlm_lock_reorder_req(lock);
761 req = ptlrpc_request_alloc_pack(lock->l_export->exp_imp_reverse,
762 &RQF_LDLM_BL_CALLBACK,
763 LUSTRE_DLM_VERSION, LDLM_BL_CALLBACK);
767 CLASSERT(sizeof(*ca) <= sizeof(req->rq_async_args));
768 ca = ptlrpc_req_async_args(req);
769 ca->ca_set_arg = arg;
772 req->rq_interpret_reply = ldlm_cb_interpret;
773 req->rq_no_resend = 1;
775 lock_res(lock->l_resource);
776 if (lock->l_granted_mode != lock->l_req_mode) {
777 /* this blocking AST will be communicated as part of the
778 * completion AST instead */
779 unlock_res(lock->l_resource);
780 ptlrpc_req_finished(req);
781 LDLM_DEBUG(lock, "lock not granted, not sending blocking AST");
785 if (lock->l_destroyed) {
786 /* What's the point? */
787 unlock_res(lock->l_resource);
788 ptlrpc_req_finished(req);
792 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)
795 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
796 body->lock_handle[0] = lock->l_remote_handle;
797 body->lock_desc = *desc;
798 body->lock_flags |= (lock->l_flags & LDLM_AST_FLAGS);
800 LDLM_DEBUG(lock, "server preparing blocking AST");
802 ptlrpc_request_set_replen(req);
803 if (instant_cancel) {
804 unlock_res(lock->l_resource);
805 ldlm_lock_cancel(lock);
807 LASSERT(lock->l_granted_mode == lock->l_req_mode);
808 ldlm_add_waiting_lock(lock);
809 unlock_res(lock->l_resource);
812 req->rq_send_state = LUSTRE_IMP_FULL;
813 /* ptlrpc_request_alloc_pack already set timeout */
815 req->rq_timeout = ldlm_get_rq_timeout();
817 if (lock->l_export && lock->l_export->exp_nid_stats &&
818 lock->l_export->exp_nid_stats->nid_ldlm_stats)
819 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
820 LDLM_BL_CALLBACK - LDLM_FIRST_OPC);
822 rc = ldlm_bl_and_cp_ast_tail(req, arg, lock, instant_cancel);
827 int ldlm_server_completion_ast(struct ldlm_lock *lock, int flags, void *data)
829 struct ldlm_cb_set_arg *arg = data;
830 struct ldlm_request *body;
831 struct ptlrpc_request *req;
832 struct ldlm_cb_async_args *ca;
833 long total_enqueue_wait;
834 int instant_cancel = 0;
838 LASSERT(lock != NULL);
839 LASSERT(data != NULL);
841 total_enqueue_wait = cfs_time_sub(cfs_time_current_sec(),
842 lock->l_last_activity);
844 req = ptlrpc_request_alloc(lock->l_export->exp_imp_reverse,
845 &RQF_LDLM_CP_CALLBACK);
849 /* server namespace, doesn't need lock */
850 if (lock->l_resource->lr_lvb_len) {
851 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_CLIENT,
852 lock->l_resource->lr_lvb_len);
855 rc = ptlrpc_request_pack(req, LUSTRE_DLM_VERSION, LDLM_CP_CALLBACK);
857 ptlrpc_request_free(req);
861 CLASSERT(sizeof(*ca) <= sizeof(req->rq_async_args));
862 ca = ptlrpc_req_async_args(req);
863 ca->ca_set_arg = arg;
866 req->rq_interpret_reply = ldlm_cb_interpret;
867 req->rq_no_resend = 1;
868 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
870 body->lock_handle[0] = lock->l_remote_handle;
871 body->lock_flags = flags;
872 ldlm_lock2desc(lock, &body->lock_desc);
873 if (lock->l_resource->lr_lvb_len) {
874 void *lvb = req_capsule_client_get(&req->rq_pill, &RMF_DLM_LVB);
876 lock_res(lock->l_resource);
877 memcpy(lvb, lock->l_resource->lr_lvb_data,
878 lock->l_resource->lr_lvb_len);
879 unlock_res(lock->l_resource);
882 LDLM_DEBUG(lock, "server preparing completion AST (after %lds wait)",
885 /* Server-side enqueue wait time estimate, used in
886 __ldlm_add_waiting_lock to set future enqueue timers */
887 if (total_enqueue_wait < ldlm_get_enq_timeout(lock))
888 at_measured(ldlm_lock_to_ns_at(lock),
891 /* bz18618. Don't add lock enqueue time we spend waiting for a
892 previous callback to fail. Locks waiting legitimately will
893 get extended by ldlm_refresh_waiting_lock regardless of the
894 estimate, so it's okay to underestimate here. */
895 LDLM_DEBUG(lock, "lock completed after %lus; estimate was %ds. "
896 "It is likely that a previous callback timed out.",
898 at_get(ldlm_lock_to_ns_at(lock)));
900 ptlrpc_request_set_replen(req);
902 req->rq_send_state = LUSTRE_IMP_FULL;
903 /* ptlrpc_request_pack already set timeout */
905 req->rq_timeout = ldlm_get_rq_timeout();
907 /* We only send real blocking ASTs after the lock is granted */
908 lock_res_and_lock(lock);
909 if (lock->l_flags & LDLM_FL_AST_SENT) {
910 body->lock_flags |= LDLM_FL_AST_SENT;
911 /* copy ast flags like LDLM_FL_DISCARD_DATA */
912 body->lock_flags |= (lock->l_flags & LDLM_AST_FLAGS);
914 /* We might get here prior to ldlm_handle_enqueue setting
915 * LDLM_FL_CANCEL_ON_BLOCK flag. Then we will put this lock
916 * into waiting list, but this is safe and similar code in
917 * ldlm_handle_enqueue will call ldlm_lock_cancel() still,
918 * that would not only cancel the lock, but will also remove
919 * it from waiting list */
920 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK) {
921 unlock_res_and_lock(lock);
922 ldlm_lock_cancel(lock);
924 lock_res_and_lock(lock);
926 /* start the lock-timeout clock */
927 ldlm_add_waiting_lock(lock);
930 unlock_res_and_lock(lock);
932 if (lock->l_export && lock->l_export->exp_nid_stats &&
933 lock->l_export->exp_nid_stats->nid_ldlm_stats)
934 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
935 LDLM_CP_CALLBACK - LDLM_FIRST_OPC);
937 rc = ldlm_bl_and_cp_ast_tail(req, arg, lock, instant_cancel);
942 int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data)
944 struct ldlm_resource *res = lock->l_resource;
945 struct ldlm_request *body;
946 struct ptlrpc_request *req;
950 LASSERT(lock != NULL);
952 req = ptlrpc_request_alloc_pack(lock->l_export->exp_imp_reverse,
953 &RQF_LDLM_GL_CALLBACK,
954 LUSTRE_DLM_VERSION, LDLM_GL_CALLBACK);
959 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
960 body->lock_handle[0] = lock->l_remote_handle;
961 ldlm_lock2desc(lock, &body->lock_desc);
963 /* server namespace, doesn't need lock */
964 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER,
965 lock->l_resource->lr_lvb_len);
966 res = lock->l_resource;
967 ptlrpc_request_set_replen(req);
970 req->rq_send_state = LUSTRE_IMP_FULL;
971 /* ptlrpc_request_alloc_pack already set timeout */
973 req->rq_timeout = ldlm_get_rq_timeout();
975 if (lock->l_export && lock->l_export->exp_nid_stats &&
976 lock->l_export->exp_nid_stats->nid_ldlm_stats)
977 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
978 LDLM_GL_CALLBACK - LDLM_FIRST_OPC);
980 rc = ptlrpc_queue_wait(req);
981 /* Update the LVB from disk if the AST failed (this is a legal race)
983 * - Glimpse callback of local lock just return -ELDLM_NO_LOCK_DATA.
984 * - Glimpse callback of remote lock might return -ELDLM_NO_LOCK_DATA
985 * when inode is cleared. LU-274
987 if (rc == -ELDLM_NO_LOCK_DATA) {
988 LDLM_DEBUG(lock, "lost race - client has a lock but no inode");
989 ldlm_res_lvbo_update(res, NULL, 1);
990 } else if (rc != 0) {
991 rc = ldlm_handle_ast_error(lock, req, rc, "glimpse");
993 rc = ldlm_res_lvbo_update(res, req, 1);
996 ptlrpc_req_finished(req);
998 ldlm_reprocess_all(res);
1003 static void ldlm_svc_get_eopc(const struct ldlm_request *dlm_req,
1004 struct lprocfs_stats *srv_stats)
1006 int lock_type = 0, op = 0;
1008 lock_type = dlm_req->lock_desc.l_resource.lr_type;
1010 switch (lock_type) {
1012 op = PTLRPC_LAST_CNTR + LDLM_PLAIN_ENQUEUE;
1015 if (dlm_req->lock_flags & LDLM_FL_HAS_INTENT)
1016 op = PTLRPC_LAST_CNTR + LDLM_GLIMPSE_ENQUEUE;
1018 op = PTLRPC_LAST_CNTR + LDLM_EXTENT_ENQUEUE;
1021 op = PTLRPC_LAST_CNTR + LDLM_FLOCK_ENQUEUE;
1024 op = PTLRPC_LAST_CNTR + LDLM_IBITS_ENQUEUE;
1032 lprocfs_counter_incr(srv_stats, op);
1038 * Main server-side entry point into LDLM. This is called by ptlrpc service
1039 * threads to carry out client lock enqueueing requests.
1041 int ldlm_handle_enqueue0(struct ldlm_namespace *ns,
1042 struct ptlrpc_request *req,
1043 const struct ldlm_request *dlm_req,
1044 const struct ldlm_callback_suite *cbs)
1046 struct ldlm_reply *dlm_rep;
1048 ldlm_error_t err = ELDLM_OK;
1049 struct ldlm_lock *lock = NULL;
1050 void *cookie = NULL;
1054 LDLM_DEBUG_NOLOCK("server-side enqueue handler START");
1056 ldlm_request_cancel(req, dlm_req, LDLM_ENQUEUE_CANCEL_OFF);
1057 flags = dlm_req->lock_flags;
1059 LASSERT(req->rq_export);
1061 if (ptlrpc_req2svc(req)->srv_stats != NULL)
1062 ldlm_svc_get_eopc(dlm_req, ptlrpc_req2svc(req)->srv_stats);
1064 if (req->rq_export && req->rq_export->exp_nid_stats &&
1065 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1066 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1067 LDLM_ENQUEUE - LDLM_FIRST_OPC);
1069 if (unlikely(dlm_req->lock_desc.l_resource.lr_type < LDLM_MIN_TYPE ||
1070 dlm_req->lock_desc.l_resource.lr_type >= LDLM_MAX_TYPE)) {
1071 DEBUG_REQ(D_ERROR, req, "invalid lock request type %d",
1072 dlm_req->lock_desc.l_resource.lr_type);
1073 GOTO(out, rc = -EFAULT);
1076 if (unlikely(dlm_req->lock_desc.l_req_mode <= LCK_MINMODE ||
1077 dlm_req->lock_desc.l_req_mode >= LCK_MAXMODE ||
1078 dlm_req->lock_desc.l_req_mode &
1079 (dlm_req->lock_desc.l_req_mode-1))) {
1080 DEBUG_REQ(D_ERROR, req, "invalid lock request mode %d",
1081 dlm_req->lock_desc.l_req_mode);
1082 GOTO(out, rc = -EFAULT);
1085 if (req->rq_export->exp_connect_flags & OBD_CONNECT_IBITS) {
1086 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
1088 DEBUG_REQ(D_ERROR, req,
1089 "PLAIN lock request from IBITS client?");
1090 GOTO(out, rc = -EPROTO);
1092 } else if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
1094 DEBUG_REQ(D_ERROR, req,
1095 "IBITS lock request from unaware client?");
1096 GOTO(out, rc = -EPROTO);
1100 /* FIXME this makes it impossible to use LDLM_PLAIN locks -- check
1101 against server's _CONNECT_SUPPORTED flags? (I don't want to use
1102 ibits for mgc/mgs) */
1104 /* INODEBITS_INTEROP: Perform conversion from plain lock to
1105 * inodebits lock if client does not support them. */
1106 if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_IBITS) &&
1107 (dlm_req->lock_desc.l_resource.lr_type == LDLM_PLAIN)) {
1108 dlm_req->lock_desc.l_resource.lr_type = LDLM_IBITS;
1109 dlm_req->lock_desc.l_policy_data.l_inodebits.bits =
1110 MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
1111 if (dlm_req->lock_desc.l_req_mode == LCK_PR)
1112 dlm_req->lock_desc.l_req_mode = LCK_CR;
1116 if (unlikely(flags & LDLM_FL_REPLAY)) {
1117 /* Find an existing lock in the per-export lock hash */
1118 lock = cfs_hash_lookup(req->rq_export->exp_lock_hash,
1119 (void *)&dlm_req->lock_handle[0]);
1121 DEBUG_REQ(D_DLMTRACE, req, "found existing lock cookie "
1122 LPX64, lock->l_handle.h_cookie);
1123 GOTO(existing_lock, rc = 0);
1127 /* The lock's callback data might be set in the policy function */
1128 lock = ldlm_lock_create(ns, &dlm_req->lock_desc.l_resource.lr_name,
1129 dlm_req->lock_desc.l_resource.lr_type,
1130 dlm_req->lock_desc.l_req_mode,
1134 GOTO(out, rc = -ENOMEM);
1136 lock->l_last_activity = cfs_time_current_sec();
1137 lock->l_remote_handle = dlm_req->lock_handle[0];
1138 LDLM_DEBUG(lock, "server-side enqueue handler, new lock created");
1140 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_ENQUEUE_BLOCKED, obd_timeout * 2);
1141 /* Don't enqueue a lock onto the export if it is been disonnected
1142 * due to eviction (bug 3822) or server umount (bug 24324).
1143 * Cancel it now instead. */
1144 if (req->rq_export->exp_disconnected) {
1145 LDLM_ERROR(lock, "lock on disconnected export %p",
1147 GOTO(out, rc = -ENOTCONN);
1150 lock->l_export = class_export_lock_get(req->rq_export, lock);
1151 if (lock->l_export->exp_lock_hash)
1152 cfs_hash_add(lock->l_export->exp_lock_hash,
1153 &lock->l_remote_handle,
1158 if (flags & LDLM_FL_HAS_INTENT) {
1159 /* In this case, the reply buffer is allocated deep in
1160 * local_lock_enqueue by the policy function. */
1163 /* based on the assumption that lvb size never changes during
1164 * resource life time otherwise it need resource->lr_lock's
1166 if (lock->l_resource->lr_lvb_len) {
1167 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB,
1169 lock->l_resource->lr_lvb_len);
1172 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR))
1173 GOTO(out, rc = -ENOMEM);
1175 rc = req_capsule_server_pack(&req->rq_pill);
1180 if (dlm_req->lock_desc.l_resource.lr_type != LDLM_PLAIN)
1181 ldlm_convert_policy_to_local(req->rq_export,
1182 dlm_req->lock_desc.l_resource.lr_type,
1183 &dlm_req->lock_desc.l_policy_data,
1184 &lock->l_policy_data);
1185 if (dlm_req->lock_desc.l_resource.lr_type == LDLM_EXTENT)
1186 lock->l_req_extent = lock->l_policy_data.l_extent;
1188 err = ldlm_lock_enqueue(ns, &lock, cookie, (int *)&flags);
1192 dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
1193 dlm_rep->lock_flags = flags;
1195 ldlm_lock2desc(lock, &dlm_rep->lock_desc);
1196 ldlm_lock2handle(lock, &dlm_rep->lock_handle);
1198 /* We never send a blocking AST until the lock is granted, but
1199 * we can tell it right now */
1200 lock_res_and_lock(lock);
1202 /* Now take into account flags to be inherited from original lock
1203 request both in reply to client and in our own lock flags. */
1204 dlm_rep->lock_flags |= dlm_req->lock_flags & LDLM_INHERIT_FLAGS;
1205 lock->l_flags |= dlm_req->lock_flags & LDLM_INHERIT_FLAGS;
1207 /* Don't move a pending lock onto the export if it has already been
1208 * disconnected due to eviction (bug 5683) or server umount (bug 24324).
1209 * Cancel it now instead. */
1210 if (unlikely(req->rq_export->exp_disconnected ||
1211 OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT))) {
1212 LDLM_ERROR(lock, "lock on destroyed export %p", req->rq_export);
1214 } else if (lock->l_flags & LDLM_FL_AST_SENT) {
1215 dlm_rep->lock_flags |= LDLM_FL_AST_SENT;
1216 if (lock->l_granted_mode == lock->l_req_mode) {
1218 * Only cancel lock if it was granted, because it would
1219 * be destroyed immediately and would never be granted
1220 * in the future, causing timeouts on client. Not
1221 * granted lock will be cancelled immediately after
1222 * sending completion AST.
1224 if (dlm_rep->lock_flags & LDLM_FL_CANCEL_ON_BLOCK) {
1225 unlock_res_and_lock(lock);
1226 ldlm_lock_cancel(lock);
1227 lock_res_and_lock(lock);
1229 ldlm_add_waiting_lock(lock);
1232 /* Make sure we never ever grant usual metadata locks to liblustre
1234 if ((dlm_req->lock_desc.l_resource.lr_type == LDLM_PLAIN ||
1235 dlm_req->lock_desc.l_resource.lr_type == LDLM_IBITS) &&
1236 req->rq_export->exp_libclient) {
1237 if (unlikely(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK) ||
1238 !(dlm_rep->lock_flags & LDLM_FL_CANCEL_ON_BLOCK))){
1239 CERROR("Granting sync lock to libclient. "
1240 "req fl %d, rep fl %d, lock fl "LPX64"\n",
1241 dlm_req->lock_flags, dlm_rep->lock_flags,
1243 LDLM_ERROR(lock, "sync lock");
1244 if (dlm_req->lock_flags & LDLM_FL_HAS_INTENT) {
1245 struct ldlm_intent *it;
1247 it = req_capsule_client_get(&req->rq_pill,
1250 CERROR("This is intent %s ("LPU64")\n",
1251 ldlm_it2str(it->opc), it->opc);
1257 unlock_res_and_lock(lock);
1261 req->rq_status = rc ?: err; /* return either error - bug 11190 */
1262 if (!req->rq_packed_final) {
1263 err = lustre_pack_reply(req, 1, NULL, NULL);
1268 /* The LOCK_CHANGED code in ldlm_lock_enqueue depends on this
1269 * ldlm_reprocess_all. If this moves, revisit that code. -phil */
1271 LDLM_DEBUG(lock, "server-side enqueue handler, sending reply"
1272 "(err=%d, rc=%d)", err, rc);
1275 if (lock->l_resource->lr_lvb_len > 0) {
1276 /* MDT path won't handle lr_lvb_data, so
1277 * lock/unlock better be contained in the
1281 lvb = req_capsule_server_get(&req->rq_pill,
1283 LASSERTF(lvb != NULL, "req %p, lock %p\n",
1285 lock_res(lock->l_resource);
1286 memcpy(lvb, lock->l_resource->lr_lvb_data,
1287 lock->l_resource->lr_lvb_len);
1288 unlock_res(lock->l_resource);
1291 lock_res_and_lock(lock);
1292 ldlm_resource_unlink_lock(lock);
1293 ldlm_lock_destroy_nolock(lock);
1294 unlock_res_and_lock(lock);
1297 if (!err && dlm_req->lock_desc.l_resource.lr_type != LDLM_FLOCK)
1298 ldlm_reprocess_all(lock->l_resource);
1300 LDLM_LOCK_RELEASE(lock);
1303 LDLM_DEBUG_NOLOCK("server-side enqueue handler END (lock %p, rc %d)",
1309 int ldlm_handle_enqueue(struct ptlrpc_request *req,
1310 ldlm_completion_callback completion_callback,
1311 ldlm_blocking_callback blocking_callback,
1312 ldlm_glimpse_callback glimpse_callback)
1314 struct ldlm_request *dlm_req;
1315 struct ldlm_callback_suite cbs = {
1316 .lcs_completion = completion_callback,
1317 .lcs_blocking = blocking_callback,
1318 .lcs_glimpse = glimpse_callback
1322 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1323 if (dlm_req != NULL) {
1324 rc = ldlm_handle_enqueue0(req->rq_export->exp_obd->obd_namespace,
1325 req, dlm_req, &cbs);
1332 int ldlm_handle_convert0(struct ptlrpc_request *req,
1333 const struct ldlm_request *dlm_req)
1335 struct ldlm_reply *dlm_rep;
1336 struct ldlm_lock *lock;
1340 if (req->rq_export && req->rq_export->exp_nid_stats &&
1341 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1342 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1343 LDLM_CONVERT - LDLM_FIRST_OPC);
1345 rc = req_capsule_server_pack(&req->rq_pill);
1349 dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
1350 dlm_rep->lock_flags = dlm_req->lock_flags;
1352 lock = ldlm_handle2lock(&dlm_req->lock_handle[0]);
1354 req->rq_status = EINVAL;
1358 LDLM_DEBUG(lock, "server-side convert handler START");
1360 lock->l_last_activity = cfs_time_current_sec();
1361 res = ldlm_lock_convert(lock, dlm_req->lock_desc.l_req_mode,
1362 &dlm_rep->lock_flags);
1364 if (ldlm_del_waiting_lock(lock))
1365 LDLM_DEBUG(lock, "converted waiting lock");
1368 req->rq_status = EDEADLOCK;
1373 if (!req->rq_status)
1374 ldlm_reprocess_all(lock->l_resource);
1375 LDLM_DEBUG(lock, "server-side convert handler END");
1376 LDLM_LOCK_PUT(lock);
1378 LDLM_DEBUG_NOLOCK("server-side convert handler END");
1383 int ldlm_handle_convert(struct ptlrpc_request *req)
1386 struct ldlm_request *dlm_req;
1388 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1389 if (dlm_req != NULL) {
1390 rc = ldlm_handle_convert0(req, dlm_req);
1392 CERROR ("Can't unpack dlm_req\n");
1398 /* Cancel all the locks whos handles are packed into ldlm_request */
1399 int ldlm_request_cancel(struct ptlrpc_request *req,
1400 const struct ldlm_request *dlm_req, int first)
1402 struct ldlm_resource *res, *pres = NULL;
1403 struct ldlm_lock *lock;
1404 int i, count, done = 0;
1407 count = dlm_req->lock_count ? dlm_req->lock_count : 1;
1411 /* There is no lock on the server at the replay time,
1412 * skip lock cancelling to make replay tests to pass. */
1413 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1416 LDLM_DEBUG_NOLOCK("server-side cancel handler START: %d locks, "
1417 "starting at %d", count, first);
1419 for (i = first; i < count; i++) {
1420 lock = ldlm_handle2lock(&dlm_req->lock_handle[i]);
1422 LDLM_DEBUG_NOLOCK("server-side cancel handler stale "
1423 "lock (cookie "LPU64")",
1424 dlm_req->lock_handle[i].cookie);
1428 res = lock->l_resource;
1433 ldlm_reprocess_all(pres);
1434 LDLM_RESOURCE_DELREF(pres);
1435 ldlm_resource_putref(pres);
1438 ldlm_resource_getref(res);
1439 LDLM_RESOURCE_ADDREF(res);
1440 ldlm_res_lvbo_update(res, NULL, 1);
1444 ldlm_lock_cancel(lock);
1445 LDLM_LOCK_PUT(lock);
1448 ldlm_reprocess_all(pres);
1449 LDLM_RESOURCE_DELREF(pres);
1450 ldlm_resource_putref(pres);
1452 LDLM_DEBUG_NOLOCK("server-side cancel handler END");
1456 int ldlm_handle_cancel(struct ptlrpc_request *req)
1458 struct ldlm_request *dlm_req;
1462 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1463 if (dlm_req == NULL) {
1464 CDEBUG(D_INFO, "bad request buffer for cancel\n");
1468 if (req->rq_export && req->rq_export->exp_nid_stats &&
1469 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1470 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1471 LDLM_CANCEL - LDLM_FIRST_OPC);
1473 rc = req_capsule_server_pack(&req->rq_pill);
1477 if (!ldlm_request_cancel(req, dlm_req, 0))
1478 req->rq_status = ESTALE;
1480 RETURN(ptlrpc_reply(req));
1482 #endif /* HAVE_SERVER_SUPPORT */
1484 void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
1485 struct ldlm_lock_desc *ld, struct ldlm_lock *lock)
1490 LDLM_DEBUG(lock, "client blocking AST callback handler");
1492 lock_res_and_lock(lock);
1493 lock->l_flags |= LDLM_FL_CBPENDING;
1495 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)
1496 lock->l_flags |= LDLM_FL_CANCEL;
1498 do_ast = (!lock->l_readers && !lock->l_writers);
1499 unlock_res_and_lock(lock);
1502 CDEBUG(D_DLMTRACE, "Lock %p already unused, calling callback (%p)\n",
1503 lock, lock->l_blocking_ast);
1504 if (lock->l_blocking_ast != NULL)
1505 lock->l_blocking_ast(lock, ld, lock->l_ast_data,
1508 CDEBUG(D_DLMTRACE, "Lock %p is referenced, will be cancelled later\n",
1512 LDLM_DEBUG(lock, "client blocking callback handler END");
1513 LDLM_LOCK_RELEASE(lock);
1517 static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
1518 struct ldlm_namespace *ns,
1519 struct ldlm_request *dlm_req,
1520 struct ldlm_lock *lock)
1522 CFS_LIST_HEAD(ast_list);
1525 LDLM_DEBUG(lock, "client completion callback handler START");
1527 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE)) {
1528 int to = cfs_time_seconds(1);
1530 cfs_schedule_timeout_and_set_state(
1531 CFS_TASK_INTERRUPTIBLE, to);
1532 if (lock->l_granted_mode == lock->l_req_mode ||
1538 lock_res_and_lock(lock);
1539 if (lock->l_destroyed ||
1540 lock->l_granted_mode == lock->l_req_mode) {
1541 /* bug 11300: the lock has already been granted */
1542 unlock_res_and_lock(lock);
1543 LDLM_DEBUG(lock, "Double grant race happened");
1544 LDLM_LOCK_RELEASE(lock);
1549 /* If we receive the completion AST before the actual enqueue returned,
1550 * then we might need to switch lock modes, resources, or extents. */
1551 if (dlm_req->lock_desc.l_granted_mode != lock->l_req_mode) {
1552 lock->l_req_mode = dlm_req->lock_desc.l_granted_mode;
1553 LDLM_DEBUG(lock, "completion AST, new lock mode");
1556 if (lock->l_resource->lr_type != LDLM_PLAIN) {
1557 ldlm_convert_policy_to_local(req->rq_export,
1558 dlm_req->lock_desc.l_resource.lr_type,
1559 &dlm_req->lock_desc.l_policy_data,
1560 &lock->l_policy_data);
1561 LDLM_DEBUG(lock, "completion AST, new policy data");
1564 ldlm_resource_unlink_lock(lock);
1565 if (memcmp(&dlm_req->lock_desc.l_resource.lr_name,
1566 &lock->l_resource->lr_name,
1567 sizeof(lock->l_resource->lr_name)) != 0) {
1568 unlock_res_and_lock(lock);
1569 if (ldlm_lock_change_resource(ns, lock,
1570 &dlm_req->lock_desc.l_resource.lr_name) != 0) {
1571 LDLM_ERROR(lock, "Failed to allocate resource");
1572 LDLM_LOCK_RELEASE(lock);
1576 LDLM_DEBUG(lock, "completion AST, new resource");
1577 CERROR("change resource!\n");
1578 lock_res_and_lock(lock);
1581 if (dlm_req->lock_flags & LDLM_FL_AST_SENT) {
1582 /* BL_AST locks are not needed in lru.
1583 * let ldlm_cancel_lru() be fast. */
1584 ldlm_lock_remove_from_lru(lock);
1585 lock->l_flags |= LDLM_FL_CBPENDING | LDLM_FL_BL_AST;
1586 LDLM_DEBUG(lock, "completion AST includes blocking AST");
1589 if (lock->l_lvb_len) {
1590 if (req_capsule_get_size(&req->rq_pill, &RMF_DLM_LVB,
1591 RCL_CLIENT) < lock->l_lvb_len) {
1592 LDLM_ERROR(lock, "completion AST did not contain "
1595 void *lvb = req_capsule_client_get(&req->rq_pill,
1597 memcpy(lock->l_lvb_data, lvb, lock->l_lvb_len);
1601 ldlm_grant_lock(lock, &ast_list);
1602 unlock_res_and_lock(lock);
1604 LDLM_DEBUG(lock, "callback handler finished, about to run_ast_work");
1606 /* Let Enqueue to call osc_lock_upcall() and initialize
1608 OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_CP_ENQ_RACE, 2);
1610 ldlm_run_ast_work(ns, &ast_list, LDLM_WORK_CP_AST);
1612 LDLM_DEBUG_NOLOCK("client completion callback handler END (lock %p)",
1614 LDLM_LOCK_RELEASE(lock);
1618 static void ldlm_handle_gl_callback(struct ptlrpc_request *req,
1619 struct ldlm_namespace *ns,
1620 struct ldlm_request *dlm_req,
1621 struct ldlm_lock *lock)
1626 LDLM_DEBUG(lock, "client glimpse AST callback handler");
1628 if (lock->l_glimpse_ast != NULL)
1629 rc = lock->l_glimpse_ast(lock, req);
1631 if (req->rq_repmsg != NULL) {
1634 req->rq_status = rc;
1638 lock_res_and_lock(lock);
1639 if (lock->l_granted_mode == LCK_PW &&
1640 !lock->l_readers && !lock->l_writers &&
1641 cfs_time_after(cfs_time_current(),
1642 cfs_time_add(lock->l_last_used,
1643 cfs_time_seconds(10)))) {
1644 unlock_res_and_lock(lock);
1645 if (ldlm_bl_to_thread_lock(ns, NULL, lock))
1646 ldlm_handle_bl_callback(ns, NULL, lock);
1651 unlock_res_and_lock(lock);
1652 LDLM_LOCK_RELEASE(lock);
1656 static int ldlm_callback_reply(struct ptlrpc_request *req, int rc)
1658 if (req->rq_no_reply)
1661 req->rq_status = rc;
1662 if (!req->rq_packed_final) {
1663 rc = lustre_pack_reply(req, 1, NULL, NULL);
1667 return ptlrpc_reply(req);
1671 static int __ldlm_bl_to_thread(struct ldlm_bl_work_item *blwi, int mode)
1673 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
1676 cfs_spin_lock(&blp->blp_lock);
1677 if (blwi->blwi_lock && blwi->blwi_lock->l_flags & LDLM_FL_DISCARD_DATA) {
1678 /* add LDLM_FL_DISCARD_DATA requests to the priority list */
1679 cfs_list_add_tail(&blwi->blwi_entry, &blp->blp_prio_list);
1681 /* other blocking callbacks are added to the regular list */
1682 cfs_list_add_tail(&blwi->blwi_entry, &blp->blp_list);
1684 cfs_spin_unlock(&blp->blp_lock);
1686 cfs_waitq_signal(&blp->blp_waitq);
1688 /* can not use blwi->blwi_mode as blwi could be already freed in
1690 if (mode == LDLM_SYNC)
1691 cfs_wait_for_completion(&blwi->blwi_comp);
1696 static inline void init_blwi(struct ldlm_bl_work_item *blwi,
1697 struct ldlm_namespace *ns,
1698 struct ldlm_lock_desc *ld,
1699 cfs_list_t *cancels, int count,
1700 struct ldlm_lock *lock,
1703 cfs_init_completion(&blwi->blwi_comp);
1704 CFS_INIT_LIST_HEAD(&blwi->blwi_head);
1706 if (cfs_memory_pressure_get())
1707 blwi->blwi_mem_pressure = 1;
1710 blwi->blwi_mode = mode;
1712 blwi->blwi_ld = *ld;
1714 cfs_list_add(&blwi->blwi_head, cancels);
1715 cfs_list_del_init(cancels);
1716 blwi->blwi_count = count;
1718 blwi->blwi_lock = lock;
1722 static int ldlm_bl_to_thread(struct ldlm_namespace *ns,
1723 struct ldlm_lock_desc *ld, struct ldlm_lock *lock,
1724 cfs_list_t *cancels, int count, int mode)
1728 if (cancels && count == 0)
1731 if (mode == LDLM_SYNC) {
1732 /* if it is synchronous call do minimum mem alloc, as it could
1733 * be triggered from kernel shrinker
1735 struct ldlm_bl_work_item blwi;
1736 memset(&blwi, 0, sizeof(blwi));
1737 init_blwi(&blwi, ns, ld, cancels, count, lock, LDLM_SYNC);
1738 RETURN(__ldlm_bl_to_thread(&blwi, LDLM_SYNC));
1740 struct ldlm_bl_work_item *blwi;
1741 OBD_ALLOC(blwi, sizeof(*blwi));
1744 init_blwi(blwi, ns, ld, cancels, count, lock, LDLM_ASYNC);
1746 RETURN(__ldlm_bl_to_thread(blwi, LDLM_ASYNC));
1752 int ldlm_bl_to_thread_lock(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
1753 struct ldlm_lock *lock)
1756 RETURN(ldlm_bl_to_thread(ns, ld, lock, NULL, 0, LDLM_ASYNC));
1762 int ldlm_bl_to_thread_list(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
1763 cfs_list_t *cancels, int count, int mode)
1766 RETURN(ldlm_bl_to_thread(ns, ld, NULL, cancels, count, mode));
1772 /* Setinfo coming from Server (eg MDT) to Client (eg MDC)! */
1773 static int ldlm_handle_setinfo(struct ptlrpc_request *req)
1775 struct obd_device *obd = req->rq_export->exp_obd;
1782 DEBUG_REQ(D_HSM, req, "%s: handle setinfo\n", obd->obd_name);
1784 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
1786 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1788 DEBUG_REQ(D_IOCTL, req, "no set_info key");
1791 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1793 val = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1795 DEBUG_REQ(D_IOCTL, req, "no set_info val");
1798 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1801 /* We are responsible for swabbing contents of val */
1803 if (KEY_IS(KEY_HSM_COPYTOOL_SEND))
1804 /* Pass it on to mdc (the "export" in this case) */
1805 rc = obd_set_info_async(req->rq_svc_thread->t_env,
1807 sizeof(KEY_HSM_COPYTOOL_SEND),
1808 KEY_HSM_COPYTOOL_SEND,
1811 DEBUG_REQ(D_WARNING, req, "ignoring unknown key %s", key);
1816 static inline void ldlm_callback_errmsg(struct ptlrpc_request *req,
1817 const char *msg, int rc,
1818 struct lustre_handle *handle)
1820 DEBUG_REQ((req->rq_no_reply || rc) ? D_WARNING : D_DLMTRACE, req,
1821 "%s: [nid %s] [rc %d] [lock "LPX64"]",
1822 msg, libcfs_id2str(req->rq_peer), rc,
1823 handle ? handle->cookie : 0);
1824 if (req->rq_no_reply)
1825 CWARN("No reply was sent, maybe cause bug 21636.\n");
1827 CWARN("Send reply failed, maybe cause bug 21636.\n");
1830 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1831 static int ldlm_callback_handler(struct ptlrpc_request *req)
1833 struct ldlm_namespace *ns;
1834 struct ldlm_request *dlm_req;
1835 struct ldlm_lock *lock;
1839 /* Requests arrive in sender's byte order. The ptlrpc service
1840 * handler has already checked and, if necessary, byte-swapped the
1841 * incoming request message body, but I am responsible for the
1842 * message buffers. */
1844 /* do nothing for sec context finalize */
1845 if (lustre_msg_get_opc(req->rq_reqmsg) == SEC_CTX_FINI)
1848 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1850 if (req->rq_export == NULL) {
1851 rc = ldlm_callback_reply(req, -ENOTCONN);
1852 ldlm_callback_errmsg(req, "Operate on unconnected server",
1857 LASSERT(req->rq_export != NULL);
1858 LASSERT(req->rq_export->exp_obd != NULL);
1860 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1861 case LDLM_BL_CALLBACK:
1862 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_BL_CALLBACK))
1865 case LDLM_CP_CALLBACK:
1866 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CP_CALLBACK))
1869 case LDLM_GL_CALLBACK:
1870 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_GL_CALLBACK))
1874 rc = ldlm_handle_setinfo(req);
1875 ldlm_callback_reply(req, rc);
1877 case OBD_LOG_CANCEL: /* remove this eventually - for 1.4.0 compat */
1878 CERROR("shouldn't be handling OBD_LOG_CANCEL on DLM thread\n");
1879 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1880 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1882 rc = llog_origin_handle_cancel(req);
1883 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
1885 ldlm_callback_reply(req, rc);
1887 case OBD_QC_CALLBACK:
1888 req_capsule_set(&req->rq_pill, &RQF_QC_CALLBACK);
1889 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_QC_CALLBACK_NET))
1891 rc = target_handle_qc_callback(req);
1892 ldlm_callback_reply(req, rc);
1896 /* reply in handler */
1897 req_capsule_set(&req->rq_pill, &RQF_MDS_QUOTA_DQACQ);
1898 rc = target_handle_dqacq_callback(req);
1900 case LLOG_ORIGIN_HANDLE_CREATE:
1901 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1902 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1904 rc = llog_origin_handle_create(req);
1905 ldlm_callback_reply(req, rc);
1907 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1908 req_capsule_set(&req->rq_pill,
1909 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1910 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1912 rc = llog_origin_handle_next_block(req);
1913 ldlm_callback_reply(req, rc);
1915 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1916 req_capsule_set(&req->rq_pill,
1917 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1918 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1920 rc = llog_origin_handle_read_header(req);
1921 ldlm_callback_reply(req, rc);
1923 case LLOG_ORIGIN_HANDLE_CLOSE:
1924 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1926 rc = llog_origin_handle_close(req);
1927 ldlm_callback_reply(req, rc);
1930 CERROR("unknown opcode %u\n",
1931 lustre_msg_get_opc(req->rq_reqmsg));
1932 ldlm_callback_reply(req, -EPROTO);
1936 ns = req->rq_export->exp_obd->obd_namespace;
1937 LASSERT(ns != NULL);
1939 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
1941 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1942 if (dlm_req == NULL) {
1943 rc = ldlm_callback_reply(req, -EPROTO);
1944 ldlm_callback_errmsg(req, "Operate without parameter", rc,
1949 /* Force a known safe race, send a cancel to the server for a lock
1950 * which the server has already started a blocking callback on. */
1951 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE) &&
1952 lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) {
1953 rc = ldlm_cli_cancel(&dlm_req->lock_handle[0]);
1955 CERROR("ldlm_cli_cancel: %d\n", rc);
1958 lock = ldlm_handle2lock_long(&dlm_req->lock_handle[0], 0);
1960 CDEBUG(D_DLMTRACE, "callback on lock "LPX64" - lock "
1961 "disappeared\n", dlm_req->lock_handle[0].cookie);
1962 rc = ldlm_callback_reply(req, -EINVAL);
1963 ldlm_callback_errmsg(req, "Operate with invalid parameter", rc,
1964 &dlm_req->lock_handle[0]);
1968 if ((lock->l_flags & LDLM_FL_FAIL_LOC) &&
1969 lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK)
1970 OBD_RACE(OBD_FAIL_LDLM_CP_BL_RACE);
1972 /* Copy hints/flags (e.g. LDLM_FL_DISCARD_DATA) from AST. */
1973 lock_res_and_lock(lock);
1974 lock->l_flags |= (dlm_req->lock_flags & LDLM_AST_FLAGS);
1975 if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) {
1976 /* If somebody cancels lock and cache is already dropped,
1977 * or lock is failed before cp_ast received on client,
1978 * we can tell the server we have no lock. Otherwise, we
1979 * should send cancel after dropping the cache. */
1980 if (((lock->l_flags & LDLM_FL_CANCELING) &&
1981 (lock->l_flags & LDLM_FL_BL_DONE)) ||
1982 (lock->l_flags & LDLM_FL_FAILED)) {
1983 LDLM_DEBUG(lock, "callback on lock "
1984 LPX64" - lock disappeared\n",
1985 dlm_req->lock_handle[0].cookie);
1986 unlock_res_and_lock(lock);
1987 LDLM_LOCK_RELEASE(lock);
1988 rc = ldlm_callback_reply(req, -EINVAL);
1989 ldlm_callback_errmsg(req, "Operate on stale lock", rc,
1990 &dlm_req->lock_handle[0]);
1993 /* BL_AST locks are not needed in lru.
1994 * let ldlm_cancel_lru() be fast. */
1995 ldlm_lock_remove_from_lru(lock);
1996 lock->l_flags |= LDLM_FL_BL_AST;
1998 unlock_res_and_lock(lock);
2000 /* We want the ost thread to get this reply so that it can respond
2001 * to ost requests (write cache writeback) that might be triggered
2004 * But we'd also like to be able to indicate in the reply that we're
2005 * cancelling right now, because it's unused, or have an intent result
2006 * in the reply, so we might have to push the responsibility for sending
2007 * the reply down into the AST handlers, alas. */
2009 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2010 case LDLM_BL_CALLBACK:
2011 CDEBUG(D_INODE, "blocking ast\n");
2012 req_capsule_extend(&req->rq_pill, &RQF_LDLM_BL_CALLBACK);
2013 if (!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)) {
2014 rc = ldlm_callback_reply(req, 0);
2015 if (req->rq_no_reply || rc)
2016 ldlm_callback_errmsg(req, "Normal process", rc,
2017 &dlm_req->lock_handle[0]);
2019 if (ldlm_bl_to_thread_lock(ns, &dlm_req->lock_desc, lock))
2020 ldlm_handle_bl_callback(ns, &dlm_req->lock_desc, lock);
2022 case LDLM_CP_CALLBACK:
2023 CDEBUG(D_INODE, "completion ast\n");
2024 req_capsule_extend(&req->rq_pill, &RQF_LDLM_CP_CALLBACK);
2025 ldlm_callback_reply(req, 0);
2026 ldlm_handle_cp_callback(req, ns, dlm_req, lock);
2028 case LDLM_GL_CALLBACK:
2029 CDEBUG(D_INODE, "glimpse ast\n");
2030 req_capsule_extend(&req->rq_pill, &RQF_LDLM_GL_CALLBACK);
2031 ldlm_handle_gl_callback(req, ns, dlm_req, lock);
2034 LBUG(); /* checked above */
2040 #ifdef HAVE_SERVER_SUPPORT
2041 static int ldlm_cancel_handler(struct ptlrpc_request *req)
2046 /* Requests arrive in sender's byte order. The ptlrpc service
2047 * handler has already checked and, if necessary, byte-swapped the
2048 * incoming request message body, but I am responsible for the
2049 * message buffers. */
2051 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2053 if (req->rq_export == NULL) {
2054 struct ldlm_request *dlm_req;
2056 CERROR("%s from %s arrived at %lu with bad export cookie "
2058 ll_opcode2str(lustre_msg_get_opc(req->rq_reqmsg)),
2059 libcfs_nid2str(req->rq_peer.nid),
2060 req->rq_arrival_time.tv_sec,
2061 lustre_msg_get_handle(req->rq_reqmsg)->cookie);
2063 if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_CANCEL) {
2064 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
2065 dlm_req = req_capsule_client_get(&req->rq_pill,
2067 if (dlm_req != NULL)
2068 ldlm_lock_dump_handle(D_ERROR,
2069 &dlm_req->lock_handle[0]);
2071 ldlm_callback_reply(req, -ENOTCONN);
2075 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2077 /* XXX FIXME move this back to mds/handler.c, bug 249 */
2079 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2080 CDEBUG(D_INODE, "cancel\n");
2081 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2083 rc = ldlm_handle_cancel(req);
2087 case OBD_LOG_CANCEL:
2088 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2089 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2091 rc = llog_origin_handle_cancel(req);
2092 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2094 ldlm_callback_reply(req, rc);
2097 CERROR("invalid opcode %d\n",
2098 lustre_msg_get_opc(req->rq_reqmsg));
2099 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
2100 ldlm_callback_reply(req, -EINVAL);
2106 static int ldlm_cancel_hpreq_lock_match(struct ptlrpc_request *req,
2107 struct ldlm_lock *lock)
2109 struct ldlm_request *dlm_req;
2110 struct lustre_handle lockh;
2115 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
2116 if (dlm_req == NULL)
2119 ldlm_lock2handle(lock, &lockh);
2120 for (i = 0; i < dlm_req->lock_count; i++) {
2121 if (lustre_handle_equal(&dlm_req->lock_handle[i],
2123 DEBUG_REQ(D_RPCTRACE, req,
2124 "Prio raised by lock "LPX64".", lockh.cookie);
2135 static int ldlm_cancel_hpreq_check(struct ptlrpc_request *req)
2137 struct ldlm_request *dlm_req;
2142 /* no prolong in recovery */
2143 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
2146 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
2147 if (dlm_req == NULL)
2150 for (i = 0; i < dlm_req->lock_count; i++) {
2151 struct ldlm_lock *lock;
2153 lock = ldlm_handle2lock(&dlm_req->lock_handle[i]);
2157 rc = !!(lock->l_flags & LDLM_FL_AST_SENT);
2159 LDLM_DEBUG(lock, "hpreq cancel lock");
2160 LDLM_LOCK_PUT(lock);
2169 static struct ptlrpc_hpreq_ops ldlm_cancel_hpreq_ops = {
2170 .hpreq_lock_match = ldlm_cancel_hpreq_lock_match,
2171 .hpreq_check = ldlm_cancel_hpreq_check
2174 static int ldlm_hpreq_handler(struct ptlrpc_request *req)
2178 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2180 if (req->rq_export == NULL)
2183 if (LDLM_CANCEL == lustre_msg_get_opc(req->rq_reqmsg)) {
2184 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2185 req->rq_ops = &ldlm_cancel_hpreq_ops;
2190 int ldlm_revoke_lock_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd,
2191 cfs_hlist_node_t *hnode, void *data)
2194 cfs_list_t *rpc_list = data;
2195 struct ldlm_lock *lock = cfs_hash_object(hs, hnode);
2197 lock_res_and_lock(lock);
2199 if (lock->l_req_mode != lock->l_granted_mode) {
2200 unlock_res_and_lock(lock);
2204 LASSERT(lock->l_resource);
2205 if (lock->l_resource->lr_type != LDLM_IBITS &&
2206 lock->l_resource->lr_type != LDLM_PLAIN) {
2207 unlock_res_and_lock(lock);
2211 if (lock->l_flags & LDLM_FL_AST_SENT) {
2212 unlock_res_and_lock(lock);
2216 LASSERT(lock->l_blocking_ast);
2217 LASSERT(!lock->l_blocking_lock);
2219 lock->l_flags |= LDLM_FL_AST_SENT;
2220 if (lock->l_export && lock->l_export->exp_lock_hash) {
2221 /* NB: it's safe to call cfs_hash_del() even lock isn't
2222 * in exp_lock_hash. */
2223 cfs_hash_del(lock->l_export->exp_lock_hash,
2224 &lock->l_remote_handle, &lock->l_exp_hash);
2227 cfs_list_add_tail(&lock->l_rk_ast, rpc_list);
2228 LDLM_LOCK_GET(lock);
2230 unlock_res_and_lock(lock);
2234 void ldlm_revoke_export_locks(struct obd_export *exp)
2236 cfs_list_t rpc_list;
2239 CFS_INIT_LIST_HEAD(&rpc_list);
2240 cfs_hash_for_each_empty(exp->exp_lock_hash,
2241 ldlm_revoke_lock_cb, &rpc_list);
2242 ldlm_run_ast_work(exp->exp_obd->obd_namespace, &rpc_list,
2243 LDLM_WORK_REVOKE_AST);
2247 #endif /* HAVE_SERVER_SUPPORT */
2250 static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp)
2252 struct ldlm_bl_work_item *blwi = NULL;
2253 static unsigned int num_bl = 0;
2255 cfs_spin_lock(&blp->blp_lock);
2256 /* process a request from the blp_list at least every blp_num_threads */
2257 if (!cfs_list_empty(&blp->blp_list) &&
2258 (cfs_list_empty(&blp->blp_prio_list) || num_bl == 0))
2259 blwi = cfs_list_entry(blp->blp_list.next,
2260 struct ldlm_bl_work_item, blwi_entry);
2262 if (!cfs_list_empty(&blp->blp_prio_list))
2263 blwi = cfs_list_entry(blp->blp_prio_list.next,
2264 struct ldlm_bl_work_item,
2268 if (++num_bl >= cfs_atomic_read(&blp->blp_num_threads))
2270 cfs_list_del(&blwi->blwi_entry);
2272 cfs_spin_unlock(&blp->blp_lock);
2277 /* This only contains temporary data until the thread starts */
2278 struct ldlm_bl_thread_data {
2279 char bltd_name[CFS_CURPROC_COMM_MAX];
2280 struct ldlm_bl_pool *bltd_blp;
2281 cfs_completion_t bltd_comp;
2285 static int ldlm_bl_thread_main(void *arg);
2287 static int ldlm_bl_thread_start(struct ldlm_bl_pool *blp)
2289 struct ldlm_bl_thread_data bltd = { .bltd_blp = blp };
2292 cfs_init_completion(&bltd.bltd_comp);
2293 rc = cfs_create_thread(ldlm_bl_thread_main, &bltd, 0);
2295 CERROR("cannot start LDLM thread ldlm_bl_%02d: rc %d\n",
2296 cfs_atomic_read(&blp->blp_num_threads), rc);
2299 cfs_wait_for_completion(&bltd.bltd_comp);
2304 static int ldlm_bl_thread_main(void *arg)
2306 struct ldlm_bl_pool *blp;
2310 struct ldlm_bl_thread_data *bltd = arg;
2312 blp = bltd->bltd_blp;
2315 cfs_atomic_inc_return(&blp->blp_num_threads) - 1;
2316 cfs_atomic_inc(&blp->blp_busy_threads);
2318 snprintf(bltd->bltd_name, sizeof(bltd->bltd_name) - 1,
2319 "ldlm_bl_%02d", bltd->bltd_num);
2320 cfs_daemonize(bltd->bltd_name);
2322 cfs_complete(&bltd->bltd_comp);
2323 /* cannot use bltd after this, it is only on caller's stack */
2327 struct l_wait_info lwi = { 0 };
2328 struct ldlm_bl_work_item *blwi = NULL;
2331 blwi = ldlm_bl_get_work(blp);
2334 cfs_atomic_dec(&blp->blp_busy_threads);
2335 l_wait_event_exclusive(blp->blp_waitq,
2336 (blwi = ldlm_bl_get_work(blp)) != NULL,
2338 busy = cfs_atomic_inc_return(&blp->blp_busy_threads);
2340 busy = cfs_atomic_read(&blp->blp_busy_threads);
2343 if (blwi->blwi_ns == NULL)
2344 /* added by ldlm_cleanup() */
2347 /* Not fatal if racy and have a few too many threads */
2348 if (unlikely(busy < blp->blp_max_threads &&
2349 busy >= cfs_atomic_read(&blp->blp_num_threads) &&
2350 !blwi->blwi_mem_pressure))
2351 /* discard the return value, we tried */
2352 ldlm_bl_thread_start(blp);
2354 if (blwi->blwi_mem_pressure)
2355 cfs_memory_pressure_set();
2357 if (blwi->blwi_count) {
2359 /* The special case when we cancel locks in lru
2360 * asynchronously, we pass the list of locks here.
2361 * Thus locks are marked LDLM_FL_CANCELING, but NOT
2362 * canceled locally yet. */
2363 count = ldlm_cli_cancel_list_local(&blwi->blwi_head,
2366 ldlm_cli_cancel_list(&blwi->blwi_head, count, NULL, 0);
2368 ldlm_handle_bl_callback(blwi->blwi_ns, &blwi->blwi_ld,
2371 if (blwi->blwi_mem_pressure)
2372 cfs_memory_pressure_clr();
2374 if (blwi->blwi_mode == LDLM_ASYNC)
2375 OBD_FREE(blwi, sizeof(*blwi));
2377 cfs_complete(&blwi->blwi_comp);
2380 cfs_atomic_dec(&blp->blp_busy_threads);
2381 cfs_atomic_dec(&blp->blp_num_threads);
2382 cfs_complete(&blp->blp_comp);
2388 static int ldlm_setup(void);
2389 static int ldlm_cleanup(void);
2391 int ldlm_get_ref(void)
2395 cfs_mutex_lock(&ldlm_ref_mutex);
2396 if (++ldlm_refcount == 1) {
2401 cfs_mutex_unlock(&ldlm_ref_mutex);
2406 void ldlm_put_ref(void)
2409 cfs_mutex_lock(&ldlm_ref_mutex);
2410 if (ldlm_refcount == 1) {
2411 int rc = ldlm_cleanup();
2413 CERROR("ldlm_cleanup failed: %d\n", rc);
2419 cfs_mutex_unlock(&ldlm_ref_mutex);
2425 * Export handle<->lock hash operations.
2428 ldlm_export_lock_hash(cfs_hash_t *hs, const void *key, unsigned mask)
2430 return cfs_hash_u64_hash(((struct lustre_handle *)key)->cookie, mask);
2434 ldlm_export_lock_key(cfs_hlist_node_t *hnode)
2436 struct ldlm_lock *lock;
2438 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2439 return &lock->l_remote_handle;
2443 ldlm_export_lock_keycpy(cfs_hlist_node_t *hnode, void *key)
2445 struct ldlm_lock *lock;
2447 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2448 lock->l_remote_handle = *(struct lustre_handle *)key;
2452 ldlm_export_lock_keycmp(const void *key, cfs_hlist_node_t *hnode)
2454 return lustre_handle_equal(ldlm_export_lock_key(hnode), key);
2458 ldlm_export_lock_object(cfs_hlist_node_t *hnode)
2460 return cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2464 ldlm_export_lock_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
2466 struct ldlm_lock *lock;
2468 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2469 LDLM_LOCK_GET(lock);
2473 ldlm_export_lock_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
2475 struct ldlm_lock *lock;
2477 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2478 LDLM_LOCK_RELEASE(lock);
2481 static cfs_hash_ops_t ldlm_export_lock_ops = {
2482 .hs_hash = ldlm_export_lock_hash,
2483 .hs_key = ldlm_export_lock_key,
2484 .hs_keycmp = ldlm_export_lock_keycmp,
2485 .hs_keycpy = ldlm_export_lock_keycpy,
2486 .hs_object = ldlm_export_lock_object,
2487 .hs_get = ldlm_export_lock_get,
2488 .hs_put = ldlm_export_lock_put,
2489 .hs_put_locked = ldlm_export_lock_put,
2492 int ldlm_init_export(struct obd_export *exp)
2496 exp->exp_lock_hash =
2497 cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
2498 HASH_EXP_LOCK_CUR_BITS,
2499 HASH_EXP_LOCK_MAX_BITS,
2500 HASH_EXP_LOCK_BKT_BITS, 0,
2501 CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA,
2502 &ldlm_export_lock_ops,
2503 CFS_HASH_DEFAULT | CFS_HASH_REHASH_KEY |
2504 CFS_HASH_NBLK_CHANGE);
2506 if (!exp->exp_lock_hash)
2511 EXPORT_SYMBOL(ldlm_init_export);
2513 void ldlm_destroy_export(struct obd_export *exp)
2516 cfs_hash_putref(exp->exp_lock_hash);
2517 exp->exp_lock_hash = NULL;
2520 EXPORT_SYMBOL(ldlm_destroy_export);
2522 static int ldlm_setup(void)
2524 static struct ptlrpc_service_conf conf;
2525 struct ldlm_bl_pool *blp = NULL;
2532 if (ldlm_state != NULL)
2535 OBD_ALLOC(ldlm_state, sizeof(*ldlm_state));
2536 if (ldlm_state == NULL)
2540 rc = ldlm_proc_setup();
2545 memset(&conf, 0, sizeof(conf));
2546 conf = (typeof(conf)) {
2547 .psc_name = "ldlm_cbd",
2548 .psc_watchdog_factor = 2,
2550 .bc_nbufs = LDLM_NBUFS,
2551 .bc_buf_size = LDLM_BUFSIZE,
2552 .bc_req_max_size = LDLM_MAXREQSIZE,
2553 .bc_rep_max_size = LDLM_MAXREPSIZE,
2554 .bc_req_portal = LDLM_CB_REQUEST_PORTAL,
2555 .bc_rep_portal = LDLM_CB_REPLY_PORTAL,
2558 .tc_thr_name = "ldlm_cb",
2559 .tc_nthrs_min = LDLM_THREADS_AUTO_MIN,
2560 .tc_nthrs_max = LDLM_THREADS_AUTO_MAX,
2561 .tc_nthrs_user = ldlm_num_threads,
2562 .tc_ctx_tags = LCT_MD_THREAD | \
2566 .so_req_handler = ldlm_callback_handler,
2569 ldlm_state->ldlm_cb_service = \
2570 ptlrpc_register_service(&conf, ldlm_svc_proc_dir);
2571 if (IS_ERR(ldlm_state->ldlm_cb_service)) {
2572 CERROR("failed to start service\n");
2573 rc = PTR_ERR(ldlm_state->ldlm_cb_service);
2574 ldlm_state->ldlm_cb_service = NULL;
2578 #ifdef HAVE_SERVER_SUPPORT
2579 memset(&conf, 0, sizeof(conf));
2580 conf = (typeof(conf)) {
2581 .psc_name = "ldlm_canceld",
2582 .psc_watchdog_factor = 6,
2584 .bc_nbufs = LDLM_NBUFS,
2585 .bc_buf_size = LDLM_BUFSIZE,
2586 .bc_req_max_size = LDLM_MAXREQSIZE,
2587 .bc_rep_max_size = LDLM_MAXREPSIZE,
2588 .bc_req_portal = LDLM_CANCEL_REQUEST_PORTAL,
2589 .bc_rep_portal = LDLM_CANCEL_REPLY_PORTAL,
2593 .tc_thr_name = "ldlm_cn",
2594 .tc_nthrs_min = LDLM_THREADS_AUTO_MIN,
2595 .tc_nthrs_max = LDLM_THREADS_AUTO_MAX,
2596 .tc_nthrs_user = ldlm_num_threads,
2597 .tc_ctx_tags = LCT_MD_THREAD | \
2602 .so_req_handler = ldlm_cancel_handler,
2603 .so_hpreq_handler = ldlm_hpreq_handler,
2606 ldlm_state->ldlm_cancel_service = \
2607 ptlrpc_register_service(&conf, ldlm_svc_proc_dir);
2608 if (IS_ERR(ldlm_state->ldlm_cancel_service)) {
2609 CERROR("failed to start service\n");
2610 rc = PTR_ERR(ldlm_state->ldlm_cancel_service);
2611 ldlm_state->ldlm_cancel_service = NULL;
2616 OBD_ALLOC(blp, sizeof(*blp));
2618 GOTO(out, rc = -ENOMEM);
2619 ldlm_state->ldlm_bl_pool = blp;
2621 cfs_spin_lock_init(&blp->blp_lock);
2622 CFS_INIT_LIST_HEAD(&blp->blp_list);
2623 CFS_INIT_LIST_HEAD(&blp->blp_prio_list);
2624 cfs_waitq_init(&blp->blp_waitq);
2625 cfs_atomic_set(&blp->blp_num_threads, 0);
2626 cfs_atomic_set(&blp->blp_busy_threads, 0);
2629 if (ldlm_num_threads == 0) {
2630 blp->blp_min_threads = LDLM_THREADS_AUTO_MIN;
2631 blp->blp_max_threads = LDLM_THREADS_AUTO_MAX;
2633 blp->blp_min_threads = blp->blp_max_threads = \
2634 min_t(int, LDLM_THREADS_AUTO_MAX,
2635 max_t(int, LDLM_THREADS_AUTO_MIN,
2639 for (i = 0; i < blp->blp_min_threads; i++) {
2640 rc = ldlm_bl_thread_start(blp);
2645 CFS_INIT_LIST_HEAD(&expired_lock_thread.elt_expired_locks);
2646 expired_lock_thread.elt_state = ELT_STOPPED;
2647 cfs_waitq_init(&expired_lock_thread.elt_waitq);
2649 CFS_INIT_LIST_HEAD(&waiting_locks_list);
2650 cfs_spin_lock_init(&waiting_locks_spinlock);
2651 cfs_timer_init(&waiting_locks_timer, waiting_locks_callback, 0);
2653 rc = cfs_create_thread(expired_lock_main, NULL, CFS_DAEMON_FLAGS);
2655 CERROR("Cannot start ldlm expired-lock thread: %d\n", rc);
2659 cfs_wait_event(expired_lock_thread.elt_waitq,
2660 expired_lock_thread.elt_state == ELT_READY);
2662 rc = ldlm_pools_init();
2673 static int ldlm_cleanup(void)
2677 if (!cfs_list_empty(ldlm_namespace_list(LDLM_NAMESPACE_SERVER)) ||
2678 !cfs_list_empty(ldlm_namespace_list(LDLM_NAMESPACE_CLIENT))) {
2679 CERROR("ldlm still has namespaces; clean these up first.\n");
2680 ldlm_dump_all_namespaces(LDLM_NAMESPACE_SERVER, D_DLMTRACE);
2681 ldlm_dump_all_namespaces(LDLM_NAMESPACE_CLIENT, D_DLMTRACE);
2688 if (ldlm_state->ldlm_bl_pool != NULL) {
2689 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
2691 while (cfs_atomic_read(&blp->blp_num_threads) > 0) {
2692 struct ldlm_bl_work_item blwi = { .blwi_ns = NULL };
2694 cfs_init_completion(&blp->blp_comp);
2696 cfs_spin_lock(&blp->blp_lock);
2697 cfs_list_add_tail(&blwi.blwi_entry, &blp->blp_list);
2698 cfs_waitq_signal(&blp->blp_waitq);
2699 cfs_spin_unlock(&blp->blp_lock);
2701 cfs_wait_for_completion(&blp->blp_comp);
2704 OBD_FREE(blp, sizeof(*blp));
2706 #endif /* __KERNEL__ */
2708 if (ldlm_state->ldlm_cb_service != NULL)
2709 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
2710 # ifdef HAVE_SERVER_SUPPORT
2711 if (ldlm_state->ldlm_cancel_service != NULL)
2712 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
2715 ldlm_proc_cleanup();
2717 if (expired_lock_thread.elt_state != ELT_STOPPED) {
2718 expired_lock_thread.elt_state = ELT_TERMINATE;
2719 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
2720 cfs_wait_event(expired_lock_thread.elt_waitq,
2721 expired_lock_thread.elt_state == ELT_STOPPED);
2723 #endif /* __KERNEL__ */
2725 OBD_FREE(ldlm_state, sizeof(*ldlm_state));
2733 cfs_mutex_init(&ldlm_ref_mutex);
2734 cfs_mutex_init(ldlm_namespace_lock(LDLM_NAMESPACE_SERVER));
2735 cfs_mutex_init(ldlm_namespace_lock(LDLM_NAMESPACE_CLIENT));
2736 ldlm_resource_slab = cfs_mem_cache_create("ldlm_resources",
2737 sizeof(struct ldlm_resource), 0,
2738 CFS_SLAB_HWCACHE_ALIGN);
2739 if (ldlm_resource_slab == NULL)
2742 ldlm_lock_slab = cfs_mem_cache_create("ldlm_locks",
2743 sizeof(struct ldlm_lock), 0,
2744 CFS_SLAB_HWCACHE_ALIGN | CFS_SLAB_DESTROY_BY_RCU);
2745 if (ldlm_lock_slab == NULL) {
2746 cfs_mem_cache_destroy(ldlm_resource_slab);
2750 ldlm_interval_slab = cfs_mem_cache_create("interval_node",
2751 sizeof(struct ldlm_interval),
2752 0, CFS_SLAB_HWCACHE_ALIGN);
2753 if (ldlm_interval_slab == NULL) {
2754 cfs_mem_cache_destroy(ldlm_resource_slab);
2755 cfs_mem_cache_destroy(ldlm_lock_slab);
2758 #if LUSTRE_TRACKS_LOCK_EXP_REFS
2759 class_export_dump_hook = ldlm_dump_export_locks;
2764 void ldlm_exit(void)
2768 CERROR("ldlm_refcount is %d in ldlm_exit!\n", ldlm_refcount);
2769 rc = cfs_mem_cache_destroy(ldlm_resource_slab);
2770 LASSERTF(rc == 0, "couldn't free ldlm resource slab\n");
2772 /* ldlm_lock_put() use RCU to call ldlm_lock_free, so need call
2773 * synchronize_rcu() to wait a grace period elapsed, so that
2774 * ldlm_lock_free() get a chance to be called. */
2777 rc = cfs_mem_cache_destroy(ldlm_lock_slab);
2778 LASSERTF(rc == 0, "couldn't free ldlm lock slab\n");
2779 rc = cfs_mem_cache_destroy(ldlm_interval_slab);
2780 LASSERTF(rc == 0, "couldn't free interval node slab\n");
2784 EXPORT_SYMBOL(ldlm_extent_shift_kms);
2787 #ifdef HAVE_SERVER_SUPPORT
2788 EXPORT_SYMBOL(ldlm_get_processing_policy);
2790 EXPORT_SYMBOL(ldlm_lock2desc);
2791 EXPORT_SYMBOL(ldlm_register_intent);
2792 EXPORT_SYMBOL(ldlm_lockname);
2793 EXPORT_SYMBOL(ldlm_typename);
2794 EXPORT_SYMBOL(ldlm_lock2handle);
2795 EXPORT_SYMBOL(__ldlm_handle2lock);
2796 EXPORT_SYMBOL(ldlm_lock_get);
2797 EXPORT_SYMBOL(ldlm_lock_put);
2798 EXPORT_SYMBOL(ldlm_lock_match);
2799 EXPORT_SYMBOL(ldlm_lock_cancel);
2800 EXPORT_SYMBOL(ldlm_lock_addref);
2801 EXPORT_SYMBOL(ldlm_lock_addref_try);
2802 EXPORT_SYMBOL(ldlm_lock_decref);
2803 EXPORT_SYMBOL(ldlm_lock_decref_and_cancel);
2804 EXPORT_SYMBOL(ldlm_lock_change_resource);
2805 EXPORT_SYMBOL(ldlm_it2str);
2806 EXPORT_SYMBOL(ldlm_lock_dump_handle);
2807 EXPORT_SYMBOL(ldlm_reprocess_all_ns);
2808 EXPORT_SYMBOL(ldlm_lock_allow_match_locked);
2809 EXPORT_SYMBOL(ldlm_lock_allow_match);
2810 EXPORT_SYMBOL(ldlm_lock_downgrade);
2811 EXPORT_SYMBOL(ldlm_lock_convert);
2813 /* ldlm_request.c */
2814 EXPORT_SYMBOL(ldlm_completion_ast_async);
2815 EXPORT_SYMBOL(ldlm_blocking_ast_nocheck);
2816 EXPORT_SYMBOL(ldlm_completion_ast);
2817 EXPORT_SYMBOL(ldlm_blocking_ast);
2818 EXPORT_SYMBOL(ldlm_glimpse_ast);
2819 EXPORT_SYMBOL(ldlm_expired_completion_wait);
2820 EXPORT_SYMBOL(ldlm_prep_enqueue_req);
2821 EXPORT_SYMBOL(ldlm_prep_elc_req);
2822 EXPORT_SYMBOL(ldlm_cli_convert);
2823 EXPORT_SYMBOL(ldlm_cli_enqueue);
2824 EXPORT_SYMBOL(ldlm_cli_enqueue_fini);
2825 EXPORT_SYMBOL(ldlm_cli_enqueue_local);
2826 EXPORT_SYMBOL(ldlm_cli_cancel);
2827 EXPORT_SYMBOL(ldlm_cli_cancel_unused);
2828 EXPORT_SYMBOL(ldlm_cli_cancel_unused_resource);
2829 EXPORT_SYMBOL(ldlm_cli_cancel_req);
2830 EXPORT_SYMBOL(ldlm_replay_locks);
2831 EXPORT_SYMBOL(ldlm_resource_foreach);
2832 EXPORT_SYMBOL(ldlm_namespace_foreach);
2833 EXPORT_SYMBOL(ldlm_resource_iterate);
2834 EXPORT_SYMBOL(ldlm_cancel_resource_local);
2835 EXPORT_SYMBOL(ldlm_cli_cancel_list_local);
2836 EXPORT_SYMBOL(ldlm_cli_cancel_list);
2839 #ifdef HAVE_SERVER_SUPPORT
2840 EXPORT_SYMBOL(ldlm_server_blocking_ast);
2841 EXPORT_SYMBOL(ldlm_server_completion_ast);
2842 EXPORT_SYMBOL(ldlm_server_glimpse_ast);
2843 EXPORT_SYMBOL(ldlm_handle_enqueue);
2844 EXPORT_SYMBOL(ldlm_handle_enqueue0);
2845 EXPORT_SYMBOL(ldlm_handle_cancel);
2846 EXPORT_SYMBOL(ldlm_request_cancel);
2847 EXPORT_SYMBOL(ldlm_handle_convert);
2848 EXPORT_SYMBOL(ldlm_handle_convert0);
2849 EXPORT_SYMBOL(ldlm_revoke_export_locks);
2851 EXPORT_SYMBOL(ldlm_del_waiting_lock);
2852 EXPORT_SYMBOL(ldlm_get_ref);
2853 EXPORT_SYMBOL(ldlm_put_ref);
2854 EXPORT_SYMBOL(ldlm_refresh_waiting_lock);
2856 /* ldlm_resource.c */
2857 EXPORT_SYMBOL(ldlm_namespace_new);
2858 EXPORT_SYMBOL(ldlm_namespace_cleanup);
2859 EXPORT_SYMBOL(ldlm_namespace_free);
2860 EXPORT_SYMBOL(ldlm_namespace_dump);
2861 EXPORT_SYMBOL(ldlm_dump_all_namespaces);
2862 EXPORT_SYMBOL(ldlm_resource_get);
2863 EXPORT_SYMBOL(ldlm_resource_putref);
2864 EXPORT_SYMBOL(ldlm_resource_unlink_lock);
2867 EXPORT_SYMBOL(client_import_add_conn);
2868 EXPORT_SYMBOL(client_import_del_conn);
2869 EXPORT_SYMBOL(client_obd_setup);
2870 EXPORT_SYMBOL(client_obd_cleanup);
2871 EXPORT_SYMBOL(client_connect_import);
2872 EXPORT_SYMBOL(client_disconnect_export);
2873 EXPORT_SYMBOL(target_send_reply);
2874 EXPORT_SYMBOL(target_pack_pool_reply);
2876 #ifdef HAVE_SERVER_SUPPORT
2877 EXPORT_SYMBOL(server_disconnect_export);
2878 EXPORT_SYMBOL(target_stop_recovery_thread);
2879 EXPORT_SYMBOL(target_handle_connect);
2880 EXPORT_SYMBOL(target_cleanup_recovery);
2881 EXPORT_SYMBOL(target_destroy_export);
2882 EXPORT_SYMBOL(target_cancel_recovery_timer);
2883 EXPORT_SYMBOL(target_queue_recovery_request);
2884 EXPORT_SYMBOL(target_handle_ping);
2885 EXPORT_SYMBOL(target_handle_disconnect);
2889 EXPORT_SYMBOL(lock_res_and_lock);
2890 EXPORT_SYMBOL(unlock_res_and_lock);