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.
Unified · Split
| @@ -143,23 +143,28 @@ nfs_iocounter_wait(struct nfs_io_counter *c) · 142 unmodified lines | ||
| 143 | 143 | * |
| 144 | 144 | * this lock must be held if modifying the page group list |
| 145 | 145 | * |
| 146 | − * returns result from wait_on_bit_lock: 0 on success, < 0 on error | |
| 146 | + * return 0 on success, < 0 on error: -EDELAY if nonblocking or the | |
| 147 | + * result from wait_on_bit_lock | |
| 148 | + * | |
| 149 | + * NOTE: calling with nonblock=false should always have set the | |
| 150 | + * lock bit (see fs/buffer.c and other uses of wait_on_bit_lock | |
| 151 | + * with TASK_UNINTERRUPTIBLE), so there is no need to check the result. | |
| 147 | 152 | */ |
| 148 | 153 | int |
| 149 | 154 | nfs_page_group_lock(struct nfs_page *req, bool nonblock) |
| 150 | 155 | { |
| 151 | 156 | struct nfs_page *head = req->wb_head; |
| 152 | − int ret; | |
| 153 | 157 | |
| 154 | 158 | WARN_ON_ONCE(head != head->wb_head); |
| 155 | 159 | |
| 156 | − do { | |
| 157 | − ret = wait_on_bit_lock(&head->wb_flags, PG_HEADLOCK, | |
| 158 | − TASK_UNINTERRUPTIBLE); | |
| 159 | − } while (!nonblock && ret != 0); | |
| 160 | + if (!test_and_set_bit(PG_HEADLOCK, &head->wb_flags)) | |
| 161 | + return 0; | |
| 160 | 162 | |
| 161 | − WARN_ON_ONCE(ret > 0); | |
| 162 | − return ret; | |
| 163 | + if (!nonblock) | |
| 164 | + return wait_on_bit_lock(&head->wb_flags, PG_HEADLOCK, | |
| 165 | + TASK_UNINTERRUPTIBLE); | |
| 166 | + | |
| 167 | + return -EAGAIN; | |
| 163 | 168 | } |
| 164 | 169 | |
| 165 | 170 | /* |