@@ -325,18 +325,52 @@ int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio,
325
325
}
326
326
327
327
/*
328
- * Read a page over NFS.
329
- * We read the page synchronously in the following case:
330
- * - The error flag is set for this page. This happens only when a
331
- * previous async read operation failed.
328
+ * Actually read a folio over the wire.
329
+ */
330
+ static int nfs_do_read_folio (struct file * file , struct folio * folio )
331
+ {
332
+ struct inode * inode = file_inode (file );
333
+ struct nfs_pageio_descriptor pgio ;
334
+ struct nfs_open_context * ctx ;
335
+ int ret ;
336
+
337
+ ctx = get_nfs_open_context (nfs_file_open_context (file ));
338
+
339
+ xchg (& ctx -> error , 0 );
340
+ nfs_pageio_init_read (& pgio , inode , false,
341
+ & nfs_async_read_completion_ops );
342
+
343
+ ret = nfs_read_add_folio (& pgio , ctx , folio );
344
+ if (ret )
345
+ goto out_put ;
346
+
347
+ nfs_pageio_complete_read (& pgio );
348
+ nfs_update_delegated_atime (inode );
349
+ if (pgio .pg_error < 0 ) {
350
+ ret = pgio .pg_error ;
351
+ goto out_put ;
352
+ }
353
+
354
+ ret = folio_wait_locked_killable (folio );
355
+ if (!folio_test_uptodate (folio ) && !ret )
356
+ ret = xchg (& ctx -> error , 0 );
357
+
358
+ out_put :
359
+ put_nfs_open_context (ctx );
360
+ return ret ;
361
+ }
362
+
363
+ /*
364
+ * Synchronously read a folio.
365
+ *
366
+ * This is not heavily used as most users to try an asynchronous
367
+ * large read through ->readahead first.
332
368
*/
333
369
int nfs_read_folio (struct file * file , struct folio * folio )
334
370
{
335
371
struct inode * inode = file_inode (file );
336
372
loff_t pos = folio_pos (folio );
337
373
size_t len = folio_size (folio );
338
- struct nfs_pageio_descriptor pgio ;
339
- struct nfs_open_context * ctx ;
340
374
int ret ;
341
375
342
376
trace_nfs_aop_readpage (inode , pos , len );
@@ -361,29 +395,8 @@ int nfs_read_folio(struct file *file, struct folio *folio)
361
395
goto out_unlock ;
362
396
363
397
ret = nfs_netfs_read_folio (file , folio );
364
- if (!ret )
365
- goto out ;
366
-
367
- ctx = get_nfs_open_context (nfs_file_open_context (file ));
368
-
369
- xchg (& ctx -> error , 0 );
370
- nfs_pageio_init_read (& pgio , inode , false,
371
- & nfs_async_read_completion_ops );
372
-
373
- ret = nfs_read_add_folio (& pgio , ctx , folio );
374
398
if (ret )
375
- goto out_put ;
376
-
377
- nfs_pageio_complete_read (& pgio );
378
- nfs_update_delegated_atime (inode );
379
- ret = pgio .pg_error < 0 ? pgio .pg_error : 0 ;
380
- if (!ret ) {
381
- ret = folio_wait_locked_killable (folio );
382
- if (!folio_test_uptodate (folio ) && !ret )
383
- ret = xchg (& ctx -> error , 0 );
384
- }
385
- out_put :
386
- put_nfs_open_context (ctx );
399
+ ret = nfs_do_read_folio (file , folio );
387
400
out :
388
401
trace_nfs_aop_readpage_done (inode , pos , len , ret );
389
402
return ret ;
0 commit comments