linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Brandenburg <martin@omnibond.com>
To: hubcap@omnibond.com, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Martin Brandenburg <martin@omnibond.com>
Subject: [PATCH 06/10] orangefs: support llseek on directories
Date: Fri,  7 Apr 2017 17:17:08 -0400	[thread overview]
Message-ID: <1491599832-17773-7-git-send-email-martin@omnibond.com> (raw)
In-Reply-To: <1491599832-17773-1-git-send-email-martin@omnibond.com>

This and the previous commit fix xfstests generic/257.

Signed-off-by: Martin Brandenburg <martin@omnibond.com>
---
 fs/orangefs/dir.c | 48 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/fs/orangefs/dir.c b/fs/orangefs/dir.c
index 3f82a73..c48220f 100644
--- a/fs/orangefs/dir.c
+++ b/fs/orangefs/dir.c
@@ -17,7 +17,7 @@
 struct orangefs_dir {
 	__u64 token;
 	void *directory;
-	size_t i, len;
+	size_t len;
 	int error;
 };
 
@@ -124,31 +124,36 @@ static int orangefs_dir_fill(struct orangefs_inode_s *oi,
 {
 	struct orangefs_khandle *khandle;
 	__u32 *len, padlen;
+	loff_t i;
 	char *s;
-	while (od->i < od->len) {
-		if (od->len < od->i + sizeof *len)
+	i = ctx->pos - 2;
+	while (i < od->len) {
+		if (od->len < i + sizeof *len)
 			goto eio;
-		len = od->directory + od->i;
+		len = od->directory + i;
 		/* len does not include trailing zero but padlen does. */
 		padlen = (*len + 1) + (4 - (*len + 1)%4)%4;
-		if (od->len < od->i + sizeof *len + padlen + sizeof *khandle)
+		if (od->len < i + sizeof *len + padlen + sizeof *khandle)
 			goto eio;
-		s = od->directory + od->i + sizeof *len;
+		s = od->directory + i + sizeof *len;
 		if (s[*len] != 0)
 			goto eio;
-		khandle = od->directory + od->i + sizeof *len + padlen;
+		khandle = od->directory + i + sizeof *len + padlen;
 
 		if (!dir_emit(ctx, s, *len, orangefs_khandle_to_ino(khandle),
 		    DT_UNKNOWN))
 			return 0;
-		od->i += sizeof *len + padlen + sizeof *khandle;
-		od->i = od->i + (8 - od->i%8)%8;
-		ctx->pos = 2 + od->i;
+		i += sizeof *len + padlen + sizeof *khandle;
+		i = i + (8 - i%8)%8;
+		ctx->pos = i + 2;
 	}
-	BUG_ON(od->i > od->len);
+	BUG_ON(i > od->len);
 	return 0;
 eio:
-	gossip_err("orangefs_dir_fill: userspace returns corrupt data\n");
+	/*
+	 * Here either data from userspace is corrupt or the application has
+	 * sought to an invalid location.
+	 */
 	od->error = -EIO;
 	return -EIO;
 }
@@ -180,12 +185,27 @@ static int orangefs_dir_iterate(struct file *file, struct dir_context *ctx)
 
 	r = 0;
 
-	if (od->i < od->len) {
+	/*
+	 * Must read more if the user has sought past what has been read so far.
+	 * Stop a user who has sought past the end.
+	 */
+	while (od->token != ORANGEFS_READDIR_END && ctx->pos - 2 > od->len) {
+		r = orangefs_dir_more(oi, od, dentry);
+		if (r)
+			return r;
+	}
+	if (od->token == ORANGEFS_READDIR_END && ctx->pos - 2 > od->len) {
+		return -EIO;
+	}
+
+	/* Then try to fill if there's any left in the buffer. */
+	if (ctx->pos - 2 < od->len) {
 		r = orangefs_dir_fill(oi, od, dentry, ctx);
 		if (r)
 			return r;
 	}
 
+	/* Finally get some more and try to fill. */
 	if (od->token != ORANGEFS_READDIR_END) {
 		r = orangefs_dir_more(oi, od, dentry);
 		if (r)
@@ -213,7 +233,6 @@ static int orangefs_dir_open(struct inode *inode, struct file *file)
 		kfree(file->private_data);
 		return -ENOMEM;
 	}
-	od->i = 0;
 	od->len = 0;
 	od->error = 0;
 	return 0;
@@ -229,6 +248,7 @@ static int orangefs_dir_release(struct inode *inode, struct file *file)
 }
 
 const struct file_operations orangefs_dir_operations = {
+	.llseek = default_llseek,
 	.read = generic_read_dir,
 	.iterate = orangefs_dir_iterate,
 	.open = orangefs_dir_open,
-- 
2.1.4

  parent reply	other threads:[~2017-04-07 21:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-07 21:17 [PATCH 00/10] orangefs changes for 4.12 Martin Brandenburg
2017-04-07 21:17 ` [PATCH 01/10] orangefs: remove unused get_fsid_from_ino Martin Brandenburg
2017-04-07 21:17 ` [PATCH 02/10] orangefs: fix bounds check for listxattr Martin Brandenburg
2017-04-07 21:17 ` [PATCH 03/10] orangefs: clean up oversize xattr validation Martin Brandenburg
2017-04-07 21:17 ` [PATCH 04/10] orangefs: do not set getattr_time on orangefs_lookup Martin Brandenburg
2017-04-07 21:17 ` [PATCH 05/10] orangefs: rewrite readdir to fix several bugs Martin Brandenburg
2017-04-07 21:17 ` Martin Brandenburg [this message]
2017-04-07 21:17 ` [PATCH 07/10] orangefs: support very large directories Martin Brandenburg
2017-04-07 21:17 ` [PATCH 08/10] orangefs: remove ORANGEFS_READDIR macros Martin Brandenburg
2017-04-07 21:17 ` [PATCH 09/10] orangefs: implement statx Martin Brandenburg
2017-04-07 21:17 ` [PATCH 10/10] orangefs: do not check possibly stale size on truncate Martin Brandenburg

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=1491599832-17773-7-git-send-email-martin@omnibond.com \
    --to=martin@omnibond.com \
    --cc=hubcap@omnibond.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@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
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).