From: Al Viro <viro@zeniv.linux.org.uk>
To: Chuck Lever <cel@kernel.org>
Cc: akpm@linux-foundation.org, brauner@kernel.org, hughd@google.com,
jlayton@redhat.com, Tavian Barnes <tavianator@tavianator.com>,
Chuck Lever <chuck.lever@oracle.com>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v2] libfs: getdents() should return 0 after reaching EOD
Date: Sat, 18 Nov 2023 16:28:38 +0000 [thread overview]
Message-ID: <20231118162838.GE1957730@ZenIV> (raw)
In-Reply-To: <170007970281.4975.12356401645395490640.stgit@bazille.1015granger.net>
On Wed, Nov 15, 2023 at 03:22:52PM -0500, Chuck Lever wrote:
> static int offset_readdir(struct file *file, struct dir_context *ctx)
> {
> + struct dentry *cursor = file->private_data;
> struct dentry *dir = file->f_path.dentry;
>
> lockdep_assert_held(&d_inode(dir)->i_rwsem);
> @@ -479,11 +481,19 @@ 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)
> + cursor->d_flags &= ~DCACHE_EOD;
> + else if (cursor->d_flags & DCACHE_EOD)
> + return 0;
> +
> + if (offset_iterate_dir(d_inode(dir), ctx))
> + cursor->d_flags |= DCACHE_EOD;
This is simply grotesque - "it's better to keep ->private_data constant,
so we will allocate a dentry, just to store the one bit of data we need to
keep track of; oh, and let's grab a bit out of ->d_flags, while we are at it;
we will ignore the usual locking rules for ->d_flags modifications, 'cause
it's all serialized on ->f_pos_lock".
No. If nothing else, this is harder to follow than the original. It's
far easier to verify that these struct file instances only use ->private_data
as a flag and these accesses are serialized on ->f_pos_lock as claimed
than go through the accesses to ->d_flags, prove that the one above is
the only one that can happen to such dentries (while they are live, that
is - once they are in __dentry_kill(), there will be modifications of ->d_flags)
and that it can't happen to any other instances.
NAKed-by: Al Viro <viro@zeniv.linux.org.uk>
next prev parent reply other threads:[~2023-11-18 16:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-15 20:22 Chuck Lever
2023-11-18 16:28 ` Al Viro [this message]
2023-11-18 16:40 ` Chuck Lever III
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=20231118162838.GE1957730@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.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 \
/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