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 (total_enqueue_wait / 1000000 > obd_timeout)
482 LDLM_ERROR(lock, "enqueue wait took %ldus", total_enqueue_wait);
484 lock_res_and_lock(lock);
485 if (lock->l_resource->lr_lvb_len) {
487 size[1] = lock->l_resource->lr_lvb_len;
489 unlock_res_and_lock(lock);
491 req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse,
492 LUSTRE_DLM_VERSION, LDLM_CP_CALLBACK,
493 buffers, size, NULL);
497 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
498 memcpy(&body->lock_handle1, &lock->l_remote_handle,
499 sizeof(body->lock_handle1));
500 body->lock_flags = flags;
501 ldlm_lock2desc(lock, &body->lock_desc);
506 lvb = lustre_msg_buf(req->rq_reqmsg, 1,
507 lock->l_resource->lr_lvb_len);
508 lock_res_and_lock(lock);
509 memcpy(lvb, lock->l_resource->lr_lvb_data,
510 lock->l_resource->lr_lvb_len);
511 unlock_res_and_lock(lock);
514 LDLM_DEBUG(lock, "server preparing completion AST (after %ldus wait)",
516 req->rq_replen = lustre_msg_size(0, NULL);
518 req->rq_send_state = LUSTRE_IMP_FULL;
519 req->rq_timeout = ldlm_timeout; /* timeout for initial AST reply */
521 /* We only send real blocking ASTs after the lock is granted */
522 lock_res_and_lock(lock);
523 if (lock->l_flags & LDLM_FL_AST_SENT) {
524 body->lock_flags |= LDLM_FL_AST_SENT;
525 ldlm_add_waiting_lock(lock); /* start the lock-timeout clock */
527 unlock_res_and_lock(lock);
529 rc = ptlrpc_queue_wait(req);
531 rc = ldlm_handle_ast_error(lock, req, rc, "completion");
533 ptlrpc_req_finished(req);
538 int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data)
540 struct ldlm_resource *res;
541 struct ldlm_request *body;
542 struct ptlrpc_request *req;
543 int rc = 0, size = sizeof(*body);
546 LASSERT(lock != NULL);
548 req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse,
549 LUSTRE_DLM_VERSION, LDLM_GL_CALLBACK,
554 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
555 memcpy(&body->lock_handle1, &lock->l_remote_handle,
556 sizeof(body->lock_handle1));
557 ldlm_lock2desc(lock, &body->lock_desc);
559 lock_res_and_lock(lock);
560 size = lock->l_resource->lr_lvb_len;
561 unlock_res_and_lock(lock);
562 res = lock->l_resource;
563 req->rq_replen = lustre_msg_size(1, &size);
565 req->rq_send_state = LUSTRE_IMP_FULL;
566 req->rq_timeout = 2; /* 2 second timeout for initial AST reply */
568 rc = ptlrpc_queue_wait(req);
569 if (rc == -ELDLM_NO_LOCK_DATA)
570 LDLM_DEBUG(lock, "lost race - client has a lock but no inode");
572 rc = ldlm_handle_ast_error(lock, req, rc, "glimpse");
574 rc = res->lr_namespace->ns_lvbo->lvbo_update
575 (res, req->rq_repmsg, 0, 1);
576 ptlrpc_req_finished(req);
580 static struct ldlm_lock *
581 find_existing_lock(struct obd_export *exp, struct lustre_handle *remote_hdl)
583 struct list_head *iter;
585 spin_lock(&exp->exp_ldlm_data.led_lock);
586 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
587 struct ldlm_lock *lock;
588 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
589 if (lock->l_remote_handle.cookie == remote_hdl->cookie) {
591 spin_unlock(&exp->exp_ldlm_data.led_lock);
595 spin_unlock(&exp->exp_ldlm_data.led_lock);
599 int ldlm_handle_enqueue(struct ptlrpc_request *req,
600 ldlm_completion_callback completion_callback,
601 ldlm_blocking_callback blocking_callback,
602 ldlm_glimpse_callback glimpse_callback)
604 struct obd_device *obddev = req->rq_export->exp_obd;
605 struct ldlm_reply *dlm_rep;
606 struct ldlm_request *dlm_req;
607 int rc = 0, size[2] = {sizeof(*dlm_rep)};
609 ldlm_error_t err = ELDLM_OK;
610 struct ldlm_lock *lock = NULL;
614 LDLM_DEBUG_NOLOCK("server-side enqueue handler START");
616 dlm_req = lustre_swab_reqbuf (req, MDS_REQ_INTENT_LOCKREQ_OFF,
618 lustre_swab_ldlm_request);
619 if (dlm_req == NULL) {
620 CERROR ("Can't unpack dlm_req\n");
621 GOTO(out, rc = -EFAULT);
624 flags = dlm_req->lock_flags;
626 LASSERT(req->rq_export);
628 if (flags & LDLM_FL_REPLAY) {
629 lock = find_existing_lock(req->rq_export,
630 &dlm_req->lock_handle1);
632 DEBUG_REQ(D_HA, req, "found existing lock cookie "LPX64,
633 lock->l_handle.h_cookie);
634 GOTO(existing_lock, rc = 0);
638 /* The lock's callback data might be set in the policy function */
639 lock = ldlm_lock_create(obddev->obd_namespace, &dlm_req->lock_handle2,
640 dlm_req->lock_desc.l_resource.lr_name,
641 dlm_req->lock_desc.l_resource.lr_type,
642 dlm_req->lock_desc.l_req_mode,
643 blocking_callback, completion_callback,
644 glimpse_callback, NULL, 0);
646 GOTO(out, rc = -ENOMEM);
648 do_gettimeofday(&lock->l_enqueued_time);
649 memcpy(&lock->l_remote_handle, &dlm_req->lock_handle1,
650 sizeof(lock->l_remote_handle));
651 LDLM_DEBUG(lock, "server-side enqueue handler, new lock created");
653 LASSERT(req->rq_export);
654 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_ENQUEUE_BLOCKED, obd_timeout * 2);
655 if (req->rq_export->exp_failed) {
656 LDLM_ERROR(lock,"lock on destroyed export %p\n",req->rq_export);
657 GOTO(out, err = -ENOTCONN);
660 lock->l_export = class_export_get(req->rq_export);
661 spin_lock(&lock->l_export->exp_ldlm_data.led_lock);
662 list_add(&lock->l_export_chain,
663 &lock->l_export->exp_ldlm_data.led_held_locks);
664 spin_unlock(&lock->l_export->exp_ldlm_data.led_lock);
668 if (flags & LDLM_FL_HAS_INTENT) {
669 /* In this case, the reply buffer is allocated deep in
670 * local_lock_enqueue by the policy function. */
674 lock_res_and_lock(lock);
675 if (lock->l_resource->lr_lvb_len) {
676 size[1] = lock->l_resource->lr_lvb_len;
679 unlock_res_and_lock(lock);
680 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR))
681 GOTO(out, rc = -ENOMEM);
683 rc = lustre_pack_reply(req, buffers, size, NULL);
688 if (dlm_req->lock_desc.l_resource.lr_type != LDLM_PLAIN)
689 memcpy(&lock->l_policy_data, &dlm_req->lock_desc.l_policy_data,
690 sizeof(ldlm_policy_data_t));
691 if (dlm_req->lock_desc.l_resource.lr_type == LDLM_EXTENT)
692 memcpy(&lock->l_req_extent, &lock->l_policy_data.l_extent,
693 sizeof(lock->l_req_extent));
695 err = ldlm_lock_enqueue(obddev->obd_namespace, &lock,
696 cookie, (int *)&flags);
700 dlm_rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*dlm_rep));
701 dlm_rep->lock_flags = flags;
703 ldlm_lock2desc(lock, &dlm_rep->lock_desc);
704 ldlm_lock2handle(lock, &dlm_rep->lock_handle);
706 /* We never send a blocking AST until the lock is granted, but
707 * we can tell it right now */
708 lock_res_and_lock(lock);
709 if (lock->l_flags & LDLM_FL_AST_SENT) {
710 dlm_rep->lock_flags |= LDLM_FL_AST_SENT;
711 if (lock->l_granted_mode == lock->l_req_mode)
712 ldlm_add_waiting_lock(lock);
714 unlock_res_and_lock(lock);
718 req->rq_status = err;
719 if (req->rq_reply_state == NULL) {
720 err = lustre_pack_reply(req, 0, NULL, NULL);
726 /* The LOCK_CHANGED code in ldlm_lock_enqueue depends on this
727 * ldlm_reprocess_all. If this moves, revisit that code. -phil */
729 LDLM_DEBUG(lock, "server-side enqueue handler, sending reply"
730 "(err=%d, rc=%d)", err, rc);
733 lock_res_and_lock(lock);
734 size[1] = lock->l_resource->lr_lvb_len;
736 void *lvb = lustre_msg_buf(req->rq_repmsg,
738 LASSERTF(lvb != NULL, "req %p, lock %p\n",
741 memcpy(lvb, lock->l_resource->lr_lvb_data,
744 unlock_res_and_lock(lock);
746 ldlm_lock_destroy(lock);
749 if (!err && dlm_req->lock_desc.l_resource.lr_type != LDLM_FLOCK)
750 ldlm_reprocess_all(lock->l_resource);
753 LDLM_DEBUG_NOLOCK("server-side enqueue handler END (lock %p, rc %d)",
759 int ldlm_handle_convert(struct ptlrpc_request *req)
761 struct ldlm_request *dlm_req;
762 struct ldlm_reply *dlm_rep;
763 struct ldlm_lock *lock;
764 int rc, size = sizeof(*dlm_rep);
767 dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req),
768 lustre_swab_ldlm_request);
769 if (dlm_req == NULL) {
770 CERROR ("Can't unpack dlm_req\n");
774 rc = lustre_pack_reply(req, 1, &size, NULL);
776 CERROR("out of memory\n");
779 dlm_rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*dlm_rep));
780 dlm_rep->lock_flags = dlm_req->lock_flags;
782 lock = ldlm_handle2lock(&dlm_req->lock_handle1);
784 req->rq_status = EINVAL;
788 LDLM_DEBUG(lock, "server-side convert handler START");
790 do_gettimeofday(&lock->l_enqueued_time);
791 res = ldlm_lock_convert(lock, dlm_req->lock_desc.l_req_mode,
792 (int *)&dlm_rep->lock_flags);
794 if (ldlm_del_waiting_lock(lock))
795 LDLM_DEBUG(lock, "converted waiting lock");
798 req->rq_status = EDEADLOCK;
804 ldlm_reprocess_all(lock->l_resource);
805 LDLM_DEBUG(lock, "server-side convert handler END");
808 LDLM_DEBUG_NOLOCK("server-side convert handler END");
813 int ldlm_handle_cancel(struct ptlrpc_request *req)
815 struct ldlm_request *dlm_req;
816 struct ldlm_lock *lock;
817 struct ldlm_resource *res;
821 dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req),
822 lustre_swab_ldlm_request);
823 if (dlm_req == NULL) {
824 CERROR("bad request buffer for cancel\n");
828 rc = lustre_pack_reply(req, 0, NULL, NULL);
830 CERROR("out of memory\n");
834 lock = ldlm_handle2lock(&dlm_req->lock_handle1);
836 CERROR("received cancel for unknown lock cookie "LPX64
837 " from client %s id %s\n",
838 dlm_req->lock_handle1.cookie,
839 req->rq_export->exp_client_uuid.uuid,
841 LDLM_DEBUG_NOLOCK("server-side cancel handler stale lock "
843 dlm_req->lock_handle1.cookie);
844 req->rq_status = ESTALE;
846 LDLM_DEBUG(lock, "server-side cancel handler START");
847 res = lock->l_resource;
848 if (res && res->lr_namespace->ns_lvbo &&
849 res->lr_namespace->ns_lvbo->lvbo_update) {
850 (void)res->lr_namespace->ns_lvbo->lvbo_update
852 //(res, req->rq_reqmsg, 1);
855 ldlm_lock_cancel(lock);
856 if (ldlm_del_waiting_lock(lock))
857 CDEBUG(D_DLMTRACE, "cancelled waiting lock %p\n", lock);
861 if (ptlrpc_reply(req) != 0)
865 ldlm_reprocess_all(lock->l_resource);
866 LDLM_DEBUG(lock, "server-side cancel handler END");
873 void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
874 struct ldlm_lock_desc *ld, struct ldlm_lock *lock)
879 LDLM_DEBUG(lock, "client blocking AST callback handler START");
881 lock_res_and_lock(lock);
882 lock->l_flags |= LDLM_FL_CBPENDING;
883 do_ast = (!lock->l_readers && !lock->l_writers);
884 unlock_res_and_lock(lock);
887 LDLM_DEBUG(lock, "already unused, calling "
888 "callback (%p)", lock->l_blocking_ast);
889 if (lock->l_blocking_ast != NULL)
890 lock->l_blocking_ast(lock, ld, lock->l_ast_data,
893 LDLM_DEBUG(lock, "Lock still has references, will be"
897 LDLM_DEBUG(lock, "client blocking callback handler END");
902 static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
903 struct ldlm_namespace *ns,
904 struct ldlm_request *dlm_req,
905 struct ldlm_lock *lock)
910 LDLM_DEBUG(lock, "client completion callback handler START");
912 lock_res_and_lock(lock);
914 /* If we receive the completion AST before the actual enqueue returned,
915 * then we might need to switch lock modes, resources, or extents. */
916 if (dlm_req->lock_desc.l_granted_mode != lock->l_req_mode) {
917 lock->l_req_mode = dlm_req->lock_desc.l_granted_mode;
918 LDLM_DEBUG(lock, "completion AST, new lock mode");
921 if (lock->l_resource->lr_type != LDLM_PLAIN) {
922 memcpy(&lock->l_policy_data, &dlm_req->lock_desc.l_policy_data,
923 sizeof(lock->l_policy_data));
924 LDLM_DEBUG(lock, "completion AST, new policy data");
927 ldlm_resource_unlink_lock(lock);
928 if (memcmp(&dlm_req->lock_desc.l_resource.lr_name,
929 &lock->l_resource->lr_name,
930 sizeof(lock->l_resource->lr_name)) != 0) {
931 unlock_res_and_lock(lock);
932 ldlm_lock_change_resource(ns, lock,
933 dlm_req->lock_desc.l_resource.lr_name);
934 LDLM_DEBUG(lock, "completion AST, new resource");
935 CERROR("change resource!\n");
936 lock_res_and_lock(lock);
939 if (dlm_req->lock_flags & LDLM_FL_AST_SENT) {
940 lock->l_flags |= LDLM_FL_CBPENDING;
941 LDLM_DEBUG(lock, "completion AST includes blocking AST");
944 if (lock->l_lvb_len) {
946 lvb = lustre_swab_reqbuf(req, 1, lock->l_lvb_len,
947 lock->l_lvb_swabber);
949 LDLM_ERROR(lock, "completion AST did not contain "
952 memcpy(lock->l_lvb_data, lvb, lock->l_lvb_len);
956 ldlm_grant_lock(lock, &ast_list);
957 unlock_res_and_lock(lock);
959 LDLM_DEBUG(lock, "callback handler finished, about to run_ast_work");
962 ldlm_run_cp_ast_work(&ast_list);
964 LDLM_DEBUG_NOLOCK("client completion callback handler END (lock %p)",
969 static void ldlm_handle_gl_callback(struct ptlrpc_request *req,
970 struct ldlm_namespace *ns,
971 struct ldlm_request *dlm_req,
972 struct ldlm_lock *lock)
977 LDLM_DEBUG(lock, "client glimpse AST callback handler");
979 if (lock->l_glimpse_ast != NULL)
980 rc = lock->l_glimpse_ast(lock, req);
982 if (req->rq_repmsg != NULL) {
989 lock_res_and_lock(lock);
990 if (lock->l_granted_mode == LCK_PW &&
991 !lock->l_readers && !lock->l_writers &&
992 time_after(jiffies, lock->l_last_used + 10 * HZ)) {
993 unlock_res_and_lock(lock);
994 if (ldlm_bl_to_thread(ns, NULL, lock))
995 ldlm_handle_bl_callback(ns, NULL, lock);
1000 unlock_res_and_lock(lock);
1001 LDLM_LOCK_PUT(lock);
1005 static int ldlm_callback_reply(struct ptlrpc_request *req, int rc)
1007 req->rq_status = rc;
1008 if (req->rq_reply_state == NULL) {
1009 rc = lustre_pack_reply(req, 0, NULL, NULL);
1013 return ptlrpc_reply(req);
1016 int ldlm_bl_to_thread(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
1017 struct ldlm_lock *lock)
1020 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
1021 struct ldlm_bl_work_item *blwi;
1024 OBD_ALLOC(blwi, sizeof(*blwi));
1030 blwi->blwi_ld = *ld;
1031 blwi->blwi_lock = lock;
1033 spin_lock(&blp->blp_lock);
1034 list_add_tail(&blwi->blwi_entry, &blp->blp_list);
1035 wake_up(&blp->blp_waitq);
1036 spin_unlock(&blp->blp_lock);
1045 static int ldlm_msg_check_version(struct lustre_msg *msg)
1053 case LDLM_BL_CALLBACK:
1054 case LDLM_CP_CALLBACK:
1055 case LDLM_GL_CALLBACK:
1056 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1058 CERROR("bad opc %u version %08x, expecting %08x\n",
1059 msg->opc, msg->version, LUSTRE_DLM_VERSION);
1061 case OBD_LOG_CANCEL:
1062 case LLOG_ORIGIN_HANDLE_OPEN:
1063 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1064 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
1065 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1066 case LLOG_ORIGIN_HANDLE_CLOSE:
1068 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1070 CERROR("bad opc %u version %08x, expecting %08x\n",
1071 msg->opc, msg->version, LUSTRE_LOG_VERSION);
1074 CERROR("LDLM unknown opcode %d\n", msg->opc);
1082 static int ldlm_callback_handler(struct ptlrpc_request *req)
1084 struct ldlm_namespace *ns;
1085 struct ldlm_request *dlm_req;
1086 struct ldlm_lock *lock;
1090 rc = ldlm_msg_check_version(req->rq_reqmsg);
1092 CERROR("LDLM_CB drop mal-formed request\n");
1096 /* Requests arrive in sender's byte order. The ptlrpc service
1097 * handler has already checked and, if necessary, byte-swapped the
1098 * incoming request message body, but I am responsible for the
1099 * message buffers. */
1101 if (req->rq_export == NULL) {
1102 struct ldlm_request *dlm_req;
1104 CDEBUG(D_RPCTRACE, "operation %d from %s with bad "
1105 "export cookie "LPX64"; this is "
1106 "normal if this node rebooted with a lock held\n",
1107 req->rq_reqmsg->opc,
1109 req->rq_reqmsg->handle.cookie);
1110 dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req),
1111 lustre_swab_ldlm_request);
1112 if (dlm_req != NULL)
1113 CDEBUG(D_RPCTRACE, "--> lock cookie: "LPX64"\n",
1114 dlm_req->lock_handle1.cookie);
1116 ldlm_callback_reply(req, -ENOTCONN);
1120 LASSERT(req->rq_export != NULL);
1121 LASSERT(req->rq_export->exp_obd != NULL);
1123 switch(req->rq_reqmsg->opc) {
1124 case LDLM_BL_CALLBACK:
1125 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
1127 case LDLM_CP_CALLBACK:
1128 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CP_CALLBACK, 0);
1130 case LDLM_GL_CALLBACK:
1131 OBD_FAIL_RETURN(OBD_FAIL_LDLM_GL_CALLBACK, 0);
1133 case OBD_LOG_CANCEL:
1134 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1135 rc = llog_origin_handle_cancel(req);
1136 ldlm_callback_reply(req, rc);
1138 case LLOG_ORIGIN_HANDLE_OPEN:
1139 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1140 rc = llog_origin_handle_open(req);
1141 ldlm_callback_reply(req, rc);
1143 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1144 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1145 rc = llog_origin_handle_next_block(req);
1146 ldlm_callback_reply(req, rc);
1148 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
1149 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1150 rc = llog_origin_handle_prev_block(req);
1151 ldlm_callback_reply(req, rc);
1153 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1154 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1155 rc = llog_origin_handle_read_header(req);
1156 ldlm_callback_reply(req, rc);
1158 case LLOG_ORIGIN_HANDLE_CLOSE:
1159 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1160 rc = llog_origin_handle_close(req);
1161 ldlm_callback_reply(req, rc);
1164 CERROR("unknown opcode %u\n", req->rq_reqmsg->opc);
1165 ldlm_callback_reply(req, -EPROTO);
1169 ns = req->rq_export->exp_obd->obd_namespace;
1170 LASSERT(ns != NULL);
1172 dlm_req = lustre_swab_reqbuf (req, 0, sizeof (*dlm_req),
1173 lustre_swab_ldlm_request);
1174 if (dlm_req == NULL) {
1175 CERROR ("can't unpack dlm_req\n");
1176 ldlm_callback_reply (req, -EPROTO);
1180 lock = ldlm_handle2lock_ns(ns, &dlm_req->lock_handle1);
1182 LDLM_DEBUG_NOLOCK("callback on lock "LPX64" - lock "
1183 "disappeared\n",dlm_req->lock_handle1.cookie);
1184 ldlm_callback_reply(req, -EINVAL);
1188 /* Copy hints/flags (e.g. LDLM_FL_DISCARD_DATA) from AST. */
1189 lock_res_and_lock(lock);
1190 lock->l_flags |= (dlm_req->lock_flags & LDLM_AST_FLAGS);
1191 unlock_res_and_lock(lock);
1193 /* We want the ost thread to get this reply so that it can respond
1194 * to ost requests (write cache writeback) that might be triggered
1197 * But we'd also like to be able to indicate in the reply that we're
1198 * cancelling right now, because it's unused, or have an intent result
1199 * in the reply, so we might have to push the responsibility for sending
1200 * the reply down into the AST handlers, alas. */
1202 switch (req->rq_reqmsg->opc) {
1203 case LDLM_BL_CALLBACK:
1204 CDEBUG(D_INODE, "blocking ast\n");
1205 ldlm_callback_reply(req, 0);
1206 if (ldlm_bl_to_thread(ns, &dlm_req->lock_desc, lock))
1207 ldlm_handle_bl_callback(ns, &dlm_req->lock_desc, lock);
1210 case LDLM_CP_CALLBACK:
1211 CDEBUG(D_INODE, "completion ast\n");
1212 ldlm_callback_reply(req, 0);
1213 ldlm_handle_cp_callback(req, ns, dlm_req, lock);
1215 case LDLM_GL_CALLBACK:
1216 CDEBUG(D_INODE, "glimpse ast\n");
1217 ldlm_handle_gl_callback(req, ns, dlm_req, lock);
1220 LBUG(); /* checked above */
1226 static int ldlm_cancel_handler(struct ptlrpc_request *req)
1231 rc = ldlm_msg_check_version(req->rq_reqmsg);
1233 CERROR("LDLM_CL drop mal-formed request\n");
1237 /* Requests arrive in sender's byte order. The ptlrpc service
1238 * handler has already checked and, if necessary, byte-swapped the
1239 * incoming request message body, but I am responsible for the
1240 * message buffers. */
1242 if (req->rq_export == NULL) {
1243 struct ldlm_request *dlm_req;
1244 CERROR("operation %d with bad export from %s\n",
1245 req->rq_reqmsg->opc,
1247 CERROR("--> export cookie: "LPX64"\n",
1248 req->rq_reqmsg->handle.cookie);
1249 dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req),
1250 lustre_swab_ldlm_request);
1251 if (dlm_req != NULL)
1252 ldlm_lock_dump_handle(D_ERROR, &dlm_req->lock_handle1);
1253 ldlm_callback_reply(req, -ENOTCONN);
1257 switch (req->rq_reqmsg->opc) {
1259 /* XXX FIXME move this back to mds/handler.c, bug 249 */
1261 CDEBUG(D_INODE, "cancel\n");
1262 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1263 rc = ldlm_handle_cancel(req);
1266 CERROR("invalid opcode %d\n", req->rq_reqmsg->opc);
1267 ldlm_callback_reply(req, -EINVAL);
1274 static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp)
1276 struct ldlm_bl_work_item *blwi = NULL;
1278 spin_lock(&blp->blp_lock);
1279 if (!list_empty(&blp->blp_list)) {
1280 blwi = list_entry(blp->blp_list.next, struct ldlm_bl_work_item,
1282 list_del(&blwi->blwi_entry);
1284 spin_unlock(&blp->blp_lock);
1289 struct ldlm_bl_thread_data {
1291 struct ldlm_bl_pool *bltd_blp;
1294 static int ldlm_bl_thread_main(void *arg)
1296 struct ldlm_bl_thread_data *bltd = arg;
1297 struct ldlm_bl_pool *blp = bltd->bltd_blp;
1298 unsigned long flags;
1301 /* XXX boiler-plate */
1303 char name[sizeof(current->comm)];
1304 snprintf(name, sizeof(name) - 1, "ldlm_bl_%02d",
1306 kportal_daemonize(name);
1308 SIGNAL_MASK_LOCK(current, flags);
1309 sigfillset(¤t->blocked);
1311 SIGNAL_MASK_UNLOCK(current, flags);
1313 atomic_inc(&blp->blp_num_threads);
1314 complete(&blp->blp_comp);
1317 struct l_wait_info lwi = { 0 };
1318 struct ldlm_bl_work_item *blwi = NULL;
1320 l_wait_event_exclusive(blp->blp_waitq,
1321 (blwi = ldlm_bl_get_work(blp)) != NULL,
1324 if (blwi->blwi_ns == NULL)
1327 ldlm_handle_bl_callback(blwi->blwi_ns, &blwi->blwi_ld,
1329 OBD_FREE(blwi, sizeof(*blwi));
1332 atomic_dec(&blp->blp_num_threads);
1333 complete(&blp->blp_comp);
1339 static int ldlm_setup(void);
1340 static int ldlm_cleanup(int force);
1342 int ldlm_get_ref(void)
1345 down(&ldlm_ref_sem);
1346 if (++ldlm_refcount == 1) {
1356 void ldlm_put_ref(int force)
1358 down(&ldlm_ref_sem);
1359 if (ldlm_refcount == 1) {
1360 int rc = ldlm_cleanup(force);
1362 CERROR("ldlm_cleanup failed: %d\n", rc);
1373 static int ldlm_setup(void)
1375 struct ldlm_bl_pool *blp;
1382 if (ldlm_state != NULL)
1385 OBD_ALLOC(ldlm_state, sizeof(*ldlm_state));
1386 if (ldlm_state == NULL)
1390 rc = ldlm_proc_setup();
1395 ldlm_state->ldlm_cb_service =
1396 ptlrpc_init_svc(LDLM_NBUFS, LDLM_BUFSIZE, LDLM_MAXREQSIZE,
1397 LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1398 1500, ldlm_callback_handler, "ldlm_cbd",
1401 if (!ldlm_state->ldlm_cb_service) {
1402 CERROR("failed to start service\n");
1403 GOTO(out_proc, rc = -ENOMEM);
1406 ldlm_state->ldlm_cancel_service =
1407 ptlrpc_init_svc(LDLM_NBUFS, LDLM_BUFSIZE, LDLM_MAXREQSIZE,
1408 LDLM_CANCEL_REQUEST_PORTAL,
1409 LDLM_CANCEL_REPLY_PORTAL, 30000,
1410 ldlm_cancel_handler, "ldlm_canceld",
1413 if (!ldlm_state->ldlm_cancel_service) {
1414 CERROR("failed to start service\n");
1415 GOTO(out_proc, rc = -ENOMEM);
1418 OBD_ALLOC(blp, sizeof(*blp));
1420 GOTO(out_proc, rc = -ENOMEM);
1421 ldlm_state->ldlm_bl_pool = blp;
1423 atomic_set(&blp->blp_num_threads, 0);
1424 init_waitqueue_head(&blp->blp_waitq);
1425 spin_lock_init(&blp->blp_lock);
1427 INIT_LIST_HEAD(&blp->blp_list);
1430 for (i = 0; i < LDLM_NUM_THREADS; i++) {
1431 struct ldlm_bl_thread_data bltd = {
1435 init_completion(&blp->blp_comp);
1436 rc = kernel_thread(ldlm_bl_thread_main, &bltd, 0);
1438 CERROR("cannot start LDLM thread #%d: rc %d\n", i, rc);
1439 GOTO(out_thread, rc);
1441 wait_for_completion(&blp->blp_comp);
1444 rc = ptlrpc_start_n_threads(NULL, ldlm_state->ldlm_cancel_service,
1445 LDLM_NUM_THREADS, "ldlm_cn");
1447 GOTO(out_thread, rc);
1449 rc = ptlrpc_start_n_threads(NULL, ldlm_state->ldlm_cb_service,
1450 LDLM_NUM_THREADS, "ldlm_cb");
1452 GOTO(out_thread, rc);
1454 INIT_LIST_HEAD(&expired_lock_thread.elt_expired_locks);
1455 spin_lock_init(&expired_lock_thread.elt_lock);
1456 expired_lock_thread.elt_state = ELT_STOPPED;
1457 init_waitqueue_head(&expired_lock_thread.elt_waitq);
1459 rc = kernel_thread(expired_lock_main, NULL, CLONE_VM | CLONE_FS);
1461 CERROR("Cannot start ldlm expired-lock thread: %d\n", rc);
1462 GOTO(out_thread, rc);
1465 wait_event(expired_lock_thread.elt_waitq,
1466 expired_lock_thread.elt_state == ELT_READY);
1468 INIT_LIST_HEAD(&waiting_locks_list);
1469 spin_lock_init(&waiting_locks_spinlock);
1470 waiting_locks_timer.function = waiting_locks_callback;
1471 waiting_locks_timer.data = 0;
1472 init_timer(&waiting_locks_timer);
1479 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
1480 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
1485 ldlm_proc_cleanup();
1488 OBD_FREE(ldlm_state, sizeof(*ldlm_state));
1493 static int ldlm_cleanup(int force)
1496 struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
1500 if (!list_empty(&ldlm_namespace_list)) {
1501 CERROR("ldlm still has namespaces; clean these up first.\n");
1502 ldlm_dump_all_namespaces(D_DLMTRACE);
1507 while (atomic_read(&blp->blp_num_threads) > 0) {
1508 struct ldlm_bl_work_item blwi = { .blwi_ns = NULL };
1510 init_completion(&blp->blp_comp);
1512 spin_lock(&blp->blp_lock);
1513 list_add_tail(&blwi.blwi_entry, &blp->blp_list);
1514 wake_up(&blp->blp_waitq);
1515 spin_unlock(&blp->blp_lock);
1517 wait_for_completion(&blp->blp_comp);
1519 OBD_FREE(blp, sizeof(*blp));
1521 ptlrpc_stop_all_threads(ldlm_state->ldlm_cb_service);
1522 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
1523 ptlrpc_stop_all_threads(ldlm_state->ldlm_cancel_service);
1524 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
1525 ldlm_proc_cleanup();
1527 expired_lock_thread.elt_state = ELT_TERMINATE;
1528 wake_up(&expired_lock_thread.elt_waitq);
1529 wait_event(expired_lock_thread.elt_waitq,
1530 expired_lock_thread.elt_state == ELT_STOPPED);
1532 ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
1533 ptlrpc_unregister_service(ldlm_state->ldlm_cancel_service);
1536 OBD_FREE(ldlm_state, sizeof(*ldlm_state));
1542 int __init ldlm_init(void)
1544 ldlm_resource_slab = kmem_cache_create("ldlm_resources",
1545 sizeof(struct ldlm_resource), 0,
1546 SLAB_HWCACHE_ALIGN, NULL, NULL);
1547 if (ldlm_resource_slab == NULL)
1550 ldlm_lock_slab = kmem_cache_create("ldlm_locks",
1551 sizeof(struct ldlm_lock), 0,
1552 SLAB_HWCACHE_ALIGN, NULL, NULL);
1553 if (ldlm_lock_slab == NULL) {
1554 kmem_cache_destroy(ldlm_resource_slab);
1561 void __exit ldlm_exit(void)
1563 if ( ldlm_refcount )
1564 CERROR("ldlm_refcount is %d in ldlm_exit!\n", ldlm_refcount);
1565 LASSERTF(kmem_cache_destroy(ldlm_resource_slab) == 0,
1566 "couldn't free ldlm resource slab\n");
1567 LASSERTF(kmem_cache_destroy(ldlm_lock_slab) == 0,
1568 "couldn't free ldlm lock slab\n");
1573 EXPORT_SYMBOL(ldlm_flock_completion_ast);
1576 EXPORT_SYMBOL(ldlm_extent_shift_kms);
1579 EXPORT_SYMBOL(ldlm_get_processing_policy);
1580 EXPORT_SYMBOL(ldlm_lock2desc);
1581 EXPORT_SYMBOL(ldlm_register_intent);
1582 EXPORT_SYMBOL(ldlm_lockname);
1583 EXPORT_SYMBOL(ldlm_typename);
1584 EXPORT_SYMBOL(ldlm_lock2handle);
1585 EXPORT_SYMBOL(__ldlm_handle2lock);
1586 EXPORT_SYMBOL(ldlm_lock_get);
1587 EXPORT_SYMBOL(ldlm_lock_put);
1588 EXPORT_SYMBOL(ldlm_lock_match);
1589 EXPORT_SYMBOL(ldlm_lock_cancel);
1590 EXPORT_SYMBOL(ldlm_lock_addref);
1591 EXPORT_SYMBOL(ldlm_lock_decref);
1592 EXPORT_SYMBOL(ldlm_lock_decref_and_cancel);
1593 EXPORT_SYMBOL(ldlm_lock_change_resource);
1594 EXPORT_SYMBOL(ldlm_lock_set_data);
1595 EXPORT_SYMBOL(ldlm_it2str);
1596 EXPORT_SYMBOL(ldlm_lock_dump);
1597 EXPORT_SYMBOL(ldlm_lock_dump_handle);
1598 EXPORT_SYMBOL(ldlm_cancel_locks_for_export);
1599 EXPORT_SYMBOL(ldlm_reprocess_all_ns);
1600 EXPORT_SYMBOL(ldlm_lock_allow_match);
1602 /* ldlm_request.c */
1603 EXPORT_SYMBOL(ldlm_completion_ast);
1604 EXPORT_SYMBOL(ldlm_expired_completion_wait);
1605 EXPORT_SYMBOL(ldlm_cli_convert);
1606 EXPORT_SYMBOL(ldlm_cli_enqueue);
1607 EXPORT_SYMBOL(ldlm_cli_cancel);
1608 EXPORT_SYMBOL(ldlm_cli_cancel_unused);
1609 EXPORT_SYMBOL(ldlm_replay_locks);
1610 EXPORT_SYMBOL(ldlm_resource_foreach);
1611 EXPORT_SYMBOL(ldlm_namespace_foreach);
1612 EXPORT_SYMBOL(ldlm_namespace_foreach_res);
1613 EXPORT_SYMBOL(ldlm_change_cbdata);
1616 EXPORT_SYMBOL(ldlm_server_blocking_ast);
1617 EXPORT_SYMBOL(ldlm_server_completion_ast);
1618 EXPORT_SYMBOL(ldlm_server_glimpse_ast);
1619 EXPORT_SYMBOL(ldlm_handle_enqueue);
1620 EXPORT_SYMBOL(ldlm_handle_cancel);
1621 EXPORT_SYMBOL(ldlm_handle_convert);
1622 EXPORT_SYMBOL(ldlm_del_waiting_lock);
1623 EXPORT_SYMBOL(ldlm_get_ref);
1624 EXPORT_SYMBOL(ldlm_put_ref);
1628 EXPORT_SYMBOL(ldlm_test);
1629 EXPORT_SYMBOL(ldlm_regression_start);
1630 EXPORT_SYMBOL(ldlm_regression_stop);
1633 /* ldlm_resource.c */
1634 EXPORT_SYMBOL(ldlm_namespace_new);
1635 EXPORT_SYMBOL(ldlm_namespace_cleanup);
1636 EXPORT_SYMBOL(ldlm_namespace_free);
1637 EXPORT_SYMBOL(ldlm_namespace_dump);
1638 EXPORT_SYMBOL(ldlm_dump_all_namespaces);
1639 EXPORT_SYMBOL(ldlm_resource_get);
1640 EXPORT_SYMBOL(ldlm_resource_putref);
1643 EXPORT_SYMBOL(client_import_add_conn);
1644 EXPORT_SYMBOL(client_import_del_conn);
1645 EXPORT_SYMBOL(client_obd_setup);
1646 EXPORT_SYMBOL(client_obd_cleanup);
1647 EXPORT_SYMBOL(client_connect_import);
1648 EXPORT_SYMBOL(client_disconnect_export);
1649 EXPORT_SYMBOL(target_start_recovery_thread);
1650 EXPORT_SYMBOL(target_stop_recovery_thread);
1651 EXPORT_SYMBOL(target_handle_connect);
1652 EXPORT_SYMBOL(target_cleanup_recovery);
1653 EXPORT_SYMBOL(target_destroy_export);
1654 EXPORT_SYMBOL(target_cancel_recovery_timer);
1655 EXPORT_SYMBOL(target_send_reply);
1656 EXPORT_SYMBOL(target_queue_recovery_request);
1657 EXPORT_SYMBOL(target_handle_ping);
1658 EXPORT_SYMBOL(target_handle_disconnect);
1661 EXPORT_SYMBOL(lock_res_and_lock);
1662 EXPORT_SYMBOL(unlock_res_and_lock);