Skip to content

Commit 9eb7c48

Browse files
Christoph Hellwigamschuma-ntap
authored andcommitted
nfs: simplify nfs_folio_find_and_lock_request
nfs_folio_find_and_lock_request and the nfs_page_group_lock_head helper called by it spend quite some effort to deal with head vs subrequests. But given that only the head request can be stashed in the folio private data, non of that is required. Fold the locking logic from nfs_page_group_lock_head into nfs_folio_find_and_lock_request and simplify the result based on the invariant that we always find the head request in the folio private data. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 02e61ec commit 9eb7c48

File tree

3 files changed

+21
-37
lines changed

3 files changed

+21
-37
lines changed

fs/nfs/pagelist.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,6 @@ nfs_async_iocounter_wait(struct rpc_task *task, struct nfs_lock_context *l_ctx)
187187
}
188188
EXPORT_SYMBOL_GPL(nfs_async_iocounter_wait);
189189

190-
/*
191-
* nfs_page_lock_head_request - page lock the head of the page group
192-
* @req: any member of the page group
193-
*/
194-
struct nfs_page *
195-
nfs_page_group_lock_head(struct nfs_page *req)
196-
{
197-
struct nfs_page *head = req->wb_head;
198-
199-
while (!nfs_lock_request(head)) {
200-
int ret = nfs_wait_on_request(head);
201-
if (ret < 0)
202-
return ERR_PTR(ret);
203-
}
204-
if (head != req)
205-
kref_get(&head->wb_kref);
206-
return head;
207-
}
208-
209190
/*
210191
* nfs_unroll_locks - unlock all newly locked reqs and wait on @req
211192
* @head: head request of page group, must be holding head lock

fs/nfs/write.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,28 +197,32 @@ static struct nfs_page *nfs_folio_find_head_request(struct folio *folio)
197197
static struct nfs_page *nfs_folio_find_and_lock_request(struct folio *folio)
198198
{
199199
struct inode *inode = folio->mapping->host;
200-
struct nfs_page *req, *head;
200+
struct nfs_page *head;
201201
int ret;
202202

203-
for (;;) {
204-
req = nfs_folio_find_head_request(folio);
205-
if (!req)
206-
return req;
207-
head = nfs_page_group_lock_head(req);
208-
if (head != req)
209-
nfs_release_request(req);
210-
if (IS_ERR(head))
211-
return head;
212-
ret = nfs_cancel_remove_inode(head, inode);
213-
if (ret < 0) {
214-
nfs_unlock_and_release_request(head);
203+
retry:
204+
head = nfs_folio_find_head_request(folio);
205+
if (!head)
206+
return NULL;
207+
208+
while (!nfs_lock_request(head)) {
209+
ret = nfs_wait_on_request(head);
210+
if (ret < 0)
215211
return ERR_PTR(ret);
216-
}
217-
/* Ensure that nobody removed the request before we locked it */
218-
if (head == folio->private)
219-
break;
212+
}
213+
214+
/* Ensure that nobody removed the request before we locked it */
215+
if (head != folio->private) {
220216
nfs_unlock_and_release_request(head);
217+
goto retry;
221218
}
219+
220+
ret = nfs_cancel_remove_inode(head, inode);
221+
if (ret < 0) {
222+
nfs_unlock_and_release_request(head);
223+
return ERR_PTR(ret);
224+
}
225+
222226
return head;
223227
}
224228

include/linux/nfs_page.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ extern size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc,
155155
extern int nfs_wait_on_request(struct nfs_page *);
156156
extern void nfs_unlock_request(struct nfs_page *req);
157157
extern void nfs_unlock_and_release_request(struct nfs_page *);
158-
extern struct nfs_page *nfs_page_group_lock_head(struct nfs_page *req);
159158
extern int nfs_page_group_lock_subrequests(struct nfs_page *head);
160159
extern void nfs_join_page_group(struct nfs_page *head,
161160
struct nfs_commit_info *cinfo,

0 commit comments

Comments
 (0)