Lines Matching refs: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)
95 dprintk("lockd: nlmsvc_insert_block(%p, %ld)\n", block, when);
96 if (list_empty(&block->b_list)) {
97 kref_get(&block->b_count);
99 list_del_init(&block->b_list);
116 list_add_tail(&block->b_list, pos);
117 block->b_when = when;
120 static void nlmsvc_insert_block(struct nlm_block *block, unsigned long when)
123 nlmsvc_insert_block_locked(block, when);
128 * Remove a block from the global list
131 nlmsvc_remove_block(struct nlm_block *block)
134 if (!list_empty(&block->b_list)) {
135 list_del_init(&block->b_list);
137 nlmsvc_release_block(block);
144 * Find a block for a given lock
149 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->c.flc_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
485 struct nlm_block *block = NULL;
506 /* Get existing block (in case client is busy-waiting)
507 * or create new block
509 block = nlmsvc_lookup_block(file, lock);
510 if (block == NULL) {
511 block = nlmsvc_create_block(rqstp, host, file, lock, cookie);
513 if (block == NULL)
515 lock = &block->b_call->a_args.lock;
519 if (block->b_flags & B_QUEUED) {
520 dprintk("lockd: nlmsvc_lock deferred block %p flags %d\n",
521 block, block->b_flags);
522 if (block->b_granted) {
523 nlmsvc_unlink_block(block);
527 if (block->b_flags & B_TIMED_OUT) {
528 nlmsvc_unlink_block(block);
554 !list_empty(&block->b_list)) {
561 nlmsvc_insert_block_locked(block, NLM_NEVER);
573 nlmsvc_remove_block(block);
578 nlmsvc_remove_block(block);
586 ret = nlmsvc_defer_lock_rqst(rqstp, block);
589 nlmsvc_remove_block(block);
593 nlmsvc_remove_block(block);
601 nlmsvc_release_block(block);
667 * afterwards. In this case the block will still be there, and hence
708 struct nlm_block *block;
723 block = nlmsvc_lookup_block(file, lock);
725 if (block != NULL) {
726 struct file_lock *fl = &block->b_call->a_args.lock.fl;
729 vfs_cancel_lock(block->b_file->f_file[mode], fl);
730 status = nlmsvc_unlink_block(block);
731 nlmsvc_release_block(block);
741 * In all cases it will move the block to the head of nlm_blocked q where
746 nlmsvc_update_deferred_block(struct nlm_block *block, int result)
748 block->b_flags |= B_GOT_CALLBACK;
750 block->b_granted = 1;
752 block->b_flags |= B_TIMED_OUT;
757 struct nlm_block *block;
761 list_for_each_entry(block, &nlm_blocked, b_list) {
762 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
763 dprintk("lockd: nlmsvc_notify_blocked block %p flags %d\n",
764 block, block->b_flags);
765 if (block->b_flags & B_QUEUED) {
766 if (block->b_flags & B_TIMED_OUT) {
770 nlmsvc_update_deferred_block(block, result);
772 block->b_granted = 1;
774 nlmsvc_insert_block_locked(block, 0);
775 svc_wake_up(block->b_daemon);
782 printk(KERN_WARNING "lockd: grant for unknown block\n");
791 * the block to the head of nlm_blocked where it can be picked up by lockd.
796 struct nlm_block *block;
798 dprintk("lockd: VFS unblock notification for block %p\n", fl);
800 list_for_each_entry(block, &nlm_blocked, b_list) {
801 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
802 nlmsvc_insert_block_locked(block, 0);
804 svc_wake_up(block->b_daemon);
809 printk(KERN_WARNING "lockd: notification for unknown block!\n");
841 nlmsvc_grant_blocked(struct nlm_block *block)
843 struct nlm_file *file = block->b_file;
844 struct nlm_lock *lock = &block->b_call->a_args.lock;
849 dprintk("lockd: grant blocked lock %p\n", block);
851 kref_get(&block->b_count);
853 /* Unlink block request from list */
854 nlmsvc_unlink_block(block);
859 if (block->b_granted) {
860 nlm_rebind_host(block->b_host);
882 nlmsvc_insert_block(block, NLM_NEVER);
883 nlmsvc_release_block(block);
888 nlmsvc_insert_block(block, 10 * HZ);
889 nlmsvc_release_block(block);
896 block->b_granted = 1;
898 /* keep block on the list, but don't reattempt until the RPC
901 nlmsvc_insert_block(block, NLM_NEVER);
906 error = nlm_async_call(block->b_call, NLMPROC_GRANTED_MSG,
911 nlmsvc_insert_block(block, 10 * HZ);
925 struct nlm_block *block = call->a_block;
931 /* if the block is not on a list at this point then it has
934 * FIXME: it's possible that the block is removed from the list
939 if (list_empty(&block->b_list))
943 * move the block towards the head of the queue only, no harm
952 nlmsvc_insert_block_locked(block, timeout);
953 svc_wake_up(block->b_daemon);
975 * block.
980 struct nlm_block *block;
986 if (!(block = nlmsvc_find_block(cookie)))
992 nlmsvc_insert_block(block, 10 * HZ);
996 nlmsvc_unlink_block(block);
997 fl = &block->b_call->a_args.lock.fl;
1008 nlmsvc_unlink_block(block);
1010 nlmsvc_release_block(block);
1013 /* Helper function to handle retry of a deferred block.
1018 retry_deferred_block(struct nlm_block *block)
1020 if (!(block->b_flags & B_GOT_CALLBACK))
1021 block->b_flags |= B_TIMED_OUT;
1022 nlmsvc_insert_block(block, NLM_TIMEOUT);
1023 dprintk("revisit block %p flags %d\n", block, block->b_flags);
1024 if (block->b_deferred_req) {
1025 block->b_deferred_req->revisit(block->b_deferred_req, 0);
1026 block->b_deferred_req = NULL;
1039 struct nlm_block *block;
1043 block = list_entry(nlm_blocked.next, struct nlm_block, b_list);
1045 if (block->b_when == NLM_NEVER)
1047 if (time_after(block->b_when, jiffies)) {
1048 timeout = block->b_when - jiffies;
1054 block, block->b_when);
1055 if (block->b_flags & B_QUEUED) {
1056 dprintk("nlmsvc_retry_blocked delete block (%p, granted=%d, flags=%d)\n",
1057 block, block->b_granted, block->b_flags);
1058 retry_deferred_block(block);
1060 nlmsvc_grant_blocked(block);