@@ -466,10 +466,9 @@ nfs_page_group_destroy(struct kref *kref)
466466 nfs_release_request (head );
467467}
468468
469- static struct nfs_page *
470- __nfs_create_request (struct nfs_lock_context * l_ctx , struct page * page ,
471- unsigned int pgbase , unsigned int offset ,
472- unsigned int count )
469+ static struct nfs_page * nfs_page_create (struct nfs_lock_context * l_ctx ,
470+ unsigned int pgbase , pgoff_t index ,
471+ unsigned int offset , unsigned int count )
473472{
474473 struct nfs_page * req ;
475474 struct nfs_open_context * ctx = l_ctx -> open_context ;
@@ -488,19 +487,32 @@ __nfs_create_request(struct nfs_lock_context *l_ctx, struct page *page,
488487 /* Initialize the request struct. Initially, we assume a
489488 * long write-back delay. This will be adjusted in
490489 * update_nfs_request below if the region is not locked. */
491- req -> wb_page = page ;
492- if (page ) {
493- req -> wb_index = page_index (page );
494- get_page (page );
495- }
496- req -> wb_offset = offset ;
497- req -> wb_pgbase = pgbase ;
498- req -> wb_bytes = count ;
490+ req -> wb_pgbase = pgbase ;
491+ req -> wb_index = index ;
492+ req -> wb_offset = offset ;
493+ req -> wb_bytes = count ;
499494 kref_init (& req -> wb_kref );
500495 req -> wb_nio = 0 ;
501496 return req ;
502497}
503498
499+ static void nfs_page_assign_folio (struct nfs_page * req , struct folio * folio )
500+ {
501+ if (folio != NULL ) {
502+ req -> wb_folio = folio ;
503+ folio_get (folio );
504+ set_bit (PG_FOLIO , & req -> wb_flags );
505+ }
506+ }
507+
508+ static void nfs_page_assign_page (struct nfs_page * req , struct page * page )
509+ {
510+ if (page != NULL ) {
511+ req -> wb_page = page ;
512+ get_page (page );
513+ }
514+ }
515+
504516/**
505517 * nfs_create_request - Create an NFS read/write request.
506518 * @ctx: open context to use
@@ -521,9 +533,11 @@ nfs_create_request(struct nfs_open_context *ctx, struct page *page,
521533
522534 if (IS_ERR (l_ctx ))
523535 return ERR_CAST (l_ctx );
524- ret = __nfs_create_request (l_ctx , page , offset , offset , count );
525- if (!IS_ERR (ret ))
536+ ret = nfs_page_create (l_ctx , offset , page_index (page ), offset , count );
537+ if (!IS_ERR (ret )) {
538+ nfs_page_assign_page (ret , page );
526539 nfs_page_group_init (ret , NULL );
540+ }
527541 nfs_put_lock_context (l_ctx );
528542 return ret ;
529543}
@@ -536,19 +550,23 @@ nfs_create_subreq(struct nfs_page *req,
536550{
537551 struct nfs_page * last ;
538552 struct nfs_page * ret ;
553+ struct folio * folio = nfs_page_to_folio (req );
539554 struct page * page = nfs_page_to_page (req , pgbase );
540555
541- ret = __nfs_create_request (req -> wb_lock_context , page , pgbase , offset ,
542- count );
556+ ret = nfs_page_create (req -> wb_lock_context , pgbase , req -> wb_index ,
557+ offset , count );
543558 if (!IS_ERR (ret )) {
559+ if (folio )
560+ nfs_page_assign_folio (ret , folio );
561+ else
562+ nfs_page_assign_page (ret , page );
544563 /* find the last request */
545564 for (last = req -> wb_head ;
546565 last -> wb_this_page != req -> wb_head ;
547566 last = last -> wb_this_page )
548567 ;
549568
550569 nfs_lock_request (ret );
551- ret -> wb_index = req -> wb_index ;
552570 nfs_page_group_init (ret , last );
553571 ret -> wb_nio = req -> wb_nio ;
554572 }
@@ -587,11 +605,16 @@ void nfs_unlock_and_release_request(struct nfs_page *req)
587605 */
588606static void nfs_clear_request (struct nfs_page * req )
589607{
608+ struct folio * folio = nfs_page_to_folio (req );
590609 struct page * page = req -> wb_page ;
591610 struct nfs_lock_context * l_ctx = req -> wb_lock_context ;
592611 struct nfs_open_context * ctx ;
593612
594- if (page != NULL ) {
613+ if (folio != NULL ) {
614+ folio_put (folio );
615+ req -> wb_folio = NULL ;
616+ clear_bit (PG_FOLIO , & req -> wb_flags );
617+ } else if (page != NULL ) {
595618 put_page (page );
596619 req -> wb_page = NULL ;
597620 }
@@ -1471,16 +1494,21 @@ void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index)
14711494{
14721495 struct nfs_pgio_mirror * mirror ;
14731496 struct nfs_page * prev ;
1497+ struct folio * folio ;
14741498 u32 midx ;
14751499
14761500 for (midx = 0 ; midx < desc -> pg_mirror_count ; midx ++ ) {
14771501 mirror = nfs_pgio_get_mirror (desc , midx );
14781502 if (!list_empty (& mirror -> pg_list )) {
14791503 prev = nfs_list_entry (mirror -> pg_list .prev );
1480- if (index != prev -> wb_index + 1 ) {
1481- nfs_pageio_complete (desc );
1482- break ;
1483- }
1504+ folio = nfs_page_to_folio (prev );
1505+ if (folio ) {
1506+ if (index == folio_next_index (folio ))
1507+ continue ;
1508+ } else if (index == prev -> wb_index + 1 )
1509+ continue ;
1510+ nfs_pageio_complete (desc );
1511+ break ;
14841512 }
14851513 }
14861514}
0 commit comments