History

nfs: fix nonblocking calls to nfs_page_group_lock

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.

Weston Andros Adamson committed 12 years ago

Commit bc8a3091 parent fd2f3a01 file · +13 −8Browse files

Unified · Split

fs/nfs/pagelist.c+13−8
@@ -143,23 +143,28 @@ nfs_iocounter_wait(struct nfs_io_counter *c) · 142 unmodified lines
143143 *
144144 * this lock must be held if modifying the page group list
145145 *
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.
147152 */
148153 int
149154 nfs_page_group_lock(struct nfs_page *req, bool nonblock)
150155 {
151156 struct nfs_page *head = req->wb_head;
152− int ret;
153157
154158 WARN_ON_ONCE(head != head->wb_head);
155159
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;
160162
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;
163168 }
164169
165170 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t