linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Kleikamp <dave.kleikamp@oracle.com>
To: Christian Kujau <lists@nerdbynature.de>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
	Karl Schmidt <karl@xtronics.com>,
	Jonathan McDowell <noodles@earth.li>,
	jfs-discussion@lists.sourceforge.net, 714974@bugs.debian.org,
	Ben Hutchings <ben@decadent.org.uk>,
	linux-nfs@vger.kernel.org
Subject: [PATCH] jfs: fix readdir cookie incompatibility with NFSv4
Date: Thu, 15 Aug 2013 15:48:39 -0500	[thread overview]
Message-ID: <520D3EA7.1010109@oracle.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1308150001530.7081@trent.utfs.org>

This patch replaces the one I posted yesterday. I like this better since
it doesn't require fixing existing on-disk cookies or skipping a
position in the in-inode index table.

NFSv4 reserves readdir cookie values 0-2 for special entries (. and ..),
but jfs allows a value of 2 for a non-special entry. This incompatibility
can result in the nfs client reporting a readdir loop.

This patch doesn't change the value stored internally, but adds one to
the value exposed to the iterate method.

Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
---
 fs/jfs/jfs_dtree.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index 8743ba9..0ec767e 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -3047,6 +3047,14 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
 
 		dir_index = (u32) ctx->pos;
 
+		/*
+		 * NFSv4 reserves cookies 1 and 2 for . and .. so we add
+		 * the value we return to the vfs is one greater than the
+		 * one we use internally.
+		 */
+		if (dir_index)
+			dir_index--;
+
 		if (dir_index > 1) {
 			struct dir_table_slot dirtab_slot;
 
@@ -3086,7 +3094,7 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
 			if (p->header.flag & BT_INTERNAL) {
 				jfs_err("jfs_readdir: bad index table");
 				DT_PUTPAGE(mp);
-				ctx->pos = -1;
+				ctx->pos = DIREND;
 				return 0;
 			}
 		} else {
@@ -3094,14 +3102,14 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
 				/*
 				 * self "."
 				 */
-				ctx->pos = 0;
+				ctx->pos = 1;
 				if (!dir_emit(ctx, ".", 1, ip->i_ino, DT_DIR))
 					return 0;
 			}
 			/*
 			 * parent ".."
 			 */
-			ctx->pos = 1;
+			ctx->pos = 2;
 			if (!dir_emit(ctx, "..", 2, PARENT(ip), DT_DIR))
 				return 0;
 
@@ -3122,22 +3130,23 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
 		/*
 		 * Legacy filesystem - OS/2 & Linux JFS < 0.3.6
 		 *
-		 * pn = index = 0:	First entry "."
-		 * pn = 0; index = 1:	Second entry ".."
+		 * pn = 0; index = 1:	First entry "."
+		 * pn = 0; index = 2:	Second entry ".."
 		 * pn > 0:		Real entries, pn=1 -> leftmost page
 		 * pn = index = -1:	No more entries
 		 */
 		dtpos = ctx->pos;
-		if (dtpos == 0) {
+		if (dtpos < 2) {
 			/* build "." entry */
+			ctx->pos = 1;
 			if (!dir_emit(ctx, ".", 1, ip->i_ino, DT_DIR))
 				return 0;
-			dtoffset->index = 1;
+			dtoffset->index = 2;
 			ctx->pos = dtpos;
 		}
 
 		if (dtoffset->pn == 0) {
-			if (dtoffset->index == 1) {
+			if (dtoffset->index == 2) {
 				/* build ".." entry */
 				if (!dir_emit(ctx, "..", 2, PARENT(ip), DT_DIR))
 					return 0;
@@ -3228,6 +3237,12 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
 					}
 					jfs_dirent->position = unique_pos++;
 				}
+				/*
+				 * We add 1 to the index because we may
+				 * use a value of 2 internally, and NFSv4
+				 * doesn't like that.
+				 */
+				jfs_dirent->position++;
 			} else {
 				jfs_dirent->position = dtpos;
 				len = min(d_namleft, DTLHDRDATALEN_LEGACY);
-- 
1.8.3.4


  parent reply	other threads:[~2013-08-15 20:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-08  1:13 NFS 'readdir loop' error on JFS Ben Hutchings
2013-07-08 14:02 ` bjschuma
2013-07-08 15:43 ` Karl Schmidt
2013-08-09 20:44 ` Karl Schmidt
2013-08-10  7:28   ` [Jfs-discussion] " Christian Kujau
2013-08-10 19:43     ` Karl Schmidt
2013-08-12  8:18     ` Christian Kujau
2013-08-12  8:29       ` Christian Kujau
2013-08-12 16:29         ` J. Bruce Fields
2013-08-12 20:04           ` Christian Kujau
2013-08-15  3:54           ` [PATCH] jfs: avoid misuse of cookie value of 2 Dave Kleikamp
2013-08-15  4:29             ` Christian Kujau
2013-08-15  7:09               ` Christian Kujau
2013-08-15 13:38                 ` Dave Kleikamp
2013-08-15 20:48                 ` Dave Kleikamp [this message]
2013-08-15 21:26                   ` [PATCH] jfs: fix readdir cookie incompatibility with NFSv4 Christian Kujau
2013-08-15 22:09                     ` Dave Kleikamp
2013-08-17 20:01                     ` Ben Hutchings
2013-08-19 19:11                       ` [JunkMail] " ben
2013-08-29 22:48                       ` Jonathan McDowell
2013-09-05  3:40                         ` Bug#714974: " Jonathan McDowell
2013-08-24 22:21                   ` [Jfs-discussion] " Christian Kujau
2013-08-26 22:27                     ` Dave Kleikamp
2013-08-15 13:38             ` [PATCH] jfs: avoid misuse of cookie value of 2 J. Bruce Fields

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=520D3EA7.1010109@oracle.com \
    --to=dave.kleikamp@oracle.com \
    --cc=714974@bugs.debian.org \
    --cc=ben@decadent.org.uk \
    --cc=bfields@fieldses.org \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=karl@xtronics.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=lists@nerdbynature.de \
    --cc=noodles@earth.li \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).