1 From 6dfbd84684700cb58b34e8602c01c12f3d2595c8 Mon Sep 17 00:00:00 2001
2 From: Pavel Shilovsky <piastryyy@gmail.com>
3 Date: Mon, 4 Mar 2019 17:48:01 -0800
4 Subject: CIFS: Fix read after write for files with read caching
6 From: Pavel Shilovsky <piastryyy@gmail.com>
8 commit 6dfbd84684700cb58b34e8602c01c12f3d2595c8 upstream.
10 When we have a READ lease for a file and have just issued a write
11 operation to the server we need to purge the cache and set oplock/lease
12 level to NONE to avoid reading stale data. Currently we do that
13 only if a write operation succedeed thus not covering cases when
14 a request was sent to the server but a negative error code was
15 returned later for some other reasons (e.g. -EIOCBQUEUED or -EINTR).
16 Fix this by turning off caching regardless of the error code being
19 The patches fixes generic tests 075 and 112 from the xfs-tests.
21 Cc: <stable@vger.kernel.org>
22 Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
23 Signed-off-by: Steve French <stfrench@microsoft.com>
24 Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 fs/cifs/file.c | 12 +++++++-----
29 1 file changed, 7 insertions(+), 5 deletions(-)
33 @@ -2871,14 +2871,16 @@ cifs_strict_writev(struct kiocb *iocb, s
34 * these pages but not on the region from pos to ppos+len-1.
36 written = cifs_user_writev(iocb, from);
37 - if (written > 0 && CIFS_CACHE_READ(cinode)) {
38 + if (CIFS_CACHE_READ(cinode)) {
40 - * Windows 7 server can delay breaking level2 oplock if a write
41 - * request comes - break it on the client to prevent reading
43 + * We have read level caching and we have just sent a write
44 + * request to the server thus making data in the cache stale.
45 + * Zap the cache and set oplock/lease level to NONE to avoid
46 + * reading stale data from the cache. All subsequent read
47 + * operations will read new data from the server.
49 cifs_zap_mapping(inode);
50 - cifs_dbg(FYI, "Set no oplock for inode=%p after a write operation\n",
51 + cifs_dbg(FYI, "Set Oplock/Lease to NONE for inode=%p after write\n",