nfsd: sample writeback error cursor before async COPY loop
Subsystems (2)
Chuck Lever
maintainerPATCH 1/1 nfsd: sample writeback error cursor before async COPY loop
From: Chuck Lever <[email protected]>
_nfsd_copy_file_range() samples dst->f_wb_err into "since" after the copy loop, then uses it to detect writeback errors via filemap_check_wb_err() once vfs_fsync_range() returns. Because the nfsd_file cache reuses a single struct file across requests targeting the same inode, a concurrent COMMIT or stable WRITE on dst advances dst->f_wb_err to the current mapping->wb_err via file_check_and_advance_wb_err() during its own vfs_fsync_range(). If that advancement lands between the writeback error appearing in mapping->wb_err and the COPY worker sampling "since", the worker captures the already-advanced cursor, errseq_check() sees cur == since and returns zero, and NFSD4_COPY_F_COMMITTED is set even though writeback failed. CB_OFFLOAD then encodes wr_stable_how = FILE_SYNC4, the client treats the copied data as durable, and the failure becomes silent data loss.
Sample since once at the start of the function. The cursor then reflects state in effect before this COPY issues any writes, and filemap_check_wb_err() detects any error that occurs during the copy regardless of which thread first observes it. This matches the pattern used by nfsd_vfs_write() and nfsd4_clone_file_range().
--- fs/nfsd/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +1 -1
@@ -1950,6 +1950,7 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy,/* See RFC 7862 p.67: */ if (bytes_total ==0 ) bytes_total =ULLONG_MAX ; + since =READ_ONCE (dst->f_wb_err); do { /* Only async copies can be stopped here */ if (kthread_should_stop())
@@ -1965,7 +1966,6 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy, }while (bytes_total >0 &&nfsd4_copy_is_async (copy));/* for a non-zero asynchronous copy do a commit of data */ if (nfsd4_copy_is_async (copy) && copy->cp_res.wr_bytes_written >0 ) { - since =READ_ONCE (dst->f_wb_err); end = copy->cp_dst_pos + copy->cp_res.wr_bytes_written -1 ; status =vfs_fsync_range (dst, copy->cp_dst_pos, end,0 );if (!status)
Signature · 1 line
2.54.0
Quoted 46 lines · Chuck Lever
From: Chuck Lever <[email protected]>
_nfsd_copy_file_range()samplesdst->f_wb_errinto "since" after the copy loop, then uses it to detect writeback errors viafilemap_check_wb_err()oncevfs_fsync_range()returns. Because thenfsd_filecache reuses a single struct file across requests targeting the same inode, a concurrent COMMIT or stable WRITE on dst advancesdst->f_wb_errto the currentmapping->wb_errviafile_check_and_advance_wb_err()during its ownvfs_fsync_range(). If that advancement lands between the writeback error appearing inmapping->wb_errand the COPY worker sampling "since", the worker captures the already-advanced cursor,errseq_check()sees cur == since and returns zero, andNFSD4_COPY_F_COMMITTEDis set even though writeback failed.CB_OFFLOADthen encodeswr_stable_how=FILE_SYNC4, the client treats the copied data as durable, and the failure becomes silent data loss.Sample since once at the start of the function. The cursor then reflects state in effect before this COPY issues any writes, and
filemap_check_wb_err()detects any error that occurs during the copy regardless of which thread first observes it. This matches the pattern used bynfsd_vfs_write()andnfsd4_clone_file_range().Reported-by sashiko-bot <[email protected]>Fixes 555dbf1a9aac ("nfsd: Replace use of rwsem with errseq_t")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4proc.c +1
-0@@ -1950,6 +1950,7 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy,/* See RFC 7862 p.67: */ if (bytes_total ==0 ) bytes_total =ULLONG_MAX ; + since =READ_ONCE (dst->f_wb_err); do { /* Only async copies can be stopped here */ if (kthread_should_stop())
fs/nfsd/nfs4proc.c static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy, · line 1971
Quoted 7 lines
fs/nfsd/nfs4proc.c +0
-1@@ -1965,7 +1966,6 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy, }while (bytes_total >0 &&nfsd4_copy_is_async (copy));/* for a non-zero asynchronous copy do a commit of data */ if (nfsd4_copy_is_async (copy) && copy->cp_res.wr_bytes_written >0 ) { - since =READ_ONCE (dst->f_wb_err); end = copy->cp_dst_pos + copy->cp_res.wr_bytes_written -1 ; status =vfs_fsync_range (dst, copy->cp_dst_pos, end,0 );if (!status)
That makes a lot more sense.