]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.18.137/cifs-fix-read-after-write-for-files-with-read-caching.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.18.137 / cifs-fix-read-after-write-for-files-with-read-caching.patch
CommitLineData
5e0829c0
GKH
1From 6dfbd84684700cb58b34e8602c01c12f3d2595c8 Mon Sep 17 00:00:00 2001
2From: Pavel Shilovsky <piastryyy@gmail.com>
3Date: Mon, 4 Mar 2019 17:48:01 -0800
4Subject: CIFS: Fix read after write for files with read caching
5
6From: Pavel Shilovsky <piastryyy@gmail.com>
7
8commit 6dfbd84684700cb58b34e8602c01c12f3d2595c8 upstream.
9
10When we have a READ lease for a file and have just issued a write
11operation to the server we need to purge the cache and set oplock/lease
12level to NONE to avoid reading stale data. Currently we do that
13only if a write operation succedeed thus not covering cases when
14a request was sent to the server but a negative error code was
15returned later for some other reasons (e.g. -EIOCBQUEUED or -EINTR).
16Fix this by turning off caching regardless of the error code being
17returned.
18
19The patches fixes generic tests 075 and 112 from the xfs-tests.
20
21Cc: <stable@vger.kernel.org>
22Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
23Signed-off-by: Steve French <stfrench@microsoft.com>
24Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>
25Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26
27---
28 fs/cifs/file.c | 12 +++++++-----
29 1 file changed, 7 insertions(+), 5 deletions(-)
30
31--- a/fs/cifs/file.c
32+++ b/fs/cifs/file.c
33@@ -2772,14 +2772,16 @@ cifs_strict_writev(struct kiocb *iocb, s
34 * these pages but not on the region from pos to ppos+len-1.
35 */
36 written = cifs_user_writev(iocb, from);
37- if (written > 0 && CIFS_CACHE_READ(cinode)) {
38+ if (CIFS_CACHE_READ(cinode)) {
39 /*
40- * Windows 7 server can delay breaking level2 oplock if a write
41- * request comes - break it on the client to prevent reading
42- * an old data.
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.
48 */
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",
52 inode);
53 cinode->oplock = 0;
54 }