Lines Matching full:block

43 static void nlmsvc_release_block(struct nlm_block *block);
44 static void nlmsvc_insert_block(struct nlm_block *block, unsigned long);
45 static void nlmsvc_remove_block(struct nlm_block *block);
90 nlmsvc_insert_block_locked(struct nlm_block *block, unsigned long when) in nlmsvc_insert_block_locked() argument
95 dprintk("lockd: nlmsvc_insert_block(%p, %ld)\n", block, when); in nlmsvc_insert_block_locked()
96 if (list_empty(&block->b_list)) { in nlmsvc_insert_block_locked()
97 kref_get(&block->b_count); in nlmsvc_insert_block_locked()
99 list_del_init(&block->b_list); in nlmsvc_insert_block_locked()
116 list_add_tail(&block->b_list, pos); in nlmsvc_insert_block_locked()
117 block->b_when = when; in nlmsvc_insert_block_locked()
120 static void nlmsvc_insert_block(struct nlm_block *block, unsigned long when) in nlmsvc_insert_block() argument
123 nlmsvc_insert_block_locked(block, when); in nlmsvc_insert_block()
128 * Remove a block from the global list
131 nlmsvc_remove_block(struct nlm_block *block) in nlmsvc_remove_block() argument
133 if (!list_empty(&block->b_list)) { in nlmsvc_remove_block()
135 list_del_init(&block->b_list); in nlmsvc_remove_block()
137 nlmsvc_release_block(block); in nlmsvc_remove_block()
142 * Find a block for a given lock
147 struct nlm_block *block; in nlmsvc_lookup_block() local
154 list_for_each_entry(block, &nlm_blocked, b_list) { in nlmsvc_lookup_block()
155 fl = &block->b_call->a_args.lock.fl; in nlmsvc_lookup_block()
157 block->b_file, fl->fl_pid, in nlmsvc_lookup_block()
160 nlmdbg_cookie2a(&block->b_call->a_args.cookie)); in nlmsvc_lookup_block()
161 if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) { in nlmsvc_lookup_block()
162 kref_get(&block->b_count); in nlmsvc_lookup_block()
163 return block; in nlmsvc_lookup_block()
180 * Find a block with a given NLM cookie.
185 struct nlm_block *block; in nlmsvc_find_block() local
187 list_for_each_entry(block, &nlm_blocked, b_list) { in nlmsvc_find_block()
188 if (nlm_cookie_match(&block->b_call->a_args.cookie,cookie)) in nlmsvc_find_block()
195 dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block); in nlmsvc_find_block()
196 kref_get(&block->b_count); in nlmsvc_find_block()
197 return block; in nlmsvc_find_block()
201 * Create a block and initialize it.
220 struct nlm_block *block; in nlmsvc_create_block() local
227 /* Allocate memory for block, and initialize arguments */ in nlmsvc_create_block()
228 block = kzalloc(sizeof(*block), GFP_KERNEL); in nlmsvc_create_block()
229 if (block == NULL) in nlmsvc_create_block()
231 kref_init(&block->b_count); in nlmsvc_create_block()
232 INIT_LIST_HEAD(&block->b_list); in nlmsvc_create_block()
233 INIT_LIST_HEAD(&block->b_flist); in nlmsvc_create_block()
243 dprintk("lockd: created block %p...\n", block); in nlmsvc_create_block()
245 /* Create and initialize the block */ in nlmsvc_create_block()
246 block->b_daemon = rqstp->rq_server; in nlmsvc_create_block()
247 block->b_host = host; in nlmsvc_create_block()
248 block->b_file = file; in nlmsvc_create_block()
252 list_add(&block->b_flist, &file->f_blocks); in nlmsvc_create_block()
255 block->b_call = call; in nlmsvc_create_block()
257 call->a_block = block; in nlmsvc_create_block()
259 return block; in nlmsvc_create_block()
262 kfree(block); in nlmsvc_create_block()
269 * Delete a block.
273 static int nlmsvc_unlink_block(struct nlm_block *block) in nlmsvc_unlink_block() argument
276 dprintk("lockd: unlinking block %p...\n", block); in nlmsvc_unlink_block()
278 /* Remove block from list */ in nlmsvc_unlink_block()
279 status = locks_delete_block(&block->b_call->a_args.lock.fl); in nlmsvc_unlink_block()
280 nlmsvc_remove_block(block); in nlmsvc_unlink_block()
286 struct nlm_block *block = container_of(kref, struct nlm_block, b_count); in nlmsvc_free_block() local
287 struct nlm_file *file = block->b_file; in nlmsvc_free_block()
289 dprintk("lockd: freeing block %p...\n", block); in nlmsvc_free_block()
291 /* Remove block from file's list of blocks */ in nlmsvc_free_block()
292 list_del_init(&block->b_flist); in nlmsvc_free_block()
295 nlmsvc_freegrantargs(block->b_call); in nlmsvc_free_block()
296 nlmsvc_release_call(block->b_call); in nlmsvc_free_block()
297 nlm_release_file(block->b_file); in nlmsvc_free_block()
298 kfree(block); in nlmsvc_free_block()
301 static void nlmsvc_release_block(struct nlm_block *block) in nlmsvc_release_block() argument
303 if (block != NULL) in nlmsvc_release_block()
304 kref_put_mutex(&block->b_count, nlmsvc_free_block, &block->b_file->f_mutex); in nlmsvc_release_block()
315 struct nlm_block *block, *next; in nlmsvc_traverse_blocks() local
319 list_for_each_entry_safe(block, next, &file->f_blocks, b_flist) { in nlmsvc_traverse_blocks()
320 if (!match(block->b_host, host)) in nlmsvc_traverse_blocks()
324 if (list_empty(&block->b_list)) in nlmsvc_traverse_blocks()
326 kref_get(&block->b_count); in nlmsvc_traverse_blocks()
328 nlmsvc_unlink_block(block); in nlmsvc_traverse_blocks()
329 nlmsvc_release_block(block); in nlmsvc_traverse_blocks()
460 nlmsvc_defer_lock_rqst(struct svc_rqst *rqstp, struct nlm_block *block) in nlmsvc_defer_lock_rqst() argument
464 block->b_flags |= B_QUEUED; in nlmsvc_defer_lock_rqst()
466 nlmsvc_insert_block(block, NLM_TIMEOUT); in nlmsvc_defer_lock_rqst()
468 block->b_cache_req = &rqstp->rq_chandle; in nlmsvc_defer_lock_rqst()
470 block->b_deferred_req = in nlmsvc_defer_lock_rqst()
471 rqstp->rq_chandle.defer(block->b_cache_req); in nlmsvc_defer_lock_rqst()
472 if (block->b_deferred_req != NULL) in nlmsvc_defer_lock_rqst()
475 dprintk("lockd: nlmsvc_defer_lock_rqst block %p flags %d status %d\n", in nlmsvc_defer_lock_rqst()
476 block, block->b_flags, ntohl(status)); in nlmsvc_defer_lock_rqst()
482 * Attempt to establish a lock, and if it can't be granted, block it
490 struct nlm_block *block = NULL; in nlmsvc_lock() local
504 /* Get existing block (in case client is busy-waiting) in nlmsvc_lock()
505 * or create new block in nlmsvc_lock()
507 block = nlmsvc_lookup_block(file, lock); in nlmsvc_lock()
508 if (block == NULL) { in nlmsvc_lock()
509 block = nlmsvc_create_block(rqstp, host, file, lock, cookie); in nlmsvc_lock()
511 if (block == NULL) in nlmsvc_lock()
513 lock = &block->b_call->a_args.lock; in nlmsvc_lock()
517 if (block->b_flags & B_QUEUED) { in nlmsvc_lock()
518 dprintk("lockd: nlmsvc_lock deferred block %p flags %d\n", in nlmsvc_lock()
519 block, block->b_flags); in nlmsvc_lock()
520 if (block->b_granted) { in nlmsvc_lock()
521 nlmsvc_unlink_block(block); in nlmsvc_lock()
525 if (block->b_flags & B_TIMED_OUT) { in nlmsvc_lock()
526 nlmsvc_unlink_block(block); in nlmsvc_lock()
557 * to put it back on lockd's block list in nlmsvc_lock()
568 ret = nlmsvc_defer_lock_rqst(rqstp, block); in nlmsvc_lock()
581 nlmsvc_insert_block(block, NLM_NEVER); in nlmsvc_lock()
584 nlmsvc_release_block(block); in nlmsvc_lock()
656 * afterwards. In this case the block will still be there, and hence
690 struct nlm_block *block; in nlmsvc_cancel_blocked() local
704 block = nlmsvc_lookup_block(file, lock); in nlmsvc_cancel_blocked()
706 if (block != NULL) { in nlmsvc_cancel_blocked()
707 vfs_cancel_lock(block->b_file->f_file, in nlmsvc_cancel_blocked()
708 &block->b_call->a_args.lock.fl); in nlmsvc_cancel_blocked()
709 status = nlmsvc_unlink_block(block); in nlmsvc_cancel_blocked()
710 nlmsvc_release_block(block); in nlmsvc_cancel_blocked()
720 * In all cases it will move the block to the head of nlm_blocked q where
725 nlmsvc_update_deferred_block(struct nlm_block *block, int result) in nlmsvc_update_deferred_block() argument
727 block->b_flags |= B_GOT_CALLBACK; in nlmsvc_update_deferred_block()
729 block->b_granted = 1; in nlmsvc_update_deferred_block()
731 block->b_flags |= B_TIMED_OUT; in nlmsvc_update_deferred_block()
736 struct nlm_block *block; in nlmsvc_grant_deferred() local
740 list_for_each_entry(block, &nlm_blocked, b_list) { in nlmsvc_grant_deferred()
741 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) { in nlmsvc_grant_deferred()
742 dprintk("lockd: nlmsvc_notify_blocked block %p flags %d\n", in nlmsvc_grant_deferred()
743 block, block->b_flags); in nlmsvc_grant_deferred()
744 if (block->b_flags & B_QUEUED) { in nlmsvc_grant_deferred()
745 if (block->b_flags & B_TIMED_OUT) { in nlmsvc_grant_deferred()
749 nlmsvc_update_deferred_block(block, result); in nlmsvc_grant_deferred()
751 block->b_granted = 1; in nlmsvc_grant_deferred()
753 nlmsvc_insert_block_locked(block, 0); in nlmsvc_grant_deferred()
754 svc_wake_up(block->b_daemon); in nlmsvc_grant_deferred()
761 printk(KERN_WARNING "lockd: grant for unknown block\n"); in nlmsvc_grant_deferred()
770 * the block to the head of nlm_blocked where it can be picked up by lockd.
775 struct nlm_block *block; in nlmsvc_notify_blocked() local
777 dprintk("lockd: VFS unblock notification for block %p\n", fl); in nlmsvc_notify_blocked()
779 list_for_each_entry(block, &nlm_blocked, b_list) { in nlmsvc_notify_blocked()
780 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) { in nlmsvc_notify_blocked()
781 nlmsvc_insert_block_locked(block, 0); in nlmsvc_notify_blocked()
783 svc_wake_up(block->b_daemon); in nlmsvc_notify_blocked()
788 printk(KERN_WARNING "lockd: notification for unknown block!\n"); in nlmsvc_notify_blocked()
808 nlmsvc_grant_blocked(struct nlm_block *block) in nlmsvc_grant_blocked() argument
810 struct nlm_file *file = block->b_file; in nlmsvc_grant_blocked()
811 struct nlm_lock *lock = &block->b_call->a_args.lock; in nlmsvc_grant_blocked()
815 dprintk("lockd: grant blocked lock %p\n", block); in nlmsvc_grant_blocked()
817 kref_get(&block->b_count); in nlmsvc_grant_blocked()
819 /* Unlink block request from list */ in nlmsvc_grant_blocked()
820 nlmsvc_unlink_block(block); in nlmsvc_grant_blocked()
825 if (block->b_granted) { in nlmsvc_grant_blocked()
826 nlm_rebind_host(block->b_host); in nlmsvc_grant_blocked()
847 nlmsvc_insert_block(block, NLM_NEVER); in nlmsvc_grant_blocked()
848 nlmsvc_release_block(block); in nlmsvc_grant_blocked()
853 nlmsvc_insert_block(block, 10 * HZ); in nlmsvc_grant_blocked()
854 nlmsvc_release_block(block); in nlmsvc_grant_blocked()
861 block->b_granted = 1; in nlmsvc_grant_blocked()
863 /* keep block on the list, but don't reattempt until the RPC in nlmsvc_grant_blocked()
866 nlmsvc_insert_block(block, NLM_NEVER); in nlmsvc_grant_blocked()
871 error = nlm_async_call(block->b_call, NLMPROC_GRANTED_MSG, in nlmsvc_grant_blocked()
876 nlmsvc_insert_block(block, 10 * HZ); in nlmsvc_grant_blocked()
890 struct nlm_block *block = call->a_block; in nlmsvc_grant_callback() local
896 /* if the block is not on a list at this point then it has in nlmsvc_grant_callback()
899 * FIXME: it's possible that the block is removed from the list in nlmsvc_grant_callback()
904 if (list_empty(&block->b_list)) in nlmsvc_grant_callback()
908 * move the block towards the head of the queue only, no harm in nlmsvc_grant_callback()
917 nlmsvc_insert_block_locked(block, timeout); in nlmsvc_grant_callback()
918 svc_wake_up(block->b_daemon); in nlmsvc_grant_callback()
940 * block.
945 struct nlm_block *block; in nlmsvc_grant_reply() local
949 if (!(block = nlmsvc_find_block(cookie))) in nlmsvc_grant_reply()
954 nlmsvc_insert_block(block, 10 * HZ); in nlmsvc_grant_reply()
958 * In both cases, the block should be removed. in nlmsvc_grant_reply()
960 nlmsvc_unlink_block(block); in nlmsvc_grant_reply()
962 nlmsvc_release_block(block); in nlmsvc_grant_reply()
965 /* Helper function to handle retry of a deferred block.
970 retry_deferred_block(struct nlm_block *block) in retry_deferred_block() argument
972 if (!(block->b_flags & B_GOT_CALLBACK)) in retry_deferred_block()
973 block->b_flags |= B_TIMED_OUT; in retry_deferred_block()
974 nlmsvc_insert_block(block, NLM_TIMEOUT); in retry_deferred_block()
975 dprintk("revisit block %p flags %d\n", block, block->b_flags); in retry_deferred_block()
976 if (block->b_deferred_req) { in retry_deferred_block()
977 block->b_deferred_req->revisit(block->b_deferred_req, 0); in retry_deferred_block()
978 block->b_deferred_req = NULL; in retry_deferred_block()
991 struct nlm_block *block; in nlmsvc_retry_blocked() local
995 block = list_entry(nlm_blocked.next, struct nlm_block, b_list); in nlmsvc_retry_blocked()
997 if (block->b_when == NLM_NEVER) in nlmsvc_retry_blocked()
999 if (time_after(block->b_when, jiffies)) { in nlmsvc_retry_blocked()
1000 timeout = block->b_when - jiffies; in nlmsvc_retry_blocked()
1006 block, block->b_when); in nlmsvc_retry_blocked()
1007 if (block->b_flags & B_QUEUED) { in nlmsvc_retry_blocked()
1008 dprintk("nlmsvc_retry_blocked delete block (%p, granted=%d, flags=%d)\n", in nlmsvc_retry_blocked()
1009 block, block->b_granted, block->b_flags); in nlmsvc_retry_blocked()
1010 retry_deferred_block(block); in nlmsvc_retry_blocked()
1012 nlmsvc_grant_blocked(block); in nlmsvc_retry_blocked()