diff mbox series

[v7,06/21] NFS: If the cookie verifier changes, we must invalidate the page cache

Message ID 20220223211305.296816-7-trondmy@kernel.org (mailing list archive)
State New, archived
Headers show
Series Readdir improvements | expand

Commit Message

Trond Myklebust Feb. 23, 2022, 9:12 p.m. UTC
From: Trond Myklebust <trond.myklebust@hammerspace.com>

Ensure that if the cookie verifier changes when we use the zero-valued
cookie, then we invalidate any cached pages.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/dir.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Anna Schumaker Feb. 24, 2022, 4:18 p.m. UTC | #1
Hi Trond,

On Wed, Feb 23, 2022 at 7:48 PM <trondmy@kernel.org> wrote:
>
> From: Trond Myklebust <trond.myklebust@hammerspace.com>
>
> Ensure that if the cookie verifier changes when we use the zero-valued
> cookie, then we invalidate any cached pages.
>
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>  fs/nfs/dir.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> index 5d9367d9b651..7932d474ce00 100644
> --- a/fs/nfs/dir.c
> +++ b/fs/nfs/dir.c
> @@ -945,9 +945,14 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
>                 /*
>                  * Set the cookie verifier if the page cache was empty
>                  */
> -               if (desc->page_index == 0)
> +               if (desc->last_cookie == 0 &&
> +                   memcmp(nfsi->cookieverf, verf, sizeof(nfsi->cookieverf))) {
>                         memcpy(nfsi->cookieverf, verf,
>                                sizeof(nfsi->cookieverf));
> +                       invalidate_inode_pages2_range(desc->file->f_mapping,
> +                                                     desc->page_index_max + 1,

I'm getting this when I try to compile this patch:

fs/nfs/dir.c: In function ‘find_and_lock_cache_page’:
fs/nfs/dir.c:953:61: error: ‘struct nfs_readdir_descriptor’ has no
member named ‘page_index_max’; did you mean ‘page_index’?
  953 |
desc->page_index_max + 1,
      |
^~~~~~~~~~~~~~
      |                                                             page_index
make[2]: *** [scripts/Makefile.build:288: fs/nfs/dir.o] Error 1
make[1]: *** [scripts/Makefile.build:550: fs/nfs] Error 2
make: *** [Makefile:1831: fs] Error 2
make: *** Waiting for unfinished jobs....

It looks like the "page_index_max" field is added in patch 8.

Anna


Anna
> +                                                     -1);
> +               }
>         }
>         res = nfs_readdir_search_array(desc);
>         if (res == 0)
> --
> 2.35.1
>
diff mbox series

Patch

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 5d9367d9b651..7932d474ce00 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -945,9 +945,14 @@  static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
 		/*
 		 * Set the cookie verifier if the page cache was empty
 		 */
-		if (desc->page_index == 0)
+		if (desc->last_cookie == 0 &&
+		    memcmp(nfsi->cookieverf, verf, sizeof(nfsi->cookieverf))) {
 			memcpy(nfsi->cookieverf, verf,
 			       sizeof(nfsi->cookieverf));
+			invalidate_inode_pages2_range(desc->file->f_mapping,
+						      desc->page_index_max + 1,
+						      -1);
+		}
 	}
 	res = nfs_readdir_search_array(desc);
 	if (res == 0)