mm, netfs, cifs: Miscellaneous fixes
Subsystems (9)
David Howells
maintainercover mm, netfs, cifs: Miscellaneous fixes
Hi Christian, Steve,
Firstly, here are some fixes to DIO read handling and the retrying of reads, particularly in relation to cifs:
(1) Fix the missing credit renegotiation in cifs on the retrying of reads. The credits we had ended with the original read (or the last retry) and to perform a new read we need more credits otherwise the server can reject our read with EINVAL.
(2) Fix the handling of short DIO reads to avoid ENODATA when the read retry tries to access a portion of the file after the EOF.
Secondly, some patches fixing cifs copy and zero offload:
(3) Fix cifs_file_copychunk_range() to not try to partially invalidate folios that are only partly covered by the range, but rather flush them back and invalidate them.
(4) Fix filemap_invalidate_inode() to use the correct invalidation function so that it doesn't leave partially invalidated folios hanging around (which may hide part of the result of an offloaded copy).
(5) Fix smb3_zero_data() to correctly handle zeroing of data that's buffered locally but not yet written back and with the EOF position on the server short of the local EOF position.
Note that this will also affect afs and 9p, particularly with regard to direct I/O writes.
And finally, here's an adjustment to debugging statements:
(6) Adjust three debugging output statements. Not strictly a fix, so could be dropped. Including the subreq ID in some extra debug lines helps a bit, though.
The patches can also be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-fixes
Thanks,
David
David Howells (6):
cifs: Fix lack of credit renegotiation on read retry netfs, cifs: Fix handling of short DIO read
cifs: Fix copy offload to flush destination region
mm: Fix filemap_invalidate_inode() to use
invalidate_inode_pages2_range()
cifs: Fix FALLOC_FL_ZERO_RANGE to preflush buffered part of target
region
netfs, cifs: Improve some debugging bits
fs/netfs/io.c | 21 +++++++++++++------- fs/smb/client/cifsfs.c | 21 ++++---------------- fs/smb/client/cifsglob.h | 1 + fs/smb/client/file.c | 37 ++++++++++++++++++++++++++++++++---- fs/smb/client/smb2ops.c | 26 +++++++++++++++++++------ fs/smb/client/smb2pdu.c | 41 +++++++++++++++++++++++++--------------- fs/smb/client/trace.h | 1 + include/linux/netfs.h | 1 + mm/filemap.c | 2 +- 9 files changed, 101 insertions(+), 50 deletions(-)
David Howells
maintainerPATCH 1/6 cifs: Fix lack of credit renegotiation on read retry
When netfslib asks cifs to issue a read operation, it prefaces this with a call to ->clamp_length() which cifs uses to negotiate credits, providing receive capacity on the server; however, in the event that a read op needs reissuing, netfslib doesn't call ->clamp_length() again as that could shorten the subrequest, leaving a gap.
This causes the retried read to be done with zero credits which causes the server to reject it with STATUS_INVALID_PARAMETER. This is a problem for a DIO read that is requested that would go over the EOF. The short read will be retried, causing EINVAL to be returned to the user when it fails.
Fix this by making cifs_req_issue_read() negotiate new credits if retrying (NETFS_SREQ_RETRYING now gets set in the read side as well as the write side in this instance).
This isn't sufficient, however: the new credits might not be sufficient to complete the remainder of the read, so also add an additional field, rreq->actual_len, that holds the actual size of the op we want to perform without having to alter subreq->len.
We then rely on repeated short reads being retried until we finish the read or reach the end of file and make a zero-length read.
Also fix a couple of places where the subrequest start and length need to be altered by the amount so far transferred when being used.
--- fs/netfs/io.c | 2 ++ fs/smb/client/cifsglob.h | 1 + fs/smb/client/file.c | 37 +++++++++++++++++++++++++++++++++---- fs/smb/client/smb2ops.c | 2 +- fs/smb/client/smb2pdu.c | 28 +++++++++++++++++----------- fs/smb/client/trace.h | 1 + 6 files changed, 55 insertions(+), 16 deletions(-)
fs/netfs/io.c +2 -0
@@ -306,6 +306,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq)break ; subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; subreq->error =0 ; +__set_bit (NETFS_SREQ_RETRYING , &subreq->flags);netfs_stat (&netfs_n_rh_download_instead);trace_netfs_sreq (subreq, netfs_sreq_trace_download_instead);netfs_get_subrequest (subreq, netfs_sreq_trace_get_resubmit);
@@ -313,6 +314,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq)netfs_reset_subreq_iter (rreq, subreq);netfs_read_from_server (rreq, subreq); }else if (test_bit (NETFS_SREQ_SHORT_IO , &subreq->flags)) { +__set_bit (NETFS_SREQ_RETRYING , &subreq->flags);netfs_reset_subreq_iter (rreq, subreq);netfs_rreq_short_read (rreq, subreq); }
fs/smb/client/cifsglob.h +1 -0
@@ -1485,6 +1485,7 @@ struct cifs_io_subrequest {struct cifs_io_request *req; };ssize_t got_bytes; +size_t actual_len;unsigned int xid;int result;bool have_xid;
fs/smb/client/file.c +33 -4
@@ -111,6 +111,7 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq) goto fail; } + wdata->actual_len = wdata->subreq.len; rc =adjust_credits (wdata->server, wdata, cifs_trace_rw_credits_issue_write_adjust);if (rc) goto fail;
@@ -153,7 +154,7 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq);struct TCP_Server_Info *server = req->server;struct cifs_sb_info *cifs_sb =CIFS_SB (rreq->inode->i_sb); -size_t rsize =0 ; +size_t rsize;int rc; rdata->xid =get_xid ();
@@ -166,8 +167,8 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) cifs_sb->ctx); - rc = server->ops->wait_mtu_credits (server, cifs_sb->ctx->rsize, &rsize, - &rdata->credits); + rc = server->ops->wait_mtu_credits (server, cifs_sb->ctx->rsize, + &rsize, &rdata->credits);if (rc) { subreq->error = rc;return false;
@@ -183,7 +184,8 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) server->credits, server->in_flight,0 , cifs_trace_rw_credits_read_submit); - subreq->len =min_t (size_t, subreq->len, rsize); + subreq->len =umin (subreq->len, rsize); + rdata->actual_len = subreq->len;#ifdef CONFIG_CIFS_SMB_DIRECT if (server->smbd_conn)
@@ -203,12 +205,39 @@ static void cifs_req_issue_read(struct netfs_io_subrequest *subreq)struct netfs_io_request *rreq = subreq->rreq; struct cifs_io_subrequest *rdata = container_of(subreq, struct cifs_io_subrequest, subreq); struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq); +struct TCP_Server_Info *server = req->server; +struct cifs_sb_info *cifs_sb =CIFS_SB (rreq->inode->i_sb);int rc =0 ;cifs_dbg (FYI ,"%s: op=%08x[%x] mapping=%p len=%zu/%zu\n" , __func__, rreq->debug_id, subreq->debug_index, rreq->mapping, subreq->transferred, subreq->len); +if (test_bit (NETFS_SREQ_RETRYING , &subreq->flags)) { +/* +* As we're issuing a retry, we need to negotiate some new +* credits otherwise the server may reject the op with +* INVALID_PARAMETER. Note, however, we may get back less +* credit than we need to complete the op, in which case, we +* shorten the op and rely on additional rounds of retry. +*/ +size_t rsize =umin (subreq->len - subreq->transferred, + cifs_sb->ctx->rsize); + + rc = server->ops->wait_mtu_credits (server, rsize, &rdata->actual_len, + &rdata->credits); +if (rc) + goto out; + + rdata->credits.in_flight_check =1 ; + +trace_smb3_rw_credits (rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->credits.value, + server->credits, server->in_flight,0 , + cifs_trace_rw_credits_read_resubmit); + } +if (req->cfile->invalidHandle) { do { rc = cifs_reopen_file(req->cfile, true);
fs/smb/client/smb2ops.c +1 -1
@@ -301,7 +301,7 @@ smb2_adjust_credits(struct TCP_Server_Info *server, unsigned int /*enum smb3_rw_credits_trace*/ trace) {struct cifs_credits *credits = &subreq->credits; -int new_val =DIV_ROUND_UP (subreq->subreq.len,SMB2_MAX_BUFFER_SIZE ); +int new_val =DIV_ROUND_UP (subreq->actual_len,SMB2_MAX_BUFFER_SIZE );int scredits, in_flight;if (!credits->value || credits->value == new_val)
fs/smb/client/smb2pdu.c +17 -11
@@ -4529,9 +4529,9 @@ smb2_readv_callback(struct mid_q_entry *mid)"rdata server %p != mid server %p" , rdata->server, mid->server); -cifs_dbg (FYI ,"%s: mid=%llu state=%d result=%d bytes=%zu\n" , +cifs_dbg (FYI ,"%s: mid=%llu state=%d result=%d bytes=%zu/%zu\n" , __func__, mid->mid, mid->mid_state, rdata->result, - rdata->subreq.len); + rdata->actual_len, rdata->subreq.len - rdata->subreq.transferred);switch (mid->mid_state) {case MID_RESPONSE_RECEIVED :
@@ -4585,15 +4585,18 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->subreq.debug_index, rdata->xid, rdata->req->cfile->fid.persistent_fid, - tcon->tid, tcon->ses->Suid, rdata->subreq.start, - rdata->subreq.len, rdata->result); + tcon->tid, tcon->ses->Suid, + rdata->subreq.start + rdata->subreq.transferred, + rdata->actual_len, + rdata->result); }else trace_smb3_read_done (rdata->rreq->debug_id, rdata->subreq.debug_index, rdata->xid, rdata->req->cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, - rdata->subreq.start, rdata->got_bytes); + rdata->subreq.start + rdata->subreq.transferred, + rdata->got_bytes);if (rdata->result == -ENODATA ) {/* We may have got an EOF error because fallocate
@@ -4621,6 +4624,7 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) {int rc, flags =0 ;char *buf; +struct netfs_io_subrequest *subreq = &rdata->subreq;struct smb2_hdr *shdr;struct cifs_io_parms io_parms;struct smb_rqst rqst = { .rq_iov = rdata->iov,
@@ -4631,15 +4635,15 @@ smb2_async_readv(struct cifs_io_subrequest *rdata)int credit_request;cifs_dbg (FYI ,"%s: offset=%llu bytes=%zu\n" , - __func__, rdata->subreq.start, rdata->subreq.len); + __func__, subreq->start, subreq->len);if (!rdata->server) rdata->server =cifs_pick_channel (tcon->ses); io_parms.tcon =tlink_tcon (rdata->req->cfile->tlink); io_parms.server = server = rdata->server; - io_parms.offset = rdata->subreq.start; - io_parms.length = rdata->subreq.len; + io_parms.offset = subreq->start + subreq->transferred; + io_parms.length = rdata->actual_len; io_parms.persistent_fid = rdata->req->cfile->fid.persistent_fid; io_parms.volatile_fid = rdata->req->cfile->fid.volatile_fid; io_parms.pid = rdata->req->pid;
@@ -4654,11 +4658,13 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) rdata->iov[0 ].iov_base = buf; rdata->iov[0 ].iov_len = total_len; + rdata->got_bytes =0 ; + rdata->result =0 ; shdr = (struct smb2_hdr *)buf;if (rdata->credits.value >0 ) { - shdr->CreditCharge =cpu_to_le16 (DIV_ROUND_UP (rdata->subreq.len, + shdr->CreditCharge =cpu_to_le16 (DIV_ROUND_UP (rdata->actual_len,SMB2_MAX_BUFFER_SIZE )); credit_request =le16_to_cpu (shdr->CreditCharge) +8 ;if (server->credits >= server->max_credits)
@@ -4682,11 +4688,11 @@ smb2_async_readv(struct cifs_io_subrequest *rdata)if (rc) {cifs_stats_fail_inc (io_parms.tcon,SMB2_READ_HE );trace_smb3_read_err (rdata->rreq->debug_id, - rdata->subreq.debug_index, + subreq->debug_index, rdata->xid, io_parms.persistent_fid, io_parms.tcon->tid, io_parms.tcon->ses->Suid, - io_parms.offset, io_parms.length, rc); + io_parms.offset, rdata->actual_len, rc); } async_readv_out:
fs/smb/client/trace.h +1 -0
@@ -30,6 +30,7 @@ EM(cifs_trace_rw_credits_old_session, "old-session") \ EM(cifs_trace_rw_credits_read_response_add, "rd-resp-add") \ EM(cifs_trace_rw_credits_read_response_clear, "rd-resp-clr") \ + EM(cifs_trace_rw_credits_read_resubmit, "rd-resubmit") \ EM(cifs_trace_rw_credits_read_submit, "rd-submit ") \ EM(cifs_trace_rw_credits_write_prepare, "wr-prepare ") \EM (cifs_trace_rw_credits_write_response_add,"wr-resp-add" ) \
David Howells
maintainerPATCH 2/6 netfs, cifs: Fix handling of short DIO read
In reply to David HowellsShort DIO reads, particularly in relation to cifs, are not being handled correctly by cifs and netfslib. This can be tested by doing a DIO read of a file where the size of read is larger than the size of the file. When it crosses the EOF, it gets a short read and this gets retried, and in the case of cifs, the retry read fails, with the failure being translated to ENODATA.
Fix this by the following means:
(1) Add a flag, NETFS_SREQ_HIT_EOF, for the filesystem to set when it detects that the read did hit the EOF.
(2) Make the netfslib read assessment stop processing subrequests when it encounters one with that flag set.
(3) Return rreq->transferred, the accumulated contiguous amount read to that point, to userspace for a DIO read.
(4) Make cifs set the flag and clear the error if the read RPC returned ENODATA.
(5) Make cifs set the flag and clear the error if a short read occurred without error and the read-to file position is now at the remote inode size.
--- fs/netfs/io.c | 17 +++++++++++------ fs/smb/client/smb2pdu.c | 13 +++++++++---- include/linux/netfs.h | 1 + 3 files changed, 21 insertions(+), 10 deletions(-)
fs/netfs/io.c +11 -6
@@ -368,7 +368,8 @@ static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)if (subreq->error || subreq->transferred ==0 )break ; transferred += subreq->transferred; -if (subreq->transferred < subreq->len) +if (subreq->transferred < subreq->len || +test_bit (NETFS_SREQ_HIT_EOF , &subreq->flags))break ; }
@@ -503,7 +504,8 @@ void netfs_subreq_terminated(struct netfs_io_subrequest *subreq, subreq->error =0 ; subreq->transferred += transferred_or_error; -if (subreq->transferred < subreq->len) +if (subreq->transferred < subreq->len && + !test_bit (NETFS_SREQ_HIT_EOF , &subreq->flags)) goto incomplete; complete:
@@ -782,10 +784,13 @@ int netfs_begin_read(struct netfs_io_request *rreq, bool sync) TASK_UNINTERRUPTIBLE); ret = rreq->error; -if (ret ==0 && rreq->submitted < rreq->len && - rreq->origin !=NETFS_DIO_READ ) { -trace_netfs_failure (rreq,NULL , ret, netfs_fail_short_read); - ret = -EIO ; +if (ret ==0 ) { +if (rreq->origin ==NETFS_DIO_READ ) { + ret = rreq->transferred; + }else if (rreq->submitted < rreq->len) { +trace_netfs_failure (rreq,NULL , ret, netfs_fail_short_read); + ret = -EIO ; + } } }else {/* If we decrement nr_outstanding to 0, the ref belongs to us. */
fs/smb/client/smb2pdu.c +9 -4
@@ -4507,6 +4507,7 @@ static void smb2_readv_callback(struct mid_q_entry *mid) {struct cifs_io_subrequest *rdata = mid->callback_data; +struct netfs_inode *ictx =netfs_inode (rdata->rreq->inode);struct cifs_tcon *tcon =tlink_tcon (rdata->req->cfile->tlink);struct TCP_Server_Info *server = rdata->server; struct smb2_hdr *shdr =
@@ -4599,11 +4600,15 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->got_bytes);if (rdata->result == -ENODATA ) { -/* We may have got an EOF error because fallocate -* failed to enlarge the file. -*/ -if (rdata->subreq.start < rdata->subreq.rreq->i_size) +__set_bit (NETFS_SREQ_HIT_EOF , &rdata->subreq.flags); + rdata->result =0 ; + }else { +if (rdata->got_bytes < rdata->actual_len && + rdata->subreq.start + rdata->subreq.transferred + rdata->got_bytes == + ictx->remote_i_size) { +__set_bit (NETFS_SREQ_HIT_EOF , &rdata->subreq.flags); rdata->result =0 ; + } } trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value, server->credits, server->in_flight,
include/linux/netfs.h +1 -0
@@ -198,6 +198,7 @@ struct netfs_io_subrequest {#define NETFS_SREQ_NEED_RETRY 9/* Set if the filesystem requests a retry */ #define NETFS_SREQ_RETRYING 10/* Set if we're retrying */ #define NETFS_SREQ_FAILED 11/* Set if the subreq failed unretryably */ +#define NETFS_SREQ_HIT_EOF 12/* Set if we hit the EOF */ };enum netfs_io_origin {
David Howells
maintainerPATCH 3/6 cifs: Fix copy offload to flush destination region
In reply to David HowellsFix cifs_file_copychunk_range() to flush the destination region before invalidating it to avoid potential loss of data should the copy fail, in whole or in part, in some way.
--- fs/smb/client/cifsfs.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
fs/smb/client/cifsfs.c +4 -17
@@ -1341,7 +1341,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,struct cifsFileInfo *smb_file_target;struct cifs_tcon *src_tcon;struct cifs_tcon *target_tcon; -unsigned long long destend, fstart, fend;ssize_t rc;cifs_dbg (FYI ,"copychunk range\n" );
@@ -1391,25 +1390,13 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, goto unlock; } - destend = destoff + len -1 ; - -/* Flush the folios at either end of the destination range to prevent -* accidental loss of dirty data outside of the range. +/* Flush and invalidate all the folios in the destination region. If +* the copy was successful, then some of the flush is extra overhead, +* but we need to allow for the copy failing in some way (eg. ENOSPC). */ - fstart = destoff; - fend = destend; - - rc =cifs_flush_folio (target_inode, destoff, &fstart, &fend, true); + rc =filemap_invalidate_inode (target_inode, true, destoff, destoff + len -1 );if (rc) goto unlock; - rc =cifs_flush_folio (target_inode, destend, &fstart, &fend, false); -if (rc) - goto unlock; -if (fend > target_cifsi->netfs.zero_point) - target_cifsi->netfs.zero_point = fend +1 ; - -/* Discard all the folios that overlap the destination region. */ -truncate_inode_pages_range (&target_inode->i_data, fstart, fend);fscache_invalidate (cifs_inode_cookie (target_inode),NULL ,i_size_read (target_inode),0 );
David Howells
maintainerPATCH 4/6 mm: Fix filemap_invalidate_inode() to use invalidate_inode_pages2_range()
In reply to David HowellsFix filemap_invalidate_inode() to use invalidate_inode_pages2_range() rather than truncate_inode_pages_range(). The latter clears the invalidated bit of a partial pages rather than discarding it entirely. This causes copy_file_range() to fail on cifs because the partial pages at either end of the destination range aren't evicted and reread, but rather just partly cleared.
This causes generic/075 and generic/112 xfstests to fail.
--- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c +1 -1
@@ -4231,7 +4231,7 @@ int filemap_invalidate_inode(struct inode *inode, bool flush, }/* Wait for writeback to complete on all folios and discard. */ -truncate_inode_pages_range (mapping, start, end); +invalidate_inode_pages2_range (mapping, start /PAGE_SIZE , end /PAGE_SIZE ); unlock:filemap_invalidate_unlock (mapping);
Re: (subset) [PATCH 4/6] mm: Fix filemap_invalidate_inode() to use invalidate_inode_pages2_range()
Quoted 8 lines · David Howells
Fix
filemap_invalidate_inode()to useinvalidate_inode_pages2_range()rather thantruncate_inode_pages_range(). The latter clears the invalidated bit of a partial pages rather than discarding it entirely. This causescopy_file_range()to fail on cifs because the partial pages at either end of the destination range aren't evicted and reread, but rather just partly cleared.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[4/6] mm: Fix filemap_invalidate_inode() to use invalidate_inode_pages2_range()
https://git.kernel.org/vfs/vfs/c/c26096ee0278
Re: (subset) [PATCH 4/6] mm: Fix filemap_invalidate_inode() to use invalidate_inode_pages2_range()
This looks like an important one as it fixes multiple xfstests see e.g. with the patch:
http://smb311-linux-testing.southcentralus.cloudapp.azure.com/#/builders/3/builds/213
vs without
http://smb311-linux-testing.southcentralus.cloudapp.azure.com/#/builders/3/builds/212
Can add:
Quoted 29 lines · Christian Brauner
Quoted 8 lines · David Howells
Fix
filemap_invalidate_inode()to useinvalidate_inode_pages2_range()rather thantruncate_inode_pages_range(). The latter clears the invalidated bit of a partial pages rather than discarding it entirely. This causescopy_file_range()to fail on cifs because the partial pages at either end of the destination range aren't evicted and reread, but rather just partly cleared.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes[4/6] mm: Fix
filemap_invalidate_inode()to useinvalidate_inode_pages2_range()https://git.kernel.org/vfs/vfs/c/c26096ee0278
Signature · 3 lines
Thanks, Steve
David Howells
maintainerPATCH 5/6 cifs: Fix FALLOC_FL_ZERO_RANGE to preflush buffered part of target region
In reply to David HowellsUnder certain conditions, the range to be cleared by FALLOC_FL_ZERO_RANGE may only be buffered locally and not yet have been flushed to the server. For example:
xfs_io -f -t -c "pwrite -S 0x41 0 4k" \ -c "pwrite -S 0x42 4k 4k" \ -c "fzero 0 4k" \ -c "pread -v 0 8k" /xfstest.test/foo
will write two 4KiB blocks of data, which get buffered in the pagecache, and then fallocate() is used to clear the first 4KiB block on the server - but we don't flush the data first, which means the EOF position on the server is wrong, and so the FSCTL_SET_ZERO_DATA RPC fails (and xfs_io ignores the error), but then when we try to read it, we see the old data.
Fix this by preflushing any part of the target region that above the server's idea of the EOF position to force the server to update its EOF position.
Note, however, that we don't want to simply expand the file by moving the EOF before doing the FSCTL_SET_ZERO_DATA[*] because someone else might see the zeroed region or if the RPC fails we then have to try to clean it up or risk getting corruption.
[*] And we have to move the EOF first otherwise FSCTL_SET_ZERO_DATA won't do what we want.
This fixes the generic/008 xfstest.
[!] Note: A better way to do this might be to split the operation into two
parts: we only do FSCTL_SET_ZERO_DATA for the part of the range below the server's EOF and then, if that worked, invalidate the buffered pages for the part above the range.
--- fs/smb/client/smb2ops.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
fs/smb/client/smb2ops.c +14 -2
@@ -3237,13 +3237,15 @@ static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon, }static long smb3_zero_range (struct file *file,struct cifs_tcon *tcon, -loff_t offset,loff_t len,bool keep_size) +unsigned long long offset,unsigned long long len, +bool keep_size) {struct cifs_ses *ses = tcon->ses;struct inode *inode =file_inode (file);struct cifsInodeInfo *cifsi =CIFS_I (inode);struct cifsFileInfo *cfile = file->private_data; -unsigned long long new_size; +struct netfs_inode *ictx =netfs_inode (inode); +unsigned long long i_size, new_size, remote_size;long rc;unsigned int xid;
@@ -3255,6 +3257,16 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,inode_lock (inode);filemap_invalidate_lock (inode->i_mapping); + i_size =i_size_read (inode); + remote_size = ictx->remote_i_size; +if (offset + len >= remote_size && offset < i_size) { +unsigned long long top =umin (offset + len, i_size); + + rc =filemap_write_and_wait_range (inode->i_mapping, offset, top -1 ); +if (rc <0 ) + goto zero_range_exit; + } +/* * We zero the range through ioctl, so we need remove the page caches * first, otherwise the data may be inconsistent with the server.
David Howells
maintainerPATCH 6/6 netfs, cifs: Improve some debugging bits
In reply to David HowellsImprove some debugging bits:
(1) The netfslib _debug() macro doesn't need a newline in its format string.
(2) Display the request debug ID and subrequest index in messages emitted in smb2_adjust_credits() to make it easier to reference in traces.
--- fs/netfs/io.c | 2 +- fs/smb/client/smb2ops.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
fs/netfs/io.c +1 -1
@@ -270,7 +270,7 @@ static void netfs_reset_subreq_iter(struct netfs_io_request *rreq,if (count == remaining)return ; - _debug("R=%08x[%u] ITER RESUB-MISMATCH %zx != %zx-%zx-%llx %x\n", + _debug("R=%08x[%u] ITER RESUB-MISMATCH %zx != %zx-%zx-%llx %x", rreq->debug_id, subreq->debug_index, iov_iter_count(&subreq->io_iter), subreq->transferred, subreq->len, rreq->i_size,
fs/smb/client/smb2ops.c +5 -3
@@ -316,7 +316,8 @@ smb2_adjust_credits(struct TCP_Server_Info *server, cifs_trace_rw_credits_no_adjust_up);trace_smb3_too_many_credits (server->CurrentMid, server->conn_id, server->hostname,0 , credits->value - new_val,0 ); -cifs_server_dbg (VFS ,"request has less credits (%d) than required (%d)" , +cifs_server_dbg (VFS ,"R=%x[%x] request has less credits (%d) than required (%d)" , + subreq->rreq->debug_id, subreq->subreq.debug_index, credits->value, new_val);return -EOPNOTSUPP ;
@@ -338,8 +339,9 @@ smb2_adjust_credits(struct TCP_Server_Info *server,trace_smb3_reconnect_detected (server->CurrentMid, server->conn_id, server->hostname, scredits, credits->value - new_val, in_flight); -cifs_server_dbg (VFS ,"trying to return %d credits to old session\n" , - credits->value - new_val); +cifs_server_dbg (VFS ,"R=%x[%x] trying to return %d credits to old session\n" , + subreq->rreq->debug_id, subreq->subreq.debug_index, + credits->value - new_val);return -EAGAIN ; }
testing is going fine so far with David's series ontop of current mainline
(I see one possible intermittent server bug failure - on test generic/728 - but no red flags testing so far)
http://smb311-linux-testing.southcentralus.cloudapp.azure.com/#/builders/3/builds/207
Quoted 66 lines · David Howells
Hi Christian, Steve,
Firstly, here are some fixes to DIO read handling and the retrying of reads, particularly in relation to cifs:
(1) Fix the missing credit renegotiation in cifs on the retrying of reads. The credits we had ended with the original read (or the last retry) and to perform a new read we need more credits otherwise the server can reject our read with EINVAL.
(2) Fix the handling of short DIO reads to avoid ENODATA when the read retry tries to access a portion of the file after the EOF.
Secondly, some patches fixing cifs copy and zero offload:
(3) Fix
cifs_file_copychunk_range()to not try to partially invalidate folios that are only partly covered by the range, but rather flush them back and invalidate them.(4) Fix
filemap_invalidate_inode()to use the correct invalidation function so that it doesn't leave partially invalidated folios hanging around (which may hide part of the result of an offloaded copy).(5) Fix
smb3_zero_data()to correctly handle zeroing of data that's buffered locally but not yet written back and with the EOF position on the server short of the local EOF position.Note that this will also affect afs and 9p, particularly with regard to direct I/O writes.
And finally, here's an adjustment to debugging statements:
(6) Adjust three debugging output statements. Not strictly a fix, so could be dropped. Including the subreq ID in some extra debug lines helps a bit, though.
The patches can also be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-fixes
Thanks,
DavidDavid Howells (6):
cifs: Fix lack of credit renegotiation on read retry netfs, cifs: Fix handling of short DIO read
cifs: Fix copy offload to flush destination region
mm: Fixfilemap_invalidate_inode()to use
invalidate_inode_pages2_range()
cifs: FixFALLOC_FL_ZERO_RANGEto preflush buffered part of target
region
netfs, cifs: Improve some debugging bitsfs/netfs/io.c | 21 +++++++++++++------- fs/smb/client/cifsfs.c | 21 ++++---------------- fs/smb/client/cifsglob.h | 1 + fs/smb/client/file.c | 37 ++++++++++++++++++++++++++++++++---- fs/smb/client/smb2ops.c | 26 +++++++++++++++++++------ fs/smb/client/smb2pdu.c | 41 +++++++++++++++++++++++++--------------- fs/smb/client/trace.h | 1 + include/linux/netfs.h | 1 + mm/filemap.c | 2 +- 9 files changed, 101 insertions(+), 50 deletions(-)
Signature · 3 lines
Thanks, Steve