1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Peter Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # define EXPORT_SYMTAB
27 #define DEBUG_SUBSYSTEM S_LDLM
30 # include <linux/module.h>
31 # include <linux/slab.h>
32 # include <linux/init.h>
33 # include <linux/wait.h>
35 # include <liblustre.h>
38 #include <linux/lustre_dlm.h>
39 #include <linux/obd_class.h>
40 #include <libcfs/list.h>
41 #include "ldlm_internal.h"
43 extern kmem_cache_t *ldlm_resource_slab;
44 extern kmem_cache_t *ldlm_lock_slab;
45 extern struct list_head ldlm_namespace_list;
47 static DECLARE_MUTEX(ldlm_ref_sem);
48 static int ldlm_refcount;
51 static struct ldlm_state *ldlm_state;
53 static inline unsigned long
54 round_timeout(unsigned long timeout)
56 return ((timeout / HZ) + 1) * HZ;
60 /* XXX should this be per-ldlm? */
61 static struct list_head waiting_locks_list;
62 static spinlock_t waiting_locks_spinlock;
63 static struct timer_list waiting_locks_timer;
65 static struct expired_lock_thread {
66 wait_queue_head_t elt_waitq;
68 struct list_head elt_expired_locks;
70 } expired_lock_thread;
73 #if !defined(ENOTSUPP)
79 #define ELT_TERMINATE 2
83 struct list_head blp_list;
84 wait_queue_head_t blp_waitq;
85 atomic_t blp_num_threads;
86 struct completion blp_comp;
89 struct ldlm_bl_work_item {
90 struct list_head blwi_entry;
91 struct ldlm_namespace *blwi_ns;
92 struct ldlm_lock_desc blwi_ld;
93 struct ldlm_lock *blwi_lock;
98 static int ldlm_add_waiting_lock(struct ldlm_lock *lock);
100 static inline int have_expired_locks(void)
104 spin_lock_bh(&expired_lock_thread.elt_lock);
105 need_to_run = !list_empty(&expired_lock_thread.elt_expired_locks);
106 spin_unlock_bh(&expired_lock_thread.elt_lock);
111 static int expired_lock_main(void *arg)
113 struct list_head *expired = &expired_lock_thread.elt_expired_locks;
114 struct l_wait_info lwi = { 0 };
119 kportal_daemonize("ldlm_elt");
121 SIGNAL_MASK_LOCK(current, flags);
122 sigfillset(¤t->blocked);
124 SIGNAL_MASK_UNLOCK(current, flags);
128 expired_lock_thread.elt_state = ELT_READY;
129 wake_up(&expired_lock_thread.elt_waitq);
132 l_wait_event(expired_lock_thread.elt_waitq,
133 have_expired_locks() ||
134 expired_lock_thread.elt_state == ELT_TERMINATE,
137 spin_lock_bh(&expired_lock_thread.elt_lock);
138 while (!list_empty(expired)) {
139 struct obd_export *export;
140 struct ldlm_lock *lock;
142 lock = list_entry(expired->next, struct ldlm_lock,
144 if ((void *)lock < LP_POISON + PAGE_SIZE &&
145 (void *)lock >= LP_POISON) {
146 CERROR("free lock on elt list %p\n", lock);
149 list_del_init(&lock->l_pending_chain);
150 if ((void *)lock->l_export < LP_POISON + PAGE_SIZE &&
151 (void *)lock->l_export >= LP_POISON + PAGE_SIZE) {
152 CERROR("lock with free export on elt list %p\n",
154 lock->l_export = NULL;
155 LDLM_ERROR(lock, "free export\n");
158 export = class_export_get(lock->l_export);
159 spin_unlock_bh(&expired_lock_thread.elt_lock);
161 ptlrpc_fail_export(export);
162 class_export_put(export);
163 spin_lock_bh(&expired_lock_thread.elt_lock);
165 spin_unlock_bh(&expired_lock_thread.elt_lock);
167 if (expired_lock_thread.elt_state == ELT_TERMINATE)
171 expired_lock_thread.elt_state = ELT_STOPPED;
172 wake_up(&expired_lock_thread.elt_waitq);
176 static void waiting_locks_callback(unsigned long unused)
178 struct ldlm_lock *lock;
179 char str[PTL_NALFMT_SIZE];
181 if (obd_dump_on_timeout)
182 portals_debug_dumplog();
185 spin_lock_bh(&waiting_locks_spinlock);
186 while (!list_empty(&waiting_locks_list)) {
187 lock = list_entry(waiting_locks_list.next, struct ldlm_lock,
190 if ((lock->l_callback_timeout > jiffies) ||
191 (lock->l_req_mode == LCK_GROUP))
194 if (ptlrpc_check_suspend()) {
195 /* there is a case when we talk to one mds, holding
196 * lock from another mds. this way we easily can get
197 * here, if second mds is being recovered. so, we
198 * suspend timeouts. bug 6019 */
200 LDLM_ERROR(lock, "recharge timeout: %s@%s nid %s ",
201 lock->l_export->exp_client_uuid.uuid,
202 lock->l_export->exp_connection->c_remote_uuid.uuid,
203 ptlrpc_peernid2str(&lock->l_export->exp_connection->c_peer, str));
205 list_del_init(&lock->l_pending_chain);
206 spin_unlock_bh(&waiting_locks_spinlock);
207 ldlm_add_waiting_lock(lock);
212 LDLM_ERROR(lock, "lock callback timer expired: evicting client "
214 lock->l_export->exp_client_uuid.uuid,
215 lock->l_export->exp_connection->c_remote_uuid.uuid,
216 ptlrpc_peernid2str(&lock->l_export->exp_connection->c_peer, str));
218 spin_lock_bh(&expired_lock_thread.elt_lock);
219 list_del(&lock->l_pending_chain);
220 list_add(&lock->l_pending_chain,
221 &expired_lock_thread.elt_expired_locks);
222 spin_unlock_bh(&expired_lock_thread.elt_lock);
223 wake_up(&expired_lock_thread.elt_waitq);
227 * Make sure the timer will fire again if we have any locks
230 if (!list_empty(&waiting_locks_list)) {
231 unsigned long timeout_rounded;
232 lock = list_entry(waiting_locks_list.next, struct ldlm_lock,
234 timeout_rounded = round_timeout(lock->l_callback_timeout);
235 mod_timer(&waiting_locks_timer, timeout_rounded);
237 spin_unlock_bh(&waiting_locks_spinlock);
241 * Indicate that we're waiting for a client to call us back cancelling a given
242 * lock. We add it to the pending-callback chain, and schedule the lock-timeout
243 * timer to fire appropriately. (We round up to the next second, to avoid
244 * floods of timer firings during periods of high lock contention and traffic).
246 static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
248 unsigned long timeout_rounded;
250 spin_lock_bh(&waiting_locks_spinlock);
251 if (!list_empty(&lock->l_pending_chain)) {
252 LDLM_DEBUG(lock, "not re-adding to wait list");
253 spin_unlock_bh(&waiting_locks_spinlock);
256 LDLM_DEBUG(lock, "adding to wait list");
258 lock->l_callback_timeout = jiffies + (obd_timeout * HZ / 2);
260 timeout_rounded = round_timeout(lock->l_callback_timeout);
262 if (timeout_rounded < waiting_locks_timer.expires ||
263 !timer_pending(&waiting_locks_timer)) {
264 mod_timer(&waiting_locks_timer, timeout_rounded);
266 list_add_tail(&lock->l_pending_chain, &waiting_locks_list); /* FIFO */
267 spin_unlock_bh(&waiting_locks_spinlock);
272 * Remove a lock from the pending list, likely because it had its cancellation
273 * callback arrive without incident. This adjusts the lock-timeout timer if
274 * needed. Returns 0 if the lock wasn't pending after all, 1 if it was.
276 int ldlm_del_waiting_lock(struct ldlm_lock *lock)
278 struct list_head *list_next;
280 if (lock->l_export == NULL) {
281 /* We don't have a "waiting locks list" on clients. */
282 LDLM_DEBUG(lock, "client lock: no-op");
286 spin_lock_bh(&waiting_locks_spinlock);
288 if (list_empty(&lock->l_pending_chain)) {
289 spin_unlock_bh(&waiting_locks_spinlock);
290 LDLM_DEBUG(lock, "wasn't waiting");
294 list_next = lock->l_pending_chain.next;
295 if (lock->l_pending_chain.prev == &waiting_locks_list) {
296 /* Removing the head of the list, adjust timer. */
297 if (list_next == &waiting_locks_list) {
298 /* No more, just cancel. */
299 del_timer(&waiting_locks_timer);
301 struct ldlm_lock *next;
302 next = list_entry(list_next, struct ldlm_lock,
304 mod_timer(&waiting_locks_timer,
305 round_timeout(next->l_callback_timeout));
309 spin_lock_bh(&expired_lock_thread.elt_lock);
310 list_del_init(&lock->l_pending_chain);
311 spin_unlock_bh(&expired_lock_thread.elt_lock);
313 spin_unlock_bh(&waiting_locks_spinlock);
314 LDLM_DEBUG(lock, "removed");
318 #else /* !__KERNEL__ */
320 static int ldlm_add_waiting_lock(struct ldlm_lock *lock)
325 int ldlm_del_waiting_lock(struct ldlm_lock *lock)
330 #endif /* __KERNEL__ */
332 static void ldlm_failed_ast(struct ldlm_lock *lock, int rc,const char *ast_type)
334 struct ptlrpc_connection *conn = lock->l_export->exp_connection;
335 char str[PTL_NALFMT_SIZE];
337 LDLM_ERROR(lock, "%s AST failed (%d): evicting client %s@%s NID "LPX64
338 " (%s)", ast_type, rc, lock->l_export->exp_client_uuid.uuid,
339 conn->c_remote_uuid.uuid, conn->c_peer.peer_id.nid,
340 ptlrpc_peernid2str(&conn->c_peer, str));
342 if (obd_dump_on_timeout)
343 portals_debug_dumplog();
344 ptlrpc_fail_export(lock->l_export);
347 static int ldlm_handle_ast_error(struct ldlm_lock *lock,
348 struct ptlrpc_request *req, int rc,
349 const char *ast_type)
351 struct ptlrpc_peer *peer = &req->rq_import->imp_connection->c_peer;
352 char str[PTL_NALFMT_SIZE];
354 if (rc == -ETIMEDOUT || rc == -EINTR || rc == -ENOTCONN) {
355 LASSERT(lock->l_export);
356 if (lock->l_export->exp_libclient) {
357 LDLM_DEBUG(lock, "%s AST to liblustre client (nid %s)"
358 " timeout, just cancelling lock", ast_type,
359 ptlrpc_peernid2str(peer, str));
360 ldlm_lock_cancel(lock);
363 ldlm_del_waiting_lock(lock);
364 ldlm_failed_ast(lock, rc, ast_type);
368 LDLM_DEBUG(lock, "client (nid %s) returned %d"
369 " from %s AST - normal race",
370 ptlrpc_peernid2str(peer, str),
371 req->rq_repmsg->status, ast_type);
373 LDLM_ERROR(lock, "client (nid %s) returned %d "
374 "from %s AST", ptlrpc_peernid2str(peer, str),
375 (req->rq_repmsg != NULL) ?
376 req->rq_repmsg->status : 0, ast_type);
377 ldlm_lock_cancel(lock);
378 /* Server-side AST functions are called from ldlm_reprocess_all,
379 * which needs to be told to please restart its reprocessing. */
386 int ldlm_server_blocking_ast(struct ldlm_lock *lock,
387 struct ldlm_lock_desc *desc,
388 void *data, int flag)
390 struct ldlm_request *body;
391 struct ptlrpc_request *req;
392 int rc = 0, size = sizeof(*body);
395 if (flag == LDLM_CB_CANCELING) {
396 /* Don't need to do anything here. */
400 LASSERTF(lock->l_export->exp_obd->obd_recovering == 0,
401 "BUG 6063: lock collide during recovery");
406 if (LTIME_S(CURRENT_TIME) - lock->l_export->exp_last_request_time > 30){
407 ldlm_failed_ast(lock, -ETIMEDOUT, "Not-attempted blocking");
408 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
413 req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse,
414 LUSTRE_DLM_VERSION, LDLM_BL_CALLBACK,
419 lock_res_and_lock(lock);
420 if (lock->l_granted_mode != lock->l_req_mode) {
421 /* this blocking AST will be communicated as part of the
422 * completion AST instead */
423 unlock_res_and_lock(lock);
424 LDLM_DEBUG(lock, "lock not granted, not sending blocking AST");
425 ptlrpc_req_finished(req);
429 if (lock->l_destroyed) {
430 /* What's the point? */
431 unlock_res_and_lock(lock);
432 ptlrpc_req_finished(req);
436 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
437 memcpy(&body->lock_handle1, &lock->l_remote_handle,
438 sizeof(body->lock_handle1));
439 memcpy(&body->lock_desc, desc, sizeof(*desc));
440 body->lock_flags |= (lock->l_flags & LDLM_AST_FLAGS);
442 LDLM_DEBUG(lock, "server preparing blocking AST");
443 req->rq_replen = lustre_msg_size(0, NULL);
445 if (lock->l_granted_mode == lock->l_req_mode)
446 ldlm_add_waiting_lock(lock);
447 unlock_res_and_lock(lock);
449 req->rq_send_state = LUSTRE_IMP_FULL;
450 req->rq_timeout = ldlm_timeout; /* timeout for initial AST reply */
451 rc = ptlrpc_queue_wait(req);
453 rc = ldlm_handle_ast_error(lock, req, rc, "blocking");
455 ptlrpc_req_finished(req);
460 /* XXX copied from ptlrpc/service.c */
461 static long timeval_sub(struct timeval *large, struct timeval *small)
463 return (large->tv_sec - small->tv_sec) * 1000000 +
464 (large->tv_usec - small->tv_usec);
467 int ldlm_server_completion_ast(struct ldlm_lock *lock, int flags, void *data)
469 struct ldlm_request *body;
470 struct ptlrpc_request *req;
471 struct timeval granted_time;
472 long total_enqueue_wait;
473 int rc = 0, size[2] = {sizeof(*body)}, buffers = 1;
476 LASSERT(lock != NULL);
478 do_gettimeofday(&granted_time);
479 total_enqueue_wait = timeval_sub(&granted_time, &lock->l_enqueued_time);
481 if (((flags & LDLM_FL_NO_TIMEOUT) == 0) &&
482 ((total_enqueue_wait / 1000000) > obd_timeout))
483 LDLM_ERROR(lock, "enqueue wait took %ldus", total_enqueue_wait);
485 lock_res_and_lock(lock);
486 if (lock->l_resource->lr_lvb_len) {
488 size[1] = lock->l_resource->lr_lvb_len;
490 unlock_res_and_lock(lock);
492 req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse,
493 LUSTRE_DLM_VERSION, LDLM_CP_CALLBACK,
494 buffers, size, NULL);
498 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
499 memcpy(&body->lock_handle1, &lock->l_remote_handle,
500 sizeof(body->lock_handle1));
501 body->lock_flags = flags;
502 ldlm_lock2desc(lock, &body->lock_desc);
507 lvb = lustre_msg_buf(req->rq_reqmsg, 1,
508 lock->l_resource->lr_lvb_len);
509 lock_res_and_lock(lock);
510 memcpy(lvb, lock->l_resource->lr_lvb_data,
511 lock->l_resource->lr_lvb_len);
512 unlock_res_and_lock(lock);
515 LDLM_DEBUG(lock, "server preparing completion AST (after %ldus wait)",
517 req->rq_replen = lustre_msg_size(0, NULL);
519 req->rq_send_state = LUSTRE_IMP_FULL;
520 req->rq_timeout = ldlm_timeout; /* timeout for initial AST reply */
522 /* We only send real blocking ASTs after the lock is granted */
523 lock_res_and_lock(lock);
524 if (lock->l_flags & LDLM_FL_AST_SENT) {
525 body->lock_flags |= LDLM_FL_AST_SENT;
526 ldlm_add_waiting_lock(lock); /* start the lock-timeout clock */
528 unlock_res_and_lock(lock);
530 rc = ptlrpc_queue_wait(req);
532 rc = ldlm_handle_ast_error(lock, req, rc, "completion");
534 ptlrpc_req_finished(req);
539 int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data)
541 struct ldlm_resource *res;
542 struct ldlm_request *body;
543 struct ptlrpc_request *req;
544 int rc = 0, size = sizeof(*body);
547 LASSERT(lock != NULL);
549 req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse,
550 LUSTRE_DLM_VERSION, LDLM_GL_CALLBACK,
555 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
556 memcpy(&body->lock_handle1, &lock->l_remote_handle,
557 sizeof(body->lock_handle1));
558 ldlm_lock2desc(lock, &body->lock_desc);
560 lock_res_and_lock(lock);
561 size = lock->l_resource->lr_lvb_len;
562 unlock_res_and_lock(lock);
563 res = lock->l_resource;
564 req->rq_replen = lustre_msg_size(1, &size);
566 req->rq_send_state = LUSTRE_IMP_FULL;
567 req->rq_timeout = 2; /* 2 second timeout for initial AST reply */
569 rc = ptlrpc_queue_wait(req);
570 if (rc == -ELDLM_NO_LOCK_DATA)
571 LDLM_DEBUG(lock, "lost race - client has a lock but no inode");
573 rc = ldlm_handle_ast_error(lock, req, rc, "glimpse");
575 rc = res->lr_namespace->ns_lvbo->lvbo_update
576 (res, req->rq_repmsg, 0, 1);
577 ptlrpc_req_finished(req);
581 static struct ldlm_lock *
582 find_existing_lock(struct obd_export *exp, struct lustre_handle *remote_hdl)
584 struct list_head *iter;
586 spin_lock(&exp->exp_ldlm_data.led_lock);
587 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
588 struct ldlm_lock *lock;
589 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
590 if (lock->l_remote_handle.cookie == remote_hdl->cookie) {
592 spin_unlock(&exp->exp_ldlm_data.led_lock);
596 spin_unlock(&exp->exp_ldlm_data.led_lock);
600 int ldlm_handle_enqueue(struct ptlrpc_request *req,
601 ldlm_completion_callback completion_callback,
602 ldlm_blocking_callback blocking_callback,
603 ldlm_glimpse_callback glimpse_callback)
605 struct obd_device *obddev = req->rq_export->exp_obd;
606 struct ldlm_reply *dlm_rep;
607 struct ldlm_request *dlm_req;
608 int rc = 0, size[2] = {sizeof(*dlm_rep)};
610 ldlm_error_t err = ELDLM_OK;
611 struct ldlm_lock *lock = NULL;
615 LDLM_DEBUG_NOLOCK("server-side enqueue handler START");
617 dlm_req = lustre_swab_reqbuf (req, MDS_REQ_INTENT_LOCKREQ_OFF,
619 lustre_swab_ldlm_request);
620 if (dlm_req == NULL) {
621 CERROR ("Can't unpack dlm_req\n");
622 GOTO(out, rc = -EFAULT);
625 flags = dlm_req->lock_flags;
627 LASSERT(req->rq_export);
629 if (flags & LDLM_FL_REPLAY) {
630 lock = find_existing_lock(req->rq_export,
631 &dlm_req->lock_handle1);
633 DEBUG_REQ(D_HA, req, "found existing lock cookie "LPX64,
634 lock->l_handle.h_cookie);
635 GOTO(existing_lock, rc = 0);
639 /* The lock's callback data might be set in the policy function */
640 lock = ldlm_lock_create(obddev->obd_namespace, &dlm_req->lock_handle2,
641 dlm_req->lock_desc.l_resource.lr_name,
642 dlm_req->lock_desc.l_resource.lr_type,
643 dlm_req->lock_desc.l_req_mode,
644 blocking_callback, completion_callback,
645 glimpse_callback, NULL, 0);
647 GOTO(out, rc = -ENOMEM);
649 do_gettimeofday(&lock->l_enqueued_time);
650 memcpy(&lock->l_remote_handle, &dlm_req->lock_handle1,
651 sizeof(lock->l_remote_handle));
652 LDLM_DEBUG(lock, "server-side enqueue handler, new lock created");
654 LASSERT(req->rq_export);
655 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_ENQUEUE_BLOCKED, obd_timeout * 2);
656 if (req->rq_export->exp_failed) {
657 LDLM_ERROR(lock,"lock on destroyed export %p\n",req->rq_export);
658 GOTO(out, err = -ENOTCONN);
661 lock->l_export = class_export_get(req->rq_export);
662 spin_lock(&lock->l_export->exp_ldlm_data.led_lock);
663 list_add(&lock->l_export_chain,
664 &lock->l_export->exp_ldlm_data.led_held_locks);
665 spin_unlock(&lock->l_export->exp_ldlm_data.led_lock);
669 if (flags & LDLM_FL_HAS_INTENT) {
670 /* In this case, the reply buffer is allocated deep in
671 * local_lock_enqueue by the policy function. */
675 lock_res_and_lock(lock);
676 if (lock->l_resource->lr_lvb_len) {
677 size[1] = lock->l_resource->lr_lvb_len;
680 unlock_res_and_lock(lock);
681 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR))
682 GOTO(out, rc = -ENOMEM);
684 rc = lustre_pack_reply(req, buffers, size, NULL);
689 if (dlm_req->lock_desc.l_resource.lr_type != LDLM_PLAIN)
690 memcpy(&lock->l_policy_data, &dlm_req->lock_desc.l_policy_data,
691 sizeof(ldlm_policy_data_t));
692 if (dlm_req->lock_desc.l_resource.lr_type == LDLM_EXTENT)
693 memcpy(&lock->l_req_extent, &lock->l_policy_data.l_extent,
694 sizeof(lock->l_req_extent));
696 err = ldlm_lock_enqueue(obddev->obd_namespace, &lock,
697 cookie, (int *)&flags);
701 dlm_rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*dlm_rep));
702 dlm_rep->lock_flags = flags;
704 ldlm_lock2desc(lock, &dlm_rep->lock_desc);
705 ldlm_lock2handle(lock, &dlm_rep->lock_handle);
707 /* We never send a blocking AST until the lock is granted, but
708 * we can tell it right now */
709 lock_res_and_lock(lock);
710 if (lock->l_flags & LDLM_FL_AST_SENT) {
711 dlm_rep->lock_flags |= LDLM_FL_AST_SENT;
712 if (lock->l_granted_mode == lock->l_req_mode)
713 ldlm_add_waiting_lock(lock);
715 unlock_res_and_lock(lock);
719 req->rq_status = err;
720 if (req->rq_reply_state == NULL) {
721 err = lustre_pack_reply(req, 0, NULL, NULL);
727 /* The LOCK_CHANGED code in ldlm_lock_enqueue depends on this
728 * ldlm_reprocess_all. If this moves, revisit that code. -phil */
730 LDLM_DEBUG(lock, "server-side enqueue handler, sending reply"
731 "(err=%d, rc=%d)", err, rc);
734 lock_res_and_lock(lock);
735 size[1] = lock->l_resource->lr_lvb_len;
737 void *lvb = lustre_msg_buf(req->rq_repmsg,
739 LASSERTF(lvb != NULL, "req %p, lock %p\n",
742 memcpy(lvb, lock->l_resource->lr_lvb_data,
745 unlock_res_and_lock(lock);
747 ldlm_lock_destroy(lock);
750 if (!err && dlm_req->lock_desc.l_resource.lr_type != LDLM_FLOCK)
751 ldlm_reprocess_all(lock->l_resource);
754 LDLM_DEBUG_NOLOCK("server-side enqueue handler END (lock %p, rc %d)",
760 int ldlm_handle_convert(struct ptlrpc_request *req)
762 struct ldlm_request *dlm_req;
763 struct ldlm_reply *dlm_rep;
764 struct ldlm_lock *lock;
765 int rc, size = sizeof(*dlm_rep);
768 dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req),
769 lustre_swab_ldlm_request);
770 if (dlm_req == NULL) {
771 CERROR ("Can't unpack dlm_req\n");
775 rc = lustre_pack_reply(req, 1, &size, NULL);
777 CERROR("out of memory\n");
780 dlm_rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*dlm_rep));
781 dlm_rep->lock_flags = dlm_req->lock_flags;
783 lock = ldlm_handle2lock(&dlm_req->lock_handle1);
785 req->rq_status = EINVAL;
789 LDLM_DEBUG(lock, "server-side convert handler START");
791 do_gettimeofday(&lock->l_enqueued_time);
792 res = ldlm_lock_convert(lock, dlm_req->lock_desc.l_req_mode,
793 (int *)&dlm_rep->lock_flags);
795 if (ldlm_del_waiting_lock(lock))
796 LDLM_DEBUG(lock, "converted waiting lock");
799 req->rq_status = EDEADLOCK;
805 ldlm_reprocess_all(lock->l_resource);
806 LDLM_DEBUG(lock, "server-side convert handler END");
809 LDLM_DEBUG_NOLOCK("server-side convert handler END");
814 int ldlm_handle_cancel(struct ptlrpc_request *req)
816 struct ldlm_request *dlm_req;
817 struct ldlm_lock *lock;
818 struct ldlm_resource *res;
822 dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req),
823 lustre_swab_ldlm_request);
824 if (dlm_req == NULL) {
825 CERROR("bad request buffer for cancel\n");
829 rc = lustre_pack_reply(req, 0, NULL, NULL);
831 CERROR("out of memory\n");
835 lock = ldlm_handle2lock(&dlm_req->lock_handle1);
837 CERROR("received cancel for unknown lock cookie "LPX64
838 " from client %s id %s\n",
839 dlm_req->lock_handle1.cookie,
840 req->rq_export->exp_client_uuid.uuid,
842 LDLM_DEBUG_NOLOCK("server-side cancel handler stale lock "
844 dlm_req->lock_handle1.cookie);
845 req->rq_status = ESTALE;
847 LDLM_DEBUG(lock, "server-side cancel handler START");
848 res = lock->l_resource;
849 if (res && res->lr_namespace->ns_lvbo &&
850 res->lr_namespace->ns_lvbo->lvbo_update) {
851 (void)res->lr_namespace->ns_lvbo->lvbo_update
853 //(res, req->rq_reqmsg, 1);
856 ldlm_lock_cancel(lock);
857 if (ldlm_del_waiting_lock(lock))
858 CDEBUG(D_DLMTRACE, "cancelled waiting lock %p\n", lock);
862 if (ptlrpc_reply(req) != 0)
866 ldlm_reprocess_all(lock->l_resource);
867 LDLM_DEBUG(lock, "server-side cancel handler END");
874 void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
875 struct ldlm_lock_desc *ld, struct ldlm_lock *lock)
880 LDLM_DEBUG(lock, "client blocking AST callback handler START");
882 lock_res_and_lock(lock);
883 lock->l_flags |= LDLM_FL_CBPENDING;
884 do_ast = (!lock->l_readers && !lock->l_writers);
885 unlock_res_and_lock(lock);
888 LDLM_DEBUG(lock, "already unused, calling "
889 "callback (%p)", lock->l_blocking_ast);
890 if (lock->l_blocking_ast != NULL)
891 lock->l_blocking_ast(lock, ld, lock->l_ast_data,
894 LDLM_DEBUG(lock, "Lock still has references, will be"
898 LDLM_DEBUG(lock, "client blocking callback handler END");
903 static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
904 struct ldlm_namespace *ns,
905 struct ldlm_request *dlm_req,
906 struct ldlm_lock *lock)
911 LDLM_DEBUG(lock, "client completion callback handler START");
913 lock_res_and_lock(lock);
915 /* If we receive the completion AST before the actual enqueue returned,
916 * then we might need to switch lock modes, resources, or extents. */
917 if (dlm_req->lock_desc.l_granted_mode != lock->l_req_mode) {
918 lock->l_req_mode = dlm_req->lock_desc.l_granted_mode;
919 LDLM_DEBUG(lock, "completion AST, new lock mode");
922 if (lock->l_resource->lr_type != LDLM_PLAIN) {
923 memcpy(&lock->l_policy_data, &dlm_req->lock_desc.l_policy_data,
924 sizeof(lock->l_policy_data));
925 LDLM_DEBUG(lock, "completion AST, new policy data");
928 ldlm_resource_unlink_lock(lock);
929 if (memcmp(&dlm_req->lock_desc.l_resource.lr_name,
930 &lock->l_resource->lr_name,
931 sizeof(lock->l_resource->lr_name)) != 0) {
932 unlock_res_and_lock(lock);
933 ldlm_lock_change_resource(ns, lock,
934 dlm_req->lock_desc.l_resource.lr_name);
935 LDLM_DEBUG(lock, "completion AST, new resource");
936 CERROR("change resource!\n");
937 lock_res_and_lock(lock);
940 if (dlm_req->lock_flags & LDLM_FL_AST_SENT) {
941 lock->l_flags |= LDLM_FL_CBPENDING;
942 LDLM_DEBUG(lock, "completion AST includes blocking AST");
945 if (lock->l_lvb_len) {
947 lvb = lustre_swab_reqbuf(req, 1, lock->l_lvb_len,
948 lock->l_lvb_swabber);
950 LDLM_ERROR(lock, "completion AST did not contain "
953 memcpy(lock->l_lvb_data, lvb, lock->l_lvb_len);
957 ldlm_grant_lock(lock, &ast_list);
958 unlock_res_and_lock(lock);
960 LDLM_DEBUG(lock, "callback handler finished, about to run_ast_work");
963 ldlm_run_cp_ast_work(&ast_list);
965 LDLM_DEBUG_NOLOCK("client completion callback handler END (lock %p)",
970 static void ldlm_handle_gl_callback(struct ptlrpc_request *req,
971 struct ldlm_namespace *ns,
972 struct ldlm_request *dlm_req,
973 struct ldlm_lock *lock)
978 LDLM_DEBUG(lock, "client glimpse AST callback handler");
980 if (lock->l_glimpse_ast != NULL)
981 rc = lock->l_glimpse_ast(lock, req);
983 if (req->rq_repmsg != NULL) {
990 lock_res_and_lock(lock);
991 if (lock->l_granted_mode == LCK_PW &&
992 !lock->l_readers && !lock->l_writers &&
993 time_after(jiffies, lock->l_last_used + 10 * HZ)) {
994 unlock_res_and_lock(lock);
995 if (ldlm_bl_to_thread(ns, NULL, lock))
996 ldlm_handle_bl_callback(ns, NULL, lock);
1001 unlock_res_and_lock(lock);
1002 LDLM_LOCK_PUT(lock);
1006 static int ldlm_callback_reply(struct ptlrpc_request *req, int rc)
1008 req->rq_status = rc;
1009 if (req->rq_reply_state == NULL) {
1010 rc = lustre_pack_reply(req, 0, NULL, NULL);
1014 return ptlrpc_reply(req);
1017 int ldlm_bl_to_thread(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
1018 struct ldlm_lock *lock)
1021 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
1022 struct ldlm_bl_work_item *blwi;
1025 OBD_ALLOC(blwi, sizeof(*blwi));
1031 blwi->blwi_ld = *ld;
1032 blwi->blwi_lock = lock;
1034 spin_lock(&blp->blp_lock);
1035 list_add_tail(&blwi->blwi_entry, &blp->blp_list);
1036 wake_up(&blp->blp_waitq);
1037 spin_unlock(&blp->blp_lock);
1046 static int ldlm_msg_check_version(struct lustre_msg *msg)
1054 case LDLM_BL_CALLBACK:
1055 case LDLM_CP_CALLBACK:
1056 case LDLM_GL_CALLBACK:
1057 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1059 CERROR("bad opc %u version %08x, expecting %08x\n",
1060 msg->opc, msg->version, LUSTRE_DLM_VERSION);
1062 case OBD_LOG_CANCEL:
1063 case LLOG_ORIGIN_HANDLE_OPEN:
1064 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1065 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
1066 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1067 case LLOG_ORIGIN_HANDLE_CLOSE:
1069 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1071 CERROR("bad opc %u version %08x, expecting %08x\n",
1072 msg->opc, msg->version, LUSTRE_LOG_VERSION);
1075 CERROR("LDLM unknown opcode %d\n", msg->opc);
1083 static int ldlm_callback_handler(struct ptlrpc_request *req)
1085 struct ldlm_namespace *ns;
1086 struct ldlm_request *dlm_req;
1087 struct ldlm_lock *lock;
1091 rc = ldlm_msg_check_version(req->rq_reqmsg);
1093 CERROR("LDLM_CB drop mal-formed request\n");
1097 /* Requests arrive in sender's byte order. The ptlrpc service
1098 * handler has already checked and, if necessary, byte-swapped the
1099 * incoming request message body, but I am responsible for the
1100 * message buffers. */
1102 if (req->rq_export == NULL) {
1103 struct ldlm_request *dlm_req;
1105 CDEBUG(D_RPCTRACE, "operation %d from %s with bad "
1106 "export cookie "LPX64"; this is "
1107 "normal if this node rebooted with a lock held\n",
1108 req->rq_reqmsg->opc,
1110 req->rq_reqmsg->handle.cookie);
1111 dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req),
1112 lustre_swab_ldlm_request);
1113 if (dlm_req != NULL)
1114 CDEBUG(D_RPCTRACE, "--> lock cookie: "LPX64"\n",
1115 dlm_req->lock_handle1.cookie);
1117 ldlm_callback_reply(req, -ENOTCONN);
1121 LASSERT(req->rq_export != NULL);
1122 LASSERT(req->rq_export->exp_obd != NULL);
1124 switch(req->rq_reqmsg->opc) {
1125 case LDLM_BL_CALLBACK:
1126 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
1128 case LDLM_CP_CALLBACK:
1129 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CP_CALLBACK, 0);
1131 case LDLM_GL_CALLBACK:
1132 OBD_FAIL_RETURN(OBD_FAIL_LDLM_GL_CALLBACK, 0);
1134 case OBD_LOG_CANCEL:
1135 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1136 rc = llog_origin_handle_cancel(req);
1137 ldlm_callback_reply(req, rc);
1139 case LLOG_ORIGIN_HANDLE_OPEN:
1140 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1141 rc = llog_origin_handle_open(req);
1142 ldlm_callback_reply(req, rc);
1144 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1145 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1146 rc = llog_origin_handle_next_block(req);
1147 ldlm_callback_reply(req, rc);
1149 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
1150 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1151 rc = llog_origin_handle_prev_block(req);
1152 ldlm_callback_reply(req, rc);
1154 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1155 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1156 rc = llog_origin_handle_read_header(req);
1157 ldlm_callback_reply(req, rc);
1159 case LLOG_ORIGIN_HANDLE_CLOSE:
1160 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1161 rc = llog_origin_handle_close(req);
1162 ldlm_callback_reply(req, rc);
1165 CERROR("unknown opcode %u\n", req->rq_reqmsg->opc);
1166 ldlm_callback_reply(req, -EPROTO);
1170 ns = req->rq_export->exp_obd->obd_namespace;
1171 LASSERT(ns != NULL);
1173 dlm_req = lustre_swab_reqbuf (req, 0, sizeof (*dlm_req),
1174 lustre_swab_ldlm_request);
1175 if (dlm_req == NULL) {
1176 CERROR ("can't unpack dlm_req\n");
1177 ldlm_callback_reply (req, -EPROTO);
1181 lock = ldlm_handle2lock_ns(ns, &dlm_req->lock_handle1);
1183 LDLM_DEBUG_NOLOCK("callback on lock "LPX64" - lock "
1184 "disappeared\n",dlm_req->lock_handle1.cookie);
1185 ldlm_callback_reply(req, -EINVAL);
1189 /* Copy hints/flags (e.g. LDLM_FL_DISCARD_DATA) from AST. */
1190 lock_res_and_lock(lock);
1191 lock->l_flags |= (dlm_req->lock_flags & LDLM_AST_FLAGS);
1192 unlock_res_and_lock(lock);
1194 /* We want the ost thread to get this reply so that it can respond
1195 * to ost requests (write cache writeback) that might be triggered
1198 * But we'd also like to be able to indicate in the reply that we're
1199 * cancelling right now, because it's unused, or have an intent result
1200 * in the reply, so we might have to push the responsibility for sending
1201 * the reply down into the AST handlers, alas. */
1203 switch (req->rq_reqmsg->opc) {
1204 case LDLM_BL_CALLBACK:
1205 CDEBUG(D_INODE, "blocking ast\n");
1206 ldlm_callback_reply(req, 0);
1207 if (ldlm_bl_to_thread(ns, &dlm_req->lock_desc, lock))
1208 ldlm_handle_bl_callback(ns, &dlm_req->lock_desc, lock);
1211 case LDLM_CP_CALLBACK:
1212 CDEBUG(D_INODE, "completion ast\n");
1213 ldlm_callback_reply(req, 0);
1214 ldlm_handle_cp_callback(req, ns, dlm_req, lock);
1216 case LDLM_GL_CALLBACK:
1217 CDEBUG(D_INODE, "glimpse ast\n");
1218 ldlm_handle_gl_callback(req, ns, dlm_req, lock);
1221 LBUG(); /* checked above */
1227 static int ldlm_cancel_handler(struct ptlrpc_request *req)
1232 rc = ldlm_msg_check_version(req->rq_reqmsg);
1234 CERROR("LDLM_CL drop mal-formed request\n");
1238 /* Requests arrive in sender's byte order. The ptlrpc service
1239 * handler has already checked and, if necessary, byte-swapped the
1240 * incoming request message body, but I am responsible for the
1241 * message buffers. */
1243 if (req->rq_export == NULL) {
1244 struct ldlm_request *dlm_req;
1245 CERROR("operation %d with bad export from %s\n",
1246 req->rq_reqmsg->opc,
1248 CERROR("--> export cookie: "LPX64"\n",
1249 req->rq_reqmsg->handle.cookie);
1250 dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req),
1251 lustre_swab_ldlm_request);
1252 if (dlm_req != NULL)
1253 ldlm_lock_dump_handle(D_ERROR, &dlm_req->lock_handle1);
1254 ldlm_callback_reply(req, -ENOTCONN);
1258 switch (req->rq_reqmsg->opc) {
1260 /* XXX FIXME move this back to mds/handler.c, bug 249 */
1262 CDEBUG(D_INODE, "cancel\n");
1263 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1264 rc = ldlm_handle_cancel(req);
1267 CERROR("invalid opcode %d\n", req->rq_reqmsg->opc);
1268 ldlm_callback_reply(req, -EINVAL);
1275 static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp)
1277 struct ldlm_bl_work_item *blwi = NULL;
1279 spin_lock(&blp->blp_lock);
1280 if (!list_empty(&blp->blp_list)) {
1281 blwi = list_entry(blp->blp_list.next, struct ldlm_bl_work_item,
1283 list_del(&blwi->blwi_entry);
1285 spin_unlock(&blp->blp_lock);
1290 struct ldlm_bl_thread_data {
1292 struct ldlm_bl_pool *bltd_blp;
1295 static int ldlm_bl_thread_main(void *arg)
1297 struct ldlm_bl_thread_data *bltd = arg;
1298 struct ldlm_bl_pool *blp = bltd->bltd_blp;
1299 unsigned long flags;
1302 /* XXX boiler-plate */
1304 char name[sizeof(current->comm)];
1305 snprintf(name, sizeof(name) - 1, "ldlm_bl_%02d",
1307 kportal_daemonize(name);
1309 SIGNAL_MASK_LOCK(current, flags);
1310 sigfillset(¤t->blocked);
1312 SIGNAL_MASK_UNLOCK(current, flags);
1314 atomic_inc(&blp->blp_num_threads);
1315 complete(&blp->blp_comp);
1318 struct l_wait_info lwi = { 0 };
1319 struct ldlm_bl_work_item *blwi = NULL;
1321 l_wait_event_exclusive(blp->blp_waitq,
1322 (blwi = ldlm_bl_get_work(blp)) != NULL,
1325 if (blwi->blwi_ns == NULL)
1328 ldlm_handle_bl_callback(blwi->blwi_ns, &blwi->blwi_ld,
1330 OBD_FREE(blwi, sizeof(*blwi));
1333 atomic_dec(&blp->blp_num_threads);
1334 complete(&blp->blp_comp);
1340 static int ldlm_setup(void);
1341 static int ldlm_cleanup(int force);
1343 int ldlm_get_ref(void)
1346 down(&ldlm_ref_sem);
1347 if (++ldlm_refcount == 1) {
1357 void ldlm_put_ref(int force)
1359 down(&ldlm_ref_sem);
1360 if (ldlm_refcount == 1) {
1361 int rc = ldlm_cleanup(force);
1363 CERROR("ldlm_cleanup failed: %d\n", rc);
1374 static int ldlm_setup(void)
1376 struct ldlm_bl_pool *blp;
1383 if (ldlm_state != NULL)
1386 OBD_ALLOC(ldlm_state, sizeof(*ldlm_state));
1387 if (ldlm_state == NULL)
1391 rc = ldlm_proc_setup();
1396 ldlm_state->ldlm_cb_service =
1397 ptlrpc_init_svc(LDLM_NBUFS, LDLM_BUFSIZE, LDLM_MAXREQSIZE,
1398 LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1399 1500, ldlm_callback_handler, "ldlm_cbd",
1402 if (!ldlm_state->ldlm_cb_service) {
1403 CERROR("failed to start service\n");
1404 GOTO(out_proc, rc = -ENOMEM);
1407 ldlm_state->ldlm_cancel_service =
1408 ptlrpc_init_svc(LDLM_NBUFS, LDLM_BUFSIZE, LDLM_MAXREQSIZE,
1409 LDLM_CANCEL_REQUEST_PORTAL,
1410 LDLM_CANCEL_REPLY_PORTAL, 30000,
1411 ldlm_cancel_handler, "ldlm_canceld",
1414 if (!ldlm_state->ldlm_cancel_service) {
1415 CERROR("failed to start service\n");
1416 GOTO(out_proc, rc = -ENOMEM);
1419 OBD_ALLOC(blp, sizeof(*blp));
1421 GOTO(out_proc, rc = -ENOMEM);
1422 ldlm_state->ldlm_bl_pool = blp;
1424 atomic_set(&blp->blp_num_threads, 0);
1425 init_waitqueue_head(&blp->blp_waitq);
1426 spin_lock_init(&blp->blp_lock);
1428 INIT_LIST_HEAD(&blp->blp_list);
1431 for (i = 0; i < LDLM_NUM_THREADS; i++) {
1432 struct ldlm_bl_thread_data bltd = {
1436 init_completion(&blp->blp_comp);
1437 rc = kernel_thread(ldlm_bl_thread_main, &bltd, 0);
1439 CERROR("cannot start LDLM thread #%d: rc %d\n", i, rc);
1440 GOTO(out_thread, rc);
1442 wait_for_completion(&blp->blp_comp);
1445 rc = ptlrpc_start_n_threads(NULL, ldlm_state->ldlm_cancel_service,
1446 LDLM_NUM_THREADS, "ldlm_cn");
1448 GOTO(out_thread, rc);
1450 rc = ptlrpc_start_n_threads(NULL, ldlm_state->ldlm_cb_service,
1451 LDLM_NUM_THREADS, "ldlm_cb");
1453 GOTO(out_thread, rc);
1455 INIT_LIST_HEAD(&expired_lock_thread.elt_expired_locks);
1456 spin_lock_init(&expired_lock_thread.elt_lock);
1457 expired_lock_thread.elt_state = ELT_STOPPED;
1458 init_waitqueue_head(&expired_lock_thread.elt_waitq);
1460 rc = kernel_thread(expired_lock_main, NULL, CLONE_VM | CLONE_FS);
1462 CERROR("Cannot start ldlm expired-lock thread: %d\n", rc);
1463 GOTO(out_thread, rc);
1466 wait_event(expired_lock_thread.elt_waitq,
1467 expired_lock_thread.elt_state == ELT_READY);
1469 INIT_LIST_HEAD(&waiting_locks_list);
1470 spin_lock_init(&waiting_locks_spinlock);
1471 waiting_locks_timer.function = waiting_locks_callback;
1472 waiting_locks_timer.data = 0;
1473 init_timer(&waiting_locks_timer);
1480 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
1481 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
1486 ldlm_proc_cleanup();
1489 OBD_FREE(ldlm_state, sizeof(*ldlm_state));
1494 static int ldlm_cleanup(int force)
1497 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
1501 if (!list_empty(&ldlm_namespace_list)) {
1502 CERROR("ldlm still has namespaces; clean these up first.\n");
1503 ldlm_dump_all_namespaces(D_DLMTRACE);
1508 while (atomic_read(&blp->blp_num_threads) > 0) {
1509 struct ldlm_bl_work_item blwi = { .blwi_ns = NULL };
1511 init_completion(&blp->blp_comp);
1513 spin_lock(&blp->blp_lock);
1514 list_add_tail(&blwi.blwi_entry, &blp->blp_list);
1515 wake_up(&blp->blp_waitq);
1516 spin_unlock(&blp->blp_lock);
1518 wait_for_completion(&blp->blp_comp);
1520 OBD_FREE(blp, sizeof(*blp));
1522 ptlrpc_stop_all_threads(ldlm_state->ldlm_cb_service);
1523 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
1524 ptlrpc_stop_all_threads(ldlm_state->ldlm_cancel_service);
1525 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
1526 ldlm_proc_cleanup();
1528 expired_lock_thread.elt_state = ELT_TERMINATE;
1529 wake_up(&expired_lock_thread.elt_waitq);
1530 wait_event(expired_lock_thread.elt_waitq,
1531 expired_lock_thread.elt_state == ELT_STOPPED);
1533 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
1534 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
1537 OBD_FREE(ldlm_state, sizeof(*ldlm_state));
1543 int __init ldlm_init(void)
1545 ldlm_resource_slab = kmem_cache_create("ldlm_resources",
1546 sizeof(struct ldlm_resource), 0,
1547 SLAB_HWCACHE_ALIGN, NULL, NULL);
1548 if (ldlm_resource_slab == NULL)
1551 ldlm_lock_slab = kmem_cache_create("ldlm_locks",
1552 sizeof(struct ldlm_lock), 0,
1553 SLAB_HWCACHE_ALIGN, NULL, NULL);
1554 if (ldlm_lock_slab == NULL) {
1555 kmem_cache_destroy(ldlm_resource_slab);
1562 void __exit ldlm_exit(void)
1564 if ( ldlm_refcount )
1565 CERROR("ldlm_refcount is %d in ldlm_exit!\n", ldlm_refcount);
1566 LASSERTF(kmem_cache_destroy(ldlm_resource_slab) == 0,
1567 "couldn't free ldlm resource slab\n");
1568 LASSERTF(kmem_cache_destroy(ldlm_lock_slab) == 0,
1569 "couldn't free ldlm lock slab\n");
1574 EXPORT_SYMBOL(ldlm_flock_completion_ast);
1577 EXPORT_SYMBOL(ldlm_extent_shift_kms);
1580 EXPORT_SYMBOL(ldlm_get_processing_policy);
1581 EXPORT_SYMBOL(ldlm_lock2desc);
1582 EXPORT_SYMBOL(ldlm_register_intent);
1583 EXPORT_SYMBOL(ldlm_lockname);
1584 EXPORT_SYMBOL(ldlm_typename);
1585 EXPORT_SYMBOL(ldlm_lock2handle);
1586 EXPORT_SYMBOL(__ldlm_handle2lock);
1587 EXPORT_SYMBOL(ldlm_lock_get);
1588 EXPORT_SYMBOL(ldlm_lock_put);
1589 EXPORT_SYMBOL(ldlm_lock_match);
1590 EXPORT_SYMBOL(ldlm_lock_cancel);
1591 EXPORT_SYMBOL(ldlm_lock_addref);
1592 EXPORT_SYMBOL(ldlm_lock_decref);
1593 EXPORT_SYMBOL(ldlm_lock_decref_and_cancel);
1594 EXPORT_SYMBOL(ldlm_lock_change_resource);
1595 EXPORT_SYMBOL(ldlm_lock_set_data);
1596 EXPORT_SYMBOL(ldlm_it2str);
1597 EXPORT_SYMBOL(ldlm_lock_dump);
1598 EXPORT_SYMBOL(ldlm_lock_dump_handle);
1599 EXPORT_SYMBOL(ldlm_cancel_locks_for_export);
1600 EXPORT_SYMBOL(ldlm_reprocess_all_ns);
1601 EXPORT_SYMBOL(ldlm_lock_allow_match);
1603 /* ldlm_request.c */
1604 EXPORT_SYMBOL(ldlm_completion_ast);
1605 EXPORT_SYMBOL(ldlm_expired_completion_wait);
1606 EXPORT_SYMBOL(ldlm_cli_convert);
1607 EXPORT_SYMBOL(ldlm_cli_enqueue);
1608 EXPORT_SYMBOL(ldlm_cli_cancel);
1609 EXPORT_SYMBOL(ldlm_cli_cancel_unused);
1610 EXPORT_SYMBOL(ldlm_replay_locks);
1611 EXPORT_SYMBOL(ldlm_resource_foreach);
1612 EXPORT_SYMBOL(ldlm_namespace_foreach);
1613 EXPORT_SYMBOL(ldlm_namespace_foreach_res);
1614 EXPORT_SYMBOL(ldlm_change_cbdata);
1617 EXPORT_SYMBOL(ldlm_server_blocking_ast);
1618 EXPORT_SYMBOL(ldlm_server_completion_ast);
1619 EXPORT_SYMBOL(ldlm_server_glimpse_ast);
1620 EXPORT_SYMBOL(ldlm_handle_enqueue);
1621 EXPORT_SYMBOL(ldlm_handle_cancel);
1622 EXPORT_SYMBOL(ldlm_handle_convert);
1623 EXPORT_SYMBOL(ldlm_del_waiting_lock);
1624 EXPORT_SYMBOL(ldlm_get_ref);
1625 EXPORT_SYMBOL(ldlm_put_ref);
1629 EXPORT_SYMBOL(ldlm_test);
1630 EXPORT_SYMBOL(ldlm_regression_start);
1631 EXPORT_SYMBOL(ldlm_regression_stop);
1634 /* ldlm_resource.c */
1635 EXPORT_SYMBOL(ldlm_namespace_new);
1636 EXPORT_SYMBOL(ldlm_namespace_cleanup);
1637 EXPORT_SYMBOL(ldlm_namespace_free);
1638 EXPORT_SYMBOL(ldlm_namespace_dump);
1639 EXPORT_SYMBOL(ldlm_dump_all_namespaces);
1640 EXPORT_SYMBOL(ldlm_resource_get);
1641 EXPORT_SYMBOL(ldlm_resource_putref);
1644 EXPORT_SYMBOL(client_import_add_conn);
1645 EXPORT_SYMBOL(client_import_del_conn);
1646 EXPORT_SYMBOL(client_obd_setup);
1647 EXPORT_SYMBOL(client_obd_cleanup);
1648 EXPORT_SYMBOL(client_connect_import);
1649 EXPORT_SYMBOL(client_disconnect_export);
1650 EXPORT_SYMBOL(target_start_recovery_thread);
1651 EXPORT_SYMBOL(target_stop_recovery_thread);
1652 EXPORT_SYMBOL(target_handle_connect);
1653 EXPORT_SYMBOL(target_cleanup_recovery);
1654 EXPORT_SYMBOL(target_destroy_export);
1655 EXPORT_SYMBOL(target_cancel_recovery_timer);
1656 EXPORT_SYMBOL(target_send_reply);
1657 EXPORT_SYMBOL(target_queue_recovery_request);
1658 EXPORT_SYMBOL(target_handle_ping);
1659 EXPORT_SYMBOL(target_handle_disconnect);
1662 EXPORT_SYMBOL(lock_res_and_lock);
1663 EXPORT_SYMBOL(unlock_res_and_lock);