]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
NFS: Only change the cookie verifier if the directory page cache is empty
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Wed, 17 Mar 2021 12:46:19 +0000 (08:46 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 May 2021 08:29:39 +0000 (10:29 +0200)
[ Upstream commit f892c41c14e0fa3d78ce37de1d5c8161ed13bf08 ]

The cached NFSv3/v4 readdir cookies are associated with a verifier,
which is checked by the server on subsequent calls to readdir, and is
only expected to change when the cookies (and hence also the page cache
contents) are considered invalid.
We therefore do have to store the verifier, but only when the page cache
is empty.

Fixes: b593c09f83a2 ("NFS: Improve handling of directory verifiers")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/dir.c

index ca1dddc81436ed29e99b9818d3e687ca3b7daf57..d5f28a1f3671cec3b79fd0c025614bbdbf114ad2 100644 (file)
@@ -928,7 +928,12 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
                        }
                        return res;
                }
-               memcpy(nfsi->cookieverf, verf, sizeof(nfsi->cookieverf));
+               /*
+                * Set the cookie verifier if the page cache was empty
+                */
+               if (desc->page_index == 0)
+                       memcpy(nfsi->cookieverf, verf,
+                              sizeof(nfsi->cookieverf));
        }
        res = nfs_readdir_search_array(desc);
        if (res == 0) {