Skip to content

Commit 43eaa6c

Browse files
piastrygregkh
authored andcommitted
CIFS: Fix read after write for files with read caching
commit 6dfbd84 upstream. When we have a READ lease for a file and have just issued a write operation to the server we need to purge the cache and set oplock/lease level to NONE to avoid reading stale data. Currently we do that only if a write operation succedeed thus not covering cases when a request was sent to the server but a negative error code was returned later for some other reasons (e.g. -EIOCBQUEUED or -EINTR). Fix this by turning off caching regardless of the error code being returned. The patches fixes generic tests 075 and 112 from the xfs-tests. Cc: <stable@vger.kernel.org> Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com> Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dc8e8ad commit 43eaa6c

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎fs/cifs/file.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,14 +2871,16 @@ cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from)
28712871
* these pages but not on the region from pos to ppos+len-1.
28722872
*/
28732873
written = cifs_user_writev(iocb, from);
2874-
if (written > 0 && CIFS_CACHE_READ(cinode)) {
2874+
if (CIFS_CACHE_READ(cinode)) {
28752875
/*
2876-
* Windows 7 server can delay breaking level2 oplock if a write
2877-
* request comes - break it on the client to prevent reading
2878-
* an old data.
2876+
* We have read level caching and we have just sent a write
2877+
* request to the server thus making data in the cache stale.
2878+
* Zap the cache and set oplock/lease level to NONE to avoid
2879+
* reading stale data from the cache. All subsequent read
2880+
* operations will read new data from the server.
28792881
*/
28802882
cifs_zap_mapping(inode);
2881-
cifs_dbg(FYI, "Set no oplock for inode=%p after a write operation\n",
2883+
cifs_dbg(FYI, "Set Oplock/Lease to NONE for inode=%p after write\n",
28822884
inode);
28832885
cinode->oplock = 0;
28842886
}

0 commit comments

Comments
 (0)