Skip to content

Commit

Permalink
nfs: fix nonblocking calls to nfs_page_group_lock
Browse files Browse the repository at this point in the history
nfs_page_group_lock was calling wait_on_bit_lock even when told not to
block. Fix by first trying test_and_set_bit, followed by wait_on_bit_lock
if and only if blocking is allowed.  Return -EAGAIN if nonblocking and the
test_and_set of the bit was already locked.

Signed-off-by: Weston Andros Adamson <[email protected]>
Reviewed-by: Peng Tao <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
  • Loading branch information
westonandrosadamson authored and trondmypd committed Aug 22, 2014
1 parent fd2f3a0 commit bc8a309
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions fs/nfs/pagelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,28 @@ nfs_iocounter_wait(struct nfs_io_counter *c)
*
* this lock must be held if modifying the page group list
*
* returns result from wait_on_bit_lock: 0 on success, < 0 on error
* return 0 on success, < 0 on error: -EDELAY if nonblocking or the
* result from wait_on_bit_lock
*
* NOTE: calling with nonblock=false should always have set the
* lock bit (see fs/buffer.c and other uses of wait_on_bit_lock
* with TASK_UNINTERRUPTIBLE), so there is no need to check the result.
*/
int
nfs_page_group_lock(struct nfs_page *req, bool nonblock)
{
struct nfs_page *head = req->wb_head;
int ret;

WARN_ON_ONCE(head != head->wb_head);

do {
ret = wait_on_bit_lock(&head->wb_flags, PG_HEADLOCK,
TASK_UNINTERRUPTIBLE);
} while (!nonblock && ret != 0);
if (!test_and_set_bit(PG_HEADLOCK, &head->wb_flags))
return 0;

WARN_ON_ONCE(ret > 0);
return ret;
if (!nonblock)
return wait_on_bit_lock(&head->wb_flags, PG_HEADLOCK,
TASK_UNINTERRUPTIBLE);

return -EAGAIN;
}

/*
Expand Down

0 comments on commit bc8a309

Please sign in to comment.