Lines Matching refs:block

44 static void nlmsvc_release_block(struct nlm_block *block);
45 static void nlmsvc_insert_block(struct nlm_block *block, unsigned long);
46 static void nlmsvc_remove_block(struct nlm_block *block);
91 nlmsvc_insert_block_locked(struct nlm_block *block, unsigned long when)
96 dprintk("lockd: nlmsvc_insert_block(%p, %ld)\n", block, when);
97 if (list_empty(&block->b_list)) {
98 kref_get(&block->b_count);
100 list_del_init(&block->b_list);
117 list_add_tail(&block->b_list, pos);
118 block->b_when = when;
121 static void nlmsvc_insert_block(struct nlm_block *block, unsigned long when)
124 nlmsvc_insert_block_locked(block, when);
129 * Remove a block from the global list
132 nlmsvc_remove_block(struct nlm_block *block)
135 if (!list_empty(&block->b_list)) {
136 list_del_init(&block->b_list);
138 nlmsvc_release_block(block);
145 * Find a block for a given lock
150 struct nlm_block *block;
158 list_for_each_entry(block, &nlm_blocked, b_list) {
159 fl = &block->b_call->a_args.lock.fl;
161 block->b_file, fl->fl_pid,
164 nlmdbg_cookie2a(&block->b_call->a_args.cookie));
165 if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) {
166 kref_get(&block->b_count);
168 return block;
186 * Find a block with a given NLM cookie.
191 struct nlm_block *block;
194 list_for_each_entry(block, &nlm_blocked, b_list) {
195 if (nlm_cookie_match(&block->b_call->a_args.cookie,cookie))
203 dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
204 kref_get(&block->b_count);
206 return block;
210 * Create a block and initialize it.
229 struct nlm_block *block;
236 /* Allocate memory for block, and initialize arguments */
237 block = kzalloc(sizeof(*block), GFP_KERNEL);
238 if (block == NULL)
240 kref_init(&block->b_count);
241 INIT_LIST_HEAD(&block->b_list);
242 INIT_LIST_HEAD(&block->b_flist);
252 dprintk("lockd: created block %p...\n", block);
254 /* Create and initialize the block */
255 block->b_daemon = rqstp->rq_server;
256 block->b_host = host;
257 block->b_file = file;
261 list_add(&block->b_flist, &file->f_blocks);
264 block->b_call = call;
266 call->a_block = block;
268 return block;
271 kfree(block);
278 * Delete a block.
282 static int nlmsvc_unlink_block(struct nlm_block *block)
285 dprintk("lockd: unlinking block %p...\n", block);
287 /* Remove block from list */
288 status = locks_delete_block(&block->b_call->a_args.lock.fl);
289 nlmsvc_remove_block(block);
295 struct nlm_block *block = container_of(kref, struct nlm_block, b_count);
296 struct nlm_file *file = block->b_file;
298 dprintk("lockd: freeing block %p...\n", block);
300 /* Remove block from file's list of blocks */
301 list_del_init(&block->b_flist);
304 nlmsvc_freegrantargs(block->b_call);
305 nlmsvc_release_call(block->b_call);
306 nlm_release_file(block->b_file);
307 kfree(block);
310 static void nlmsvc_release_block(struct nlm_block *block)
312 if (block != NULL)
313 kref_put_mutex(&block->b_count, nlmsvc_free_block, &block->b_file->f_mutex);
324 struct nlm_block *block, *next;
329 list_for_each_entry_safe(block, next, &file->f_blocks, b_flist) {
330 if (!match(block->b_host, host))
334 if (list_empty(&block->b_list))
336 kref_get(&block->b_count);
339 nlmsvc_unlink_block(block);
340 nlmsvc_release_block(block);
454 nlmsvc_defer_lock_rqst(struct svc_rqst *rqstp, struct nlm_block *block)
458 block->b_flags |= B_QUEUED;
460 nlmsvc_insert_block(block, NLM_TIMEOUT);
462 block->b_cache_req = &rqstp->rq_chandle;
464 block->b_deferred_req =
465 rqstp->rq_chandle.defer(block->b_cache_req);
466 if (block->b_deferred_req != NULL)
469 dprintk("lockd: nlmsvc_defer_lock_rqst block %p flags %d status %d\n",
470 block, block->b_flags, ntohl(status));
476 * Attempt to establish a lock, and if it can't be granted, block it
487 struct nlm_block *block = NULL;
507 /* Get existing block (in case client is busy-waiting)
508 * or create new block
510 block = nlmsvc_lookup_block(file, lock);
511 if (block == NULL) {
512 block = nlmsvc_create_block(rqstp, host, file, lock, cookie);
514 if (block == NULL)
516 lock = &block->b_call->a_args.lock;
520 if (block->b_flags & B_QUEUED) {
521 dprintk("lockd: nlmsvc_lock deferred block %p flags %d\n",
522 block, block->b_flags);
523 if (block->b_granted) {
524 nlmsvc_unlink_block(block);
528 if (block->b_flags & B_TIMED_OUT) {
529 nlmsvc_unlink_block(block);
561 * to put it back on lockd's block list
572 ret = nlmsvc_defer_lock_rqst(rqstp, block);
585 nlmsvc_insert_block(block, NLM_NEVER);
588 nlmsvc_release_block(block);
654 * afterwards. In this case the block will still be there, and hence
695 struct nlm_block *block;
710 block = nlmsvc_lookup_block(file, lock);
712 if (block != NULL) {
713 struct file_lock *fl = &block->b_call->a_args.lock.fl;
716 vfs_cancel_lock(block->b_file->f_file[mode], fl);
717 status = nlmsvc_unlink_block(block);
718 nlmsvc_release_block(block);
728 * In all cases it will move the block to the head of nlm_blocked q where
733 nlmsvc_update_deferred_block(struct nlm_block *block, int result)
735 block->b_flags |= B_GOT_CALLBACK;
737 block->b_granted = 1;
739 block->b_flags |= B_TIMED_OUT;
744 struct nlm_block *block;
748 list_for_each_entry(block, &nlm_blocked, b_list) {
749 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
750 dprintk("lockd: nlmsvc_notify_blocked block %p flags %d\n",
751 block, block->b_flags);
752 if (block->b_flags & B_QUEUED) {
753 if (block->b_flags & B_TIMED_OUT) {
757 nlmsvc_update_deferred_block(block, result);
759 block->b_granted = 1;
761 nlmsvc_insert_block_locked(block, 0);
762 svc_wake_up(block->b_daemon);
769 printk(KERN_WARNING "lockd: grant for unknown block\n");
778 * the block to the head of nlm_blocked where it can be picked up by lockd.
783 struct nlm_block *block;
785 dprintk("lockd: VFS unblock notification for block %p\n", fl);
787 list_for_each_entry(block, &nlm_blocked, b_list) {
788 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
789 nlmsvc_insert_block_locked(block, 0);
791 svc_wake_up(block->b_daemon);
796 printk(KERN_WARNING "lockd: notification for unknown block!\n");
828 nlmsvc_grant_blocked(struct nlm_block *block)
830 struct nlm_file *file = block->b_file;
831 struct nlm_lock *lock = &block->b_call->a_args.lock;
836 dprintk("lockd: grant blocked lock %p\n", block);
838 kref_get(&block->b_count);
840 /* Unlink block request from list */
841 nlmsvc_unlink_block(block);
846 if (block->b_granted) {
847 nlm_rebind_host(block->b_host);
869 nlmsvc_insert_block(block, NLM_NEVER);
870 nlmsvc_release_block(block);
875 nlmsvc_insert_block(block, 10 * HZ);
876 nlmsvc_release_block(block);
883 block->b_granted = 1;
885 /* keep block on the list, but don't reattempt until the RPC
888 nlmsvc_insert_block(block, NLM_NEVER);
893 error = nlm_async_call(block->b_call, NLMPROC_GRANTED_MSG,
898 nlmsvc_insert_block(block, 10 * HZ);
912 struct nlm_block *block = call->a_block;
918 /* if the block is not on a list at this point then it has
921 * FIXME: it's possible that the block is removed from the list
926 if (list_empty(&block->b_list))
930 * move the block towards the head of the queue only, no harm
939 nlmsvc_insert_block_locked(block, timeout);
940 svc_wake_up(block->b_daemon);
962 * block.
967 struct nlm_block *block;
973 if (!(block = nlmsvc_find_block(cookie)))
979 nlmsvc_insert_block(block, 10 * HZ);
983 nlmsvc_unlink_block(block);
984 fl = &block->b_call->a_args.lock.fl;
995 nlmsvc_unlink_block(block);
997 nlmsvc_release_block(block);
1000 /* Helper function to handle retry of a deferred block.
1005 retry_deferred_block(struct nlm_block *block)
1007 if (!(block->b_flags & B_GOT_CALLBACK))
1008 block->b_flags |= B_TIMED_OUT;
1009 nlmsvc_insert_block(block, NLM_TIMEOUT);
1010 dprintk("revisit block %p flags %d\n", block, block->b_flags);
1011 if (block->b_deferred_req) {
1012 block->b_deferred_req->revisit(block->b_deferred_req, 0);
1013 block->b_deferred_req = NULL;
1026 struct nlm_block *block;
1030 block = list_entry(nlm_blocked.next, struct nlm_block, b_list);
1032 if (block->b_when == NLM_NEVER)
1034 if (time_after(block->b_when, jiffies)) {
1035 timeout = block->b_when - jiffies;
1041 block, block->b_when);
1042 if (block->b_flags & B_QUEUED) {
1043 dprintk("nlmsvc_retry_blocked delete block (%p, granted=%d, flags=%d)\n",
1044 block, block->b_granted, block->b_flags);
1045 retry_deferred_block(block);
1047 nlmsvc_grant_blocked(block);