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 static char *ldlm_cpts;
60 CFS_MODULE_PARM(ldlm_cpts, "s", charp, 0444,
61 "CPU partitions ldlm threads should run on");
63 extern cfs_mem_cache_t *ldlm_resource_slab;
64 extern cfs_mem_cache_t *ldlm_lock_slab;
65 static cfs_mutex_t ldlm_ref_mutex;
66 static int ldlm_refcount;
68 struct ldlm_cb_async_args {
69 struct ldlm_cb_set_arg *ca_set_arg;
70 struct ldlm_lock *ca_lock;
75 static struct ldlm_state *ldlm_state;
77 inline cfs_time_t round_timeout(cfs_time_t timeout)
79 return cfs_time_seconds((int)cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1);
82 /* timeout for initial callback (AST) reply (bz10399) */
83 static inline unsigned int ldlm_get_rq_timeout(void)
86 unsigned int timeout = min(ldlm_timeout, obd_timeout / 3);
88 return timeout < 1 ? 1 : timeout;
93 #define ELT_TERMINATE 2
96 cfs_spinlock_t blp_lock;
99 * blp_prio_list is used for callbacks that should be handled
100 * as a priority. It is used for LDLM_FL_DISCARD_DATA requests.
103 cfs_list_t blp_prio_list;
106 * blp_list is used for all other callbacks which are likely
107 * to take longer to process.
111 cfs_waitq_t blp_waitq;
112 cfs_completion_t blp_comp;
113 cfs_atomic_t blp_num_threads;
114 cfs_atomic_t blp_busy_threads;
119 struct ldlm_bl_work_item {
120 cfs_list_t blwi_entry;
121 struct ldlm_namespace *blwi_ns;
122 struct ldlm_lock_desc blwi_ld;
123 struct ldlm_lock *blwi_lock;
124 cfs_list_t blwi_head;
126 cfs_completion_t blwi_comp;
128 int blwi_mem_pressure;
131 #if defined(HAVE_SERVER_SUPPORT) && defined(__KERNEL__)
133 /* w_l_spinlock protects both waiting_locks_list and expired_lock_thread */
134 static cfs_spinlock_t waiting_locks_spinlock; /* BH lock (timer) */
135 static cfs_list_t waiting_locks_list;
136 static cfs_timer_t waiting_locks_timer;
138 static struct expired_lock_thread {
139 cfs_waitq_t elt_waitq;
142 cfs_list_t elt_expired_locks;
143 } expired_lock_thread;
145 static inline int have_expired_locks(void)
150 cfs_spin_lock_bh(&waiting_locks_spinlock);
151 need_to_run = !cfs_list_empty(&expired_lock_thread.elt_expired_locks);
152 cfs_spin_unlock_bh(&waiting_locks_spinlock);
157 static int expired_lock_main(void *arg)
159 cfs_list_t *expired = &expired_lock_thread.elt_expired_locks;
160 struct l_wait_info lwi = { 0 };
164 cfs_daemonize("ldlm_elt");
166 expired_lock_thread.elt_state = ELT_READY;
167 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
170 l_wait_event(expired_lock_thread.elt_waitq,
171 have_expired_locks() ||
172 expired_lock_thread.elt_state == ELT_TERMINATE,
175 cfs_spin_lock_bh(&waiting_locks_spinlock);
176 if (expired_lock_thread.elt_dump) {
177 struct libcfs_debug_msg_data msgdata = {
178 .msg_file = __FILE__,
179 .msg_fn = "waiting_locks_callback",
180 .msg_line = expired_lock_thread.elt_dump };
181 cfs_spin_unlock_bh(&waiting_locks_spinlock);
183 /* from waiting_locks_callback, but not in timer */
184 libcfs_debug_dumplog();
185 libcfs_run_lbug_upcall(&msgdata);
187 cfs_spin_lock_bh(&waiting_locks_spinlock);
188 expired_lock_thread.elt_dump = 0;
193 while (!cfs_list_empty(expired)) {
194 struct obd_export *export;
195 struct ldlm_lock *lock;
197 lock = cfs_list_entry(expired->next, struct ldlm_lock,
199 if ((void *)lock < LP_POISON + CFS_PAGE_SIZE &&
200 (void *)lock >= LP_POISON) {
201 cfs_spin_unlock_bh(&waiting_locks_spinlock);
202 CERROR("free lock on elt list %p\n", lock);
205 cfs_list_del_init(&lock->l_pending_chain);
206 if ((void *)lock->l_export < LP_POISON + CFS_PAGE_SIZE &&
207 (void *)lock->l_export >= LP_POISON) {
208 CERROR("lock with free export on elt list %p\n",
210 lock->l_export = NULL;
211 LDLM_ERROR(lock, "free export");
212 /* release extra ref grabbed by
213 * ldlm_add_waiting_lock() or
214 * ldlm_failed_ast() */
215 LDLM_LOCK_RELEASE(lock);
219 if (lock->l_destroyed) {
220 /* release the lock refcount where
221 * waiting_locks_callback() founds */
222 LDLM_LOCK_RELEASE(lock);
225 export = class_export_lock_get(lock->l_export, lock);
226 cfs_spin_unlock_bh(&waiting_locks_spinlock);
229 class_fail_export(export);
230 class_export_lock_put(export, lock);
232 /* release extra ref grabbed by ldlm_add_waiting_lock()
233 * or ldlm_failed_ast() */
234 LDLM_LOCK_RELEASE(lock);
236 cfs_spin_lock_bh(&waiting_locks_spinlock);
238 cfs_spin_unlock_bh(&waiting_locks_spinlock);
240 if (do_dump && obd_dump_on_eviction) {
241 CERROR("dump the log upon eviction\n");
242 libcfs_debug_dumplog();
245 if (expired_lock_thread.elt_state == ELT_TERMINATE)
249 expired_lock_thread.elt_state = ELT_STOPPED;
250 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
254 static int ldlm_add_waiting_lock(struct ldlm_lock *lock);
255 static int __ldlm_add_waiting_lock(struct ldlm_lock *lock, int seconds);
258 * Check if there is a request in the export request list
259 * which prevents the lock canceling.
261 static int ldlm_lock_busy(struct ldlm_lock *lock)
263 struct ptlrpc_request *req;
267 if (lock->l_export == NULL)
270 cfs_spin_lock_bh(&lock->l_export->exp_rpc_lock);
271 cfs_list_for_each_entry(req, &lock->l_export->exp_hp_rpcs,
273 if (req->rq_ops->hpreq_lock_match) {
274 match = req->rq_ops->hpreq_lock_match(req, lock);
279 cfs_spin_unlock_bh(&lock->l_export->exp_rpc_lock);
283 /* This is called from within a timer interrupt and cannot schedule */
284 static void waiting_locks_callback(unsigned long unused)
286 struct ldlm_lock *lock;
289 cfs_spin_lock_bh(&waiting_locks_spinlock);
290 while (!cfs_list_empty(&waiting_locks_list)) {
291 lock = cfs_list_entry(waiting_locks_list.next, struct ldlm_lock,
293 if (cfs_time_after(lock->l_callback_timeout,
294 cfs_time_current()) ||
295 (lock->l_req_mode == LCK_GROUP))
298 if (ptlrpc_check_suspend()) {
299 /* there is a case when we talk to one mds, holding
300 * lock from another mds. this way we easily can get
301 * here, if second mds is being recovered. so, we
302 * suspend timeouts. bug 6019 */
304 LDLM_ERROR(lock, "recharge timeout: %s@%s nid %s ",
305 lock->l_export->exp_client_uuid.uuid,
306 lock->l_export->exp_connection->c_remote_uuid.uuid,
307 libcfs_nid2str(lock->l_export->exp_connection->c_peer.nid));
309 cfs_list_del_init(&lock->l_pending_chain);
310 if (lock->l_destroyed) {
311 /* relay the lock refcount decrease to
312 * expired lock thread */
313 cfs_list_add(&lock->l_pending_chain,
314 &expired_lock_thread.elt_expired_locks);
316 __ldlm_add_waiting_lock(lock,
317 ldlm_get_enq_timeout(lock));
322 /* if timeout overlaps the activation time of suspended timeouts
323 * then extend it to give a chance for client to reconnect */
324 if (cfs_time_before(cfs_time_sub(lock->l_callback_timeout,
325 cfs_time_seconds(obd_timeout)/2),
326 ptlrpc_suspend_wakeup_time())) {
327 LDLM_ERROR(lock, "extend timeout due to recovery: %s@%s nid %s ",
328 lock->l_export->exp_client_uuid.uuid,
329 lock->l_export->exp_connection->c_remote_uuid.uuid,
330 libcfs_nid2str(lock->l_export->exp_connection->c_peer.nid));
332 cfs_list_del_init(&lock->l_pending_chain);
333 if (lock->l_destroyed) {
334 /* relay the lock refcount decrease to
335 * expired lock thread */
336 cfs_list_add(&lock->l_pending_chain,
337 &expired_lock_thread.elt_expired_locks);
339 __ldlm_add_waiting_lock(lock,
340 ldlm_get_enq_timeout(lock));
345 /* Check if we need to prolong timeout */
346 if (!OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT) &&
347 ldlm_lock_busy(lock)) {
350 if (lock->l_pending_chain.next == &waiting_locks_list)
355 cfs_spin_unlock_bh(&waiting_locks_spinlock);
356 LDLM_DEBUG(lock, "prolong the busy lock");
357 ldlm_refresh_waiting_lock(lock,
358 ldlm_get_enq_timeout(lock));
359 cfs_spin_lock_bh(&waiting_locks_spinlock);
362 LDLM_LOCK_RELEASE(lock);
366 LDLM_LOCK_RELEASE(lock);
369 ldlm_lock_to_ns(lock)->ns_timeouts++;
370 LDLM_ERROR(lock, "lock callback timer expired after %lds: "
371 "evicting client at %s ",
372 cfs_time_current_sec()- lock->l_last_activity,
374 lock->l_export->exp_connection->c_peer.nid));
376 /* no needs to take an extra ref on the lock since it was in
377 * the waiting_locks_list and ldlm_add_waiting_lock()
378 * already grabbed a ref */
379 cfs_list_del(&lock->l_pending_chain);
380 cfs_list_add(&lock->l_pending_chain,
381 &expired_lock_thread.elt_expired_locks);
385 if (!cfs_list_empty(&expired_lock_thread.elt_expired_locks)) {
386 if (obd_dump_on_timeout && need_dump)
387 expired_lock_thread.elt_dump = __LINE__;
389 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
393 * Make sure the timer will fire again if we have any locks
396 if (!cfs_list_empty(&waiting_locks_list)) {
397 cfs_time_t timeout_rounded;
398 lock = cfs_list_entry(waiting_locks_list.next, struct ldlm_lock,
400 timeout_rounded = (cfs_time_t)round_timeout(lock->l_callback_timeout);
401 cfs_timer_arm(&waiting_locks_timer, timeout_rounded);
403 cfs_spin_unlock_bh(&waiting_locks_spinlock);
407 * Indicate that we're waiting for a client to call us back cancelling a given
408 * lock. We add it to the pending-callback chain, and schedule the lock-timeout
409 * timer to fire appropriately. (We round up to the next second, to avoid
410 * floods of timer firings during periods of high lock contention and traffic).
411 * As done by ldlm_add_waiting_lock(), the caller must grab a lock reference
412 * if it has been added to the waiting list (1 is returned).
414 * Called with the namespace lock held.
416 static int __ldlm_add_waiting_lock(struct ldlm_lock *lock, int seconds)
419 cfs_time_t timeout_rounded;
421 if (!cfs_list_empty(&lock->l_pending_chain))
424 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT) ||
425 OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT))
428 timeout = cfs_time_shift(seconds);
429 if (likely(cfs_time_after(timeout, lock->l_callback_timeout)))
430 lock->l_callback_timeout = timeout;
432 timeout_rounded = round_timeout(lock->l_callback_timeout);
434 if (cfs_time_before(timeout_rounded,
435 cfs_timer_deadline(&waiting_locks_timer)) ||
436 !cfs_timer_is_armed(&waiting_locks_timer)) {
437 cfs_timer_arm(&waiting_locks_timer, timeout_rounded);
439 /* if the new lock has a shorter timeout than something earlier on
440 the list, we'll wait the longer amount of time; no big deal. */
442 cfs_list_add_tail(&lock->l_pending_chain, &waiting_locks_list);
446 static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
449 int timeout = ldlm_get_enq_timeout(lock);
451 /* NB: must be called with hold of lock_res_and_lock() */
452 LASSERT(lock->l_res_locked);
455 LASSERT(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK));
457 cfs_spin_lock_bh(&waiting_locks_spinlock);
458 if (lock->l_destroyed) {
459 static cfs_time_t next;
460 cfs_spin_unlock_bh(&waiting_locks_spinlock);
461 LDLM_ERROR(lock, "not waiting on destroyed lock (bug 5653)");
462 if (cfs_time_after(cfs_time_current(), next)) {
463 next = cfs_time_shift(14400);
464 libcfs_debug_dumpstack(NULL);
469 ret = __ldlm_add_waiting_lock(lock, timeout);
471 /* grab ref on the lock if it has been added to the
475 cfs_spin_unlock_bh(&waiting_locks_spinlock);
478 cfs_spin_lock_bh(&lock->l_export->exp_bl_list_lock);
479 if (cfs_list_empty(&lock->l_exp_list))
480 cfs_list_add(&lock->l_exp_list,
481 &lock->l_export->exp_bl_list);
482 cfs_spin_unlock_bh(&lock->l_export->exp_bl_list_lock);
485 LDLM_DEBUG(lock, "%sadding to wait list(timeout: %d, AT: %s)",
486 ret == 0 ? "not re-" : "", timeout,
487 AT_OFF ? "off" : "on");
492 * Remove a lock from the pending list, likely because it had its cancellation
493 * callback arrive without incident. This adjusts the lock-timeout timer if
494 * needed. Returns 0 if the lock wasn't pending after all, 1 if it was.
495 * As done by ldlm_del_waiting_lock(), the caller must release the lock
496 * reference when the lock is removed from any list (1 is returned).
498 * Called with namespace lock held.
500 static int __ldlm_del_waiting_lock(struct ldlm_lock *lock)
502 cfs_list_t *list_next;
504 if (cfs_list_empty(&lock->l_pending_chain))
507 list_next = lock->l_pending_chain.next;
508 if (lock->l_pending_chain.prev == &waiting_locks_list) {
509 /* Removing the head of the list, adjust timer. */
510 if (list_next == &waiting_locks_list) {
511 /* No more, just cancel. */
512 cfs_timer_disarm(&waiting_locks_timer);
514 struct ldlm_lock *next;
515 next = cfs_list_entry(list_next, struct ldlm_lock,
517 cfs_timer_arm(&waiting_locks_timer,
518 round_timeout(next->l_callback_timeout));
521 cfs_list_del_init(&lock->l_pending_chain);
526 int ldlm_del_waiting_lock(struct ldlm_lock *lock)
530 if (lock->l_export == NULL) {
531 /* We don't have a "waiting locks list" on clients. */
532 CDEBUG(D_DLMTRACE, "Client lock %p : no-op\n", lock);
536 cfs_spin_lock_bh(&waiting_locks_spinlock);
537 ret = __ldlm_del_waiting_lock(lock);
538 cfs_spin_unlock_bh(&waiting_locks_spinlock);
540 /* remove the lock out of export blocking list */
541 cfs_spin_lock_bh(&lock->l_export->exp_bl_list_lock);
542 cfs_list_del_init(&lock->l_exp_list);
543 cfs_spin_unlock_bh(&lock->l_export->exp_bl_list_lock);
546 /* release lock ref if it has indeed been removed
548 LDLM_LOCK_RELEASE(lock);
551 LDLM_DEBUG(lock, "%s", ret == 0 ? "wasn't waiting" : "removed");
558 * Called with namespace lock held.
560 int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout)
562 if (lock->l_export == NULL) {
563 /* We don't have a "waiting locks list" on clients. */
564 LDLM_DEBUG(lock, "client lock: no-op");
568 cfs_spin_lock_bh(&waiting_locks_spinlock);
570 if (cfs_list_empty(&lock->l_pending_chain)) {
571 cfs_spin_unlock_bh(&waiting_locks_spinlock);
572 LDLM_DEBUG(lock, "wasn't waiting");
576 /* we remove/add the lock to the waiting list, so no needs to
577 * release/take a lock reference */
578 __ldlm_del_waiting_lock(lock);
579 __ldlm_add_waiting_lock(lock, timeout);
580 cfs_spin_unlock_bh(&waiting_locks_spinlock);
582 LDLM_DEBUG(lock, "refreshed");
586 #else /* !HAVE_SERVER_SUPPORT || !__KERNEL__ */
588 int ldlm_del_waiting_lock(struct ldlm_lock *lock)
593 int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout)
598 # ifdef HAVE_SERVER_SUPPORT
599 static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
601 LASSERT(lock->l_res_locked);
602 LASSERT(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK));
607 #endif /* HAVE_SERVER_SUPPORT && __KERNEL__ */
609 #ifdef HAVE_SERVER_SUPPORT
611 static void ldlm_failed_ast(struct ldlm_lock *lock, int rc,
612 const char *ast_type)
614 LCONSOLE_ERROR_MSG(0x138, "%s: A client on nid %s was evicted due "
615 "to a lock %s callback time out: rc %d\n",
616 lock->l_export->exp_obd->obd_name,
617 obd_export_nid2str(lock->l_export), ast_type, rc);
619 if (obd_dump_on_timeout)
620 libcfs_debug_dumplog();
622 cfs_spin_lock_bh(&waiting_locks_spinlock);
623 if (__ldlm_del_waiting_lock(lock) == 0)
624 /* the lock was not in any list, grab an extra ref before adding
625 * the lock to the expired list */
627 cfs_list_add(&lock->l_pending_chain,
628 &expired_lock_thread.elt_expired_locks);
629 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
630 cfs_spin_unlock_bh(&waiting_locks_spinlock);
632 class_fail_export(lock->l_export);
636 static int ldlm_handle_ast_error(struct ldlm_lock *lock,
637 struct ptlrpc_request *req, int rc,
638 const char *ast_type)
640 lnet_process_id_t peer = req->rq_import->imp_connection->c_peer;
642 if (rc == -ETIMEDOUT || rc == -EINTR || rc == -ENOTCONN) {
643 LASSERT(lock->l_export);
644 if (lock->l_export->exp_libclient) {
645 LDLM_DEBUG(lock, "%s AST to liblustre client (nid %s)"
646 " timeout, just cancelling lock", ast_type,
647 libcfs_nid2str(peer.nid));
648 ldlm_lock_cancel(lock);
650 } else if (lock->l_flags & LDLM_FL_CANCEL) {
651 LDLM_DEBUG(lock, "%s AST timeout from nid %s, but "
652 "cancel was received (AST reply lost?)",
653 ast_type, libcfs_nid2str(peer.nid));
654 ldlm_lock_cancel(lock);
657 ldlm_del_waiting_lock(lock);
658 ldlm_failed_ast(lock, rc, ast_type);
662 struct ldlm_resource *res = lock->l_resource;
663 LDLM_DEBUG(lock, "client (nid %s) returned %d"
664 " from %s AST - normal race",
665 libcfs_nid2str(peer.nid),
667 lustre_msg_get_status(req->rq_repmsg) : -1,
670 /* update lvbo to return proper attributes.
672 ldlm_resource_getref(res);
673 ldlm_res_lvbo_update(res, NULL, 1);
674 ldlm_resource_putref(res);
678 LDLM_ERROR(lock, "client (nid %s) returned %d "
679 "from %s AST", libcfs_nid2str(peer.nid),
680 (req->rq_repmsg != NULL) ?
681 lustre_msg_get_status(req->rq_repmsg) : 0,
684 ldlm_lock_cancel(lock);
685 /* Server-side AST functions are called from ldlm_reprocess_all,
686 * which needs to be told to please restart its reprocessing. */
693 static int ldlm_cb_interpret(const struct lu_env *env,
694 struct ptlrpc_request *req, void *data, int rc)
696 struct ldlm_cb_async_args *ca = data;
697 struct ldlm_lock *lock = ca->ca_lock;
698 struct ldlm_cb_set_arg *arg = ca->ca_set_arg;
701 LASSERT(lock != NULL);
703 rc = ldlm_handle_ast_error(lock, req, rc,
704 arg->type == LDLM_BL_CALLBACK
705 ? "blocking" : "completion");
707 cfs_atomic_inc(&arg->restart);
709 LDLM_LOCK_RELEASE(lock);
714 static inline int ldlm_bl_and_cp_ast_tail(struct ptlrpc_request *req,
715 struct ldlm_cb_set_arg *arg,
716 struct ldlm_lock *lock,
722 if (unlikely(instant_cancel)) {
723 rc = ptl_send_rpc(req, 1);
724 ptlrpc_req_finished(req);
726 cfs_atomic_inc(&arg->restart);
729 ptlrpc_set_add_req(arg->set, req);
736 * Check if there are requests in the export request list which prevent
737 * the lock canceling and make these requests high priority ones.
739 static void ldlm_lock_reorder_req(struct ldlm_lock *lock)
741 struct ptlrpc_request *req;
744 if (lock->l_export == NULL) {
745 LDLM_DEBUG(lock, "client lock: no-op");
749 cfs_spin_lock_bh(&lock->l_export->exp_rpc_lock);
750 cfs_list_for_each_entry(req, &lock->l_export->exp_hp_rpcs,
752 /* Do not process requests that were not yet added to there
753 * incoming queue or were already removed from there for
755 if (!req->rq_hp && !cfs_list_empty(&req->rq_list) &&
756 req->rq_ops->hpreq_lock_match &&
757 req->rq_ops->hpreq_lock_match(req, lock))
758 ptlrpc_hpreq_reorder(req);
760 cfs_spin_unlock_bh(&lock->l_export->exp_rpc_lock);
765 * ->l_blocking_ast() method for server-side locks. This is invoked when newly
766 * enqueued server lock conflicts with given one.
768 * Sends blocking ast rpc to the client owning that lock; arms timeout timer
769 * to wait for client response.
771 int ldlm_server_blocking_ast(struct ldlm_lock *lock,
772 struct ldlm_lock_desc *desc,
773 void *data, int flag)
775 struct ldlm_cb_async_args *ca;
776 struct ldlm_cb_set_arg *arg = data;
777 struct ldlm_request *body;
778 struct ptlrpc_request *req;
779 int instant_cancel = 0;
783 if (flag == LDLM_CB_CANCELING)
784 /* Don't need to do anything here. */
788 LASSERT(data != NULL);
789 if (lock->l_export->exp_obd->obd_recovering != 0)
790 LDLM_ERROR(lock, "BUG 6063: lock collide during recovery");
792 ldlm_lock_reorder_req(lock);
794 req = ptlrpc_request_alloc_pack(lock->l_export->exp_imp_reverse,
795 &RQF_LDLM_BL_CALLBACK,
796 LUSTRE_DLM_VERSION, LDLM_BL_CALLBACK);
800 CLASSERT(sizeof(*ca) <= sizeof(req->rq_async_args));
801 ca = ptlrpc_req_async_args(req);
802 ca->ca_set_arg = arg;
805 req->rq_interpret_reply = ldlm_cb_interpret;
806 req->rq_no_resend = 1;
808 lock_res_and_lock(lock);
809 if (lock->l_granted_mode != lock->l_req_mode) {
810 /* this blocking AST will be communicated as part of the
811 * completion AST instead */
812 unlock_res_and_lock(lock);
814 ptlrpc_req_finished(req);
815 LDLM_DEBUG(lock, "lock not granted, not sending blocking AST");
819 if (lock->l_destroyed) {
820 /* What's the point? */
821 unlock_res_and_lock(lock);
822 ptlrpc_req_finished(req);
826 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)
829 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
830 body->lock_handle[0] = lock->l_remote_handle;
831 body->lock_desc = *desc;
832 body->lock_flags |= (lock->l_flags & LDLM_AST_FLAGS);
834 LDLM_DEBUG(lock, "server preparing blocking AST");
836 ptlrpc_request_set_replen(req);
837 if (instant_cancel) {
838 unlock_res_and_lock(lock);
839 ldlm_lock_cancel(lock);
841 LASSERT(lock->l_granted_mode == lock->l_req_mode);
842 ldlm_add_waiting_lock(lock);
843 unlock_res_and_lock(lock);
846 req->rq_send_state = LUSTRE_IMP_FULL;
847 /* ptlrpc_request_alloc_pack already set timeout */
849 req->rq_timeout = ldlm_get_rq_timeout();
851 if (lock->l_export && lock->l_export->exp_nid_stats &&
852 lock->l_export->exp_nid_stats->nid_ldlm_stats)
853 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
854 LDLM_BL_CALLBACK - LDLM_FIRST_OPC);
856 rc = ldlm_bl_and_cp_ast_tail(req, arg, lock, instant_cancel);
861 int ldlm_server_completion_ast(struct ldlm_lock *lock, int flags, void *data)
863 struct ldlm_cb_set_arg *arg = data;
864 struct ldlm_request *body;
865 struct ptlrpc_request *req;
866 struct ldlm_cb_async_args *ca;
867 long total_enqueue_wait;
868 int instant_cancel = 0;
872 LASSERT(lock != NULL);
873 LASSERT(data != NULL);
875 total_enqueue_wait = cfs_time_sub(cfs_time_current_sec(),
876 lock->l_last_activity);
878 req = ptlrpc_request_alloc(lock->l_export->exp_imp_reverse,
879 &RQF_LDLM_CP_CALLBACK);
883 /* server namespace, doesn't need lock */
884 if (lock->l_resource->lr_lvb_len) {
885 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_CLIENT,
886 lock->l_resource->lr_lvb_len);
889 rc = ptlrpc_request_pack(req, LUSTRE_DLM_VERSION, LDLM_CP_CALLBACK);
891 ptlrpc_request_free(req);
895 CLASSERT(sizeof(*ca) <= sizeof(req->rq_async_args));
896 ca = ptlrpc_req_async_args(req);
897 ca->ca_set_arg = arg;
900 req->rq_interpret_reply = ldlm_cb_interpret;
901 req->rq_no_resend = 1;
902 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
904 body->lock_handle[0] = lock->l_remote_handle;
905 body->lock_flags = flags;
906 ldlm_lock2desc(lock, &body->lock_desc);
907 if (lock->l_resource->lr_lvb_len) {
908 void *lvb = req_capsule_client_get(&req->rq_pill, &RMF_DLM_LVB);
910 lock_res(lock->l_resource);
911 memcpy(lvb, lock->l_resource->lr_lvb_data,
912 lock->l_resource->lr_lvb_len);
913 unlock_res(lock->l_resource);
916 LDLM_DEBUG(lock, "server preparing completion AST (after %lds wait)",
919 /* Server-side enqueue wait time estimate, used in
920 __ldlm_add_waiting_lock to set future enqueue timers */
921 if (total_enqueue_wait < ldlm_get_enq_timeout(lock))
922 at_measured(ldlm_lock_to_ns_at(lock),
925 /* bz18618. Don't add lock enqueue time we spend waiting for a
926 previous callback to fail. Locks waiting legitimately will
927 get extended by ldlm_refresh_waiting_lock regardless of the
928 estimate, so it's okay to underestimate here. */
929 LDLM_DEBUG(lock, "lock completed after %lus; estimate was %ds. "
930 "It is likely that a previous callback timed out.",
932 at_get(ldlm_lock_to_ns_at(lock)));
934 ptlrpc_request_set_replen(req);
936 req->rq_send_state = LUSTRE_IMP_FULL;
937 /* ptlrpc_request_pack already set timeout */
939 req->rq_timeout = ldlm_get_rq_timeout();
941 /* We only send real blocking ASTs after the lock is granted */
942 lock_res_and_lock(lock);
943 if (lock->l_flags & LDLM_FL_AST_SENT) {
944 body->lock_flags |= LDLM_FL_AST_SENT;
945 /* copy ast flags like LDLM_FL_DISCARD_DATA */
946 body->lock_flags |= (lock->l_flags & LDLM_AST_FLAGS);
948 /* We might get here prior to ldlm_handle_enqueue setting
949 * LDLM_FL_CANCEL_ON_BLOCK flag. Then we will put this lock
950 * into waiting list, but this is safe and similar code in
951 * ldlm_handle_enqueue will call ldlm_lock_cancel() still,
952 * that would not only cancel the lock, but will also remove
953 * it from waiting list */
954 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK) {
955 unlock_res_and_lock(lock);
956 ldlm_lock_cancel(lock);
958 lock_res_and_lock(lock);
960 /* start the lock-timeout clock */
961 ldlm_add_waiting_lock(lock);
964 unlock_res_and_lock(lock);
966 if (lock->l_export && lock->l_export->exp_nid_stats &&
967 lock->l_export->exp_nid_stats->nid_ldlm_stats)
968 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
969 LDLM_CP_CALLBACK - LDLM_FIRST_OPC);
971 rc = ldlm_bl_and_cp_ast_tail(req, arg, lock, instant_cancel);
976 int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data)
978 struct ldlm_resource *res = lock->l_resource;
979 struct ldlm_request *body;
980 struct ptlrpc_request *req;
984 LASSERT(lock != NULL);
986 req = ptlrpc_request_alloc_pack(lock->l_export->exp_imp_reverse,
987 &RQF_LDLM_GL_CALLBACK,
988 LUSTRE_DLM_VERSION, LDLM_GL_CALLBACK);
993 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
994 body->lock_handle[0] = lock->l_remote_handle;
995 ldlm_lock2desc(lock, &body->lock_desc);
997 /* server namespace, doesn't need lock */
998 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER,
999 lock->l_resource->lr_lvb_len);
1000 res = lock->l_resource;
1001 ptlrpc_request_set_replen(req);
1004 req->rq_send_state = LUSTRE_IMP_FULL;
1005 /* ptlrpc_request_alloc_pack already set timeout */
1007 req->rq_timeout = ldlm_get_rq_timeout();
1009 if (lock->l_export && lock->l_export->exp_nid_stats &&
1010 lock->l_export->exp_nid_stats->nid_ldlm_stats)
1011 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
1012 LDLM_GL_CALLBACK - LDLM_FIRST_OPC);
1014 rc = ptlrpc_queue_wait(req);
1015 /* Update the LVB from disk if the AST failed (this is a legal race)
1017 * - Glimpse callback of local lock just return -ELDLM_NO_LOCK_DATA.
1018 * - Glimpse callback of remote lock might return -ELDLM_NO_LOCK_DATA
1019 * when inode is cleared. LU-274
1021 if (rc == -ELDLM_NO_LOCK_DATA) {
1022 LDLM_DEBUG(lock, "lost race - client has a lock but no inode");
1023 ldlm_res_lvbo_update(res, NULL, 1);
1024 } else if (rc != 0) {
1025 rc = ldlm_handle_ast_error(lock, req, rc, "glimpse");
1027 rc = ldlm_res_lvbo_update(res, req, 1);
1030 ptlrpc_req_finished(req);
1031 if (rc == -ERESTART)
1032 ldlm_reprocess_all(res);
1037 static void ldlm_svc_get_eopc(const struct ldlm_request *dlm_req,
1038 struct lprocfs_stats *srv_stats)
1040 int lock_type = 0, op = 0;
1042 lock_type = dlm_req->lock_desc.l_resource.lr_type;
1044 switch (lock_type) {
1046 op = PTLRPC_LAST_CNTR + LDLM_PLAIN_ENQUEUE;
1049 if (dlm_req->lock_flags & LDLM_FL_HAS_INTENT)
1050 op = PTLRPC_LAST_CNTR + LDLM_GLIMPSE_ENQUEUE;
1052 op = PTLRPC_LAST_CNTR + LDLM_EXTENT_ENQUEUE;
1055 op = PTLRPC_LAST_CNTR + LDLM_FLOCK_ENQUEUE;
1058 op = PTLRPC_LAST_CNTR + LDLM_IBITS_ENQUEUE;
1066 lprocfs_counter_incr(srv_stats, op);
1072 * Main server-side entry point into LDLM. This is called by ptlrpc service
1073 * threads to carry out client lock enqueueing requests.
1075 int ldlm_handle_enqueue0(struct ldlm_namespace *ns,
1076 struct ptlrpc_request *req,
1077 const struct ldlm_request *dlm_req,
1078 const struct ldlm_callback_suite *cbs)
1080 struct ldlm_reply *dlm_rep;
1082 ldlm_error_t err = ELDLM_OK;
1083 struct ldlm_lock *lock = NULL;
1084 void *cookie = NULL;
1088 LDLM_DEBUG_NOLOCK("server-side enqueue handler START");
1090 ldlm_request_cancel(req, dlm_req, LDLM_ENQUEUE_CANCEL_OFF);
1091 flags = dlm_req->lock_flags;
1093 LASSERT(req->rq_export);
1095 if (ptlrpc_req2svc(req)->srv_stats != NULL)
1096 ldlm_svc_get_eopc(dlm_req, ptlrpc_req2svc(req)->srv_stats);
1098 if (req->rq_export && req->rq_export->exp_nid_stats &&
1099 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1100 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1101 LDLM_ENQUEUE - LDLM_FIRST_OPC);
1103 if (unlikely(dlm_req->lock_desc.l_resource.lr_type < LDLM_MIN_TYPE ||
1104 dlm_req->lock_desc.l_resource.lr_type >= LDLM_MAX_TYPE)) {
1105 DEBUG_REQ(D_ERROR, req, "invalid lock request type %d",
1106 dlm_req->lock_desc.l_resource.lr_type);
1107 GOTO(out, rc = -EFAULT);
1110 if (unlikely(dlm_req->lock_desc.l_req_mode <= LCK_MINMODE ||
1111 dlm_req->lock_desc.l_req_mode >= LCK_MAXMODE ||
1112 dlm_req->lock_desc.l_req_mode &
1113 (dlm_req->lock_desc.l_req_mode-1))) {
1114 DEBUG_REQ(D_ERROR, req, "invalid lock request mode %d",
1115 dlm_req->lock_desc.l_req_mode);
1116 GOTO(out, rc = -EFAULT);
1119 if (req->rq_export->exp_connect_flags & OBD_CONNECT_IBITS) {
1120 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
1122 DEBUG_REQ(D_ERROR, req,
1123 "PLAIN lock request from IBITS client?");
1124 GOTO(out, rc = -EPROTO);
1126 } else if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
1128 DEBUG_REQ(D_ERROR, req,
1129 "IBITS lock request from unaware client?");
1130 GOTO(out, rc = -EPROTO);
1134 /* FIXME this makes it impossible to use LDLM_PLAIN locks -- check
1135 against server's _CONNECT_SUPPORTED flags? (I don't want to use
1136 ibits for mgc/mgs) */
1138 /* INODEBITS_INTEROP: Perform conversion from plain lock to
1139 * inodebits lock if client does not support them. */
1140 if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_IBITS) &&
1141 (dlm_req->lock_desc.l_resource.lr_type == LDLM_PLAIN)) {
1142 dlm_req->lock_desc.l_resource.lr_type = LDLM_IBITS;
1143 dlm_req->lock_desc.l_policy_data.l_inodebits.bits =
1144 MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
1145 if (dlm_req->lock_desc.l_req_mode == LCK_PR)
1146 dlm_req->lock_desc.l_req_mode = LCK_CR;
1150 if (unlikely(flags & LDLM_FL_REPLAY)) {
1151 /* Find an existing lock in the per-export lock hash */
1152 lock = cfs_hash_lookup(req->rq_export->exp_lock_hash,
1153 (void *)&dlm_req->lock_handle[0]);
1155 DEBUG_REQ(D_DLMTRACE, req, "found existing lock cookie "
1156 LPX64, lock->l_handle.h_cookie);
1157 GOTO(existing_lock, rc = 0);
1161 /* The lock's callback data might be set in the policy function */
1162 lock = ldlm_lock_create(ns, &dlm_req->lock_desc.l_resource.lr_name,
1163 dlm_req->lock_desc.l_resource.lr_type,
1164 dlm_req->lock_desc.l_req_mode,
1168 GOTO(out, rc = -ENOMEM);
1170 lock->l_last_activity = cfs_time_current_sec();
1171 lock->l_remote_handle = dlm_req->lock_handle[0];
1172 LDLM_DEBUG(lock, "server-side enqueue handler, new lock created");
1174 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_ENQUEUE_BLOCKED, obd_timeout * 2);
1175 /* Don't enqueue a lock onto the export if it is been disonnected
1176 * due to eviction (bug 3822) or server umount (bug 24324).
1177 * Cancel it now instead. */
1178 if (req->rq_export->exp_disconnected) {
1179 LDLM_ERROR(lock, "lock on disconnected export %p",
1181 GOTO(out, rc = -ENOTCONN);
1184 lock->l_export = class_export_lock_get(req->rq_export, lock);
1185 if (lock->l_export->exp_lock_hash)
1186 cfs_hash_add(lock->l_export->exp_lock_hash,
1187 &lock->l_remote_handle,
1192 if (flags & LDLM_FL_HAS_INTENT) {
1193 /* In this case, the reply buffer is allocated deep in
1194 * local_lock_enqueue by the policy function. */
1197 /* based on the assumption that lvb size never changes during
1198 * resource life time otherwise it need resource->lr_lock's
1200 if (lock->l_resource->lr_lvb_len) {
1201 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB,
1203 lock->l_resource->lr_lvb_len);
1206 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR))
1207 GOTO(out, rc = -ENOMEM);
1209 rc = req_capsule_server_pack(&req->rq_pill);
1214 if (dlm_req->lock_desc.l_resource.lr_type != LDLM_PLAIN)
1215 ldlm_convert_policy_to_local(req->rq_export,
1216 dlm_req->lock_desc.l_resource.lr_type,
1217 &dlm_req->lock_desc.l_policy_data,
1218 &lock->l_policy_data);
1219 if (dlm_req->lock_desc.l_resource.lr_type == LDLM_EXTENT)
1220 lock->l_req_extent = lock->l_policy_data.l_extent;
1222 err = ldlm_lock_enqueue(ns, &lock, cookie, (int *)&flags);
1226 dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
1227 dlm_rep->lock_flags = flags;
1229 ldlm_lock2desc(lock, &dlm_rep->lock_desc);
1230 ldlm_lock2handle(lock, &dlm_rep->lock_handle);
1232 /* We never send a blocking AST until the lock is granted, but
1233 * we can tell it right now */
1234 lock_res_and_lock(lock);
1236 /* Now take into account flags to be inherited from original lock
1237 request both in reply to client and in our own lock flags. */
1238 dlm_rep->lock_flags |= dlm_req->lock_flags & LDLM_INHERIT_FLAGS;
1239 lock->l_flags |= dlm_req->lock_flags & LDLM_INHERIT_FLAGS;
1241 /* Don't move a pending lock onto the export if it has already been
1242 * disconnected due to eviction (bug 5683) or server umount (bug 24324).
1243 * Cancel it now instead. */
1244 if (unlikely(req->rq_export->exp_disconnected ||
1245 OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT))) {
1246 LDLM_ERROR(lock, "lock on destroyed export %p", req->rq_export);
1248 } else if (lock->l_flags & LDLM_FL_AST_SENT) {
1249 dlm_rep->lock_flags |= LDLM_FL_AST_SENT;
1250 if (lock->l_granted_mode == lock->l_req_mode) {
1252 * Only cancel lock if it was granted, because it would
1253 * be destroyed immediately and would never be granted
1254 * in the future, causing timeouts on client. Not
1255 * granted lock will be cancelled immediately after
1256 * sending completion AST.
1258 if (dlm_rep->lock_flags & LDLM_FL_CANCEL_ON_BLOCK) {
1259 unlock_res_and_lock(lock);
1260 ldlm_lock_cancel(lock);
1261 lock_res_and_lock(lock);
1263 ldlm_add_waiting_lock(lock);
1266 /* Make sure we never ever grant usual metadata locks to liblustre
1268 if ((dlm_req->lock_desc.l_resource.lr_type == LDLM_PLAIN ||
1269 dlm_req->lock_desc.l_resource.lr_type == LDLM_IBITS) &&
1270 req->rq_export->exp_libclient) {
1271 if (unlikely(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK) ||
1272 !(dlm_rep->lock_flags & LDLM_FL_CANCEL_ON_BLOCK))){
1273 CERROR("Granting sync lock to libclient. "
1274 "req fl %d, rep fl %d, lock fl "LPX64"\n",
1275 dlm_req->lock_flags, dlm_rep->lock_flags,
1277 LDLM_ERROR(lock, "sync lock");
1278 if (dlm_req->lock_flags & LDLM_FL_HAS_INTENT) {
1279 struct ldlm_intent *it;
1281 it = req_capsule_client_get(&req->rq_pill,
1284 CERROR("This is intent %s ("LPU64")\n",
1285 ldlm_it2str(it->opc), it->opc);
1291 unlock_res_and_lock(lock);
1295 req->rq_status = rc ?: err; /* return either error - bug 11190 */
1296 if (!req->rq_packed_final) {
1297 err = lustre_pack_reply(req, 1, NULL, NULL);
1302 /* The LOCK_CHANGED code in ldlm_lock_enqueue depends on this
1303 * ldlm_reprocess_all. If this moves, revisit that code. -phil */
1305 LDLM_DEBUG(lock, "server-side enqueue handler, sending reply"
1306 "(err=%d, rc=%d)", err, rc);
1309 if (lock->l_resource->lr_lvb_len > 0) {
1310 /* MDT path won't handle lr_lvb_data, so
1311 * lock/unlock better be contained in the
1315 lvb = req_capsule_server_get(&req->rq_pill,
1317 LASSERTF(lvb != NULL, "req %p, lock %p\n",
1319 lock_res(lock->l_resource);
1320 memcpy(lvb, lock->l_resource->lr_lvb_data,
1321 lock->l_resource->lr_lvb_len);
1322 unlock_res(lock->l_resource);
1325 lock_res_and_lock(lock);
1326 ldlm_resource_unlink_lock(lock);
1327 ldlm_lock_destroy_nolock(lock);
1328 unlock_res_and_lock(lock);
1331 if (!err && dlm_req->lock_desc.l_resource.lr_type != LDLM_FLOCK)
1332 ldlm_reprocess_all(lock->l_resource);
1334 LDLM_LOCK_RELEASE(lock);
1337 LDLM_DEBUG_NOLOCK("server-side enqueue handler END (lock %p, rc %d)",
1343 int ldlm_handle_enqueue(struct ptlrpc_request *req,
1344 ldlm_completion_callback completion_callback,
1345 ldlm_blocking_callback blocking_callback,
1346 ldlm_glimpse_callback glimpse_callback)
1348 struct ldlm_request *dlm_req;
1349 struct ldlm_callback_suite cbs = {
1350 .lcs_completion = completion_callback,
1351 .lcs_blocking = blocking_callback,
1352 .lcs_glimpse = glimpse_callback
1356 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1357 if (dlm_req != NULL) {
1358 rc = ldlm_handle_enqueue0(req->rq_export->exp_obd->obd_namespace,
1359 req, dlm_req, &cbs);
1366 int ldlm_handle_convert0(struct ptlrpc_request *req,
1367 const struct ldlm_request *dlm_req)
1369 struct ldlm_reply *dlm_rep;
1370 struct ldlm_lock *lock;
1374 if (req->rq_export && req->rq_export->exp_nid_stats &&
1375 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1376 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1377 LDLM_CONVERT - LDLM_FIRST_OPC);
1379 rc = req_capsule_server_pack(&req->rq_pill);
1383 dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
1384 dlm_rep->lock_flags = dlm_req->lock_flags;
1386 lock = ldlm_handle2lock(&dlm_req->lock_handle[0]);
1388 req->rq_status = EINVAL;
1392 LDLM_DEBUG(lock, "server-side convert handler START");
1394 lock->l_last_activity = cfs_time_current_sec();
1395 res = ldlm_lock_convert(lock, dlm_req->lock_desc.l_req_mode,
1396 &dlm_rep->lock_flags);
1398 if (ldlm_del_waiting_lock(lock))
1399 LDLM_DEBUG(lock, "converted waiting lock");
1402 req->rq_status = EDEADLOCK;
1407 if (!req->rq_status)
1408 ldlm_reprocess_all(lock->l_resource);
1409 LDLM_DEBUG(lock, "server-side convert handler END");
1410 LDLM_LOCK_PUT(lock);
1412 LDLM_DEBUG_NOLOCK("server-side convert handler END");
1417 int ldlm_handle_convert(struct ptlrpc_request *req)
1420 struct ldlm_request *dlm_req;
1422 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1423 if (dlm_req != NULL) {
1424 rc = ldlm_handle_convert0(req, dlm_req);
1426 CERROR ("Can't unpack dlm_req\n");
1432 /* Cancel all the locks whos handles are packed into ldlm_request */
1433 int ldlm_request_cancel(struct ptlrpc_request *req,
1434 const struct ldlm_request *dlm_req, int first)
1436 struct ldlm_resource *res, *pres = NULL;
1437 struct ldlm_lock *lock;
1438 int i, count, done = 0;
1441 count = dlm_req->lock_count ? dlm_req->lock_count : 1;
1445 /* There is no lock on the server at the replay time,
1446 * skip lock cancelling to make replay tests to pass. */
1447 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1450 LDLM_DEBUG_NOLOCK("server-side cancel handler START: %d locks, "
1451 "starting at %d", count, first);
1453 for (i = first; i < count; i++) {
1454 lock = ldlm_handle2lock(&dlm_req->lock_handle[i]);
1456 LDLM_DEBUG_NOLOCK("server-side cancel handler stale "
1457 "lock (cookie "LPU64")",
1458 dlm_req->lock_handle[i].cookie);
1462 res = lock->l_resource;
1467 ldlm_reprocess_all(pres);
1468 LDLM_RESOURCE_DELREF(pres);
1469 ldlm_resource_putref(pres);
1472 ldlm_resource_getref(res);
1473 LDLM_RESOURCE_ADDREF(res);
1474 ldlm_res_lvbo_update(res, NULL, 1);
1478 ldlm_lock_cancel(lock);
1479 LDLM_LOCK_PUT(lock);
1482 ldlm_reprocess_all(pres);
1483 LDLM_RESOURCE_DELREF(pres);
1484 ldlm_resource_putref(pres);
1486 LDLM_DEBUG_NOLOCK("server-side cancel handler END");
1490 int ldlm_handle_cancel(struct ptlrpc_request *req)
1492 struct ldlm_request *dlm_req;
1496 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1497 if (dlm_req == NULL) {
1498 CDEBUG(D_INFO, "bad request buffer for cancel\n");
1502 if (req->rq_export && req->rq_export->exp_nid_stats &&
1503 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1504 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1505 LDLM_CANCEL - LDLM_FIRST_OPC);
1507 rc = req_capsule_server_pack(&req->rq_pill);
1511 if (!ldlm_request_cancel(req, dlm_req, 0))
1512 req->rq_status = ESTALE;
1514 RETURN(ptlrpc_reply(req));
1516 #endif /* HAVE_SERVER_SUPPORT */
1518 void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
1519 struct ldlm_lock_desc *ld, struct ldlm_lock *lock)
1524 LDLM_DEBUG(lock, "client blocking AST callback handler");
1526 lock_res_and_lock(lock);
1527 lock->l_flags |= LDLM_FL_CBPENDING;
1529 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)
1530 lock->l_flags |= LDLM_FL_CANCEL;
1532 do_ast = (!lock->l_readers && !lock->l_writers);
1533 unlock_res_and_lock(lock);
1536 CDEBUG(D_DLMTRACE, "Lock %p already unused, calling callback (%p)\n",
1537 lock, lock->l_blocking_ast);
1538 if (lock->l_blocking_ast != NULL)
1539 lock->l_blocking_ast(lock, ld, lock->l_ast_data,
1542 CDEBUG(D_DLMTRACE, "Lock %p is referenced, will be cancelled later\n",
1546 LDLM_DEBUG(lock, "client blocking callback handler END");
1547 LDLM_LOCK_RELEASE(lock);
1551 static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
1552 struct ldlm_namespace *ns,
1553 struct ldlm_request *dlm_req,
1554 struct ldlm_lock *lock)
1557 CFS_LIST_HEAD(ast_list);
1560 LDLM_DEBUG(lock, "client completion callback handler START");
1562 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE)) {
1563 int to = cfs_time_seconds(1);
1565 cfs_schedule_timeout_and_set_state(
1566 CFS_TASK_INTERRUPTIBLE, to);
1567 if (lock->l_granted_mode == lock->l_req_mode ||
1573 lvb_len = req_capsule_get_size(&req->rq_pill, &RMF_DLM_LVB, RCL_CLIENT);
1575 if (lock->l_lvb_len > 0) {
1576 /* for extent lock, lvb contains ost_lvb{}. */
1577 LASSERT(lock->l_lvb_data != NULL);
1578 LASSERTF(lock->l_lvb_len == lvb_len,
1579 "preallocated %d, actual %d.\n",
1580 lock->l_lvb_len, lvb_len);
1581 } else { /* for layout lock, lvb has variable length */
1584 OBD_ALLOC(lvb_data, lvb_len);
1585 if (lvb_data == NULL)
1586 LDLM_ERROR(lock, "no memory.\n");
1588 lock_res_and_lock(lock);
1589 if (lvb_data == NULL) {
1590 lock->l_flags |= LDLM_FL_FAILED;
1592 LASSERT(lock->l_lvb_data == NULL);
1593 lock->l_lvb_data = lvb_data;
1594 lock->l_lvb_len = lvb_len;
1596 unlock_res_and_lock(lock);
1600 lock_res_and_lock(lock);
1601 if (lock->l_destroyed ||
1602 lock->l_granted_mode == lock->l_req_mode) {
1603 /* bug 11300: the lock has already been granted */
1604 unlock_res_and_lock(lock);
1605 LDLM_DEBUG(lock, "Double grant race happened");
1606 LDLM_LOCK_RELEASE(lock);
1611 /* If we receive the completion AST before the actual enqueue returned,
1612 * then we might need to switch lock modes, resources, or extents. */
1613 if (dlm_req->lock_desc.l_granted_mode != lock->l_req_mode) {
1614 lock->l_req_mode = dlm_req->lock_desc.l_granted_mode;
1615 LDLM_DEBUG(lock, "completion AST, new lock mode");
1618 if (lock->l_resource->lr_type != LDLM_PLAIN) {
1619 ldlm_convert_policy_to_local(req->rq_export,
1620 dlm_req->lock_desc.l_resource.lr_type,
1621 &dlm_req->lock_desc.l_policy_data,
1622 &lock->l_policy_data);
1623 LDLM_DEBUG(lock, "completion AST, new policy data");
1626 ldlm_resource_unlink_lock(lock);
1627 if (memcmp(&dlm_req->lock_desc.l_resource.lr_name,
1628 &lock->l_resource->lr_name,
1629 sizeof(lock->l_resource->lr_name)) != 0) {
1630 unlock_res_and_lock(lock);
1631 if (ldlm_lock_change_resource(ns, lock,
1632 &dlm_req->lock_desc.l_resource.lr_name) != 0) {
1633 LDLM_ERROR(lock, "Failed to allocate resource");
1634 LDLM_LOCK_RELEASE(lock);
1638 LDLM_DEBUG(lock, "completion AST, new resource");
1639 CERROR("change resource!\n");
1640 lock_res_and_lock(lock);
1643 if (dlm_req->lock_flags & LDLM_FL_AST_SENT) {
1644 /* BL_AST locks are not needed in lru.
1645 * let ldlm_cancel_lru() be fast. */
1646 ldlm_lock_remove_from_lru(lock);
1647 lock->l_flags |= LDLM_FL_CBPENDING | LDLM_FL_BL_AST;
1648 LDLM_DEBUG(lock, "completion AST includes blocking AST");
1651 if (lock->l_lvb_len) {
1652 if (req_capsule_get_size(&req->rq_pill, &RMF_DLM_LVB,
1653 RCL_CLIENT) < lock->l_lvb_len) {
1654 LDLM_ERROR(lock, "completion AST did not contain "
1657 void *lvb = req_capsule_client_get(&req->rq_pill,
1659 memcpy(lock->l_lvb_data, lvb, lock->l_lvb_len);
1663 ldlm_grant_lock(lock, &ast_list);
1664 unlock_res_and_lock(lock);
1666 LDLM_DEBUG(lock, "callback handler finished, about to run_ast_work");
1668 /* Let Enqueue to call osc_lock_upcall() and initialize
1670 OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_CP_ENQ_RACE, 2);
1672 ldlm_run_ast_work(ns, &ast_list, LDLM_WORK_CP_AST);
1674 LDLM_DEBUG_NOLOCK("client completion callback handler END (lock %p)",
1676 LDLM_LOCK_RELEASE(lock);
1680 static void ldlm_handle_gl_callback(struct ptlrpc_request *req,
1681 struct ldlm_namespace *ns,
1682 struct ldlm_request *dlm_req,
1683 struct ldlm_lock *lock)
1688 LDLM_DEBUG(lock, "client glimpse AST callback handler");
1690 if (lock->l_glimpse_ast != NULL)
1691 rc = lock->l_glimpse_ast(lock, req);
1693 if (req->rq_repmsg != NULL) {
1696 req->rq_status = rc;
1700 lock_res_and_lock(lock);
1701 if (lock->l_granted_mode == LCK_PW &&
1702 !lock->l_readers && !lock->l_writers &&
1703 cfs_time_after(cfs_time_current(),
1704 cfs_time_add(lock->l_last_used,
1705 cfs_time_seconds(10)))) {
1706 unlock_res_and_lock(lock);
1707 if (ldlm_bl_to_thread_lock(ns, NULL, lock))
1708 ldlm_handle_bl_callback(ns, NULL, lock);
1713 unlock_res_and_lock(lock);
1714 LDLM_LOCK_RELEASE(lock);
1718 static int ldlm_callback_reply(struct ptlrpc_request *req, int rc)
1720 if (req->rq_no_reply)
1723 req->rq_status = rc;
1724 if (!req->rq_packed_final) {
1725 rc = lustre_pack_reply(req, 1, NULL, NULL);
1729 return ptlrpc_reply(req);
1733 static int __ldlm_bl_to_thread(struct ldlm_bl_work_item *blwi, int mode)
1735 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
1738 cfs_spin_lock(&blp->blp_lock);
1739 if (blwi->blwi_lock && blwi->blwi_lock->l_flags & LDLM_FL_DISCARD_DATA) {
1740 /* add LDLM_FL_DISCARD_DATA requests to the priority list */
1741 cfs_list_add_tail(&blwi->blwi_entry, &blp->blp_prio_list);
1743 /* other blocking callbacks are added to the regular list */
1744 cfs_list_add_tail(&blwi->blwi_entry, &blp->blp_list);
1746 cfs_spin_unlock(&blp->blp_lock);
1748 cfs_waitq_signal(&blp->blp_waitq);
1750 /* can not use blwi->blwi_mode as blwi could be already freed in
1752 if (mode == LDLM_SYNC)
1753 cfs_wait_for_completion(&blwi->blwi_comp);
1758 static inline void init_blwi(struct ldlm_bl_work_item *blwi,
1759 struct ldlm_namespace *ns,
1760 struct ldlm_lock_desc *ld,
1761 cfs_list_t *cancels, int count,
1762 struct ldlm_lock *lock,
1765 cfs_init_completion(&blwi->blwi_comp);
1766 CFS_INIT_LIST_HEAD(&blwi->blwi_head);
1768 if (cfs_memory_pressure_get())
1769 blwi->blwi_mem_pressure = 1;
1772 blwi->blwi_mode = mode;
1774 blwi->blwi_ld = *ld;
1776 cfs_list_add(&blwi->blwi_head, cancels);
1777 cfs_list_del_init(cancels);
1778 blwi->blwi_count = count;
1780 blwi->blwi_lock = lock;
1784 static int ldlm_bl_to_thread(struct ldlm_namespace *ns,
1785 struct ldlm_lock_desc *ld, struct ldlm_lock *lock,
1786 cfs_list_t *cancels, int count, int mode)
1790 if (cancels && count == 0)
1793 if (mode == LDLM_SYNC) {
1794 /* if it is synchronous call do minimum mem alloc, as it could
1795 * be triggered from kernel shrinker
1797 struct ldlm_bl_work_item blwi;
1798 memset(&blwi, 0, sizeof(blwi));
1799 init_blwi(&blwi, ns, ld, cancels, count, lock, LDLM_SYNC);
1800 RETURN(__ldlm_bl_to_thread(&blwi, LDLM_SYNC));
1802 struct ldlm_bl_work_item *blwi;
1803 OBD_ALLOC(blwi, sizeof(*blwi));
1806 init_blwi(blwi, ns, ld, cancels, count, lock, LDLM_ASYNC);
1808 RETURN(__ldlm_bl_to_thread(blwi, LDLM_ASYNC));
1814 int ldlm_bl_to_thread_lock(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
1815 struct ldlm_lock *lock)
1818 RETURN(ldlm_bl_to_thread(ns, ld, lock, NULL, 0, LDLM_ASYNC));
1824 int ldlm_bl_to_thread_list(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
1825 cfs_list_t *cancels, int count, int mode)
1828 RETURN(ldlm_bl_to_thread(ns, ld, NULL, cancels, count, mode));
1834 /* Setinfo coming from Server (eg MDT) to Client (eg MDC)! */
1835 static int ldlm_handle_setinfo(struct ptlrpc_request *req)
1837 struct obd_device *obd = req->rq_export->exp_obd;
1844 DEBUG_REQ(D_HSM, req, "%s: handle setinfo\n", obd->obd_name);
1846 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
1848 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1850 DEBUG_REQ(D_IOCTL, req, "no set_info key");
1853 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1855 val = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1857 DEBUG_REQ(D_IOCTL, req, "no set_info val");
1860 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1863 /* We are responsible for swabbing contents of val */
1865 if (KEY_IS(KEY_HSM_COPYTOOL_SEND))
1866 /* Pass it on to mdc (the "export" in this case) */
1867 rc = obd_set_info_async(req->rq_svc_thread->t_env,
1869 sizeof(KEY_HSM_COPYTOOL_SEND),
1870 KEY_HSM_COPYTOOL_SEND,
1873 DEBUG_REQ(D_WARNING, req, "ignoring unknown key %s", key);
1878 static inline void ldlm_callback_errmsg(struct ptlrpc_request *req,
1879 const char *msg, int rc,
1880 struct lustre_handle *handle)
1882 DEBUG_REQ((req->rq_no_reply || rc) ? D_WARNING : D_DLMTRACE, req,
1883 "%s: [nid %s] [rc %d] [lock "LPX64"]",
1884 msg, libcfs_id2str(req->rq_peer), rc,
1885 handle ? handle->cookie : 0);
1886 if (req->rq_no_reply)
1887 CWARN("No reply was sent, maybe cause bug 21636.\n");
1889 CWARN("Send reply failed, maybe cause bug 21636.\n");
1892 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1893 static int ldlm_callback_handler(struct ptlrpc_request *req)
1895 struct ldlm_namespace *ns;
1896 struct ldlm_request *dlm_req;
1897 struct ldlm_lock *lock;
1901 /* Requests arrive in sender's byte order. The ptlrpc service
1902 * handler has already checked and, if necessary, byte-swapped the
1903 * incoming request message body, but I am responsible for the
1904 * message buffers. */
1906 /* do nothing for sec context finalize */
1907 if (lustre_msg_get_opc(req->rq_reqmsg) == SEC_CTX_FINI)
1910 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1912 if (req->rq_export == NULL) {
1913 rc = ldlm_callback_reply(req, -ENOTCONN);
1914 ldlm_callback_errmsg(req, "Operate on unconnected server",
1919 LASSERT(req->rq_export != NULL);
1920 LASSERT(req->rq_export->exp_obd != NULL);
1922 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1923 case LDLM_BL_CALLBACK:
1924 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_BL_CALLBACK))
1927 case LDLM_CP_CALLBACK:
1928 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CP_CALLBACK))
1931 case LDLM_GL_CALLBACK:
1932 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_GL_CALLBACK))
1936 rc = ldlm_handle_setinfo(req);
1937 ldlm_callback_reply(req, rc);
1939 case OBD_LOG_CANCEL: /* remove this eventually - for 1.4.0 compat */
1940 CERROR("shouldn't be handling OBD_LOG_CANCEL on DLM thread\n");
1941 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1942 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1944 rc = llog_origin_handle_cancel(req);
1945 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
1947 ldlm_callback_reply(req, rc);
1949 case OBD_QC_CALLBACK:
1950 req_capsule_set(&req->rq_pill, &RQF_QC_CALLBACK);
1951 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_QC_CALLBACK_NET))
1953 rc = target_handle_qc_callback(req);
1954 ldlm_callback_reply(req, rc);
1958 /* reply in handler */
1959 req_capsule_set(&req->rq_pill, &RQF_MDS_QUOTA_DQACQ);
1960 rc = target_handle_dqacq_callback(req);
1962 case LLOG_ORIGIN_HANDLE_CREATE:
1963 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1964 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1966 rc = llog_origin_handle_create(req);
1967 ldlm_callback_reply(req, rc);
1969 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1970 req_capsule_set(&req->rq_pill,
1971 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1972 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1974 rc = llog_origin_handle_next_block(req);
1975 ldlm_callback_reply(req, rc);
1977 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1978 req_capsule_set(&req->rq_pill,
1979 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1980 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1982 rc = llog_origin_handle_read_header(req);
1983 ldlm_callback_reply(req, rc);
1985 case LLOG_ORIGIN_HANDLE_CLOSE:
1986 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1988 rc = llog_origin_handle_close(req);
1989 ldlm_callback_reply(req, rc);
1992 CERROR("unknown opcode %u\n",
1993 lustre_msg_get_opc(req->rq_reqmsg));
1994 ldlm_callback_reply(req, -EPROTO);
1998 ns = req->rq_export->exp_obd->obd_namespace;
1999 LASSERT(ns != NULL);
2001 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
2003 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
2004 if (dlm_req == NULL) {
2005 rc = ldlm_callback_reply(req, -EPROTO);
2006 ldlm_callback_errmsg(req, "Operate without parameter", rc,
2011 /* Force a known safe race, send a cancel to the server for a lock
2012 * which the server has already started a blocking callback on. */
2013 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE) &&
2014 lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) {
2015 rc = ldlm_cli_cancel(&dlm_req->lock_handle[0]);
2017 CERROR("ldlm_cli_cancel: %d\n", rc);
2020 lock = ldlm_handle2lock_long(&dlm_req->lock_handle[0], 0);
2022 CDEBUG(D_DLMTRACE, "callback on lock "LPX64" - lock "
2023 "disappeared\n", dlm_req->lock_handle[0].cookie);
2024 rc = ldlm_callback_reply(req, -EINVAL);
2025 ldlm_callback_errmsg(req, "Operate with invalid parameter", rc,
2026 &dlm_req->lock_handle[0]);
2030 if ((lock->l_flags & LDLM_FL_FAIL_LOC) &&
2031 lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK)
2032 OBD_RACE(OBD_FAIL_LDLM_CP_BL_RACE);
2034 /* Copy hints/flags (e.g. LDLM_FL_DISCARD_DATA) from AST. */
2035 lock_res_and_lock(lock);
2036 lock->l_flags |= (dlm_req->lock_flags & LDLM_AST_FLAGS);
2037 if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) {
2038 /* If somebody cancels lock and cache is already dropped,
2039 * or lock is failed before cp_ast received on client,
2040 * we can tell the server we have no lock. Otherwise, we
2041 * should send cancel after dropping the cache. */
2042 if (((lock->l_flags & LDLM_FL_CANCELING) &&
2043 (lock->l_flags & LDLM_FL_BL_DONE)) ||
2044 (lock->l_flags & LDLM_FL_FAILED)) {
2045 LDLM_DEBUG(lock, "callback on lock "
2046 LPX64" - lock disappeared\n",
2047 dlm_req->lock_handle[0].cookie);
2048 unlock_res_and_lock(lock);
2049 LDLM_LOCK_RELEASE(lock);
2050 rc = ldlm_callback_reply(req, -EINVAL);
2051 ldlm_callback_errmsg(req, "Operate on stale lock", rc,
2052 &dlm_req->lock_handle[0]);
2055 /* BL_AST locks are not needed in lru.
2056 * let ldlm_cancel_lru() be fast. */
2057 ldlm_lock_remove_from_lru(lock);
2058 lock->l_flags |= LDLM_FL_BL_AST;
2060 unlock_res_and_lock(lock);
2062 /* We want the ost thread to get this reply so that it can respond
2063 * to ost requests (write cache writeback) that might be triggered
2066 * But we'd also like to be able to indicate in the reply that we're
2067 * cancelling right now, because it's unused, or have an intent result
2068 * in the reply, so we might have to push the responsibility for sending
2069 * the reply down into the AST handlers, alas. */
2071 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2072 case LDLM_BL_CALLBACK:
2073 CDEBUG(D_INODE, "blocking ast\n");
2074 req_capsule_extend(&req->rq_pill, &RQF_LDLM_BL_CALLBACK);
2075 if (!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)) {
2076 rc = ldlm_callback_reply(req, 0);
2077 if (req->rq_no_reply || rc)
2078 ldlm_callback_errmsg(req, "Normal process", rc,
2079 &dlm_req->lock_handle[0]);
2081 if (ldlm_bl_to_thread_lock(ns, &dlm_req->lock_desc, lock))
2082 ldlm_handle_bl_callback(ns, &dlm_req->lock_desc, lock);
2084 case LDLM_CP_CALLBACK:
2085 CDEBUG(D_INODE, "completion ast\n");
2086 req_capsule_extend(&req->rq_pill, &RQF_LDLM_CP_CALLBACK);
2087 ldlm_callback_reply(req, 0);
2088 ldlm_handle_cp_callback(req, ns, dlm_req, lock);
2090 case LDLM_GL_CALLBACK:
2091 CDEBUG(D_INODE, "glimpse ast\n");
2092 req_capsule_extend(&req->rq_pill, &RQF_LDLM_GL_CALLBACK);
2093 ldlm_handle_gl_callback(req, ns, dlm_req, lock);
2096 LBUG(); /* checked above */
2102 #ifdef HAVE_SERVER_SUPPORT
2103 static int ldlm_cancel_handler(struct ptlrpc_request *req)
2108 /* Requests arrive in sender's byte order. The ptlrpc service
2109 * handler has already checked and, if necessary, byte-swapped the
2110 * incoming request message body, but I am responsible for the
2111 * message buffers. */
2113 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2115 if (req->rq_export == NULL) {
2116 struct ldlm_request *dlm_req;
2118 CERROR("%s from %s arrived at %lu with bad export cookie "
2120 ll_opcode2str(lustre_msg_get_opc(req->rq_reqmsg)),
2121 libcfs_nid2str(req->rq_peer.nid),
2122 req->rq_arrival_time.tv_sec,
2123 lustre_msg_get_handle(req->rq_reqmsg)->cookie);
2125 if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_CANCEL) {
2126 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
2127 dlm_req = req_capsule_client_get(&req->rq_pill,
2129 if (dlm_req != NULL)
2130 ldlm_lock_dump_handle(D_ERROR,
2131 &dlm_req->lock_handle[0]);
2133 ldlm_callback_reply(req, -ENOTCONN);
2137 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2139 /* XXX FIXME move this back to mds/handler.c, bug 249 */
2141 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2142 CDEBUG(D_INODE, "cancel\n");
2143 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2145 rc = ldlm_handle_cancel(req);
2149 case OBD_LOG_CANCEL:
2150 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2151 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2153 rc = llog_origin_handle_cancel(req);
2154 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2156 ldlm_callback_reply(req, rc);
2159 CERROR("invalid opcode %d\n",
2160 lustre_msg_get_opc(req->rq_reqmsg));
2161 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
2162 ldlm_callback_reply(req, -EINVAL);
2168 static int ldlm_cancel_hpreq_lock_match(struct ptlrpc_request *req,
2169 struct ldlm_lock *lock)
2171 struct ldlm_request *dlm_req;
2172 struct lustre_handle lockh;
2177 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
2178 if (dlm_req == NULL)
2181 ldlm_lock2handle(lock, &lockh);
2182 for (i = 0; i < dlm_req->lock_count; i++) {
2183 if (lustre_handle_equal(&dlm_req->lock_handle[i],
2185 DEBUG_REQ(D_RPCTRACE, req,
2186 "Prio raised by lock "LPX64".", lockh.cookie);
2197 static int ldlm_cancel_hpreq_check(struct ptlrpc_request *req)
2199 struct ldlm_request *dlm_req;
2204 /* no prolong in recovery */
2205 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
2208 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
2209 if (dlm_req == NULL)
2212 for (i = 0; i < dlm_req->lock_count; i++) {
2213 struct ldlm_lock *lock;
2215 lock = ldlm_handle2lock(&dlm_req->lock_handle[i]);
2219 rc = !!(lock->l_flags & LDLM_FL_AST_SENT);
2221 LDLM_DEBUG(lock, "hpreq cancel lock");
2222 LDLM_LOCK_PUT(lock);
2231 static struct ptlrpc_hpreq_ops ldlm_cancel_hpreq_ops = {
2232 .hpreq_lock_match = ldlm_cancel_hpreq_lock_match,
2233 .hpreq_check = ldlm_cancel_hpreq_check,
2237 static int ldlm_hpreq_handler(struct ptlrpc_request *req)
2241 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2243 if (req->rq_export == NULL)
2246 if (LDLM_CANCEL == lustre_msg_get_opc(req->rq_reqmsg)) {
2247 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2248 req->rq_ops = &ldlm_cancel_hpreq_ops;
2253 int ldlm_revoke_lock_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd,
2254 cfs_hlist_node_t *hnode, void *data)
2257 cfs_list_t *rpc_list = data;
2258 struct ldlm_lock *lock = cfs_hash_object(hs, hnode);
2260 lock_res_and_lock(lock);
2262 if (lock->l_req_mode != lock->l_granted_mode) {
2263 unlock_res_and_lock(lock);
2267 LASSERT(lock->l_resource);
2268 if (lock->l_resource->lr_type != LDLM_IBITS &&
2269 lock->l_resource->lr_type != LDLM_PLAIN) {
2270 unlock_res_and_lock(lock);
2274 if (lock->l_flags & LDLM_FL_AST_SENT) {
2275 unlock_res_and_lock(lock);
2279 LASSERT(lock->l_blocking_ast);
2280 LASSERT(!lock->l_blocking_lock);
2282 lock->l_flags |= LDLM_FL_AST_SENT;
2283 if (lock->l_export && lock->l_export->exp_lock_hash) {
2284 /* NB: it's safe to call cfs_hash_del() even lock isn't
2285 * in exp_lock_hash. */
2286 cfs_hash_del(lock->l_export->exp_lock_hash,
2287 &lock->l_remote_handle, &lock->l_exp_hash);
2290 cfs_list_add_tail(&lock->l_rk_ast, rpc_list);
2291 LDLM_LOCK_GET(lock);
2293 unlock_res_and_lock(lock);
2297 void ldlm_revoke_export_locks(struct obd_export *exp)
2299 cfs_list_t rpc_list;
2302 CFS_INIT_LIST_HEAD(&rpc_list);
2303 cfs_hash_for_each_empty(exp->exp_lock_hash,
2304 ldlm_revoke_lock_cb, &rpc_list);
2305 ldlm_run_ast_work(exp->exp_obd->obd_namespace, &rpc_list,
2306 LDLM_WORK_REVOKE_AST);
2310 #endif /* HAVE_SERVER_SUPPORT */
2313 static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp)
2315 struct ldlm_bl_work_item *blwi = NULL;
2316 static unsigned int num_bl = 0;
2318 cfs_spin_lock(&blp->blp_lock);
2319 /* process a request from the blp_list at least every blp_num_threads */
2320 if (!cfs_list_empty(&blp->blp_list) &&
2321 (cfs_list_empty(&blp->blp_prio_list) || num_bl == 0))
2322 blwi = cfs_list_entry(blp->blp_list.next,
2323 struct ldlm_bl_work_item, blwi_entry);
2325 if (!cfs_list_empty(&blp->blp_prio_list))
2326 blwi = cfs_list_entry(blp->blp_prio_list.next,
2327 struct ldlm_bl_work_item,
2331 if (++num_bl >= cfs_atomic_read(&blp->blp_num_threads))
2333 cfs_list_del(&blwi->blwi_entry);
2335 cfs_spin_unlock(&blp->blp_lock);
2340 /* This only contains temporary data until the thread starts */
2341 struct ldlm_bl_thread_data {
2342 char bltd_name[CFS_CURPROC_COMM_MAX];
2343 struct ldlm_bl_pool *bltd_blp;
2344 cfs_completion_t bltd_comp;
2348 static int ldlm_bl_thread_main(void *arg);
2350 static int ldlm_bl_thread_start(struct ldlm_bl_pool *blp)
2352 struct ldlm_bl_thread_data bltd = { .bltd_blp = blp };
2355 cfs_init_completion(&bltd.bltd_comp);
2356 rc = cfs_create_thread(ldlm_bl_thread_main, &bltd, 0);
2358 CERROR("cannot start LDLM thread ldlm_bl_%02d: rc %d\n",
2359 cfs_atomic_read(&blp->blp_num_threads), rc);
2362 cfs_wait_for_completion(&bltd.bltd_comp);
2367 static int ldlm_bl_thread_main(void *arg)
2369 struct ldlm_bl_pool *blp;
2373 struct ldlm_bl_thread_data *bltd = arg;
2375 blp = bltd->bltd_blp;
2378 cfs_atomic_inc_return(&blp->blp_num_threads) - 1;
2379 cfs_atomic_inc(&blp->blp_busy_threads);
2381 snprintf(bltd->bltd_name, sizeof(bltd->bltd_name) - 1,
2382 "ldlm_bl_%02d", bltd->bltd_num);
2383 cfs_daemonize(bltd->bltd_name);
2385 cfs_complete(&bltd->bltd_comp);
2386 /* cannot use bltd after this, it is only on caller's stack */
2390 struct l_wait_info lwi = { 0 };
2391 struct ldlm_bl_work_item *blwi = NULL;
2394 blwi = ldlm_bl_get_work(blp);
2397 cfs_atomic_dec(&blp->blp_busy_threads);
2398 l_wait_event_exclusive(blp->blp_waitq,
2399 (blwi = ldlm_bl_get_work(blp)) != NULL,
2401 busy = cfs_atomic_inc_return(&blp->blp_busy_threads);
2403 busy = cfs_atomic_read(&blp->blp_busy_threads);
2406 if (blwi->blwi_ns == NULL)
2407 /* added by ldlm_cleanup() */
2410 /* Not fatal if racy and have a few too many threads */
2411 if (unlikely(busy < blp->blp_max_threads &&
2412 busy >= cfs_atomic_read(&blp->blp_num_threads) &&
2413 !blwi->blwi_mem_pressure))
2414 /* discard the return value, we tried */
2415 ldlm_bl_thread_start(blp);
2417 if (blwi->blwi_mem_pressure)
2418 cfs_memory_pressure_set();
2420 if (blwi->blwi_count) {
2422 /* The special case when we cancel locks in lru
2423 * asynchronously, we pass the list of locks here.
2424 * Thus locks are marked LDLM_FL_CANCELING, but NOT
2425 * canceled locally yet. */
2426 count = ldlm_cli_cancel_list_local(&blwi->blwi_head,
2429 ldlm_cli_cancel_list(&blwi->blwi_head, count, NULL, 0);
2431 ldlm_handle_bl_callback(blwi->blwi_ns, &blwi->blwi_ld,
2434 if (blwi->blwi_mem_pressure)
2435 cfs_memory_pressure_clr();
2437 if (blwi->blwi_mode == LDLM_ASYNC)
2438 OBD_FREE(blwi, sizeof(*blwi));
2440 cfs_complete(&blwi->blwi_comp);
2443 cfs_atomic_dec(&blp->blp_busy_threads);
2444 cfs_atomic_dec(&blp->blp_num_threads);
2445 cfs_complete(&blp->blp_comp);
2451 static int ldlm_setup(void);
2452 static int ldlm_cleanup(void);
2454 int ldlm_get_ref(void)
2458 cfs_mutex_lock(&ldlm_ref_mutex);
2459 if (++ldlm_refcount == 1) {
2464 cfs_mutex_unlock(&ldlm_ref_mutex);
2469 void ldlm_put_ref(void)
2472 cfs_mutex_lock(&ldlm_ref_mutex);
2473 if (ldlm_refcount == 1) {
2474 int rc = ldlm_cleanup();
2476 CERROR("ldlm_cleanup failed: %d\n", rc);
2482 cfs_mutex_unlock(&ldlm_ref_mutex);
2488 * Export handle<->lock hash operations.
2491 ldlm_export_lock_hash(cfs_hash_t *hs, const void *key, unsigned mask)
2493 return cfs_hash_u64_hash(((struct lustre_handle *)key)->cookie, mask);
2497 ldlm_export_lock_key(cfs_hlist_node_t *hnode)
2499 struct ldlm_lock *lock;
2501 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2502 return &lock->l_remote_handle;
2506 ldlm_export_lock_keycpy(cfs_hlist_node_t *hnode, void *key)
2508 struct ldlm_lock *lock;
2510 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2511 lock->l_remote_handle = *(struct lustre_handle *)key;
2515 ldlm_export_lock_keycmp(const void *key, cfs_hlist_node_t *hnode)
2517 return lustre_handle_equal(ldlm_export_lock_key(hnode), key);
2521 ldlm_export_lock_object(cfs_hlist_node_t *hnode)
2523 return cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2527 ldlm_export_lock_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
2529 struct ldlm_lock *lock;
2531 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2532 LDLM_LOCK_GET(lock);
2536 ldlm_export_lock_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
2538 struct ldlm_lock *lock;
2540 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2541 LDLM_LOCK_RELEASE(lock);
2544 static cfs_hash_ops_t ldlm_export_lock_ops = {
2545 .hs_hash = ldlm_export_lock_hash,
2546 .hs_key = ldlm_export_lock_key,
2547 .hs_keycmp = ldlm_export_lock_keycmp,
2548 .hs_keycpy = ldlm_export_lock_keycpy,
2549 .hs_object = ldlm_export_lock_object,
2550 .hs_get = ldlm_export_lock_get,
2551 .hs_put = ldlm_export_lock_put,
2552 .hs_put_locked = ldlm_export_lock_put,
2555 int ldlm_init_export(struct obd_export *exp)
2559 exp->exp_lock_hash =
2560 cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
2561 HASH_EXP_LOCK_CUR_BITS,
2562 HASH_EXP_LOCK_MAX_BITS,
2563 HASH_EXP_LOCK_BKT_BITS, 0,
2564 CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA,
2565 &ldlm_export_lock_ops,
2566 CFS_HASH_DEFAULT | CFS_HASH_REHASH_KEY |
2567 CFS_HASH_NBLK_CHANGE);
2569 if (!exp->exp_lock_hash)
2574 EXPORT_SYMBOL(ldlm_init_export);
2576 void ldlm_destroy_export(struct obd_export *exp)
2579 cfs_hash_putref(exp->exp_lock_hash);
2580 exp->exp_lock_hash = NULL;
2582 ldlm_destroy_flock_export(exp);
2585 EXPORT_SYMBOL(ldlm_destroy_export);
2587 static int ldlm_setup(void)
2589 static struct ptlrpc_service_conf conf;
2590 struct ldlm_bl_pool *blp = NULL;
2597 if (ldlm_state != NULL)
2600 OBD_ALLOC(ldlm_state, sizeof(*ldlm_state));
2601 if (ldlm_state == NULL)
2605 rc = ldlm_proc_setup();
2610 memset(&conf, 0, sizeof(conf));
2611 conf = (typeof(conf)) {
2612 .psc_name = "ldlm_cbd",
2613 .psc_watchdog_factor = 2,
2615 .bc_nbufs = LDLM_NBUFS,
2616 .bc_buf_size = LDLM_BUFSIZE,
2617 .bc_req_max_size = LDLM_MAXREQSIZE,
2618 .bc_rep_max_size = LDLM_MAXREPSIZE,
2619 .bc_req_portal = LDLM_CB_REQUEST_PORTAL,
2620 .bc_rep_portal = LDLM_CB_REPLY_PORTAL,
2623 .tc_thr_name = "ldlm_cb",
2624 .tc_thr_factor = LDLM_THR_FACTOR,
2625 .tc_nthrs_init = LDLM_NTHRS_INIT,
2626 .tc_nthrs_base = LDLM_NTHRS_BASE,
2627 .tc_nthrs_max = LDLM_NTHRS_MAX,
2628 .tc_nthrs_user = ldlm_num_threads,
2629 .tc_cpu_affinity = 1,
2630 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD,
2633 .cc_pattern = ldlm_cpts,
2636 .so_req_handler = ldlm_callback_handler,
2639 ldlm_state->ldlm_cb_service = \
2640 ptlrpc_register_service(&conf, ldlm_svc_proc_dir);
2641 if (IS_ERR(ldlm_state->ldlm_cb_service)) {
2642 CERROR("failed to start service\n");
2643 rc = PTR_ERR(ldlm_state->ldlm_cb_service);
2644 ldlm_state->ldlm_cb_service = NULL;
2648 #ifdef HAVE_SERVER_SUPPORT
2649 memset(&conf, 0, sizeof(conf));
2650 conf = (typeof(conf)) {
2651 .psc_name = "ldlm_canceld",
2652 .psc_watchdog_factor = 6,
2654 .bc_nbufs = LDLM_NBUFS,
2655 .bc_buf_size = LDLM_BUFSIZE,
2656 .bc_req_max_size = LDLM_MAXREQSIZE,
2657 .bc_rep_max_size = LDLM_MAXREPSIZE,
2658 .bc_req_portal = LDLM_CANCEL_REQUEST_PORTAL,
2659 .bc_rep_portal = LDLM_CANCEL_REPLY_PORTAL,
2663 .tc_thr_name = "ldlm_cn",
2664 .tc_thr_factor = LDLM_THR_FACTOR,
2665 .tc_nthrs_init = LDLM_NTHRS_INIT,
2666 .tc_nthrs_base = LDLM_NTHRS_BASE,
2667 .tc_nthrs_max = LDLM_NTHRS_MAX,
2668 .tc_nthrs_user = ldlm_num_threads,
2669 .tc_cpu_affinity = 1,
2670 .tc_ctx_tags = LCT_MD_THREAD | \
2675 .cc_pattern = ldlm_cpts,
2678 .so_req_handler = ldlm_cancel_handler,
2679 .so_hpreq_handler = ldlm_hpreq_handler,
2682 ldlm_state->ldlm_cancel_service = \
2683 ptlrpc_register_service(&conf, ldlm_svc_proc_dir);
2684 if (IS_ERR(ldlm_state->ldlm_cancel_service)) {
2685 CERROR("failed to start service\n");
2686 rc = PTR_ERR(ldlm_state->ldlm_cancel_service);
2687 ldlm_state->ldlm_cancel_service = NULL;
2692 OBD_ALLOC(blp, sizeof(*blp));
2694 GOTO(out, rc = -ENOMEM);
2695 ldlm_state->ldlm_bl_pool = blp;
2697 cfs_spin_lock_init(&blp->blp_lock);
2698 CFS_INIT_LIST_HEAD(&blp->blp_list);
2699 CFS_INIT_LIST_HEAD(&blp->blp_prio_list);
2700 cfs_waitq_init(&blp->blp_waitq);
2701 cfs_atomic_set(&blp->blp_num_threads, 0);
2702 cfs_atomic_set(&blp->blp_busy_threads, 0);
2705 if (ldlm_num_threads == 0) {
2706 blp->blp_min_threads = LDLM_NTHRS_INIT;
2707 blp->blp_max_threads = LDLM_NTHRS_MAX;
2709 blp->blp_min_threads = blp->blp_max_threads = \
2710 min_t(int, LDLM_NTHRS_MAX, max_t(int, LDLM_NTHRS_INIT,
2714 for (i = 0; i < blp->blp_min_threads; i++) {
2715 rc = ldlm_bl_thread_start(blp);
2720 # ifdef HAVE_SERVER_SUPPORT
2721 CFS_INIT_LIST_HEAD(&expired_lock_thread.elt_expired_locks);
2722 expired_lock_thread.elt_state = ELT_STOPPED;
2723 cfs_waitq_init(&expired_lock_thread.elt_waitq);
2725 CFS_INIT_LIST_HEAD(&waiting_locks_list);
2726 cfs_spin_lock_init(&waiting_locks_spinlock);
2727 cfs_timer_init(&waiting_locks_timer, waiting_locks_callback, 0);
2729 rc = cfs_create_thread(expired_lock_main, NULL, CFS_DAEMON_FLAGS);
2731 CERROR("Cannot start ldlm expired-lock thread: %d\n", rc);
2735 cfs_wait_event(expired_lock_thread.elt_waitq,
2736 expired_lock_thread.elt_state == ELT_READY);
2737 # endif /* HAVE_SERVER_SUPPORT */
2739 rc = ldlm_pools_init();
2741 CERROR("Failed to initialize LDLM pools: %d\n", rc);
2752 static int ldlm_cleanup(void)
2756 if (!cfs_list_empty(ldlm_namespace_list(LDLM_NAMESPACE_SERVER)) ||
2757 !cfs_list_empty(ldlm_namespace_list(LDLM_NAMESPACE_CLIENT))) {
2758 CERROR("ldlm still has namespaces; clean these up first.\n");
2759 ldlm_dump_all_namespaces(LDLM_NAMESPACE_SERVER, D_DLMTRACE);
2760 ldlm_dump_all_namespaces(LDLM_NAMESPACE_CLIENT, D_DLMTRACE);
2767 if (ldlm_state->ldlm_bl_pool != NULL) {
2768 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
2770 while (cfs_atomic_read(&blp->blp_num_threads) > 0) {
2771 struct ldlm_bl_work_item blwi = { .blwi_ns = NULL };
2773 cfs_init_completion(&blp->blp_comp);
2775 cfs_spin_lock(&blp->blp_lock);
2776 cfs_list_add_tail(&blwi.blwi_entry, &blp->blp_list);
2777 cfs_waitq_signal(&blp->blp_waitq);
2778 cfs_spin_unlock(&blp->blp_lock);
2780 cfs_wait_for_completion(&blp->blp_comp);
2783 OBD_FREE(blp, sizeof(*blp));
2785 #endif /* __KERNEL__ */
2787 if (ldlm_state->ldlm_cb_service != NULL)
2788 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
2789 # ifdef HAVE_SERVER_SUPPORT
2790 if (ldlm_state->ldlm_cancel_service != NULL)
2791 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
2795 ldlm_proc_cleanup();
2797 # ifdef HAVE_SERVER_SUPPORT
2798 if (expired_lock_thread.elt_state != ELT_STOPPED) {
2799 expired_lock_thread.elt_state = ELT_TERMINATE;
2800 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
2801 cfs_wait_event(expired_lock_thread.elt_waitq,
2802 expired_lock_thread.elt_state == ELT_STOPPED);
2805 #endif /* __KERNEL__ */
2807 OBD_FREE(ldlm_state, sizeof(*ldlm_state));
2815 cfs_mutex_init(&ldlm_ref_mutex);
2816 cfs_mutex_init(ldlm_namespace_lock(LDLM_NAMESPACE_SERVER));
2817 cfs_mutex_init(ldlm_namespace_lock(LDLM_NAMESPACE_CLIENT));
2818 ldlm_resource_slab = cfs_mem_cache_create("ldlm_resources",
2819 sizeof(struct ldlm_resource), 0,
2820 CFS_SLAB_HWCACHE_ALIGN);
2821 if (ldlm_resource_slab == NULL)
2824 ldlm_lock_slab = cfs_mem_cache_create("ldlm_locks",
2825 sizeof(struct ldlm_lock), 0,
2826 CFS_SLAB_HWCACHE_ALIGN | CFS_SLAB_DESTROY_BY_RCU);
2827 if (ldlm_lock_slab == NULL) {
2828 cfs_mem_cache_destroy(ldlm_resource_slab);
2832 ldlm_interval_slab = cfs_mem_cache_create("interval_node",
2833 sizeof(struct ldlm_interval),
2834 0, CFS_SLAB_HWCACHE_ALIGN);
2835 if (ldlm_interval_slab == NULL) {
2836 cfs_mem_cache_destroy(ldlm_resource_slab);
2837 cfs_mem_cache_destroy(ldlm_lock_slab);
2840 #if LUSTRE_TRACKS_LOCK_EXP_REFS
2841 class_export_dump_hook = ldlm_dump_export_locks;
2846 void ldlm_exit(void)
2850 CERROR("ldlm_refcount is %d in ldlm_exit!\n", ldlm_refcount);
2851 rc = cfs_mem_cache_destroy(ldlm_resource_slab);
2852 LASSERTF(rc == 0, "couldn't free ldlm resource slab\n");
2854 /* ldlm_lock_put() use RCU to call ldlm_lock_free, so need call
2855 * synchronize_rcu() to wait a grace period elapsed, so that
2856 * ldlm_lock_free() get a chance to be called. */
2859 rc = cfs_mem_cache_destroy(ldlm_lock_slab);
2860 LASSERTF(rc == 0, "couldn't free ldlm lock slab\n");
2861 rc = cfs_mem_cache_destroy(ldlm_interval_slab);
2862 LASSERTF(rc == 0, "couldn't free interval node slab\n");
2866 EXPORT_SYMBOL(ldlm_extent_shift_kms);
2869 #ifdef HAVE_SERVER_SUPPORT
2870 EXPORT_SYMBOL(ldlm_get_processing_policy);
2872 EXPORT_SYMBOL(ldlm_lock2desc);
2873 EXPORT_SYMBOL(ldlm_register_intent);
2874 EXPORT_SYMBOL(ldlm_lockname);
2875 EXPORT_SYMBOL(ldlm_typename);
2876 EXPORT_SYMBOL(ldlm_lock2handle);
2877 EXPORT_SYMBOL(__ldlm_handle2lock);
2878 EXPORT_SYMBOL(ldlm_lock_get);
2879 EXPORT_SYMBOL(ldlm_lock_put);
2880 EXPORT_SYMBOL(ldlm_lock_match);
2881 EXPORT_SYMBOL(ldlm_lock_cancel);
2882 EXPORT_SYMBOL(ldlm_lock_addref);
2883 EXPORT_SYMBOL(ldlm_lock_addref_try);
2884 EXPORT_SYMBOL(ldlm_lock_decref);
2885 EXPORT_SYMBOL(ldlm_lock_decref_and_cancel);
2886 EXPORT_SYMBOL(ldlm_lock_change_resource);
2887 EXPORT_SYMBOL(ldlm_it2str);
2888 EXPORT_SYMBOL(ldlm_lock_dump_handle);
2889 EXPORT_SYMBOL(ldlm_reprocess_all_ns);
2890 EXPORT_SYMBOL(ldlm_lock_allow_match_locked);
2891 EXPORT_SYMBOL(ldlm_lock_allow_match);
2892 EXPORT_SYMBOL(ldlm_lock_downgrade);
2893 EXPORT_SYMBOL(ldlm_lock_convert);
2895 /* ldlm_request.c */
2896 EXPORT_SYMBOL(ldlm_completion_ast_async);
2897 EXPORT_SYMBOL(ldlm_blocking_ast_nocheck);
2898 EXPORT_SYMBOL(ldlm_completion_ast);
2899 EXPORT_SYMBOL(ldlm_blocking_ast);
2900 EXPORT_SYMBOL(ldlm_glimpse_ast);
2901 EXPORT_SYMBOL(ldlm_expired_completion_wait);
2902 EXPORT_SYMBOL(ldlm_prep_enqueue_req);
2903 EXPORT_SYMBOL(ldlm_prep_elc_req);
2904 EXPORT_SYMBOL(ldlm_cli_convert);
2905 EXPORT_SYMBOL(ldlm_cli_enqueue);
2906 EXPORT_SYMBOL(ldlm_cli_enqueue_fini);
2907 EXPORT_SYMBOL(ldlm_cli_enqueue_local);
2908 EXPORT_SYMBOL(ldlm_cli_cancel);
2909 EXPORT_SYMBOL(ldlm_cli_cancel_unused);
2910 EXPORT_SYMBOL(ldlm_cli_cancel_unused_resource);
2911 EXPORT_SYMBOL(ldlm_cli_cancel_req);
2912 EXPORT_SYMBOL(ldlm_replay_locks);
2913 EXPORT_SYMBOL(ldlm_resource_foreach);
2914 EXPORT_SYMBOL(ldlm_namespace_foreach);
2915 EXPORT_SYMBOL(ldlm_resource_iterate);
2916 EXPORT_SYMBOL(ldlm_cancel_resource_local);
2917 EXPORT_SYMBOL(ldlm_cli_cancel_list_local);
2918 EXPORT_SYMBOL(ldlm_cli_cancel_list);
2921 #ifdef HAVE_SERVER_SUPPORT
2922 EXPORT_SYMBOL(ldlm_server_blocking_ast);
2923 EXPORT_SYMBOL(ldlm_server_completion_ast);
2924 EXPORT_SYMBOL(ldlm_server_glimpse_ast);
2925 EXPORT_SYMBOL(ldlm_handle_enqueue);
2926 EXPORT_SYMBOL(ldlm_handle_enqueue0);
2927 EXPORT_SYMBOL(ldlm_handle_cancel);
2928 EXPORT_SYMBOL(ldlm_request_cancel);
2929 EXPORT_SYMBOL(ldlm_handle_convert);
2930 EXPORT_SYMBOL(ldlm_handle_convert0);
2931 EXPORT_SYMBOL(ldlm_revoke_export_locks);
2933 EXPORT_SYMBOL(ldlm_del_waiting_lock);
2934 EXPORT_SYMBOL(ldlm_get_ref);
2935 EXPORT_SYMBOL(ldlm_put_ref);
2936 EXPORT_SYMBOL(ldlm_refresh_waiting_lock);
2938 /* ldlm_resource.c */
2939 EXPORT_SYMBOL(ldlm_namespace_new);
2940 EXPORT_SYMBOL(ldlm_namespace_cleanup);
2941 EXPORT_SYMBOL(ldlm_namespace_free);
2942 EXPORT_SYMBOL(ldlm_namespace_dump);
2943 EXPORT_SYMBOL(ldlm_dump_all_namespaces);
2944 EXPORT_SYMBOL(ldlm_resource_get);
2945 EXPORT_SYMBOL(ldlm_resource_putref);
2946 EXPORT_SYMBOL(ldlm_resource_unlink_lock);
2949 EXPORT_SYMBOL(client_import_add_conn);
2950 EXPORT_SYMBOL(client_import_del_conn);
2951 EXPORT_SYMBOL(client_obd_setup);
2952 EXPORT_SYMBOL(client_obd_cleanup);
2953 EXPORT_SYMBOL(client_connect_import);
2954 EXPORT_SYMBOL(client_disconnect_export);
2955 EXPORT_SYMBOL(target_send_reply);
2956 EXPORT_SYMBOL(target_pack_pool_reply);
2958 #ifdef HAVE_SERVER_SUPPORT
2959 EXPORT_SYMBOL(server_disconnect_export);
2960 EXPORT_SYMBOL(target_stop_recovery_thread);
2961 EXPORT_SYMBOL(target_handle_connect);
2962 EXPORT_SYMBOL(target_cleanup_recovery);
2963 EXPORT_SYMBOL(target_destroy_export);
2964 EXPORT_SYMBOL(target_cancel_recovery_timer);
2965 EXPORT_SYMBOL(target_queue_recovery_request);
2966 EXPORT_SYMBOL(target_handle_ping);
2967 EXPORT_SYMBOL(target_handle_disconnect);
2971 EXPORT_SYMBOL(lock_res_and_lock);
2972 EXPORT_SYMBOL(unlock_res_and_lock);