1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/ldlm/ldlm_lockd.c
41 * Author: Peter Braam <braam@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
46 # define EXPORT_SYMTAB
48 #define DEBUG_SUBSYSTEM S_LDLM
51 # include <libcfs/libcfs.h>
53 # include <liblustre.h>
56 #include <lustre_dlm.h>
57 #include <obd_class.h>
58 #include <libcfs/list.h>
59 #include "ldlm_internal.h"
62 static int ldlm_num_threads;
63 CFS_MODULE_PARM(ldlm_num_threads, "i", int, 0444,
64 "number of DLM service threads to start");
67 extern cfs_mem_cache_t *ldlm_resource_slab;
68 extern cfs_mem_cache_t *ldlm_lock_slab;
69 static cfs_semaphore_t ldlm_ref_sem;
70 static int ldlm_refcount;
72 struct ldlm_cb_async_args {
73 struct ldlm_cb_set_arg *ca_set_arg;
74 struct ldlm_lock *ca_lock;
79 static struct ldlm_state *ldlm_state;
81 inline cfs_time_t round_timeout(cfs_time_t timeout)
83 return cfs_time_seconds((int)cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1);
86 /* timeout for initial callback (AST) reply (bz10399) */
87 static inline unsigned int ldlm_get_rq_timeout(void)
90 unsigned int timeout = min(ldlm_timeout, obd_timeout / 3);
92 return timeout < 1 ? 1 : timeout;
96 /* w_l_spinlock protects both waiting_locks_list and expired_lock_thread */
97 static cfs_spinlock_t waiting_locks_spinlock; /* BH lock (timer) */
98 static cfs_list_t waiting_locks_list;
99 static cfs_timer_t waiting_locks_timer;
101 static struct expired_lock_thread {
102 cfs_waitq_t elt_waitq;
105 cfs_list_t elt_expired_locks;
106 } expired_lock_thread;
109 #define ELT_STOPPED 0
111 #define ELT_TERMINATE 2
113 struct ldlm_bl_pool {
114 cfs_spinlock_t blp_lock;
117 * blp_prio_list is used for callbacks that should be handled
118 * as a priority. It is used for LDLM_FL_DISCARD_DATA requests.
121 cfs_list_t blp_prio_list;
124 * blp_list is used for all other callbacks which are likely
125 * to take longer to process.
129 cfs_waitq_t blp_waitq;
130 cfs_completion_t blp_comp;
131 cfs_atomic_t blp_num_threads;
132 cfs_atomic_t blp_busy_threads;
137 struct ldlm_bl_work_item {
138 cfs_list_t blwi_entry;
139 struct ldlm_namespace *blwi_ns;
140 struct ldlm_lock_desc blwi_ld;
141 struct ldlm_lock *blwi_lock;
142 cfs_list_t blwi_head;
144 cfs_completion_t blwi_comp;
146 int blwi_mem_pressure;
151 static inline int have_expired_locks(void)
156 cfs_spin_lock_bh(&waiting_locks_spinlock);
157 need_to_run = !cfs_list_empty(&expired_lock_thread.elt_expired_locks);
158 cfs_spin_unlock_bh(&waiting_locks_spinlock);
163 static int expired_lock_main(void *arg)
165 cfs_list_t *expired = &expired_lock_thread.elt_expired_locks;
166 struct l_wait_info lwi = { 0 };
170 cfs_daemonize("ldlm_elt");
172 expired_lock_thread.elt_state = ELT_READY;
173 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
176 l_wait_event(expired_lock_thread.elt_waitq,
177 have_expired_locks() ||
178 expired_lock_thread.elt_state == ELT_TERMINATE,
181 cfs_spin_lock_bh(&waiting_locks_spinlock);
182 if (expired_lock_thread.elt_dump) {
183 cfs_spin_unlock_bh(&waiting_locks_spinlock);
185 /* from waiting_locks_callback, but not in timer */
186 libcfs_debug_dumplog();
187 libcfs_run_lbug_upcall(__FILE__,
188 "waiting_locks_callback",
189 expired_lock_thread.elt_dump);
191 cfs_spin_lock_bh(&waiting_locks_spinlock);
192 expired_lock_thread.elt_dump = 0;
197 while (!cfs_list_empty(expired)) {
198 struct obd_export *export;
199 struct ldlm_lock *lock;
201 lock = cfs_list_entry(expired->next, struct ldlm_lock,
203 if ((void *)lock < LP_POISON + CFS_PAGE_SIZE &&
204 (void *)lock >= LP_POISON) {
205 cfs_spin_unlock_bh(&waiting_locks_spinlock);
206 CERROR("free lock on elt list %p\n", lock);
209 cfs_list_del_init(&lock->l_pending_chain);
210 if ((void *)lock->l_export < LP_POISON + CFS_PAGE_SIZE &&
211 (void *)lock->l_export >= LP_POISON) {
212 CERROR("lock with free export on elt list %p\n",
214 lock->l_export = NULL;
215 LDLM_ERROR(lock, "free export");
216 /* release extra ref grabbed by
217 * ldlm_add_waiting_lock() or
218 * ldlm_failed_ast() */
219 LDLM_LOCK_RELEASE(lock);
222 export = class_export_lock_get(lock->l_export, lock);
223 cfs_spin_unlock_bh(&waiting_locks_spinlock);
226 class_fail_export(export);
227 class_export_lock_put(export, lock);
229 /* release extra ref grabbed by ldlm_add_waiting_lock()
230 * or ldlm_failed_ast() */
231 LDLM_LOCK_RELEASE(lock);
233 cfs_spin_lock_bh(&waiting_locks_spinlock);
235 cfs_spin_unlock_bh(&waiting_locks_spinlock);
237 if (do_dump && obd_dump_on_eviction) {
238 CERROR("dump the log upon eviction\n");
239 libcfs_debug_dumplog();
242 if (expired_lock_thread.elt_state == ELT_TERMINATE)
246 expired_lock_thread.elt_state = ELT_STOPPED;
247 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
251 static int ldlm_add_waiting_lock(struct ldlm_lock *lock);
254 * Check if there is a request in the export request list
255 * which prevents the lock canceling.
257 static int ldlm_lock_busy(struct ldlm_lock *lock)
259 struct ptlrpc_request *req;
263 if (lock->l_export == NULL)
266 cfs_spin_lock_bh(&lock->l_export->exp_rpc_lock);
267 cfs_list_for_each_entry(req, &lock->l_export->exp_queued_rpc,
269 if (req->rq_ops->hpreq_lock_match) {
270 match = req->rq_ops->hpreq_lock_match(req, lock);
275 cfs_spin_unlock_bh(&lock->l_export->exp_rpc_lock);
279 /* This is called from within a timer interrupt and cannot schedule */
280 static void waiting_locks_callback(unsigned long unused)
282 struct ldlm_lock *lock, *last = NULL;
285 cfs_spin_lock_bh(&waiting_locks_spinlock);
286 while (!cfs_list_empty(&waiting_locks_list)) {
287 lock = cfs_list_entry(waiting_locks_list.next, struct ldlm_lock,
289 if (cfs_time_after(lock->l_callback_timeout,
290 cfs_time_current()) ||
291 (lock->l_req_mode == LCK_GROUP))
294 if (ptlrpc_check_suspend()) {
295 /* there is a case when we talk to one mds, holding
296 * lock from another mds. this way we easily can get
297 * here, if second mds is being recovered. so, we
298 * suspend timeouts. bug 6019 */
300 LDLM_ERROR(lock, "recharge timeout: %s@%s nid %s ",
301 lock->l_export->exp_client_uuid.uuid,
302 lock->l_export->exp_connection->c_remote_uuid.uuid,
303 libcfs_nid2str(lock->l_export->exp_connection->c_peer.nid));
305 cfs_list_del_init(&lock->l_pending_chain);
306 cfs_spin_unlock_bh(&waiting_locks_spinlock);
307 ldlm_add_waiting_lock(lock);
311 /* if timeout overlaps the activation time of suspended timeouts
312 * then extend it to give a chance for client to reconnect */
313 if (cfs_time_before(cfs_time_sub(lock->l_callback_timeout,
314 cfs_time_seconds(obd_timeout)/2),
315 ptlrpc_suspend_wakeup_time())) {
316 LDLM_ERROR(lock, "extend timeout due to recovery: %s@%s nid %s ",
317 lock->l_export->exp_client_uuid.uuid,
318 lock->l_export->exp_connection->c_remote_uuid.uuid,
319 libcfs_nid2str(lock->l_export->exp_connection->c_peer.nid));
321 cfs_list_del_init(&lock->l_pending_chain);
322 cfs_spin_unlock_bh(&waiting_locks_spinlock);
323 ldlm_add_waiting_lock(lock);
327 /* Check if we need to prolong timeout */
328 if (!OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT) &&
329 ldlm_lock_busy(lock)) {
332 if (lock->l_pending_chain.next == &waiting_locks_list)
337 cfs_spin_unlock_bh(&waiting_locks_spinlock);
338 LDLM_DEBUG(lock, "prolong the busy lock");
339 ldlm_refresh_waiting_lock(lock,
340 ldlm_get_enq_timeout(lock));
341 cfs_spin_lock_bh(&waiting_locks_spinlock);
344 LDLM_LOCK_RELEASE(lock);
348 LDLM_LOCK_RELEASE(lock);
351 ldlm_lock_to_ns(lock)->ns_timeouts++;
352 LDLM_ERROR(lock, "lock callback timer expired after %lds: "
353 "evicting client at %s ",
354 cfs_time_current_sec()- lock->l_last_activity,
356 lock->l_export->exp_connection->c_peer.nid));
360 /* no needs to take an extra ref on the lock since it was in
361 * the waiting_locks_list and ldlm_add_waiting_lock()
362 * already grabbed a ref */
363 cfs_list_del(&lock->l_pending_chain);
364 cfs_list_add(&lock->l_pending_chain,
365 &expired_lock_thread.elt_expired_locks);
368 if (!cfs_list_empty(&expired_lock_thread.elt_expired_locks)) {
369 if (obd_dump_on_timeout)
370 expired_lock_thread.elt_dump = __LINE__;
372 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
376 * Make sure the timer will fire again if we have any locks
379 if (!cfs_list_empty(&waiting_locks_list)) {
380 cfs_time_t timeout_rounded;
381 lock = cfs_list_entry(waiting_locks_list.next, struct ldlm_lock,
383 timeout_rounded = (cfs_time_t)round_timeout(lock->l_callback_timeout);
384 cfs_timer_arm(&waiting_locks_timer, timeout_rounded);
386 cfs_spin_unlock_bh(&waiting_locks_spinlock);
390 * Indicate that we're waiting for a client to call us back cancelling a given
391 * lock. We add it to the pending-callback chain, and schedule the lock-timeout
392 * timer to fire appropriately. (We round up to the next second, to avoid
393 * floods of timer firings during periods of high lock contention and traffic).
394 * As done by ldlm_add_waiting_lock(), the caller must grab a lock reference
395 * if it has been added to the waiting list (1 is returned).
397 * Called with the namespace lock held.
399 static int __ldlm_add_waiting_lock(struct ldlm_lock *lock, int seconds)
402 cfs_time_t timeout_rounded;
404 if (!cfs_list_empty(&lock->l_pending_chain))
407 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT) ||
408 OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_HPREQ_TIMEOUT))
411 timeout = cfs_time_shift(seconds);
412 if (likely(cfs_time_after(timeout, lock->l_callback_timeout)))
413 lock->l_callback_timeout = timeout;
415 timeout_rounded = round_timeout(lock->l_callback_timeout);
417 if (cfs_time_before(timeout_rounded,
418 cfs_timer_deadline(&waiting_locks_timer)) ||
419 !cfs_timer_is_armed(&waiting_locks_timer)) {
420 cfs_timer_arm(&waiting_locks_timer, timeout_rounded);
422 /* if the new lock has a shorter timeout than something earlier on
423 the list, we'll wait the longer amount of time; no big deal. */
425 cfs_list_add_tail(&lock->l_pending_chain, &waiting_locks_list);
429 static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
432 int timeout = ldlm_get_enq_timeout(lock);
434 LASSERT(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK));
436 cfs_spin_lock_bh(&waiting_locks_spinlock);
437 if (lock->l_destroyed) {
438 static cfs_time_t next;
439 cfs_spin_unlock_bh(&waiting_locks_spinlock);
440 LDLM_ERROR(lock, "not waiting on destroyed lock (bug 5653)");
441 if (cfs_time_after(cfs_time_current(), next)) {
442 next = cfs_time_shift(14400);
443 libcfs_debug_dumpstack(NULL);
448 ret = __ldlm_add_waiting_lock(lock, timeout);
450 /* grab ref on the lock if it has been added to the
453 cfs_spin_unlock_bh(&waiting_locks_spinlock);
455 LDLM_DEBUG(lock, "%sadding to wait list(timeout: %d, AT: %s)",
456 ret == 0 ? "not re-" : "", timeout,
457 AT_OFF ? "off" : "on");
462 * Remove a lock from the pending list, likely because it had its cancellation
463 * callback arrive without incident. This adjusts the lock-timeout timer if
464 * needed. Returns 0 if the lock wasn't pending after all, 1 if it was.
465 * As done by ldlm_del_waiting_lock(), the caller must release the lock
466 * reference when the lock is removed from any list (1 is returned).
468 * Called with namespace lock held.
470 static int __ldlm_del_waiting_lock(struct ldlm_lock *lock)
472 cfs_list_t *list_next;
474 if (cfs_list_empty(&lock->l_pending_chain))
477 list_next = lock->l_pending_chain.next;
478 if (lock->l_pending_chain.prev == &waiting_locks_list) {
479 /* Removing the head of the list, adjust timer. */
480 if (list_next == &waiting_locks_list) {
481 /* No more, just cancel. */
482 cfs_timer_disarm(&waiting_locks_timer);
484 struct ldlm_lock *next;
485 next = cfs_list_entry(list_next, struct ldlm_lock,
487 cfs_timer_arm(&waiting_locks_timer,
488 round_timeout(next->l_callback_timeout));
491 cfs_list_del_init(&lock->l_pending_chain);
496 int ldlm_del_waiting_lock(struct ldlm_lock *lock)
500 if (lock->l_export == NULL) {
501 /* We don't have a "waiting locks list" on clients. */
502 CDEBUG(D_DLMTRACE, "Client lock %p : no-op\n", lock);
506 cfs_spin_lock_bh(&waiting_locks_spinlock);
507 ret = __ldlm_del_waiting_lock(lock);
508 cfs_spin_unlock_bh(&waiting_locks_spinlock);
510 /* release lock ref if it has indeed been removed
512 LDLM_LOCK_RELEASE(lock);
514 LDLM_DEBUG(lock, "%s", ret == 0 ? "wasn't waiting" : "removed");
521 * Called with namespace lock held.
523 int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout)
525 if (lock->l_export == NULL) {
526 /* We don't have a "waiting locks list" on clients. */
527 LDLM_DEBUG(lock, "client lock: no-op");
531 cfs_spin_lock_bh(&waiting_locks_spinlock);
533 if (cfs_list_empty(&lock->l_pending_chain)) {
534 cfs_spin_unlock_bh(&waiting_locks_spinlock);
535 LDLM_DEBUG(lock, "wasn't waiting");
539 /* we remove/add the lock to the waiting list, so no needs to
540 * release/take a lock reference */
541 __ldlm_del_waiting_lock(lock);
542 __ldlm_add_waiting_lock(lock, timeout);
543 cfs_spin_unlock_bh(&waiting_locks_spinlock);
545 LDLM_DEBUG(lock, "refreshed");
548 #else /* !__KERNEL__ */
550 static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
552 LASSERT(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK));
556 int ldlm_del_waiting_lock(struct ldlm_lock *lock)
561 int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout)
565 #endif /* __KERNEL__ */
567 static void ldlm_failed_ast(struct ldlm_lock *lock, int rc,
568 const char *ast_type)
570 LCONSOLE_ERROR_MSG(0x138, "%s: A client on nid %s was evicted due "
571 "to a lock %s callback time out: rc %d\n",
572 lock->l_export->exp_obd->obd_name,
573 obd_export_nid2str(lock->l_export), ast_type, rc);
575 if (obd_dump_on_timeout)
576 libcfs_debug_dumplog();
578 cfs_spin_lock_bh(&waiting_locks_spinlock);
579 if (__ldlm_del_waiting_lock(lock) == 0)
580 /* the lock was not in any list, grab an extra ref before adding
581 * the lock to the expired list */
583 cfs_list_add(&lock->l_pending_chain,
584 &expired_lock_thread.elt_expired_locks);
585 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
586 cfs_spin_unlock_bh(&waiting_locks_spinlock);
588 class_fail_export(lock->l_export);
592 static int ldlm_handle_ast_error(struct ldlm_lock *lock,
593 struct ptlrpc_request *req, int rc,
594 const char *ast_type)
596 lnet_process_id_t peer = req->rq_import->imp_connection->c_peer;
598 if (rc == -ETIMEDOUT || rc == -EINTR || rc == -ENOTCONN) {
599 LASSERT(lock->l_export);
600 if (lock->l_export->exp_libclient) {
601 LDLM_DEBUG(lock, "%s AST to liblustre client (nid %s)"
602 " timeout, just cancelling lock", ast_type,
603 libcfs_nid2str(peer.nid));
604 ldlm_lock_cancel(lock);
606 } else if (lock->l_flags & LDLM_FL_CANCEL) {
607 LDLM_DEBUG(lock, "%s AST timeout from nid %s, but "
608 "cancel was received (AST reply lost?)",
609 ast_type, libcfs_nid2str(peer.nid));
610 ldlm_lock_cancel(lock);
613 ldlm_del_waiting_lock(lock);
614 ldlm_failed_ast(lock, rc, ast_type);
618 struct ldlm_resource *res = lock->l_resource;
619 LDLM_DEBUG(lock, "client (nid %s) returned %d"
620 " from %s AST - normal race",
621 libcfs_nid2str(peer.nid),
623 lustre_msg_get_status(req->rq_repmsg) : -1,
626 /* update lvbo to return proper attributes.
628 ldlm_resource_getref(res);
629 ldlm_res_lvbo_update(res, NULL, 1);
630 ldlm_resource_putref(res);
634 LDLM_ERROR(lock, "client (nid %s) returned %d "
635 "from %s AST", libcfs_nid2str(peer.nid),
636 (req->rq_repmsg != NULL) ?
637 lustre_msg_get_status(req->rq_repmsg) : 0,
640 ldlm_lock_cancel(lock);
641 /* Server-side AST functions are called from ldlm_reprocess_all,
642 * which needs to be told to please restart its reprocessing. */
649 static int ldlm_cb_interpret(const struct lu_env *env,
650 struct ptlrpc_request *req, void *data, int rc)
652 struct ldlm_cb_async_args *ca = data;
653 struct ldlm_lock *lock = ca->ca_lock;
654 struct ldlm_cb_set_arg *arg = ca->ca_set_arg;
655 struct ptlrpc_request_set *set = arg->set;
658 LASSERT(lock != NULL);
660 rc = ldlm_handle_ast_error(lock, req, rc,
661 arg->type == LDLM_BL_CALLBACK
662 ? "blocking" : "completion");
664 cfs_atomic_inc(&arg->restart);
666 LDLM_LOCK_RELEASE(lock);
668 cfs_waitq_signal(&set->set_waitq);
672 static inline int ldlm_bl_and_cp_ast_tail(struct ptlrpc_request *req,
673 struct ldlm_cb_set_arg *arg,
674 struct ldlm_lock *lock,
680 if (unlikely(instant_cancel)) {
681 rc = ptl_send_rpc(req, 1);
682 ptlrpc_req_finished(req);
684 cfs_atomic_inc(&arg->restart);
687 ptlrpc_set_add_req(arg->set, req);
695 * Check if there are requests in the export request list which prevent
696 * the lock canceling and make these requests high priority ones.
698 static void ldlm_lock_reorder_req(struct ldlm_lock *lock)
700 struct ptlrpc_request *req;
703 if (lock->l_export == NULL) {
704 LDLM_DEBUG(lock, "client lock: no-op");
708 cfs_spin_lock_bh(&lock->l_export->exp_rpc_lock);
709 cfs_list_for_each_entry(req, &lock->l_export->exp_queued_rpc,
711 if (!req->rq_hp && req->rq_ops->hpreq_lock_match &&
712 req->rq_ops->hpreq_lock_match(req, lock))
713 ptlrpc_hpreq_reorder(req);
715 cfs_spin_unlock_bh(&lock->l_export->exp_rpc_lock);
720 * ->l_blocking_ast() method for server-side locks. This is invoked when newly
721 * enqueued server lock conflicts with given one.
723 * Sends blocking ast rpc to the client owning that lock; arms timeout timer
724 * to wait for client response.
726 int ldlm_server_blocking_ast(struct ldlm_lock *lock,
727 struct ldlm_lock_desc *desc,
728 void *data, int flag)
730 struct ldlm_cb_async_args *ca;
731 struct ldlm_cb_set_arg *arg = data;
732 struct ldlm_request *body;
733 struct ptlrpc_request *req;
734 int instant_cancel = 0;
738 if (flag == LDLM_CB_CANCELING)
739 /* Don't need to do anything here. */
743 LASSERT(data != NULL);
744 if (lock->l_export->exp_obd->obd_recovering != 0) {
745 LDLM_ERROR(lock, "BUG 6063: lock collide during recovery");
746 ldlm_lock_dump(D_ERROR, lock, 0);
749 ldlm_lock_reorder_req(lock);
751 req = ptlrpc_request_alloc_pack(lock->l_export->exp_imp_reverse,
752 &RQF_LDLM_BL_CALLBACK,
753 LUSTRE_DLM_VERSION, LDLM_BL_CALLBACK);
757 CLASSERT(sizeof(*ca) <= sizeof(req->rq_async_args));
758 ca = ptlrpc_req_async_args(req);
759 ca->ca_set_arg = arg;
762 req->rq_interpret_reply = ldlm_cb_interpret;
763 req->rq_no_resend = 1;
765 lock_res(lock->l_resource);
766 if (lock->l_granted_mode != lock->l_req_mode) {
767 /* this blocking AST will be communicated as part of the
768 * completion AST instead */
769 unlock_res(lock->l_resource);
770 ptlrpc_req_finished(req);
771 LDLM_DEBUG(lock, "lock not granted, not sending blocking AST");
775 if (lock->l_destroyed) {
776 /* What's the point? */
777 unlock_res(lock->l_resource);
778 ptlrpc_req_finished(req);
782 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)
785 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
786 body->lock_handle[0] = lock->l_remote_handle;
787 body->lock_desc = *desc;
788 body->lock_flags |= (lock->l_flags & LDLM_AST_FLAGS);
790 LDLM_DEBUG(lock, "server preparing blocking AST");
792 ptlrpc_request_set_replen(req);
793 if (instant_cancel) {
794 unlock_res(lock->l_resource);
795 ldlm_lock_cancel(lock);
797 LASSERT(lock->l_granted_mode == lock->l_req_mode);
798 ldlm_add_waiting_lock(lock);
799 unlock_res(lock->l_resource);
802 req->rq_send_state = LUSTRE_IMP_FULL;
803 /* ptlrpc_request_alloc_pack already set timeout */
805 req->rq_timeout = ldlm_get_rq_timeout();
807 if (lock->l_export && lock->l_export->exp_nid_stats &&
808 lock->l_export->exp_nid_stats->nid_ldlm_stats)
809 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
810 LDLM_BL_CALLBACK - LDLM_FIRST_OPC);
812 rc = ldlm_bl_and_cp_ast_tail(req, arg, lock, instant_cancel);
817 int ldlm_server_completion_ast(struct ldlm_lock *lock, int flags, void *data)
819 struct ldlm_cb_set_arg *arg = data;
820 struct ldlm_request *body;
821 struct ptlrpc_request *req;
822 struct ldlm_cb_async_args *ca;
823 long total_enqueue_wait;
824 int instant_cancel = 0;
828 LASSERT(lock != NULL);
829 LASSERT(data != NULL);
831 total_enqueue_wait = cfs_time_sub(cfs_time_current_sec(),
832 lock->l_last_activity);
834 req = ptlrpc_request_alloc(lock->l_export->exp_imp_reverse,
835 &RQF_LDLM_CP_CALLBACK);
839 /* server namespace, doesn't need lock */
840 if (lock->l_resource->lr_lvb_len) {
841 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_CLIENT,
842 lock->l_resource->lr_lvb_len);
845 rc = ptlrpc_request_pack(req, LUSTRE_DLM_VERSION, LDLM_CP_CALLBACK);
847 ptlrpc_request_free(req);
851 CLASSERT(sizeof(*ca) <= sizeof(req->rq_async_args));
852 ca = ptlrpc_req_async_args(req);
853 ca->ca_set_arg = arg;
856 req->rq_interpret_reply = ldlm_cb_interpret;
857 req->rq_no_resend = 1;
858 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
860 body->lock_handle[0] = lock->l_remote_handle;
861 body->lock_flags = flags;
862 ldlm_lock2desc(lock, &body->lock_desc);
863 if (lock->l_resource->lr_lvb_len) {
864 void *lvb = req_capsule_client_get(&req->rq_pill, &RMF_DLM_LVB);
866 lock_res(lock->l_resource);
867 memcpy(lvb, lock->l_resource->lr_lvb_data,
868 lock->l_resource->lr_lvb_len);
869 unlock_res(lock->l_resource);
872 LDLM_DEBUG(lock, "server preparing completion AST (after %lds wait)",
875 /* Server-side enqueue wait time estimate, used in
876 __ldlm_add_waiting_lock to set future enqueue timers */
877 if (total_enqueue_wait < ldlm_get_enq_timeout(lock))
878 at_measured(ldlm_lock_to_ns_at(lock),
881 /* bz18618. Don't add lock enqueue time we spend waiting for a
882 previous callback to fail. Locks waiting legitimately will
883 get extended by ldlm_refresh_waiting_lock regardless of the
884 estimate, so it's okay to underestimate here. */
885 LDLM_DEBUG(lock, "lock completed after %lus; estimate was %ds. "
886 "It is likely that a previous callback timed out.",
888 at_get(ldlm_lock_to_ns_at(lock)));
890 ptlrpc_request_set_replen(req);
892 req->rq_send_state = LUSTRE_IMP_FULL;
893 /* ptlrpc_request_pack already set timeout */
895 req->rq_timeout = ldlm_get_rq_timeout();
897 /* We only send real blocking ASTs after the lock is granted */
898 lock_res_and_lock(lock);
899 if (lock->l_flags & LDLM_FL_AST_SENT) {
900 body->lock_flags |= LDLM_FL_AST_SENT;
901 /* copy ast flags like LDLM_FL_DISCARD_DATA */
902 body->lock_flags |= (lock->l_flags & LDLM_AST_FLAGS);
904 /* We might get here prior to ldlm_handle_enqueue setting
905 * LDLM_FL_CANCEL_ON_BLOCK flag. Then we will put this lock
906 * into waiting list, but this is safe and similar code in
907 * ldlm_handle_enqueue will call ldlm_lock_cancel() still,
908 * that would not only cancel the lock, but will also remove
909 * it from waiting list */
910 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK) {
911 unlock_res_and_lock(lock);
912 ldlm_lock_cancel(lock);
914 lock_res_and_lock(lock);
916 /* start the lock-timeout clock */
917 ldlm_add_waiting_lock(lock);
920 unlock_res_and_lock(lock);
922 if (lock->l_export && lock->l_export->exp_nid_stats &&
923 lock->l_export->exp_nid_stats->nid_ldlm_stats)
924 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
925 LDLM_CP_CALLBACK - LDLM_FIRST_OPC);
927 rc = ldlm_bl_and_cp_ast_tail(req, arg, lock, instant_cancel);
932 int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data)
934 struct ldlm_resource *res = lock->l_resource;
935 struct ldlm_request *body;
936 struct ptlrpc_request *req;
940 LASSERT(lock != NULL);
942 req = ptlrpc_request_alloc_pack(lock->l_export->exp_imp_reverse,
943 &RQF_LDLM_GL_CALLBACK,
944 LUSTRE_DLM_VERSION, LDLM_GL_CALLBACK);
949 body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
950 body->lock_handle[0] = lock->l_remote_handle;
951 ldlm_lock2desc(lock, &body->lock_desc);
953 /* server namespace, doesn't need lock */
954 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER,
955 lock->l_resource->lr_lvb_len);
956 res = lock->l_resource;
957 ptlrpc_request_set_replen(req);
960 req->rq_send_state = LUSTRE_IMP_FULL;
961 /* ptlrpc_request_alloc_pack already set timeout */
963 req->rq_timeout = ldlm_get_rq_timeout();
965 if (lock->l_export && lock->l_export->exp_nid_stats &&
966 lock->l_export->exp_nid_stats->nid_ldlm_stats)
967 lprocfs_counter_incr(lock->l_export->exp_nid_stats->nid_ldlm_stats,
968 LDLM_GL_CALLBACK - LDLM_FIRST_OPC);
970 rc = ptlrpc_queue_wait(req);
971 /* Update the LVB from disk if the AST failed (this is a legal race)
973 * - Glimpse callback of local lock just return -ELDLM_NO_LOCK_DATA.
974 * - Glimpse callback of remote lock might return -ELDLM_NO_LOCK_DATA
975 * when inode is cleared. LU-274
977 if (rc == -ELDLM_NO_LOCK_DATA) {
978 LDLM_DEBUG(lock, "lost race - client has a lock but no inode");
979 ldlm_res_lvbo_update(res, NULL, 1);
980 } else if (rc != 0) {
981 rc = ldlm_handle_ast_error(lock, req, rc, "glimpse");
983 rc = ldlm_res_lvbo_update(res, req, 1);
986 ptlrpc_req_finished(req);
988 ldlm_reprocess_all(res);
994 extern unsigned long long lu_time_stamp_get(void);
996 #define lu_time_stamp_get() time(NULL)
999 static void ldlm_svc_get_eopc(const struct ldlm_request *dlm_req,
1000 struct lprocfs_stats *srv_stats)
1002 int lock_type = 0, op = 0;
1004 lock_type = dlm_req->lock_desc.l_resource.lr_type;
1006 switch (lock_type) {
1008 op = PTLRPC_LAST_CNTR + LDLM_PLAIN_ENQUEUE;
1011 if (dlm_req->lock_flags & LDLM_FL_HAS_INTENT)
1012 op = PTLRPC_LAST_CNTR + LDLM_GLIMPSE_ENQUEUE;
1014 op = PTLRPC_LAST_CNTR + LDLM_EXTENT_ENQUEUE;
1017 op = PTLRPC_LAST_CNTR + LDLM_FLOCK_ENQUEUE;
1020 op = PTLRPC_LAST_CNTR + LDLM_IBITS_ENQUEUE;
1028 lprocfs_counter_incr(srv_stats, op);
1034 * Main server-side entry point into LDLM. This is called by ptlrpc service
1035 * threads to carry out client lock enqueueing requests.
1037 int ldlm_handle_enqueue0(struct ldlm_namespace *ns,
1038 struct ptlrpc_request *req,
1039 const struct ldlm_request *dlm_req,
1040 const struct ldlm_callback_suite *cbs)
1042 struct ldlm_reply *dlm_rep;
1044 ldlm_error_t err = ELDLM_OK;
1045 struct ldlm_lock *lock = NULL;
1046 void *cookie = NULL;
1050 LDLM_DEBUG_NOLOCK("server-side enqueue handler START");
1052 ldlm_request_cancel(req, dlm_req, LDLM_ENQUEUE_CANCEL_OFF);
1053 flags = dlm_req->lock_flags;
1055 LASSERT(req->rq_export);
1057 if (req->rq_rqbd->rqbd_service->srv_stats)
1058 ldlm_svc_get_eopc(dlm_req,
1059 req->rq_rqbd->rqbd_service->srv_stats);
1061 if (req->rq_export && req->rq_export->exp_nid_stats &&
1062 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1063 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1064 LDLM_ENQUEUE - LDLM_FIRST_OPC);
1066 if (unlikely(dlm_req->lock_desc.l_resource.lr_type < LDLM_MIN_TYPE ||
1067 dlm_req->lock_desc.l_resource.lr_type >= LDLM_MAX_TYPE)) {
1068 DEBUG_REQ(D_ERROR, req, "invalid lock request type %d",
1069 dlm_req->lock_desc.l_resource.lr_type);
1070 GOTO(out, rc = -EFAULT);
1073 if (unlikely(dlm_req->lock_desc.l_req_mode <= LCK_MINMODE ||
1074 dlm_req->lock_desc.l_req_mode >= LCK_MAXMODE ||
1075 dlm_req->lock_desc.l_req_mode &
1076 (dlm_req->lock_desc.l_req_mode-1))) {
1077 DEBUG_REQ(D_ERROR, req, "invalid lock request mode %d",
1078 dlm_req->lock_desc.l_req_mode);
1079 GOTO(out, rc = -EFAULT);
1082 if (req->rq_export->exp_connect_flags & OBD_CONNECT_IBITS) {
1083 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
1085 DEBUG_REQ(D_ERROR, req,
1086 "PLAIN lock request from IBITS client?");
1087 GOTO(out, rc = -EPROTO);
1089 } else if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
1091 DEBUG_REQ(D_ERROR, req,
1092 "IBITS lock request from unaware client?");
1093 GOTO(out, rc = -EPROTO);
1097 /* FIXME this makes it impossible to use LDLM_PLAIN locks -- check
1098 against server's _CONNECT_SUPPORTED flags? (I don't want to use
1099 ibits for mgc/mgs) */
1101 /* INODEBITS_INTEROP: Perform conversion from plain lock to
1102 * inodebits lock if client does not support them. */
1103 if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_IBITS) &&
1104 (dlm_req->lock_desc.l_resource.lr_type == LDLM_PLAIN)) {
1105 dlm_req->lock_desc.l_resource.lr_type = LDLM_IBITS;
1106 dlm_req->lock_desc.l_policy_data.l_inodebits.bits =
1107 MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
1108 if (dlm_req->lock_desc.l_req_mode == LCK_PR)
1109 dlm_req->lock_desc.l_req_mode = LCK_CR;
1113 if (unlikely(flags & LDLM_FL_REPLAY)) {
1114 /* Find an existing lock in the per-export lock hash */
1115 lock = cfs_hash_lookup(req->rq_export->exp_lock_hash,
1116 (void *)&dlm_req->lock_handle[0]);
1118 DEBUG_REQ(D_DLMTRACE, req, "found existing lock cookie "
1119 LPX64, lock->l_handle.h_cookie);
1120 GOTO(existing_lock, rc = 0);
1124 /* The lock's callback data might be set in the policy function */
1125 lock = ldlm_lock_create(ns, &dlm_req->lock_desc.l_resource.lr_name,
1126 dlm_req->lock_desc.l_resource.lr_type,
1127 dlm_req->lock_desc.l_req_mode,
1131 GOTO(out, rc = -ENOMEM);
1133 lock->l_last_activity = cfs_time_current_sec();
1134 lock->l_remote_handle = dlm_req->lock_handle[0];
1135 LDLM_DEBUG(lock, "server-side enqueue handler, new lock created");
1137 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_ENQUEUE_BLOCKED, obd_timeout * 2);
1138 /* Don't enqueue a lock onto the export if it is been disonnected
1139 * due to eviction (bug 3822) or server umount (bug 24324).
1140 * Cancel it now instead. */
1141 if (req->rq_export->exp_disconnected) {
1142 LDLM_ERROR(lock, "lock on disconnected export %p",
1144 GOTO(out, rc = -ENOTCONN);
1147 lock->l_export = class_export_lock_get(req->rq_export, lock);
1148 if (lock->l_export->exp_lock_hash)
1149 cfs_hash_add(lock->l_export->exp_lock_hash,
1150 &lock->l_remote_handle,
1155 if (flags & LDLM_FL_HAS_INTENT) {
1156 /* In this case, the reply buffer is allocated deep in
1157 * local_lock_enqueue by the policy function. */
1160 /* based on the assumption that lvb size never changes during
1161 * resource life time otherwise it need resource->lr_lock's
1163 if (lock->l_resource->lr_lvb_len) {
1164 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB,
1166 lock->l_resource->lr_lvb_len);
1169 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR))
1170 GOTO(out, rc = -ENOMEM);
1172 rc = req_capsule_server_pack(&req->rq_pill);
1177 if (dlm_req->lock_desc.l_resource.lr_type != LDLM_PLAIN)
1178 ldlm_convert_policy_to_local(
1179 dlm_req->lock_desc.l_resource.lr_type,
1180 &dlm_req->lock_desc.l_policy_data,
1181 &lock->l_policy_data);
1182 if (dlm_req->lock_desc.l_resource.lr_type == LDLM_EXTENT)
1183 lock->l_req_extent = lock->l_policy_data.l_extent;
1185 err = ldlm_lock_enqueue(ns, &lock, cookie, (int *)&flags);
1189 dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
1190 dlm_rep->lock_flags = flags;
1192 ldlm_lock2desc(lock, &dlm_rep->lock_desc);
1193 ldlm_lock2handle(lock, &dlm_rep->lock_handle);
1195 /* We never send a blocking AST until the lock is granted, but
1196 * we can tell it right now */
1197 lock_res_and_lock(lock);
1199 /* Now take into account flags to be inherited from original lock
1200 request both in reply to client and in our own lock flags. */
1201 dlm_rep->lock_flags |= dlm_req->lock_flags & LDLM_INHERIT_FLAGS;
1202 lock->l_flags |= dlm_req->lock_flags & LDLM_INHERIT_FLAGS;
1204 /* Don't move a pending lock onto the export if it has already been
1205 * disconnected due to eviction (bug 5683) or server umount (bug 24324).
1206 * Cancel it now instead. */
1207 if (unlikely(req->rq_export->exp_disconnected ||
1208 OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT))) {
1209 LDLM_ERROR(lock, "lock on destroyed export %p", req->rq_export);
1211 } else if (lock->l_flags & LDLM_FL_AST_SENT) {
1212 dlm_rep->lock_flags |= LDLM_FL_AST_SENT;
1213 if (lock->l_granted_mode == lock->l_req_mode) {
1215 * Only cancel lock if it was granted, because it would
1216 * be destroyed immediately and would never be granted
1217 * in the future, causing timeouts on client. Not
1218 * granted lock will be cancelled immediately after
1219 * sending completion AST.
1221 if (dlm_rep->lock_flags & LDLM_FL_CANCEL_ON_BLOCK) {
1222 unlock_res_and_lock(lock);
1223 ldlm_lock_cancel(lock);
1224 lock_res_and_lock(lock);
1226 ldlm_add_waiting_lock(lock);
1229 /* Make sure we never ever grant usual metadata locks to liblustre
1231 if ((dlm_req->lock_desc.l_resource.lr_type == LDLM_PLAIN ||
1232 dlm_req->lock_desc.l_resource.lr_type == LDLM_IBITS) &&
1233 req->rq_export->exp_libclient) {
1234 if (unlikely(!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK) ||
1235 !(dlm_rep->lock_flags & LDLM_FL_CANCEL_ON_BLOCK))){
1236 CERROR("Granting sync lock to libclient. "
1237 "req fl %d, rep fl %d, lock fl "LPX64"\n",
1238 dlm_req->lock_flags, dlm_rep->lock_flags,
1240 LDLM_ERROR(lock, "sync lock");
1241 if (dlm_req->lock_flags & LDLM_FL_HAS_INTENT) {
1242 struct ldlm_intent *it;
1244 it = req_capsule_client_get(&req->rq_pill,
1247 CERROR("This is intent %s ("LPU64")\n",
1248 ldlm_it2str(it->opc), it->opc);
1254 unlock_res_and_lock(lock);
1258 req->rq_status = rc ?: err; /* return either error - bug 11190 */
1259 if (!req->rq_packed_final) {
1260 err = lustre_pack_reply(req, 1, NULL, NULL);
1265 /* The LOCK_CHANGED code in ldlm_lock_enqueue depends on this
1266 * ldlm_reprocess_all. If this moves, revisit that code. -phil */
1268 LDLM_DEBUG(lock, "server-side enqueue handler, sending reply"
1269 "(err=%d, rc=%d)", err, rc);
1272 if (lock->l_resource->lr_lvb_len > 0) {
1273 /* MDT path won't handle lr_lvb_data, so
1274 * lock/unlock better be contained in the
1278 lvb = req_capsule_server_get(&req->rq_pill,
1280 LASSERTF(lvb != NULL, "req %p, lock %p\n",
1282 lock_res(lock->l_resource);
1283 memcpy(lvb, lock->l_resource->lr_lvb_data,
1284 lock->l_resource->lr_lvb_len);
1285 unlock_res(lock->l_resource);
1288 lock_res_and_lock(lock);
1289 ldlm_resource_unlink_lock(lock);
1290 ldlm_lock_destroy_nolock(lock);
1291 unlock_res_and_lock(lock);
1294 if (!err && dlm_req->lock_desc.l_resource.lr_type != LDLM_FLOCK)
1295 ldlm_reprocess_all(lock->l_resource);
1297 LDLM_LOCK_RELEASE(lock);
1300 LDLM_DEBUG_NOLOCK("server-side enqueue handler END (lock %p, rc %d)",
1306 int ldlm_handle_enqueue(struct ptlrpc_request *req,
1307 ldlm_completion_callback completion_callback,
1308 ldlm_blocking_callback blocking_callback,
1309 ldlm_glimpse_callback glimpse_callback)
1311 struct ldlm_request *dlm_req;
1312 struct ldlm_callback_suite cbs = {
1313 .lcs_completion = completion_callback,
1314 .lcs_blocking = blocking_callback,
1315 .lcs_glimpse = glimpse_callback
1319 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1320 if (dlm_req != NULL) {
1321 rc = ldlm_handle_enqueue0(req->rq_export->exp_obd->obd_namespace,
1322 req, dlm_req, &cbs);
1329 int ldlm_handle_convert0(struct ptlrpc_request *req,
1330 const struct ldlm_request *dlm_req)
1332 struct ldlm_reply *dlm_rep;
1333 struct ldlm_lock *lock;
1337 if (req->rq_export && req->rq_export->exp_nid_stats &&
1338 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1339 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1340 LDLM_CONVERT - LDLM_FIRST_OPC);
1342 rc = req_capsule_server_pack(&req->rq_pill);
1346 dlm_rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
1347 dlm_rep->lock_flags = dlm_req->lock_flags;
1349 lock = ldlm_handle2lock(&dlm_req->lock_handle[0]);
1351 req->rq_status = EINVAL;
1355 LDLM_DEBUG(lock, "server-side convert handler START");
1357 lock->l_last_activity = cfs_time_current_sec();
1358 res = ldlm_lock_convert(lock, dlm_req->lock_desc.l_req_mode,
1359 &dlm_rep->lock_flags);
1361 if (ldlm_del_waiting_lock(lock))
1362 LDLM_DEBUG(lock, "converted waiting lock");
1365 req->rq_status = EDEADLOCK;
1370 if (!req->rq_status)
1371 ldlm_reprocess_all(lock->l_resource);
1372 LDLM_DEBUG(lock, "server-side convert handler END");
1373 LDLM_LOCK_PUT(lock);
1375 LDLM_DEBUG_NOLOCK("server-side convert handler END");
1380 int ldlm_handle_convert(struct ptlrpc_request *req)
1383 struct ldlm_request *dlm_req;
1385 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1386 if (dlm_req != NULL) {
1387 rc = ldlm_handle_convert0(req, dlm_req);
1389 CERROR ("Can't unpack dlm_req\n");
1395 /* Cancel all the locks whos handles are packed into ldlm_request */
1396 int ldlm_request_cancel(struct ptlrpc_request *req,
1397 const struct ldlm_request *dlm_req, int first)
1399 struct ldlm_resource *res, *pres = NULL;
1400 struct ldlm_lock *lock;
1401 int i, count, done = 0;
1404 count = dlm_req->lock_count ? dlm_req->lock_count : 1;
1408 /* There is no lock on the server at the replay time,
1409 * skip lock cancelling to make replay tests to pass. */
1410 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1413 LDLM_DEBUG_NOLOCK("server-side cancel handler START: %d locks, "
1414 "starting at %d", count, first);
1416 for (i = first; i < count; i++) {
1417 lock = ldlm_handle2lock(&dlm_req->lock_handle[i]);
1419 LDLM_DEBUG_NOLOCK("server-side cancel handler stale "
1420 "lock (cookie "LPU64")",
1421 dlm_req->lock_handle[i].cookie);
1425 res = lock->l_resource;
1430 ldlm_reprocess_all(pres);
1431 LDLM_RESOURCE_DELREF(pres);
1432 ldlm_resource_putref(pres);
1435 ldlm_resource_getref(res);
1436 LDLM_RESOURCE_ADDREF(res);
1437 ldlm_res_lvbo_update(res, NULL, 1);
1441 ldlm_lock_cancel(lock);
1442 LDLM_LOCK_PUT(lock);
1445 ldlm_reprocess_all(pres);
1446 LDLM_RESOURCE_DELREF(pres);
1447 ldlm_resource_putref(pres);
1449 LDLM_DEBUG_NOLOCK("server-side cancel handler END");
1453 int ldlm_handle_cancel(struct ptlrpc_request *req)
1455 struct ldlm_request *dlm_req;
1459 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1460 if (dlm_req == NULL) {
1461 CDEBUG(D_INFO, "bad request buffer for cancel\n");
1465 if (req->rq_export && req->rq_export->exp_nid_stats &&
1466 req->rq_export->exp_nid_stats->nid_ldlm_stats)
1467 lprocfs_counter_incr(req->rq_export->exp_nid_stats->nid_ldlm_stats,
1468 LDLM_CANCEL - LDLM_FIRST_OPC);
1470 rc = req_capsule_server_pack(&req->rq_pill);
1474 if (!ldlm_request_cancel(req, dlm_req, 0))
1475 req->rq_status = ESTALE;
1477 RETURN(ptlrpc_reply(req));
1480 void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
1481 struct ldlm_lock_desc *ld, struct ldlm_lock *lock)
1486 LDLM_DEBUG(lock, "client blocking AST callback handler");
1488 lock_res_and_lock(lock);
1489 lock->l_flags |= LDLM_FL_CBPENDING;
1491 if (lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)
1492 lock->l_flags |= LDLM_FL_CANCEL;
1494 do_ast = (!lock->l_readers && !lock->l_writers);
1495 unlock_res_and_lock(lock);
1498 CDEBUG(D_DLMTRACE, "Lock %p already unused, calling callback (%p)\n",
1499 lock, lock->l_blocking_ast);
1500 if (lock->l_blocking_ast != NULL)
1501 lock->l_blocking_ast(lock, ld, lock->l_ast_data,
1504 CDEBUG(D_DLMTRACE, "Lock %p is referenced, will be cancelled later\n",
1508 LDLM_DEBUG(lock, "client blocking callback handler END");
1509 LDLM_LOCK_RELEASE(lock);
1513 static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
1514 struct ldlm_namespace *ns,
1515 struct ldlm_request *dlm_req,
1516 struct ldlm_lock *lock)
1518 CFS_LIST_HEAD(ast_list);
1521 LDLM_DEBUG(lock, "client completion callback handler START");
1523 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE)) {
1524 int to = cfs_time_seconds(1);
1526 cfs_schedule_timeout_and_set_state(
1527 CFS_TASK_INTERRUPTIBLE, to);
1528 if (lock->l_granted_mode == lock->l_req_mode ||
1534 lock_res_and_lock(lock);
1535 if (lock->l_destroyed ||
1536 lock->l_granted_mode == lock->l_req_mode) {
1537 /* bug 11300: the lock has already been granted */
1538 unlock_res_and_lock(lock);
1539 LDLM_DEBUG(lock, "Double grant race happened");
1540 LDLM_LOCK_RELEASE(lock);
1545 /* If we receive the completion AST before the actual enqueue returned,
1546 * then we might need to switch lock modes, resources, or extents. */
1547 if (dlm_req->lock_desc.l_granted_mode != lock->l_req_mode) {
1548 lock->l_req_mode = dlm_req->lock_desc.l_granted_mode;
1549 LDLM_DEBUG(lock, "completion AST, new lock mode");
1552 if (lock->l_resource->lr_type != LDLM_PLAIN) {
1553 ldlm_convert_policy_to_local(
1554 dlm_req->lock_desc.l_resource.lr_type,
1555 &dlm_req->lock_desc.l_policy_data,
1556 &lock->l_policy_data);
1557 LDLM_DEBUG(lock, "completion AST, new policy data");
1560 ldlm_resource_unlink_lock(lock);
1561 if (memcmp(&dlm_req->lock_desc.l_resource.lr_name,
1562 &lock->l_resource->lr_name,
1563 sizeof(lock->l_resource->lr_name)) != 0) {
1564 unlock_res_and_lock(lock);
1565 if (ldlm_lock_change_resource(ns, lock,
1566 &dlm_req->lock_desc.l_resource.lr_name) != 0) {
1567 LDLM_ERROR(lock, "Failed to allocate resource");
1568 LDLM_LOCK_RELEASE(lock);
1572 LDLM_DEBUG(lock, "completion AST, new resource");
1573 CERROR("change resource!\n");
1574 lock_res_and_lock(lock);
1577 if (dlm_req->lock_flags & LDLM_FL_AST_SENT) {
1578 /* BL_AST locks are not needed in lru.
1579 * let ldlm_cancel_lru() be fast. */
1580 ldlm_lock_remove_from_lru(lock);
1581 lock->l_flags |= LDLM_FL_CBPENDING | LDLM_FL_BL_AST;
1582 LDLM_DEBUG(lock, "completion AST includes blocking AST");
1585 if (lock->l_lvb_len) {
1586 if (req_capsule_get_size(&req->rq_pill, &RMF_DLM_LVB,
1587 RCL_CLIENT) < lock->l_lvb_len) {
1588 LDLM_ERROR(lock, "completion AST did not contain "
1591 void *lvb = req_capsule_client_get(&req->rq_pill,
1593 memcpy(lock->l_lvb_data, lvb, lock->l_lvb_len);
1597 ldlm_grant_lock(lock, &ast_list);
1598 unlock_res_and_lock(lock);
1600 LDLM_DEBUG(lock, "callback handler finished, about to run_ast_work");
1602 /* Let Enqueue to call osc_lock_upcall() and initialize
1604 OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_CP_ENQ_RACE, 2);
1606 ldlm_run_ast_work(ns, &ast_list, LDLM_WORK_CP_AST);
1608 LDLM_DEBUG_NOLOCK("client completion callback handler END (lock %p)",
1610 LDLM_LOCK_RELEASE(lock);
1614 static void ldlm_handle_gl_callback(struct ptlrpc_request *req,
1615 struct ldlm_namespace *ns,
1616 struct ldlm_request *dlm_req,
1617 struct ldlm_lock *lock)
1622 LDLM_DEBUG(lock, "client glimpse AST callback handler");
1624 if (lock->l_glimpse_ast != NULL)
1625 rc = lock->l_glimpse_ast(lock, req);
1627 if (req->rq_repmsg != NULL) {
1630 req->rq_status = rc;
1634 lock_res_and_lock(lock);
1635 if (lock->l_granted_mode == LCK_PW &&
1636 !lock->l_readers && !lock->l_writers &&
1637 cfs_time_after(cfs_time_current(),
1638 cfs_time_add(lock->l_last_used,
1639 cfs_time_seconds(10)))) {
1640 unlock_res_and_lock(lock);
1641 if (ldlm_bl_to_thread_lock(ns, NULL, lock))
1642 ldlm_handle_bl_callback(ns, NULL, lock);
1647 unlock_res_and_lock(lock);
1648 LDLM_LOCK_RELEASE(lock);
1652 static int ldlm_callback_reply(struct ptlrpc_request *req, int rc)
1654 if (req->rq_no_reply)
1657 req->rq_status = rc;
1658 if (!req->rq_packed_final) {
1659 rc = lustre_pack_reply(req, 1, NULL, NULL);
1663 return ptlrpc_reply(req);
1667 static int __ldlm_bl_to_thread(struct ldlm_bl_work_item *blwi, int mode)
1669 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
1672 cfs_spin_lock(&blp->blp_lock);
1673 if (blwi->blwi_lock && blwi->blwi_lock->l_flags & LDLM_FL_DISCARD_DATA) {
1674 /* add LDLM_FL_DISCARD_DATA requests to the priority list */
1675 cfs_list_add_tail(&blwi->blwi_entry, &blp->blp_prio_list);
1677 /* other blocking callbacks are added to the regular list */
1678 cfs_list_add_tail(&blwi->blwi_entry, &blp->blp_list);
1680 cfs_spin_unlock(&blp->blp_lock);
1682 cfs_waitq_signal(&blp->blp_waitq);
1684 /* can not use blwi->blwi_mode as blwi could be already freed in
1686 if (mode == LDLM_SYNC)
1687 cfs_wait_for_completion(&blwi->blwi_comp);
1692 static inline void init_blwi(struct ldlm_bl_work_item *blwi,
1693 struct ldlm_namespace *ns,
1694 struct ldlm_lock_desc *ld,
1695 cfs_list_t *cancels, int count,
1696 struct ldlm_lock *lock,
1699 cfs_init_completion(&blwi->blwi_comp);
1700 CFS_INIT_LIST_HEAD(&blwi->blwi_head);
1702 if (cfs_memory_pressure_get())
1703 blwi->blwi_mem_pressure = 1;
1706 blwi->blwi_mode = mode;
1708 blwi->blwi_ld = *ld;
1710 cfs_list_add(&blwi->blwi_head, cancels);
1711 cfs_list_del_init(cancels);
1712 blwi->blwi_count = count;
1714 blwi->blwi_lock = lock;
1718 static int ldlm_bl_to_thread(struct ldlm_namespace *ns,
1719 struct ldlm_lock_desc *ld, struct ldlm_lock *lock,
1720 cfs_list_t *cancels, int count, int mode)
1724 if (cancels && count == 0)
1727 if (mode == LDLM_SYNC) {
1728 /* if it is synchronous call do minimum mem alloc, as it could
1729 * be triggered from kernel shrinker
1731 struct ldlm_bl_work_item blwi;
1732 memset(&blwi, 0, sizeof(blwi));
1733 init_blwi(&blwi, ns, ld, cancels, count, lock, LDLM_SYNC);
1734 RETURN(__ldlm_bl_to_thread(&blwi, LDLM_SYNC));
1736 struct ldlm_bl_work_item *blwi;
1737 OBD_ALLOC(blwi, sizeof(*blwi));
1740 init_blwi(blwi, ns, ld, cancels, count, lock, LDLM_ASYNC);
1742 RETURN(__ldlm_bl_to_thread(blwi, LDLM_ASYNC));
1748 int ldlm_bl_to_thread_lock(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
1749 struct ldlm_lock *lock)
1752 RETURN(ldlm_bl_to_thread(ns, ld, lock, NULL, 0, LDLM_ASYNC));
1758 int ldlm_bl_to_thread_list(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
1759 cfs_list_t *cancels, int count, int mode)
1762 RETURN(ldlm_bl_to_thread(ns, ld, NULL, cancels, count, mode));
1768 /* Setinfo coming from Server (eg MDT) to Client (eg MDC)! */
1769 static int ldlm_handle_setinfo(struct ptlrpc_request *req)
1771 struct obd_device *obd = req->rq_export->exp_obd;
1778 DEBUG_REQ(D_HSM, req, "%s: handle setinfo\n", obd->obd_name);
1780 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
1782 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1784 DEBUG_REQ(D_IOCTL, req, "no set_info key");
1787 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1789 val = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1791 DEBUG_REQ(D_IOCTL, req, "no set_info val");
1794 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1797 /* We are responsible for swabbing contents of val */
1799 if (KEY_IS(KEY_HSM_COPYTOOL_SEND))
1800 /* Pass it on to mdc (the "export" in this case) */
1801 rc = obd_set_info_async(req->rq_export,
1802 sizeof(KEY_HSM_COPYTOOL_SEND),
1803 KEY_HSM_COPYTOOL_SEND,
1806 DEBUG_REQ(D_WARNING, req, "ignoring unknown key %s", key);
1811 static inline void ldlm_callback_errmsg(struct ptlrpc_request *req,
1812 const char *msg, int rc,
1813 struct lustre_handle *handle)
1815 DEBUG_REQ((req->rq_no_reply || rc) ? D_WARNING : D_DLMTRACE, req,
1816 "%s: [nid %s] [rc %d] [lock "LPX64"]",
1817 msg, libcfs_id2str(req->rq_peer), rc,
1818 handle ? handle->cookie : 0);
1819 if (req->rq_no_reply)
1820 CWARN("No reply was sent, maybe cause bug 21636.\n");
1822 CWARN("Send reply failed, maybe cause bug 21636.\n");
1825 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1826 static int ldlm_callback_handler(struct ptlrpc_request *req)
1828 struct ldlm_namespace *ns;
1829 struct ldlm_request *dlm_req;
1830 struct ldlm_lock *lock;
1834 /* Requests arrive in sender's byte order. The ptlrpc service
1835 * handler has already checked and, if necessary, byte-swapped the
1836 * incoming request message body, but I am responsible for the
1837 * message buffers. */
1839 /* do nothing for sec context finalize */
1840 if (lustre_msg_get_opc(req->rq_reqmsg) == SEC_CTX_FINI)
1843 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1845 if (req->rq_export == NULL) {
1846 rc = ldlm_callback_reply(req, -ENOTCONN);
1847 ldlm_callback_errmsg(req, "Operate on unconnected server",
1852 LASSERT(req->rq_export != NULL);
1853 LASSERT(req->rq_export->exp_obd != NULL);
1855 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1856 case LDLM_BL_CALLBACK:
1857 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_BL_CALLBACK))
1860 case LDLM_CP_CALLBACK:
1861 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CP_CALLBACK))
1864 case LDLM_GL_CALLBACK:
1865 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_GL_CALLBACK))
1869 rc = ldlm_handle_setinfo(req);
1870 ldlm_callback_reply(req, rc);
1872 case OBD_LOG_CANCEL: /* remove this eventually - for 1.4.0 compat */
1873 CERROR("shouldn't be handling OBD_LOG_CANCEL on DLM thread\n");
1874 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1875 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1877 rc = llog_origin_handle_cancel(req);
1878 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
1880 ldlm_callback_reply(req, rc);
1882 case OBD_QC_CALLBACK:
1883 req_capsule_set(&req->rq_pill, &RQF_QC_CALLBACK);
1884 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_QC_CALLBACK_NET))
1886 rc = target_handle_qc_callback(req);
1887 ldlm_callback_reply(req, rc);
1891 /* reply in handler */
1892 req_capsule_set(&req->rq_pill, &RQF_MDS_QUOTA_DQACQ);
1893 rc = target_handle_dqacq_callback(req);
1895 case LLOG_ORIGIN_HANDLE_CREATE:
1896 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1897 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1899 rc = llog_origin_handle_create(req);
1900 ldlm_callback_reply(req, rc);
1902 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1903 req_capsule_set(&req->rq_pill,
1904 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1905 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1907 rc = llog_origin_handle_next_block(req);
1908 ldlm_callback_reply(req, rc);
1910 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1911 req_capsule_set(&req->rq_pill,
1912 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1913 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1915 rc = llog_origin_handle_read_header(req);
1916 ldlm_callback_reply(req, rc);
1918 case LLOG_ORIGIN_HANDLE_CLOSE:
1919 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET))
1921 rc = llog_origin_handle_close(req);
1922 ldlm_callback_reply(req, rc);
1925 CERROR("unknown opcode %u\n",
1926 lustre_msg_get_opc(req->rq_reqmsg));
1927 ldlm_callback_reply(req, -EPROTO);
1931 ns = req->rq_export->exp_obd->obd_namespace;
1932 LASSERT(ns != NULL);
1934 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
1936 dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
1937 if (dlm_req == NULL) {
1938 rc = ldlm_callback_reply(req, -EPROTO);
1939 ldlm_callback_errmsg(req, "Operate without parameter", rc,
1944 /* Force a known safe race, send a cancel to the server for a lock
1945 * which the server has already started a blocking callback on. */
1946 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE) &&
1947 lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) {
1948 rc = ldlm_cli_cancel(&dlm_req->lock_handle[0]);
1950 CERROR("ldlm_cli_cancel: %d\n", rc);
1953 lock = ldlm_handle2lock_long(&dlm_req->lock_handle[0], 0);
1955 CDEBUG(D_DLMTRACE, "callback on lock "LPX64" - lock "
1956 "disappeared\n", dlm_req->lock_handle[0].cookie);
1957 rc = ldlm_callback_reply(req, -EINVAL);
1958 ldlm_callback_errmsg(req, "Operate with invalid parameter", rc,
1959 &dlm_req->lock_handle[0]);
1963 if ((lock->l_flags & LDLM_FL_FAIL_LOC) &&
1964 lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK)
1965 OBD_RACE(OBD_FAIL_LDLM_CP_BL_RACE);
1967 /* Copy hints/flags (e.g. LDLM_FL_DISCARD_DATA) from AST. */
1968 lock_res_and_lock(lock);
1969 lock->l_flags |= (dlm_req->lock_flags & LDLM_AST_FLAGS);
1970 if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) {
1971 /* If somebody cancels lock and cache is already dropped,
1972 * or lock is failed before cp_ast received on client,
1973 * we can tell the server we have no lock. Otherwise, we
1974 * should send cancel after dropping the cache. */
1975 if (((lock->l_flags & LDLM_FL_CANCELING) &&
1976 (lock->l_flags & LDLM_FL_BL_DONE)) ||
1977 (lock->l_flags & LDLM_FL_FAILED)) {
1978 LDLM_DEBUG(lock, "callback on lock "
1979 LPX64" - lock disappeared\n",
1980 dlm_req->lock_handle[0].cookie);
1981 unlock_res_and_lock(lock);
1982 LDLM_LOCK_RELEASE(lock);
1983 rc = ldlm_callback_reply(req, -EINVAL);
1984 ldlm_callback_errmsg(req, "Operate on stale lock", rc,
1985 &dlm_req->lock_handle[0]);
1988 /* BL_AST locks are not needed in lru.
1989 * let ldlm_cancel_lru() be fast. */
1990 ldlm_lock_remove_from_lru(lock);
1991 lock->l_flags |= LDLM_FL_BL_AST;
1993 unlock_res_and_lock(lock);
1995 /* We want the ost thread to get this reply so that it can respond
1996 * to ost requests (write cache writeback) that might be triggered
1999 * But we'd also like to be able to indicate in the reply that we're
2000 * cancelling right now, because it's unused, or have an intent result
2001 * in the reply, so we might have to push the responsibility for sending
2002 * the reply down into the AST handlers, alas. */
2004 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2005 case LDLM_BL_CALLBACK:
2006 CDEBUG(D_INODE, "blocking ast\n");
2007 req_capsule_extend(&req->rq_pill, &RQF_LDLM_BL_CALLBACK);
2008 if (!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)) {
2009 rc = ldlm_callback_reply(req, 0);
2010 if (req->rq_no_reply || rc)
2011 ldlm_callback_errmsg(req, "Normal process", rc,
2012 &dlm_req->lock_handle[0]);
2014 if (ldlm_bl_to_thread_lock(ns, &dlm_req->lock_desc, lock))
2015 ldlm_handle_bl_callback(ns, &dlm_req->lock_desc, lock);
2017 case LDLM_CP_CALLBACK:
2018 CDEBUG(D_INODE, "completion ast\n");
2019 req_capsule_extend(&req->rq_pill, &RQF_LDLM_CP_CALLBACK);
2020 ldlm_callback_reply(req, 0);
2021 ldlm_handle_cp_callback(req, ns, dlm_req, lock);
2023 case LDLM_GL_CALLBACK:
2024 CDEBUG(D_INODE, "glimpse ast\n");
2025 req_capsule_extend(&req->rq_pill, &RQF_LDLM_GL_CALLBACK);
2026 ldlm_handle_gl_callback(req, ns, dlm_req, lock);
2029 LBUG(); /* checked above */
2035 static int ldlm_cancel_handler(struct ptlrpc_request *req)
2040 /* Requests arrive in sender's byte order. The ptlrpc service
2041 * handler has already checked and, if necessary, byte-swapped the
2042 * incoming request message body, but I am responsible for the
2043 * message buffers. */
2045 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2047 if (req->rq_export == NULL) {
2048 struct ldlm_request *dlm_req;
2050 CERROR("%s from %s arrived at %lu with bad export cookie "
2052 ll_opcode2str(lustre_msg_get_opc(req->rq_reqmsg)),
2053 libcfs_nid2str(req->rq_peer.nid),
2054 req->rq_arrival_time.tv_sec,
2055 lustre_msg_get_handle(req->rq_reqmsg)->cookie);
2057 if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_CANCEL) {
2058 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
2059 dlm_req = req_capsule_client_get(&req->rq_pill,
2061 if (dlm_req != NULL)
2062 ldlm_lock_dump_handle(D_ERROR,
2063 &dlm_req->lock_handle[0]);
2065 ldlm_callback_reply(req, -ENOTCONN);
2069 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2071 /* XXX FIXME move this back to mds/handler.c, bug 249 */
2073 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2074 CDEBUG(D_INODE, "cancel\n");
2075 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2077 rc = ldlm_handle_cancel(req);
2081 case OBD_LOG_CANCEL:
2082 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2083 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2085 rc = llog_origin_handle_cancel(req);
2086 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2088 ldlm_callback_reply(req, rc);
2091 CERROR("invalid opcode %d\n",
2092 lustre_msg_get_opc(req->rq_reqmsg));
2093 req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK);
2094 ldlm_callback_reply(req, -EINVAL);
2100 int ldlm_revoke_lock_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd,
2101 cfs_hlist_node_t *hnode, void *data)
2104 cfs_list_t *rpc_list = data;
2105 struct ldlm_lock *lock = cfs_hash_object(hs, hnode);
2107 lock_res_and_lock(lock);
2109 if (lock->l_req_mode != lock->l_granted_mode) {
2110 unlock_res_and_lock(lock);
2114 LASSERT(lock->l_resource);
2115 if (lock->l_resource->lr_type != LDLM_IBITS &&
2116 lock->l_resource->lr_type != LDLM_PLAIN) {
2117 unlock_res_and_lock(lock);
2121 if (lock->l_flags & LDLM_FL_AST_SENT) {
2122 unlock_res_and_lock(lock);
2126 LASSERT(lock->l_blocking_ast);
2127 LASSERT(!lock->l_blocking_lock);
2129 lock->l_flags |= LDLM_FL_AST_SENT;
2130 if (lock->l_export && lock->l_export->exp_lock_hash &&
2131 !cfs_hlist_unhashed(&lock->l_exp_hash))
2132 cfs_hash_del(lock->l_export->exp_lock_hash,
2133 &lock->l_remote_handle, &lock->l_exp_hash);
2134 cfs_list_add_tail(&lock->l_rk_ast, rpc_list);
2135 LDLM_LOCK_GET(lock);
2137 unlock_res_and_lock(lock);
2141 void ldlm_revoke_export_locks(struct obd_export *exp)
2143 cfs_list_t rpc_list;
2146 CFS_INIT_LIST_HEAD(&rpc_list);
2147 cfs_hash_for_each_empty(exp->exp_lock_hash,
2148 ldlm_revoke_lock_cb, &rpc_list);
2149 ldlm_run_ast_work(exp->exp_obd->obd_namespace, &rpc_list,
2150 LDLM_WORK_REVOKE_AST);
2156 static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp)
2158 struct ldlm_bl_work_item *blwi = NULL;
2159 static unsigned int num_bl = 0;
2161 cfs_spin_lock(&blp->blp_lock);
2162 /* process a request from the blp_list at least every blp_num_threads */
2163 if (!cfs_list_empty(&blp->blp_list) &&
2164 (cfs_list_empty(&blp->blp_prio_list) || num_bl == 0))
2165 blwi = cfs_list_entry(blp->blp_list.next,
2166 struct ldlm_bl_work_item, blwi_entry);
2168 if (!cfs_list_empty(&blp->blp_prio_list))
2169 blwi = cfs_list_entry(blp->blp_prio_list.next,
2170 struct ldlm_bl_work_item,
2174 if (++num_bl >= cfs_atomic_read(&blp->blp_num_threads))
2176 cfs_list_del(&blwi->blwi_entry);
2178 cfs_spin_unlock(&blp->blp_lock);
2183 /* This only contains temporary data until the thread starts */
2184 struct ldlm_bl_thread_data {
2185 char bltd_name[CFS_CURPROC_COMM_MAX];
2186 struct ldlm_bl_pool *bltd_blp;
2187 cfs_completion_t bltd_comp;
2191 static int ldlm_bl_thread_main(void *arg);
2193 static int ldlm_bl_thread_start(struct ldlm_bl_pool *blp)
2195 struct ldlm_bl_thread_data bltd = { .bltd_blp = blp };
2198 cfs_init_completion(&bltd.bltd_comp);
2199 rc = cfs_create_thread(ldlm_bl_thread_main, &bltd, 0);
2201 CERROR("cannot start LDLM thread ldlm_bl_%02d: rc %d\n",
2202 cfs_atomic_read(&blp->blp_num_threads), rc);
2205 cfs_wait_for_completion(&bltd.bltd_comp);
2210 static int ldlm_bl_thread_main(void *arg)
2212 struct ldlm_bl_pool *blp;
2216 struct ldlm_bl_thread_data *bltd = arg;
2218 blp = bltd->bltd_blp;
2221 cfs_atomic_inc_return(&blp->blp_num_threads) - 1;
2222 cfs_atomic_inc(&blp->blp_busy_threads);
2224 snprintf(bltd->bltd_name, sizeof(bltd->bltd_name) - 1,
2225 "ldlm_bl_%02d", bltd->bltd_num);
2226 cfs_daemonize(bltd->bltd_name);
2228 cfs_complete(&bltd->bltd_comp);
2229 /* cannot use bltd after this, it is only on caller's stack */
2233 struct l_wait_info lwi = { 0 };
2234 struct ldlm_bl_work_item *blwi = NULL;
2236 blwi = ldlm_bl_get_work(blp);
2241 cfs_atomic_dec(&blp->blp_busy_threads);
2242 l_wait_event_exclusive(blp->blp_waitq,
2243 (blwi = ldlm_bl_get_work(blp)) != NULL,
2245 busy = cfs_atomic_inc_return(&blp->blp_busy_threads);
2247 if (blwi->blwi_ns == NULL)
2248 /* added by ldlm_cleanup() */
2251 /* Not fatal if racy and have a few too many threads */
2252 if (unlikely(busy < blp->blp_max_threads &&
2253 busy >= cfs_atomic_read(&blp->blp_num_threads) &&
2254 !blwi->blwi_mem_pressure))
2255 /* discard the return value, we tried */
2256 ldlm_bl_thread_start(blp);
2258 if (blwi->blwi_ns == NULL)
2259 /* added by ldlm_cleanup() */
2262 if (blwi->blwi_mem_pressure)
2263 cfs_memory_pressure_set();
2265 if (blwi->blwi_count) {
2267 /* The special case when we cancel locks in lru
2268 * asynchronously, we pass the list of locks here.
2269 * Thus locks are marked LDLM_FL_CANCELING, but NOT
2270 * canceled locally yet. */
2271 count = ldlm_cli_cancel_list_local(&blwi->blwi_head,
2274 ldlm_cli_cancel_list(&blwi->blwi_head, count, NULL, 0);
2276 ldlm_handle_bl_callback(blwi->blwi_ns, &blwi->blwi_ld,
2279 if (blwi->blwi_mem_pressure)
2280 cfs_memory_pressure_clr();
2282 if (blwi->blwi_mode == LDLM_ASYNC)
2283 OBD_FREE(blwi, sizeof(*blwi));
2285 cfs_complete(&blwi->blwi_comp);
2288 cfs_atomic_dec(&blp->blp_busy_threads);
2289 cfs_atomic_dec(&blp->blp_num_threads);
2290 cfs_complete(&blp->blp_comp);
2296 static int ldlm_setup(void);
2297 static int ldlm_cleanup(void);
2299 int ldlm_get_ref(void)
2303 cfs_mutex_down(&ldlm_ref_sem);
2304 if (++ldlm_refcount == 1) {
2309 cfs_mutex_up(&ldlm_ref_sem);
2314 void ldlm_put_ref(void)
2317 cfs_mutex_down(&ldlm_ref_sem);
2318 if (ldlm_refcount == 1) {
2319 int rc = ldlm_cleanup();
2321 CERROR("ldlm_cleanup failed: %d\n", rc);
2327 cfs_mutex_up(&ldlm_ref_sem);
2333 * Export handle<->lock hash operations.
2336 ldlm_export_lock_hash(cfs_hash_t *hs, const void *key, unsigned mask)
2338 return cfs_hash_u64_hash(((struct lustre_handle *)key)->cookie, mask);
2342 ldlm_export_lock_key(cfs_hlist_node_t *hnode)
2344 struct ldlm_lock *lock;
2346 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2347 return &lock->l_remote_handle;
2351 ldlm_export_lock_keycpy(cfs_hlist_node_t *hnode, void *key)
2353 struct ldlm_lock *lock;
2355 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2356 lock->l_remote_handle = *(struct lustre_handle *)key;
2360 ldlm_export_lock_keycmp(const void *key, cfs_hlist_node_t *hnode)
2362 return lustre_handle_equal(ldlm_export_lock_key(hnode), key);
2366 ldlm_export_lock_object(cfs_hlist_node_t *hnode)
2368 return cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2372 ldlm_export_lock_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
2374 struct ldlm_lock *lock;
2376 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2377 LDLM_LOCK_GET(lock);
2381 ldlm_export_lock_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
2383 struct ldlm_lock *lock;
2385 lock = cfs_hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
2386 LDLM_LOCK_RELEASE(lock);
2389 static cfs_hash_ops_t ldlm_export_lock_ops = {
2390 .hs_hash = ldlm_export_lock_hash,
2391 .hs_key = ldlm_export_lock_key,
2392 .hs_keycmp = ldlm_export_lock_keycmp,
2393 .hs_keycpy = ldlm_export_lock_keycpy,
2394 .hs_object = ldlm_export_lock_object,
2395 .hs_get = ldlm_export_lock_get,
2396 .hs_put = ldlm_export_lock_put,
2397 .hs_put_locked = ldlm_export_lock_put,
2400 int ldlm_init_export(struct obd_export *exp)
2404 exp->exp_lock_hash =
2405 cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
2406 HASH_EXP_LOCK_CUR_BITS,
2407 HASH_EXP_LOCK_MAX_BITS,
2408 HASH_EXP_LOCK_BKT_BITS, 0,
2409 CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA,
2410 &ldlm_export_lock_ops,
2411 CFS_HASH_DEFAULT | CFS_HASH_REHASH_KEY |
2412 CFS_HASH_NBLK_CHANGE);
2414 if (!exp->exp_lock_hash)
2419 EXPORT_SYMBOL(ldlm_init_export);
2421 void ldlm_destroy_export(struct obd_export *exp)
2424 cfs_hash_putref(exp->exp_lock_hash);
2425 exp->exp_lock_hash = NULL;
2428 EXPORT_SYMBOL(ldlm_destroy_export);
2430 static int ldlm_setup(void)
2432 struct ldlm_bl_pool *blp;
2434 int ldlm_min_threads = LDLM_THREADS_AUTO_MIN;
2435 int ldlm_max_threads = LDLM_THREADS_AUTO_MAX;
2441 if (ldlm_state != NULL)
2444 OBD_ALLOC(ldlm_state, sizeof(*ldlm_state));
2445 if (ldlm_state == NULL)
2449 rc = ldlm_proc_setup();
2455 if (ldlm_num_threads) {
2456 /* If ldlm_num_threads is set, it is the min and the max. */
2457 if (ldlm_num_threads > LDLM_THREADS_AUTO_MAX)
2458 ldlm_num_threads = LDLM_THREADS_AUTO_MAX;
2459 if (ldlm_num_threads < LDLM_THREADS_AUTO_MIN)
2460 ldlm_num_threads = LDLM_THREADS_AUTO_MIN;
2461 ldlm_min_threads = ldlm_max_threads = ldlm_num_threads;
2465 ldlm_state->ldlm_cb_service =
2466 ptlrpc_init_svc(LDLM_NBUFS, LDLM_BUFSIZE, LDLM_MAXREQSIZE,
2467 LDLM_MAXREPSIZE, LDLM_CB_REQUEST_PORTAL,
2468 LDLM_CB_REPLY_PORTAL, 2,
2469 ldlm_callback_handler, "ldlm_cbd",
2470 ldlm_svc_proc_dir, NULL,
2471 ldlm_min_threads, ldlm_max_threads,
2473 LCT_MD_THREAD|LCT_DT_THREAD, NULL);
2475 if (!ldlm_state->ldlm_cb_service) {
2476 CERROR("failed to start service\n");
2477 GOTO(out_proc, rc = -ENOMEM);
2480 ldlm_state->ldlm_cancel_service =
2481 ptlrpc_init_svc(LDLM_NBUFS, LDLM_BUFSIZE, LDLM_MAXREQSIZE,
2482 LDLM_MAXREPSIZE, LDLM_CANCEL_REQUEST_PORTAL,
2483 LDLM_CANCEL_REPLY_PORTAL, 6,
2484 ldlm_cancel_handler, "ldlm_canceld",
2485 ldlm_svc_proc_dir, NULL,
2486 ldlm_min_threads, ldlm_max_threads,
2488 LCT_MD_THREAD|LCT_DT_THREAD|LCT_CL_THREAD,
2491 if (!ldlm_state->ldlm_cancel_service) {
2492 CERROR("failed to start service\n");
2493 GOTO(out_proc, rc = -ENOMEM);
2496 OBD_ALLOC(blp, sizeof(*blp));
2498 GOTO(out_proc, rc = -ENOMEM);
2499 ldlm_state->ldlm_bl_pool = blp;
2501 cfs_spin_lock_init(&blp->blp_lock);
2502 CFS_INIT_LIST_HEAD(&blp->blp_list);
2503 CFS_INIT_LIST_HEAD(&blp->blp_prio_list);
2504 cfs_waitq_init(&blp->blp_waitq);
2505 cfs_atomic_set(&blp->blp_num_threads, 0);
2506 cfs_atomic_set(&blp->blp_busy_threads, 0);
2507 blp->blp_min_threads = ldlm_min_threads;
2508 blp->blp_max_threads = ldlm_max_threads;
2511 for (i = 0; i < blp->blp_min_threads; i++) {
2512 rc = ldlm_bl_thread_start(blp);
2514 GOTO(out_thread, rc);
2517 rc = ptlrpc_start_threads(ldlm_state->ldlm_cancel_service);
2519 GOTO(out_thread, rc);
2521 rc = ptlrpc_start_threads(ldlm_state->ldlm_cb_service);
2523 GOTO(out_thread, rc);
2525 CFS_INIT_LIST_HEAD(&expired_lock_thread.elt_expired_locks);
2526 expired_lock_thread.elt_state = ELT_STOPPED;
2527 cfs_waitq_init(&expired_lock_thread.elt_waitq);
2529 CFS_INIT_LIST_HEAD(&waiting_locks_list);
2530 cfs_spin_lock_init(&waiting_locks_spinlock);
2531 cfs_timer_init(&waiting_locks_timer, waiting_locks_callback, 0);
2533 rc = cfs_create_thread(expired_lock_main, NULL, CFS_DAEMON_FLAGS);
2535 CERROR("Cannot start ldlm expired-lock thread: %d\n", rc);
2536 GOTO(out_thread, rc);
2539 cfs_wait_event(expired_lock_thread.elt_waitq,
2540 expired_lock_thread.elt_state == ELT_READY);
2544 rc = ldlm_pools_init();
2546 GOTO(out_thread, rc);
2552 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
2553 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
2558 ldlm_proc_cleanup();
2561 OBD_FREE(ldlm_state, sizeof(*ldlm_state));
2566 static int ldlm_cleanup(void)
2569 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
2573 if (!cfs_list_empty(ldlm_namespace_list(LDLM_NAMESPACE_SERVER)) ||
2574 !cfs_list_empty(ldlm_namespace_list(LDLM_NAMESPACE_CLIENT))) {
2575 CERROR("ldlm still has namespaces; clean these up first.\n");
2576 ldlm_dump_all_namespaces(LDLM_NAMESPACE_SERVER, D_DLMTRACE);
2577 ldlm_dump_all_namespaces(LDLM_NAMESPACE_CLIENT, D_DLMTRACE);
2586 while (cfs_atomic_read(&blp->blp_num_threads) > 0) {
2587 struct ldlm_bl_work_item blwi = { .blwi_ns = NULL };
2589 cfs_init_completion(&blp->blp_comp);
2591 cfs_spin_lock(&blp->blp_lock);
2592 cfs_list_add_tail(&blwi.blwi_entry, &blp->blp_list);
2593 cfs_waitq_signal(&blp->blp_waitq);
2594 cfs_spin_unlock(&blp->blp_lock);
2596 cfs_wait_for_completion(&blp->blp_comp);
2598 OBD_FREE(blp, sizeof(*blp));
2600 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
2601 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
2602 ldlm_proc_cleanup();
2604 expired_lock_thread.elt_state = ELT_TERMINATE;
2605 cfs_waitq_signal(&expired_lock_thread.elt_waitq);
2606 cfs_wait_event(expired_lock_thread.elt_waitq,
2607 expired_lock_thread.elt_state == ELT_STOPPED);
2609 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
2610 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
2613 OBD_FREE(ldlm_state, sizeof(*ldlm_state));
2619 int __init ldlm_init(void)
2621 cfs_init_mutex(&ldlm_ref_sem);
2622 cfs_init_mutex(ldlm_namespace_lock(LDLM_NAMESPACE_SERVER));
2623 cfs_init_mutex(ldlm_namespace_lock(LDLM_NAMESPACE_CLIENT));
2624 ldlm_resource_slab = cfs_mem_cache_create("ldlm_resources",
2625 sizeof(struct ldlm_resource), 0,
2626 CFS_SLAB_HWCACHE_ALIGN);
2627 if (ldlm_resource_slab == NULL)
2630 ldlm_lock_slab = cfs_mem_cache_create("ldlm_locks",
2631 sizeof(struct ldlm_lock), 0,
2632 CFS_SLAB_HWCACHE_ALIGN | CFS_SLAB_DESTROY_BY_RCU);
2633 if (ldlm_lock_slab == NULL) {
2634 cfs_mem_cache_destroy(ldlm_resource_slab);
2638 ldlm_interval_slab = cfs_mem_cache_create("interval_node",
2639 sizeof(struct ldlm_interval),
2640 0, CFS_SLAB_HWCACHE_ALIGN);
2641 if (ldlm_interval_slab == NULL) {
2642 cfs_mem_cache_destroy(ldlm_resource_slab);
2643 cfs_mem_cache_destroy(ldlm_lock_slab);
2646 #if LUSTRE_TRACKS_LOCK_EXP_REFS
2647 class_export_dump_hook = ldlm_dump_export_locks;
2652 void __exit ldlm_exit(void)
2656 CERROR("ldlm_refcount is %d in ldlm_exit!\n", ldlm_refcount);
2657 rc = cfs_mem_cache_destroy(ldlm_resource_slab);
2658 LASSERTF(rc == 0, "couldn't free ldlm resource slab\n");
2660 /* ldlm_lock_put() use RCU to call ldlm_lock_free, so need call
2661 * synchronize_rcu() to wait a grace period elapsed, so that
2662 * ldlm_lock_free() get a chance to be called. */
2665 rc = cfs_mem_cache_destroy(ldlm_lock_slab);
2666 LASSERTF(rc == 0, "couldn't free ldlm lock slab\n");
2667 rc = cfs_mem_cache_destroy(ldlm_interval_slab);
2668 LASSERTF(rc == 0, "couldn't free interval node slab\n");
2672 EXPORT_SYMBOL(ldlm_extent_shift_kms);
2675 EXPORT_SYMBOL(ldlm_get_processing_policy);
2676 EXPORT_SYMBOL(ldlm_lock2desc);
2677 EXPORT_SYMBOL(ldlm_register_intent);
2678 EXPORT_SYMBOL(ldlm_lockname);
2679 EXPORT_SYMBOL(ldlm_typename);
2680 EXPORT_SYMBOL(ldlm_lock2handle);
2681 EXPORT_SYMBOL(__ldlm_handle2lock);
2682 EXPORT_SYMBOL(ldlm_lock_get);
2683 EXPORT_SYMBOL(ldlm_lock_put);
2684 EXPORT_SYMBOL(ldlm_lock_match);
2685 EXPORT_SYMBOL(ldlm_lock_cancel);
2686 EXPORT_SYMBOL(ldlm_lock_addref);
2687 EXPORT_SYMBOL(ldlm_lock_addref_try);
2688 EXPORT_SYMBOL(ldlm_lock_decref);
2689 EXPORT_SYMBOL(ldlm_lock_decref_and_cancel);
2690 EXPORT_SYMBOL(ldlm_lock_change_resource);
2691 EXPORT_SYMBOL(ldlm_it2str);
2692 EXPORT_SYMBOL(ldlm_lock_dump);
2693 EXPORT_SYMBOL(ldlm_lock_dump_handle);
2694 EXPORT_SYMBOL(ldlm_reprocess_all_ns);
2695 EXPORT_SYMBOL(ldlm_lock_allow_match_locked);
2696 EXPORT_SYMBOL(ldlm_lock_allow_match);
2697 EXPORT_SYMBOL(ldlm_lock_downgrade);
2698 EXPORT_SYMBOL(ldlm_lock_convert);
2700 /* ldlm_request.c */
2701 EXPORT_SYMBOL(ldlm_completion_ast_async);
2702 EXPORT_SYMBOL(ldlm_blocking_ast_nocheck);
2703 EXPORT_SYMBOL(ldlm_completion_ast);
2704 EXPORT_SYMBOL(ldlm_blocking_ast);
2705 EXPORT_SYMBOL(ldlm_glimpse_ast);
2706 EXPORT_SYMBOL(ldlm_expired_completion_wait);
2707 EXPORT_SYMBOL(ldlm_prep_enqueue_req);
2708 EXPORT_SYMBOL(ldlm_prep_elc_req);
2709 EXPORT_SYMBOL(ldlm_cli_convert);
2710 EXPORT_SYMBOL(ldlm_cli_enqueue);
2711 EXPORT_SYMBOL(ldlm_cli_enqueue_fini);
2712 EXPORT_SYMBOL(ldlm_cli_enqueue_local);
2713 EXPORT_SYMBOL(ldlm_cli_cancel);
2714 EXPORT_SYMBOL(ldlm_cli_cancel_unused);
2715 EXPORT_SYMBOL(ldlm_cli_cancel_unused_resource);
2716 EXPORT_SYMBOL(ldlm_cli_cancel_req);
2717 EXPORT_SYMBOL(ldlm_replay_locks);
2718 EXPORT_SYMBOL(ldlm_resource_foreach);
2719 EXPORT_SYMBOL(ldlm_namespace_foreach);
2720 EXPORT_SYMBOL(ldlm_resource_iterate);
2721 EXPORT_SYMBOL(ldlm_cancel_resource_local);
2722 EXPORT_SYMBOL(ldlm_cli_cancel_list_local);
2723 EXPORT_SYMBOL(ldlm_cli_cancel_list);
2726 EXPORT_SYMBOL(ldlm_server_blocking_ast);
2727 EXPORT_SYMBOL(ldlm_server_completion_ast);
2728 EXPORT_SYMBOL(ldlm_server_glimpse_ast);
2729 EXPORT_SYMBOL(ldlm_handle_enqueue);
2730 EXPORT_SYMBOL(ldlm_handle_enqueue0);
2731 EXPORT_SYMBOL(ldlm_handle_cancel);
2732 EXPORT_SYMBOL(ldlm_request_cancel);
2733 EXPORT_SYMBOL(ldlm_handle_convert);
2734 EXPORT_SYMBOL(ldlm_handle_convert0);
2735 EXPORT_SYMBOL(ldlm_del_waiting_lock);
2736 EXPORT_SYMBOL(ldlm_get_ref);
2737 EXPORT_SYMBOL(ldlm_put_ref);
2738 EXPORT_SYMBOL(ldlm_refresh_waiting_lock);
2739 EXPORT_SYMBOL(ldlm_revoke_export_locks);
2741 /* ldlm_resource.c */
2742 EXPORT_SYMBOL(ldlm_namespace_new);
2743 EXPORT_SYMBOL(ldlm_namespace_cleanup);
2744 EXPORT_SYMBOL(ldlm_namespace_free);
2745 EXPORT_SYMBOL(ldlm_namespace_dump);
2746 EXPORT_SYMBOL(ldlm_dump_all_namespaces);
2747 EXPORT_SYMBOL(ldlm_resource_get);
2748 EXPORT_SYMBOL(ldlm_resource_putref);
2749 EXPORT_SYMBOL(ldlm_resource_unlink_lock);
2752 EXPORT_SYMBOL(client_import_add_conn);
2753 EXPORT_SYMBOL(client_import_del_conn);
2754 EXPORT_SYMBOL(client_obd_setup);
2755 EXPORT_SYMBOL(client_obd_cleanup);
2756 EXPORT_SYMBOL(client_connect_import);
2757 EXPORT_SYMBOL(client_disconnect_export);
2758 EXPORT_SYMBOL(server_disconnect_export);
2759 EXPORT_SYMBOL(target_stop_recovery_thread);
2760 EXPORT_SYMBOL(target_handle_connect);
2761 EXPORT_SYMBOL(target_cleanup_recovery);
2762 EXPORT_SYMBOL(target_destroy_export);
2763 EXPORT_SYMBOL(target_cancel_recovery_timer);
2764 EXPORT_SYMBOL(target_send_reply);
2765 EXPORT_SYMBOL(target_queue_recovery_request);
2766 EXPORT_SYMBOL(target_handle_ping);
2767 EXPORT_SYMBOL(target_pack_pool_reply);
2768 EXPORT_SYMBOL(target_handle_disconnect);
2771 EXPORT_SYMBOL(lock_res_and_lock);
2772 EXPORT_SYMBOL(unlock_res_and_lock);