1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
9 * by Cluster File Systems, Inc.
10 * authors, Peter Braam <braam@clusterfs.com> &
11 * Phil Schwan <phil@clusterfs.com>
14 #define DEBUG_SUBSYSTEM S_LDLM
16 #include <linux/slab.h>
17 #include <linux/module.h>
18 #include <linux/random.h>
19 #include <linux/lustre_dlm.h>
20 #include <linux/lustre_mds.h>
23 char *ldlm_lockname[] = {
32 char *ldlm_typename[] = {
35 [LDLM_MDSINTENT] "INT"
38 extern kmem_cache_t *ldlm_lock_slab;
39 int (*mds_reint_p)(int offset, struct ptlrpc_request *req) = NULL;
40 int (*mds_getattr_name_p)(int offset, struct ptlrpc_request *req) = NULL;
42 static int ldlm_plain_compat(struct ldlm_lock *a, struct ldlm_lock *b);
43 static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
44 ldlm_mode_t mode, void *data);
46 ldlm_res_compat ldlm_res_compat_table [] = {
47 [LDLM_PLAIN] ldlm_plain_compat,
48 [LDLM_EXTENT] ldlm_extent_compat,
49 [LDLM_MDSINTENT] ldlm_plain_compat
52 ldlm_res_policy ldlm_res_policy_table [] = {
54 [LDLM_EXTENT] ldlm_extent_policy,
55 [LDLM_MDSINTENT] ldlm_intent_policy
60 * REFCOUNTED LOCK OBJECTS
65 * Lock refcounts, during creation:
66 * - one special one for allocation, dec'd only once in destroy
67 * - one for being a lock that's in-use
68 * - one for the addref associated with a new lock
70 struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock)
72 l_lock(&lock->l_resource->lr_namespace->ns_lock);
74 ldlm_resource_getref(lock->l_resource);
75 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
79 void ldlm_lock_put(struct ldlm_lock *lock)
81 struct lustre_lock *nslock = &lock->l_resource->lr_namespace->ns_lock;
86 LDLM_DEBUG(lock, "after refc--");
90 ldlm_resource_put(lock->l_resource);
92 ldlm_lock_put(lock->l_parent);
94 if (lock->l_refc == 0 && (lock->l_flags & LDLM_FL_DESTROYED)) {
95 if (lock->l_connection)
96 ptlrpc_put_connection(lock->l_connection);
97 CDEBUG(D_MALLOC, "kfreed 'lock': %d at %p (tot 1).\n",
99 kmem_cache_free(ldlm_lock_slab, lock);
105 void ldlm_lock_destroy(struct ldlm_lock *lock)
108 l_lock(&lock->l_resource->lr_namespace->ns_lock);
110 if (!list_empty(&lock->l_children)) {
111 LDLM_DEBUG(lock, "still has children (%p)!",
112 lock->l_children.next);
113 ldlm_lock_dump(lock);
116 if (lock->l_readers || lock->l_writers) {
117 LDLM_DEBUG(lock, "lock still has references");
118 ldlm_lock_dump(lock);
122 if (!list_empty(&lock->l_res_link)) {
123 ldlm_lock_dump(lock);
127 if (lock->l_flags & LDLM_FL_DESTROYED) {
128 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
133 lock->l_flags = LDLM_FL_DESTROYED;
134 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
140 usage: pass in a resource on which you have done get
141 pass in a parent lock on which you have done a get
142 do not put the resource or the parent
143 returns: lock with refcount 1
145 static struct ldlm_lock *ldlm_lock_new(struct ldlm_lock *parent,
146 struct ldlm_resource *resource)
148 struct ldlm_lock *lock;
151 if (resource == NULL)
154 lock = kmem_cache_alloc(ldlm_lock_slab, SLAB_KERNEL);
157 CDEBUG(D_MALLOC, "kmalloced 'lock': %d at "
158 "%p (tot %d).\n", sizeof(*lock), lock, 1);
160 memset(lock, 0, sizeof(*lock));
161 get_random_bytes(&lock->l_random, sizeof(__u64));
163 lock->l_resource = resource;
164 /* this refcount matches the one of the resource passed
165 in which is not being put away */
167 INIT_LIST_HEAD(&lock->l_children);
168 INIT_LIST_HEAD(&lock->l_res_link);
169 init_waitqueue_head(&lock->l_waitq);
171 if (parent != NULL) {
172 l_lock(&parent->l_resource->lr_namespace->ns_lock);
173 lock->l_parent = parent;
174 list_add(&lock->l_childof, &parent->l_children);
175 l_unlock(&parent->l_resource->lr_namespace->ns_lock);
177 /* this is the extra refcount, to prevent the lock
183 int ldlm_lock_change_resource(struct ldlm_lock *lock, __u64 new_resid[3])
185 struct ldlm_namespace *ns = lock->l_resource->lr_namespace;
186 struct ldlm_resource *oldres = lock->l_resource;
190 l_lock(&ns->ns_lock);
191 type = lock->l_resource->lr_type;
193 lock->l_resource = ldlm_resource_get(ns, NULL, new_resid, type, 1);
194 if (lock->l_resource == NULL) {
199 /* move references over */
200 for (i = 0; i < lock->l_refc; i++) {
202 ldlm_resource_getref(lock->l_resource);
203 rc = ldlm_resource_put(oldres);
204 if (rc == 1 && i != lock->l_refc - 1)
207 /* compensate for the initial get above.. */
208 ldlm_resource_put(lock->l_resource);
210 l_unlock(&ns->ns_lock);
218 void ldlm_lock2handle(struct ldlm_lock *lock, struct lustre_handle *lockh)
220 lockh->addr = (__u64)(unsigned long)lock;
221 lockh->cookie = lock->l_random;
224 struct ldlm_lock *ldlm_handle2lock(struct lustre_handle *handle)
226 struct ldlm_lock *lock = NULL;
229 if (!handle || !handle->addr)
232 lock = (struct ldlm_lock *)(unsigned long)(handle->addr);
233 if (!kmem_cache_validate(ldlm_lock_slab, (void *)lock))
236 l_lock(&lock->l_resource->lr_namespace->ns_lock);
237 if (lock->l_random != handle->cookie)
238 GOTO(out, handle = NULL);
240 if (lock->l_flags & LDLM_FL_DESTROYED)
241 GOTO(out, handle = NULL);
246 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
252 static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
253 ldlm_mode_t mode, void *data)
255 struct ptlrpc_request *req = req_cookie;
262 if (req->rq_reqmsg->bufcount > 1) {
263 /* an intent needs to be considered */
264 struct ldlm_intent *it = lustre_msg_buf(req->rq_reqmsg, 1);
265 struct mds_body *mds_rep;
266 struct ldlm_reply *rep;
267 __u64 new_resid[3] = {0, 0, 0}, old_res;
268 int bufcount = -1, rc, size[3] = {sizeof(struct ldlm_reply),
269 sizeof(struct mds_body),
270 sizeof(struct obdo)};
272 it->opc = NTOH__u64(it->opc);
274 LDLM_DEBUG(lock, "intent policy, opc: %Ld", it->opc);
279 /* Note that in the negative case you may be returning
280 * a file and its obdo */
282 case IT_CREAT|IT_OPEN:
296 size[1] = sizeof(struct obdo);
305 rc = lustre_pack_msg(bufcount, size, NULL, &req->rq_replen,
308 rc = req->rq_status = -ENOMEM;
312 rep = lustre_msg_buf(req->rq_repmsg, 0);
313 rep->lock_policy_res1 = 1;
318 case IT_CREAT|IT_OPEN:
327 if (mds_reint_p == NULL)
329 inter_module_get_request
330 ("mds_reint", "mds");
331 if (IS_ERR(mds_reint_p)) {
332 CERROR("MDSINTENT locks require the MDS "
337 rc = mds_reint_p(2, req);
345 if (mds_getattr_name_p == NULL)
347 inter_module_get_request
348 ("mds_getattr_name", "mds");
349 if (IS_ERR(mds_getattr_name_p)) {
350 CERROR("MDSINTENT locks require the MDS "
355 rc = mds_getattr_name_p(2, req);
356 /* FIXME: we need to sit down and decide on who should
357 * set req->rq_status, who should return negative and
358 * positive return values, and what they all mean. */
359 if (rc || req->rq_status != 0) {
360 mds_rep = lustre_msg_buf(req->rq_repmsg, 1);
361 rep->lock_policy_res2 = req->rq_status;
362 RETURN(ELDLM_LOCK_ABORTED);
365 case IT_READDIR|IT_OPEN:
369 CERROR("Unhandled intent\n");
373 if (it->opc == IT_UNLINK || it->opc == IT_RMDIR ||
374 it->opc == IT_RENAME || it->opc == IT_RENAME2)
375 RETURN(ELDLM_LOCK_ABORTED);
377 mds_rep = lustre_msg_buf(req->rq_repmsg, 1);
378 rep->lock_policy_res2 = req->rq_status;
379 new_resid[0] = NTOH__u32(mds_rep->ino);
380 if (new_resid[0] == 0)
382 old_res = lock->l_resource->lr_name[0];
384 CDEBUG(D_INFO, "remote intent: locking %d instead of"
385 "%ld\n", mds_rep->ino, (long)old_res);
387 ldlm_lock_change_resource(lock, new_resid);
388 if (lock->l_resource == NULL) {
392 LDLM_DEBUG(lock, "intent policy, old res %ld",
394 RETURN(ELDLM_LOCK_CHANGED);
396 int size = sizeof(struct ldlm_reply);
397 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen,
400 CERROR("out of memory\n");
408 static int ldlm_plain_compat(struct ldlm_lock *a, struct ldlm_lock *b)
410 return lockmode_compat(a->l_req_mode, b->l_req_mode);
413 void ldlm_lock2desc(struct ldlm_lock *lock, struct ldlm_lock_desc *desc)
415 ldlm_res2desc(lock->l_resource, &desc->l_resource);
416 desc->l_req_mode = lock->l_req_mode;
417 desc->l_granted_mode = lock->l_granted_mode;
418 memcpy(&desc->l_extent, &lock->l_extent, sizeof(desc->l_extent));
419 memcpy(desc->l_version, lock->l_version, sizeof(desc->l_version));
422 static void ldlm_add_ast_work_item(struct ldlm_lock *lock,
423 struct ldlm_lock *new)
425 struct ldlm_ast_work *w;
428 l_lock(&lock->l_resource->lr_namespace->ns_lock);
429 if (new && (lock->l_flags & LDLM_FL_AST_SENT))
432 OBD_ALLOC(w, sizeof(*w));
439 lock->l_flags |= LDLM_FL_AST_SENT;
441 ldlm_lock2desc(new, &w->w_desc);
444 w->w_lock = ldlm_lock_get(lock);
445 list_add(&w->w_list, lock->l_resource->lr_tmp);
447 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
451 void ldlm_lock_addref(struct lustre_handle *lockh, __u32 mode)
453 struct ldlm_lock *lock;
455 lock = ldlm_handle2lock(lockh);
456 ldlm_lock_addref_internal(lock, mode);
460 /* only called for local locks */
461 void ldlm_lock_addref_internal(struct ldlm_lock *lock, __u32 mode)
463 l_lock(&lock->l_resource->lr_namespace->ns_lock);
464 if (mode == LCK_NL || mode == LCK_CR || mode == LCK_PR)
468 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
470 LDLM_DEBUG(lock, "ldlm_lock_addref(%s)", ldlm_lockname[mode]);
473 /* Args: unlocked lock */
474 void ldlm_lock_decref(struct lustre_handle *lockh, __u32 mode)
476 struct ldlm_lock *lock = ldlm_handle2lock(lockh);
482 LDLM_DEBUG(lock, "ldlm_lock_decref(%s)", ldlm_lockname[mode]);
483 l_lock(&lock->l_resource->lr_namespace->ns_lock);
484 if (mode == LCK_NL || mode == LCK_CR || mode == LCK_PR)
489 /* If we received a blocked AST and this was the last reference,
490 * run the callback. */
491 if (!lock->l_readers && !lock->l_writers &&
492 (lock->l_flags & LDLM_FL_CBPENDING)) {
493 struct lustre_handle lockh;
495 if (!lock->l_resource->lr_namespace->ns_client) {
496 CERROR("LDLM_FL_CBPENDING set on non-local lock!\n");
500 LDLM_DEBUG(lock, "final decref done on cbpending lock");
501 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
503 ldlm_lock2handle(lock, &lockh);
504 /* FIXME: -1 is a really, really bad 'desc' */
505 lock->l_blocking_ast(&lockh, (void *)-1, lock->l_data,
508 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
510 ldlm_lock_put(lock); /* matches the ldlm_lock_get in addref */
511 ldlm_lock_put(lock); /* matches the handle2lock above */
516 static int ldlm_lock_compat_list(struct ldlm_lock *lock, int send_cbs,
517 struct list_head *queue)
519 struct list_head *tmp, *pos;
522 list_for_each_safe(tmp, pos, queue) {
523 struct ldlm_lock *child;
524 ldlm_res_compat compat;
526 child = list_entry(tmp, struct ldlm_lock, l_res_link);
530 compat = ldlm_res_compat_table[child->l_resource->lr_type];
531 if (compat && compat(child, lock)) {
532 CDEBUG(D_OTHER, "compat function succeded, next.\n");
535 if (lockmode_compat(child->l_granted_mode, lock->l_req_mode)) {
536 CDEBUG(D_OTHER, "lock modes are compatible, next.\n");
542 if (send_cbs && child->l_blocking_ast != NULL) {
543 CDEBUG(D_OTHER, "incompatible; sending blocking "
545 ldlm_add_ast_work_item(child, lock);
552 static int ldlm_lock_compat(struct ldlm_lock *lock, int send_cbs)
557 l_lock(&lock->l_resource->lr_namespace->ns_lock);
558 rc = ldlm_lock_compat_list(lock, send_cbs,
559 &lock->l_resource->lr_granted);
560 /* FIXME: should we be sending ASTs to converting? */
562 rc = ldlm_lock_compat_list
563 (lock, send_cbs, &lock->l_resource->lr_converting);
565 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
570 - ldlm_handle_enqueuque - resource
572 void ldlm_grant_lock(struct ldlm_lock *lock)
574 struct ldlm_resource *res = lock->l_resource;
577 l_lock(&lock->l_resource->lr_namespace->ns_lock);
578 ldlm_resource_add_lock(res, &res->lr_granted, lock);
579 lock->l_granted_mode = lock->l_req_mode;
581 if (lock->l_granted_mode < res->lr_most_restr)
582 res->lr_most_restr = lock->l_granted_mode;
584 if (lock->l_completion_ast) {
585 ldlm_add_ast_work_item(lock, NULL);
587 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
591 static struct ldlm_lock *search_queue(struct list_head *queue, ldlm_mode_t mode,
592 struct ldlm_extent *extent)
594 struct ldlm_lock *lock;
595 struct list_head *tmp;
597 list_for_each(tmp, queue) {
598 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
600 if (lock->l_flags & LDLM_FL_CBPENDING)
603 /* lock_convert() takes the resource lock, so we're sure that
604 * req_mode, lr_type, and l_cookie won't change beneath us */
605 if (lock->l_req_mode != mode)
608 if (lock->l_resource->lr_type == LDLM_EXTENT &&
609 (lock->l_extent.start > extent->start ||
610 lock->l_extent.end < extent->end))
613 ldlm_lock_addref_internal(lock, mode);
620 /* Must be called with no resource or lock locks held.
622 * Returns 1 if it finds an already-existing lock that is compatible; in this
623 * case, lockh is filled in with a addref()ed lock */
624 int ldlm_lock_match(struct ldlm_namespace *ns, __u64 *res_id, __u32 type,
625 void *cookie, int cookielen, ldlm_mode_t mode,
626 struct lustre_handle *lockh)
628 struct ldlm_resource *res;
629 struct ldlm_lock *lock;
633 res = ldlm_resource_get(ns, NULL, res_id, type, 0);
637 ns = res->lr_namespace;
638 l_lock(&ns->ns_lock);
640 if ((lock = search_queue(&res->lr_granted, mode, cookie)))
642 if ((lock = search_queue(&res->lr_converting, mode, cookie)))
644 if ((lock = search_queue(&res->lr_waiting, mode, cookie)))
649 ldlm_resource_put(res);
650 l_unlock(&ns->ns_lock);
653 ldlm_lock2handle(lock, lockh);
654 wait_event_interruptible(lock->l_waitq, lock->l_req_mode ==
655 lock->l_granted_mode);
658 LDLM_DEBUG(lock, "matched");
660 LDLM_DEBUG_NOLOCK("not matched");
664 /* Returns a referenced, lock */
665 struct ldlm_lock *ldlm_lock_create(struct ldlm_namespace *ns,
666 struct lustre_handle *parent_lock_handle,
667 __u64 *res_id, __u32 type,
672 struct ldlm_resource *res, *parent_res = NULL;
673 struct ldlm_lock *lock, *parent_lock;
675 parent_lock = ldlm_handle2lock(parent_lock_handle);
677 parent_res = parent_lock->l_resource;
679 res = ldlm_resource_get(ns, parent_res, res_id, type, 1);
683 lock = ldlm_lock_new(parent_lock, res);
685 ldlm_resource_put(res);
689 lock->l_req_mode = mode;
691 lock->l_data_len = data_len;
696 /* Must be called with lock->l_lock and lock->l_resource->lr_lock not held */
697 ldlm_error_t ldlm_lock_enqueue(struct ldlm_lock *lock,
698 void *cookie, int cookie_len,
700 ldlm_lock_callback completion,
701 ldlm_lock_callback blocking)
703 struct ldlm_resource *res;
705 ldlm_res_policy policy;
708 res = lock->l_resource;
709 lock->l_blocking_ast = blocking;
711 if (res->lr_type == LDLM_EXTENT)
712 memcpy(&lock->l_extent, cookie, sizeof(lock->l_extent));
714 /* policies are not executed on the client */
715 local = res->lr_namespace->ns_client;
716 if (!local && (policy = ldlm_res_policy_table[res->lr_type])) {
718 rc = policy(lock, cookie, lock->l_req_mode, NULL);
720 if (rc == ELDLM_LOCK_CHANGED) {
721 res = lock->l_resource;
722 *flags |= LDLM_FL_LOCK_CHANGED;
723 } else if (rc == ELDLM_LOCK_ABORTED) {
724 ldlm_lock_destroy(lock);
729 lock->l_cookie = cookie;
730 lock->l_cookie_len = cookie_len;
732 if (local && lock->l_req_mode == lock->l_granted_mode) {
733 /* The server returned a blocked lock, but it was granted before
734 * we got a chance to actually enqueue it. We don't need to do
739 /* If this is a local resource, put it on the appropriate list. */
740 /* FIXME: don't like this: can we call ldlm_resource_unlink_lock? */
741 list_del_init(&lock->l_res_link);
743 if (*flags & LDLM_FL_BLOCK_CONV)
744 ldlm_resource_add_lock(res, res->lr_converting.prev,
746 else if (*flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED))
747 ldlm_resource_add_lock(res, res->lr_waiting.prev, lock);
749 ldlm_grant_lock(lock);
753 /* FIXME: We may want to optimize by checking lr_most_restr */
754 if (!list_empty(&res->lr_converting)) {
755 ldlm_resource_add_lock(res, res->lr_waiting.prev, lock);
756 *flags |= LDLM_FL_BLOCK_CONV;
759 if (!list_empty(&res->lr_waiting)) {
760 ldlm_resource_add_lock(res, res->lr_waiting.prev, lock);
761 *flags |= LDLM_FL_BLOCK_WAIT;
764 if (!ldlm_lock_compat(lock,0)) {
765 ldlm_resource_add_lock(res, res->lr_waiting.prev, lock);
766 *flags |= LDLM_FL_BLOCK_GRANTED;
770 ldlm_grant_lock(lock);
773 /* Don't set 'completion_ast' until here so that if the lock is granted
774 * immediately we don't do an unnecessary completion call. */
775 lock->l_completion_ast = completion;
779 /* Must be called with namespace taken: queue is waiting or converting. */
780 static int ldlm_reprocess_queue(struct ldlm_resource *res,
781 struct list_head *queue)
783 struct list_head *tmp, *pos;
786 list_for_each_safe(tmp, pos, queue) {
787 struct ldlm_lock *pending;
788 pending = list_entry(tmp, struct ldlm_lock, l_res_link);
790 CDEBUG(D_INFO, "Reprocessing lock %p\n", pending);
792 if (!ldlm_lock_compat(pending, 1))
795 list_del_init(&pending->l_res_link);
796 ldlm_grant_lock(pending);
802 void ldlm_run_ast_work(struct list_head *rpc_list)
804 struct list_head *tmp, *pos;
808 list_for_each_safe(tmp, pos, rpc_list) {
809 struct ldlm_ast_work *w =
810 list_entry(tmp, struct ldlm_ast_work, w_list);
811 struct lustre_handle lockh;
813 ldlm_lock2handle(w->w_lock, &lockh);
815 rc = w->w_lock->l_blocking_ast
816 (&lockh, &w->w_desc, w->w_data, w->w_datalen);
818 rc = w->w_lock->l_completion_ast
819 (&lockh, NULL, w->w_data, w->w_datalen);
821 CERROR("Failed AST - should clean & disconnect "
823 ldlm_lock_put(w->w_lock);
824 list_del(&w->w_list);
825 OBD_FREE(w, sizeof(*w));
830 /* Must be called with resource->lr_lock not taken. */
831 void ldlm_reprocess_all(struct ldlm_resource *res)
833 struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
836 /* Local lock trees don't get reprocessed. */
837 if (res->lr_namespace->ns_client) {
842 l_lock(&res->lr_namespace->ns_lock);
843 res->lr_tmp = &rpc_list;
845 ldlm_reprocess_queue(res, &res->lr_converting);
846 if (list_empty(&res->lr_converting))
847 ldlm_reprocess_queue(res, &res->lr_waiting);
850 l_unlock(&res->lr_namespace->ns_lock);
852 ldlm_run_ast_work(&rpc_list);
856 /* Must be called with lock and lock->l_resource unlocked */
857 void ldlm_lock_cancel(struct ldlm_lock *lock)
859 struct ldlm_resource *res;
860 struct ldlm_namespace *ns;
863 res = lock->l_resource;
864 ns = res->lr_namespace;
866 l_lock(&ns->ns_lock);
867 if (lock->l_readers || lock->l_writers)
868 CDEBUG(D_INFO, "lock still has references (%d readers, %d "
869 "writers)\n", lock->l_readers, lock->l_writers);
871 ldlm_resource_unlink_lock(lock);
872 ldlm_lock_destroy(lock);
873 l_unlock(&ns->ns_lock);
876 /* Must be called with lock and lock->l_resource unlocked */
877 struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
880 struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
881 struct ldlm_resource *res;
882 struct ldlm_namespace *ns;
886 res = lock->l_resource;
887 ns = res->lr_namespace;
889 l_lock(&ns->ns_lock);
891 lock->l_req_mode = new_mode;
892 ldlm_resource_unlink_lock(lock);
894 /* If this is a local resource, put it on the appropriate list. */
895 if (res->lr_namespace->ns_client) {
896 if (*flags & (LDLM_FL_BLOCK_CONV | LDLM_FL_BLOCK_GRANTED))
897 ldlm_resource_add_lock(res, res->lr_converting.prev,
900 res->lr_tmp = &rpc_list;
901 ldlm_grant_lock(lock);
904 /* FIXME: completion handling not with ns_lock held ! */
905 wake_up(&lock->l_waitq);
908 list_add(&lock->l_res_link, res->lr_converting.prev);
910 l_unlock(&ns->ns_lock);
913 ldlm_run_ast_work(&rpc_list);
917 void ldlm_lock_dump(struct ldlm_lock *lock)
921 if (!(portal_debug & D_OTHER))
924 if (RES_VERSION_SIZE != 4)
928 CDEBUG(D_OTHER, " NULL LDLM lock\n");
932 snprintf(ver, sizeof(ver), "%x %x %x %x",
933 lock->l_version[0], lock->l_version[1],
934 lock->l_version[2], lock->l_version[3]);
936 CDEBUG(D_OTHER, " -- Lock dump: %p (%s)\n", lock, ver);
937 CDEBUG(D_OTHER, " Parent: %p\n", lock->l_parent);
938 CDEBUG(D_OTHER, " Resource: %p (%Ld)\n", lock->l_resource,
939 lock->l_resource->lr_name[0]);
940 CDEBUG(D_OTHER, " Requested mode: %d, granted mode: %d\n",
941 (int)lock->l_req_mode, (int)lock->l_granted_mode);
942 CDEBUG(D_OTHER, " Readers: %u ; Writers; %u\n",
943 lock->l_readers, lock->l_writers);
944 if (lock->l_resource->lr_type == LDLM_EXTENT)
945 CDEBUG(D_OTHER, " Extent: %Lu -> %Lu\n",
946 (unsigned long long)lock->l_extent.start,
947 (unsigned long long)lock->l_extent.end);