[PATCH 1/2] NFS: Report all of a read done in parts to netfs
From: Josef Bacik
Date: Fri Dec 04 2026 - 17:11:16 EST
If the server returns fewer bytes than a READ asked for, and it is not
the end of the file, nfs_readpage_retry() moves the arguments on, resets
hdr->res.count and restarts the RPC for the rest. When the header
completes, hdr->res.count is the result of the last RPC only.
That is what nfs_netfs_read_completion() adds to the number of bytes
transferred. On a mount with fscache the subrequest looks short
although all of it was read, and netfs acts on that:
- In the middle of the file there is no error, no end of file and no
progress reported. netfs fails the subrequest with -ENODATA, unlocks
the folios, which NFS has marked up to date, and copies nothing to
the cache. Nobody looks at the error of a readahead. But
nfs_read_folio() takes it for "no cache" and reads the folio again
without netfs. The folio is not locked any more, so nothing waits
for that READ: ->read_folio() returns, the page is mapped, and what
the application stores in it until the reply comes in is overwritten
with the old contents of the file. The store is lost without a
trace, in memory and, since that is what is written back, on the
server.
- If the last part ends at the end of the file, and the READ had asked
for more, as it does unless the file ends with a folio,
NFS_IOHDR_EOF makes NFS ask netfs to clear the tail. netfs clears
everything behind the bytes that it was told of: that includes the
data of all the parts but the last. The reader gets zeroes where
the file has data.
Use hdr->good_bytes, like nfs_read_completion() does for the pages: it
starts as the length of the header and is cut back at the end of the
file, counted from the start of the header.
Fixes: 000dbe0bec05 ("NFS: Convert buffered read paths to use netfs when fscache is enabled")
Signed-off-by: Josef Bacik <josef@xxxxxxxx>
---
fs/nfs/fscache.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
index 9b7fdad4a9201..8108e53addb8f 100644
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -374,7 +374,7 @@ void nfs_netfs_read_completion(struct nfs_pgio_header *hdr)
if (hdr->error)
netfs->error = hdr->error;
else
- atomic64_add(hdr->res.count, &netfs->transferred);
+ atomic64_add(hdr->good_bytes, &netfs->transferred);
nfs_netfs_put(netfs);
hdr->netfs = NULL;