From: Christian Brauner <brauner@kernel.org>
To: Chuck Lever <cel@kernel.org>
Cc: akpm@linux-foundation.org, hughd@google.com, jlayton@redhat.com,
viro@zeniv.linux.org.uk,
Tavian Barnes <tavianator@tavianator.com>,
Chuck Lever <chuck.lever@oracle.com>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH RFC] libfs: getdents() should return 0 after reaching EOD
Date: Tue, 14 Nov 2023 18:29:15 +0100 [thread overview]
Message-ID: <20231114-begleichen-miniatur-3c3a02862c4c@brauner> (raw)
In-Reply-To: <169997697704.4588.14555611205729567800.stgit@bazille.1015granger.net>
On Tue, Nov 14, 2023 at 10:49:37AM -0500, Chuck Lever wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
>
> The new directory offset helpers don't conform with the convention
> of getdents() returning no more entries once a directory file
> descriptor has reached the current end-of-directory.
>
> To address this, copy the logic from dcache_readdir() to mark the
> open directory file descriptor once EOD has been reached. Rewinding
> resets the mark.
>
> Reported-by: Tavian Barnes <tavianator@tavianator.com>
> Closes: https://lore.kernel.org/linux-fsdevel/20231113180616.2831430-1-tavianator@tavianator.com/
> Fixes: 6faddda69f62 ("libfs: Add directory operations for stable offsets")
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
> fs/libfs.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/fs/libfs.c b/fs/libfs.c
> index e9440d55073c..1c866b087f0c 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -428,7 +428,7 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry)
> inode->i_ino, fs_umode_to_dtype(inode->i_mode));
> }
>
> -static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx)
> +static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx)
> {
> struct offset_ctx *so_ctx = inode->i_op->get_offset_ctx(inode);
> XA_STATE(xas, &so_ctx->xa, ctx->pos);
> @@ -437,7 +437,8 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx)
> while (true) {
> dentry = offset_find_next(&xas);
> if (!dentry)
> - break;
> + /* readdir has reached the current EOD */
> + return (void *)0x10;
>
> if (!offset_dir_emit(ctx, dentry)) {
> dput(dentry);
> @@ -447,6 +448,7 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx)
> dput(dentry);
> ctx->pos = xas.xa_index + 1;
> }
> + return NULL;
> }
>
> /**
> @@ -479,7 +481,12 @@ static int offset_readdir(struct file *file, struct dir_context *ctx)
> if (!dir_emit_dots(file, ctx))
> return 0;
>
> - offset_iterate_dir(d_inode(dir), ctx);
> + if (ctx->pos == 2)
> + file->private_data = NULL;
> + else if (file->private_data == (void *)0x10)
> + return 0;
> +
> + file->private_data = offset_iterate_dir(d_inode(dir), ctx);
I think it's usually best practice to only modify the file->private_data
pointer during f_op->open and f_op->close but not override
file->private_data once the file is visible to other threads. I think
here it might not matter because access to file->private_data is
serialized on f_pos_lock and it's not used by anything else.
next prev parent reply other threads:[~2023-11-14 17:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 15:49 Chuck Lever
2023-11-14 15:56 ` Matthew Wilcox
2023-11-14 16:00 ` Chuck Lever
2023-11-14 17:29 ` Christian Brauner [this message]
2023-11-14 17:57 ` Al Viro
2023-11-15 20:25 ` Christian Brauner
2023-11-14 18:13 ` Chuck Lever
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=20231114-begleichen-miniatur-3c3a02862c4c@brauner \
--to=brauner@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=hughd@google.com \
--cc=jlayton@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tavianator@tavianator.com \
--cc=viro@zeniv.linux.org.uk \
/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