netfs, cifs: Further fixes
Subsystems (8)
David Howells
maintainercover netfs, cifs: Further fixes
Hi Christian, Steve,
Here are some more fixes to cifs and one to netfs:
(1) Fix cifs FALLOC_FL_PUNCH_HOLE support as best I can. If it's going to punch a hole in dirty data in the pagecacne, invalidating that data may result in the EOF not being moved correctly. The set-zero and the eof-move RPC ops really need compounding to avoid third-party interference.
(2) 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.
(3) Fix netfslib's short read retry to reset the buffer iterator otherwise the wrong part of the buffer may get written on.
(4) Further fix the early EOF detection in cifs read.
(5) Further fixes for cifs credit handling.
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 (5):
cifs: Fix FALLOC_FL_PUNCH_HOLE support
netfs, cifs: Improve some debugging bits
netfs: Fix missing iterator reset on retry of short read
cifs: Fix short read handling
cifs: Fix credit handling
fs/netfs/io.c | 3 ++- fs/smb/client/file.c | 9 +++++++++ fs/smb/client/smb2ops.c | 34 ++++++++++++++++++++++++++++++---- fs/smb/client/smb2pdu.c | 12 ++---------- fs/smb/client/trace.h | 1 + 5 files changed, 44 insertions(+), 15 deletions(-)
David Howells
maintainerPATCH 1/5 cifs: Fix FALLOC_FL_PUNCH_HOLE support
The cifs filesystem doesn't quite emulate FALLOC_FL_PUNCH_HOLE correctly (note that due to lack of protocol support, it can't actually implement it directly). Whilst it will (partially) invalidate dirty folios in the pagecache, it doesn't write them back first, and so the EOF marker on the server may be lower than inode->i_size.
This presents a problem, however, as if the punched hole invalidates the tail of the locally cached dirty data, writeback won't know it needs to move the EOF over to account for the hole punch (which isn't supposed to move the EOF). We could just write zeroes over the punched out region of the pagecache and write that back - but this is supposed to be a deallocatory operation.
Fix this by manually moving the EOF over on the server after the operation if the hole punched would corrupt it.
Note that the FSCTL_SET_ZERO_DATA RPC and the setting of the EOF should probably be compounded to stop a third party interfering (or, at least, massively reduce the chance).
This was reproducible occasionally by using fsx with the following script:
truncate 0x0 0x375e2 0x0 punch_hole 0x2f6d3 0x6ab5 0x375e2 truncate 0x0 0x3a71f 0x375e2 mapread 0xee05 0xcf12 0x3a71f write 0x2078e 0x5604 0x3a71f write 0x3ebdf 0x1421 0x3a71f * punch_hole 0x379d0 0x8630 0x40000 * mapread 0x2aaa2 0x85b 0x40000 fallocate 0x1b401 0x9ada 0x40000 read 0x15f2 0x7d32 0x40000 read 0x32f37 0x7a3b 0x40000 *
The second "write" should extend the EOF to 0x40000, and the "punch_hole" should operate inside of that - but that depends on whether the VM gets in and writes back the data first. If it doesn't, the file ends up 0x3a71f in size, not 0x40000.
--- fs/smb/client/smb2ops.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
fs/smb/client/smb2ops.c +24 -0
@@ -3305,6 +3305,7 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,struct inode *inode =file_inode (file);struct cifsFileInfo *cfile = file->private_data;struct file_zero_data_information fsctl_buf; +unsigned long long end = offset + len, i_size, remote_i_size;long rc;unsigned int xid;__u8 set_sparse =1 ;
@@ -3336,6 +3337,29 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, (char *)&fsctl_buf,sizeof (struct file_zero_data_information ), CIFSMaxBufSize, NULL, NULL); + +if (rc) + goto unlock; + +/* If there's dirty data in the buffer that would extend the EOF if it +* were written, then we need to move the EOF marker over to the lower +* of the high end of the hole and the proposed EOF. The problem is +* that we locally hole-punch the tail of the dirty data, the proposed +* EOF update will end up in the wrong place. +*/ + i_size =i_size_read (inode); + remote_i_size =netfs_inode (inode)->remote_i_size; +if (end > remote_i_size && i_size > remote_i_size) { +unsigned long long extend_to =umin (end, i_size); + rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, extend_to); +if (rc >=0 ) { +netfs_inode (inode)->remote_i_size = extend_to; +trace_netfs_set_size (inode, netfs_size_trace_punch_hole); + } + } + +unlock:filemap_invalidate_unlock (inode->i_mapping); out:inode_unlock (inode);
David Howells
maintainerPATCH 2/5 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 ; }
David Howells
maintainerPATCH 3/5 netfs: Fix missing iterator reset on retry of short read
In reply to David HowellsFix netfs_rreq_perform_resubmissions() to reset before retrying a short read, otherwise the wrong part of the output buffer will be used.
--- fs/netfs/io.c | 1 + 1 file changed, 1 insertion(+)
fs/netfs/io.c +1 -0
@@ -315,6 +315,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq)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); } }
David Howells
maintainerPATCH 4/5 cifs: Fix short read handling
In reply to David HowellsFix smb2_readv_callback() to always take -ENODATA as indicating we hit EOF and to always set the NETFS_SREQ_HIT_EOF flag rather than only doing it under some circumstances.
--- fs/smb/client/smb2pdu.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
fs/smb/client/smb2pdu.c +2 -10
@@ -4601,16 +4601,8 @@ 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.transferred < rdata->subreq.rreq->i_size) - rdata->result =0 ; -if (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 ; - } +__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 ==
David Howells
maintainerPATCH 5/5 cifs: Fix credit handling
In reply to David HowellsFix some bits of credit handling:
(1) Use the ->actual_len value rather than the total subrequest length in smb2_adjust_credits() so that we don't trip the error message that we don't have sufficient credits allocated in a retry.
(2) Set wdata->actual_len in writes as smb2_adjust_credits() now expects to see it set.
(3) Reset the in_flight_check flag on a retry as we're doing a new read.
(4) Add a missing credit resubmission trace.
--- fs/smb/client/file.c | 9 +++++++++ fs/smb/client/smb2ops.c | 2 +- fs/smb/client/trace.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-)
fs/smb/client/file.c +9 -0
@@ -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;
@@ -227,6 +228,14 @@ static void cifs_req_issue_read(struct netfs_io_subrequest *subreq) &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) {
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/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
maintainerSamba llseek bug
In reply to David HowellsNote that whilst testing my cifs fixes with the generic/075 and generic/112 xfstests, the tests occasionally hit a bug in Samba whereby llseek() fails because there are too many extents in the server file for the server to report. I've noted this before:
https://lore.kernel.org/linux-cifs/[email protected]/
is there a fix for this I can try?
David