Skip to content

Commit a308996

Browse files
Christoph Hellwigamschuma-ntap
authored andcommitted
nfs: split nfs_read_folio
nfs_read_folio is a bit hard to follow because it mixes highlevel logic with the actual data read. Split the latter into a helper and update the comments to be more accurate. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent fada32e commit a308996

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

fs/nfs/read.c

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,52 @@ int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio,
325325
}
326326

327327
/*
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.
332368
*/
333369
int nfs_read_folio(struct file *file, struct folio *folio)
334370
{
335371
struct inode *inode = file_inode(file);
336372
loff_t pos = folio_pos(folio);
337373
size_t len = folio_size(folio);
338-
struct nfs_pageio_descriptor pgio;
339-
struct nfs_open_context *ctx;
340374
int ret;
341375

342376
trace_nfs_aop_readpage(inode, pos, len);
@@ -361,29 +395,8 @@ int nfs_read_folio(struct file *file, struct folio *folio)
361395
goto out_unlock;
362396

363397
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);
374398
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);
387400
out:
388401
trace_nfs_aop_readpage_done(inode, pos, len, ret);
389402
return ret;

0 commit comments

Comments
 (0)