Linux-NFS Archive on lore.kernel.org
 help / color / Atom feed
From: trondmy@kernel.org
To: linux-nfs@vger.kernel.org
Subject: [PATCH v2 15/16] NFS: Handle NFS4ERR_NOT_SAME and NFSERR_BADCOOKIE from readdir calls
Date: Tue,  3 Nov 2020 10:33:28 -0500
Message-ID: <20201103153329.531942-16-trondmy@kernel.org> (raw)
In-Reply-To: <20201103153329.531942-15-trondmy@kernel.org>

From: Trond Myklebust <trond.myklebust@hammerspace.com>

If the server returns NFS4ERR_NOT_SAME or tells us that the cookie is
bad in response to a READDIR call, then we should empty the page cache
so that we can fill it from scratch again.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/dir.c      | 24 ++++++++++++++++--------
 fs/nfs/nfs4proc.c |  2 ++
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index d467df099c04..1c5a5f9cb228 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -862,15 +862,21 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
 		return -ENOMEM;
 	if (nfs_readdir_page_needs_filling(desc->page)) {
 		res = nfs_readdir_xdr_to_array(desc, desc->page, inode);
-		if (res < 0)
-			goto error;
+		if (res < 0) {
+			nfs_readdir_page_unlock_and_put_cached(desc);
+			if (res == -EBADCOOKIE || res == -ENOTSYNC) {
+				invalidate_inode_pages2(desc->file->f_mapping);
+				desc->page_index = 0;
+				return -EAGAIN;
+			}
+			return res;
+		}
 	}
 	res = nfs_readdir_search_array(desc);
 	if (res == 0) {
 		nfsi->page_index = desc->page_index;
 		return 0;
 	}
-error:
 	nfs_readdir_page_unlock_and_put_cached(desc);
 	return res;
 }
@@ -880,12 +886,12 @@ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc)
 {
 	int res;
 
-	if (desc->page_index == 0) {
-		desc->current_index = 0;
-		desc->prev_index = 0;
-		desc->last_cookie = 0;
-	}
 	do {
+		if (desc->page_index == 0) {
+			desc->current_index = 0;
+			desc->prev_index = 0;
+			desc->last_cookie = 0;
+		}
 		res = find_and_lock_cache_page(desc);
 	} while (res == -EAGAIN);
 	return res;
@@ -1031,6 +1037,8 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
 				res = uncached_readdir(desc);
 				if (res == 0)
 					continue;
+				if (res == -EBADCOOKIE || res == -ENOTSYNC)
+					res = 0;
 			}
 			break;
 		}
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 8e82f988a11f..3f1fdb06ba56 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -184,6 +184,8 @@ static int nfs4_map_errors(int err)
 		return -EPROTONOSUPPORT;
 	case -NFS4ERR_FILE_OPEN:
 		return -EBUSY;
+	case -NFS4ERR_NOT_SAME:
+		return -ENOTSYNC;
 	default:
 		dprintk("%s could not handle NFSv4 error %d\n",
 				__func__, -err);
-- 
2.28.0


  reply index

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-03 15:33 [PATCH v2 00/16] Readdir enhancements trondmy
2020-11-03 15:33 ` [PATCH v2 01/16] NFS: Ensure contents of struct nfs_open_dir_context are consistent trondmy
2020-11-03 15:33   ` [PATCH v2 02/16] NFS: Clean up readdir struct nfs_cache_array trondmy
2020-11-03 15:33     ` [PATCH v2 03/16] NFS: Clean up nfs_readdir_page_filler() trondmy
2020-11-03 15:33       ` [PATCH v2 04/16] NFS: Clean up directory array handling trondmy
2020-11-03 15:33         ` [PATCH v2 05/16] NFS: Don't discard readdir results trondmy
2020-11-03 15:33           ` [PATCH v2 06/16] NFS: Remove unnecessary kmap in nfs_readdir_xdr_to_array() trondmy
2020-11-03 15:33             ` [PATCH v2 07/16] NFS: Replace kmap() with kmap_atomic() in nfs_readdir_search_array() trondmy
2020-11-03 15:33               ` [PATCH v2 08/16] NFS: Simplify struct nfs_cache_array_entry trondmy
2020-11-03 15:33                 ` [PATCH v2 09/16] NFS: Support larger readdir buffers trondmy
2020-11-03 15:33                   ` [PATCH v2 10/16] NFS: More readdir cleanups trondmy
2020-11-03 15:33                     ` [PATCH v2 11/16] NFS: nfs_do_filldir() does not return a value trondmy
2020-11-03 15:33                       ` [PATCH v2 12/16] NFS: Reduce readdir stack usage trondmy
2020-11-03 15:33                         ` [PATCH v2 13/16] NFS: Cleanup to remove nfs_readdir_descriptor_t typedef trondmy
2020-11-03 15:33                           ` [PATCH v2 14/16] NFS: Allow the NFS generic code to pass in a verifier to readdir trondmy
2020-11-03 15:33                             ` trondmy [this message]
2020-11-03 15:33                               ` [PATCH v2 16/16] NFS: Improve handling of directory verifiers trondmy
2020-11-04 10:12                                 ` Mkrtchyan, Tigran
2020-11-04 17:21                                   ` Trond Myklebust
2020-11-03 15:55           ` [PATCH v2 05/16] NFS: Don't discard readdir results Benjamin Coddington
2020-11-03 16:14             ` Trond Myklebust
2020-11-04 16:14 ` [PATCH v2 00/16] Readdir enhancements Benjamin Coddington
2020-11-04 17:04   ` Trond Myklebust
2020-11-04 17:19     ` Benjamin Coddington

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201103153329.531942-16-trondmy@kernel.org \
    --to=trondmy@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-NFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nfs/0 linux-nfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nfs linux-nfs/ https://lore.kernel.org/linux-nfs \
		linux-nfs@vger.kernel.org
	public-inbox-index linux-nfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-nfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git