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)
133 if (!list_empty(&block->b_list)) {
135 list_del_init(&block->b_list);
137 nlmsvc_release_block(block);
142 * Find a block for a given lock
147 struct nlm_block *block;
154 list_for_each_entry(block, &nlm_blocked, b_list) {
155 fl = &block->b_call->a_args.lock.fl;
157 block->b_file, fl->fl_pid,
160 nlmdbg_cookie2a(&block->b_call->a_args.cookie));
161 if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) {
162 kref_get(&block->b_count);
163 return block;
180 * Find a block with a given NLM cookie.
185 struct nlm_block *block;
187 list_for_each_entry(block, &nlm_blocked, b_list) {
188 if (nlm_cookie_match(&block->b_call->a_args.cookie,cookie))
195 dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
196 kref_get(&block->b_count);
197 return block;
201 * Create a block and initialize it.
220 struct nlm_block *block;
227 /* Allocate memory for block, and initialize arguments */
228 block = kzalloc(sizeof(*block), GFP_KERNEL);
229 if (block == NULL)
231 kref_init(&block->b_count);
232 INIT_LIST_HEAD(&block->b_list);
233 INIT_LIST_HEAD(&block->b_flist);
243 dprintk("lockd: created block %p...\n", block);
245 /* Create and initialize the block */
246 block->b_daemon = rqstp->rq_server;
247 block->b_host = host;
248 block->b_file = file;
252 list_add(&block->b_flist, &file->f_blocks);
255 block->b_call = call;
257 call->a_block = block;
259 return block;
262 kfree(block);
269 * Delete a block.
273 static int nlmsvc_unlink_block(struct nlm_block *block)
276 dprintk("lockd: unlinking block %p...\n", block);
278 /* Remove block from list */
279 status = locks_delete_block(&block->b_call->a_args.lock.fl);
280 nlmsvc_remove_block(block);
286 struct nlm_block *block = container_of(kref, struct nlm_block, b_count);
287 struct nlm_file *file = block->b_file;
289 dprintk("lockd: freeing block %p...\n", block);
291 /* Remove block from file's list of blocks */
292 list_del_init(&block->b_flist);
295 nlmsvc_freegrantargs(block->b_call);
296 nlmsvc_release_call(block->b_call);
297 nlm_release_file(block->b_file);
298 kfree(block);
301 static void nlmsvc_release_block(struct nlm_block *block)
303 if (block != NULL)
304 kref_put_mutex(&block->b_count, nlmsvc_free_block, &block->b_file->f_mutex);
315 struct nlm_block *block, *next;
319 list_for_each_entry_safe(block, next, &file->f_blocks, b_flist) {
320 if (!match(block->b_host, host))
324 if (list_empty(&block->b_list))
326 kref_get(&block->b_count);
328 nlmsvc_unlink_block(block);
329 nlmsvc_release_block(block);
442 nlmsvc_defer_lock_rqst(struct svc_rqst *rqstp, struct nlm_block *block)
446 block->b_flags |= B_QUEUED;
448 nlmsvc_insert_block(block, NLM_TIMEOUT);
450 block->b_cache_req = &rqstp->rq_chandle;
452 block->b_deferred_req =
453 rqstp->rq_chandle.defer(block->b_cache_req);
454 if (block->b_deferred_req != NULL)
457 dprintk("lockd: nlmsvc_defer_lock_rqst block %p flags %d status %d\n",
458 block, block->b_flags, ntohl(status));
464 * Attempt to establish a lock, and if it can't be granted, block it
472 struct nlm_block *block = NULL;
486 /* Get existing block (in case client is busy-waiting)
487 * or create new block
489 block = nlmsvc_lookup_block(file, lock);
490 if (block == NULL) {
491 block = nlmsvc_create_block(rqstp, host, file, lock, cookie);
493 if (block == NULL)
495 lock = &block->b_call->a_args.lock;
499 if (block->b_flags & B_QUEUED) {
500 dprintk("lockd: nlmsvc_lock deferred block %p flags %d\n",
501 block, block->b_flags);
502 if (block->b_granted) {
503 nlmsvc_unlink_block(block);
507 if (block->b_flags & B_TIMED_OUT) {
508 nlmsvc_unlink_block(block);
539 * to put it back on lockd's block list
550 ret = nlmsvc_defer_lock_rqst(rqstp, block);
563 nlmsvc_insert_block(block, NLM_NEVER);
566 nlmsvc_release_block(block);
638 * afterwards. In this case the block will still be there, and hence
672 struct nlm_block *block;
686 block = nlmsvc_lookup_block(file, lock);
688 if (block != NULL) {
689 vfs_cancel_lock(block->b_file->f_file,
690 &block->b_call->a_args.lock.fl);
691 status = nlmsvc_unlink_block(block);
692 nlmsvc_release_block(block);
702 * In all cases it will move the block to the head of nlm_blocked q where
707 nlmsvc_update_deferred_block(struct nlm_block *block, int result)
709 block->b_flags |= B_GOT_CALLBACK;
711 block->b_granted = 1;
713 block->b_flags |= B_TIMED_OUT;
718 struct nlm_block *block;
722 list_for_each_entry(block, &nlm_blocked, b_list) {
723 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
724 dprintk("lockd: nlmsvc_notify_blocked block %p flags %d\n",
725 block, block->b_flags);
726 if (block->b_flags & B_QUEUED) {
727 if (block->b_flags & B_TIMED_OUT) {
731 nlmsvc_update_deferred_block(block, result);
733 block->b_granted = 1;
735 nlmsvc_insert_block_locked(block, 0);
736 svc_wake_up(block->b_daemon);
743 printk(KERN_WARNING "lockd: grant for unknown block\n");
752 * the block to the head of nlm_blocked where it can be picked up by lockd.
757 struct nlm_block *block;
759 dprintk("lockd: VFS unblock notification for block %p\n", fl);
761 list_for_each_entry(block, &nlm_blocked, b_list) {
762 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
763 nlmsvc_insert_block_locked(block, 0);
765 svc_wake_up(block->b_daemon);
770 printk(KERN_WARNING "lockd: notification for unknown block!\n");
802 nlmsvc_grant_blocked(struct nlm_block *block)
804 struct nlm_file *file = block->b_file;
805 struct nlm_lock *lock = &block->b_call->a_args.lock;
809 dprintk("lockd: grant blocked lock %p\n", block);
811 kref_get(&block->b_count);
813 /* Unlink block request from list */
814 nlmsvc_unlink_block(block);
819 if (block->b_granted) {
820 nlm_rebind_host(block->b_host);
841 nlmsvc_insert_block(block, NLM_NEVER);
842 nlmsvc_release_block(block);
847 nlmsvc_insert_block(block, 10 * HZ);
848 nlmsvc_release_block(block);
855 block->b_granted = 1;
857 /* keep block on the list, but don't reattempt until the RPC
860 nlmsvc_insert_block(block, NLM_NEVER);
865 error = nlm_async_call(block->b_call, NLMPROC_GRANTED_MSG,
870 nlmsvc_insert_block(block, 10 * HZ);
884 struct nlm_block *block = call->a_block;
890 /* if the block is not on a list at this point then it has
893 * FIXME: it's possible that the block is removed from the list
898 if (list_empty(&block->b_list))
902 * move the block towards the head of the queue only, no harm
911 nlmsvc_insert_block_locked(block, timeout);
912 svc_wake_up(block->b_daemon);
934 * block.
939 struct nlm_block *block;
943 if (!(block = nlmsvc_find_block(cookie)))
948 nlmsvc_insert_block(block, 10 * HZ);
952 * In both cases, the block should be removed.
954 nlmsvc_unlink_block(block);
956 nlmsvc_release_block(block);
959 /* Helper function to handle retry of a deferred block.
964 retry_deferred_block(struct nlm_block *block)
966 if (!(block->b_flags & B_GOT_CALLBACK))
967 block->b_flags |= B_TIMED_OUT;
968 nlmsvc_insert_block(block, NLM_TIMEOUT);
969 dprintk("revisit block %p flags %d\n", block, block->b_flags);
970 if (block->b_deferred_req) {
971 block->b_deferred_req->revisit(block->b_deferred_req, 0);
972 block->b_deferred_req = NULL;
985 struct nlm_block *block;
989 block = list_entry(nlm_blocked.next, struct nlm_block, b_list);
991 if (block->b_when == NLM_NEVER)
993 if (time_after(block->b_when, jiffies)) {
994 timeout = block->b_when - jiffies;
1000 block, block->b_when);
1001 if (block->b_flags & B_QUEUED) {
1002 dprintk("nlmsvc_retry_blocked delete block (%p, granted=%d, flags=%d)\n",
1003 block, block->b_granted, block->b_flags);
1004 retry_deferred_block(block);
1006 nlmsvc_grant_blocked(block);