Skip to content

Commit 25edbca

Browse files
Christoph Hellwigamschuma-ntap
authored andcommitted
nfs: fold nfs_page_group_lock_subrequests into nfs_lock_and_join_requests
Fold nfs_page_group_lock_subrequests into nfs_lock_and_join_requests to prepare for future changes to this code, and move the helpers to write.c as well. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent c3f2235 commit 25edbca

File tree

3 files changed

+64
-81
lines changed

3 files changed

+64
-81
lines changed

fs/nfs/pagelist.c

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -187,83 +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_unroll_locks - unlock all newly locked reqs and wait on @req
192-
* @head: head request of page group, must be holding head lock
193-
* @req: request that couldn't lock and needs to wait on the req bit lock
194-
*
195-
* This is a helper function for nfs_lock_and_join_requests
196-
* returns 0 on success, < 0 on error.
197-
*/
198-
static void
199-
nfs_unroll_locks(struct nfs_page *head, struct nfs_page *req)
200-
{
201-
struct nfs_page *tmp;
202-
203-
/* relinquish all the locks successfully grabbed this run */
204-
for (tmp = head->wb_this_page ; tmp != req; tmp = tmp->wb_this_page) {
205-
if (!kref_read(&tmp->wb_kref))
206-
continue;
207-
nfs_unlock_and_release_request(tmp);
208-
}
209-
}
210-
211-
/*
212-
* nfs_page_group_lock_subreq - try to lock a subrequest
213-
* @head: head request of page group
214-
* @subreq: request to lock
215-
*
216-
* This is a helper function for nfs_lock_and_join_requests which
217-
* must be called with the head request and page group both locked.
218-
* On error, it returns with the page group unlocked.
219-
*/
220-
static int
221-
nfs_page_group_lock_subreq(struct nfs_page *head, struct nfs_page *subreq)
222-
{
223-
int ret;
224-
225-
if (!kref_get_unless_zero(&subreq->wb_kref))
226-
return 0;
227-
while (!nfs_lock_request(subreq)) {
228-
nfs_page_group_unlock(head);
229-
ret = nfs_wait_on_request(subreq);
230-
if (!ret)
231-
ret = nfs_page_group_lock(head);
232-
if (ret < 0) {
233-
nfs_unroll_locks(head, subreq);
234-
nfs_release_request(subreq);
235-
return ret;
236-
}
237-
}
238-
return 0;
239-
}
240-
241-
/*
242-
* nfs_page_group_lock_subrequests - try to lock the subrequests
243-
* @head: head request of page group
244-
*
245-
* This is a helper function for nfs_lock_and_join_requests which
246-
* must be called with the head request locked.
247-
*/
248-
int nfs_page_group_lock_subrequests(struct nfs_page *head)
249-
{
250-
struct nfs_page *subreq;
251-
int ret;
252-
253-
ret = nfs_page_group_lock(head);
254-
if (ret < 0)
255-
return ret;
256-
/* lock each request in the page group */
257-
for (subreq = head->wb_this_page; subreq != head;
258-
subreq = subreq->wb_this_page) {
259-
ret = nfs_page_group_lock_subreq(head, subreq);
260-
if (ret < 0)
261-
return ret;
262-
}
263-
nfs_page_group_unlock(head);
264-
return 0;
265-
}
266-
267190
/*
268191
* nfs_page_set_headlock - set the request PG_HEADLOCK
269192
* @req: request that is to be locked

fs/nfs/write.c

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,57 @@ void nfs_join_page_group(struct nfs_page *head, struct nfs_commit_info *cinfo,
478478
nfs_destroy_unlinked_subrequests(destroy_list, head, inode);
479479
}
480480

481+
/*
482+
* nfs_unroll_locks - unlock all newly locked reqs and wait on @req
483+
* @head: head request of page group, must be holding head lock
484+
* @req: request that couldn't lock and needs to wait on the req bit lock
485+
*
486+
* This is a helper function for nfs_lock_and_join_requests
487+
* returns 0 on success, < 0 on error.
488+
*/
489+
static void
490+
nfs_unroll_locks(struct nfs_page *head, struct nfs_page *req)
491+
{
492+
struct nfs_page *tmp;
493+
494+
/* relinquish all the locks successfully grabbed this run */
495+
for (tmp = head->wb_this_page ; tmp != req; tmp = tmp->wb_this_page) {
496+
if (!kref_read(&tmp->wb_kref))
497+
continue;
498+
nfs_unlock_and_release_request(tmp);
499+
}
500+
}
501+
502+
/*
503+
* nfs_page_group_lock_subreq - try to lock a subrequest
504+
* @head: head request of page group
505+
* @subreq: request to lock
506+
*
507+
* This is a helper function for nfs_lock_and_join_requests which
508+
* must be called with the head request and page group both locked.
509+
* On error, it returns with the page group unlocked.
510+
*/
511+
static int
512+
nfs_page_group_lock_subreq(struct nfs_page *head, struct nfs_page *subreq)
513+
{
514+
int ret;
515+
516+
if (!kref_get_unless_zero(&subreq->wb_kref))
517+
return 0;
518+
while (!nfs_lock_request(subreq)) {
519+
nfs_page_group_unlock(head);
520+
ret = nfs_wait_on_request(subreq);
521+
if (!ret)
522+
ret = nfs_page_group_lock(head);
523+
if (ret < 0) {
524+
nfs_unroll_locks(head, subreq);
525+
nfs_release_request(subreq);
526+
return ret;
527+
}
528+
}
529+
return 0;
530+
}
531+
481532
/*
482533
* nfs_lock_and_join_requests - join all subreqs to the head req
483534
* @folio: the folio used to lookup the "page group" of nfs_page structures
@@ -496,7 +547,7 @@ void nfs_join_page_group(struct nfs_page *head, struct nfs_commit_info *cinfo,
496547
static struct nfs_page *nfs_lock_and_join_requests(struct folio *folio)
497548
{
498549
struct inode *inode = folio->mapping->host;
499-
struct nfs_page *head;
550+
struct nfs_page *head, *subreq;
500551
struct nfs_commit_info cinfo;
501552
int ret;
502553

@@ -526,11 +577,21 @@ static struct nfs_page *nfs_lock_and_join_requests(struct folio *folio)
526577
if (ret < 0)
527578
goto out_unlock;
528579

529-
/* lock each request in the page group */
530-
ret = nfs_page_group_lock_subrequests(head);
580+
ret = nfs_page_group_lock(head);
531581
if (ret < 0)
532582
goto out_unlock;
533583

584+
/* lock each request in the page group */
585+
for (subreq = head->wb_this_page;
586+
subreq != head;
587+
subreq = subreq->wb_this_page) {
588+
ret = nfs_page_group_lock_subreq(head, subreq);
589+
if (ret < 0)
590+
goto out_unlock;
591+
}
592+
593+
nfs_page_group_unlock(head);
594+
534595
nfs_init_cinfo_from_inode(&cinfo, inode);
535596
nfs_join_page_group(head, &cinfo, inode);
536597
return head;

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 int nfs_page_group_lock_subrequests(struct nfs_page *head);
159158
extern void nfs_join_page_group(struct nfs_page *head,
160159
struct nfs_commit_info *cinfo,
161160
struct inode *inode);

0 commit comments

Comments
 (0)