Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Chuck Lever <cel@kernel.org>,
	akpm@linux-foundation.org, brauner@kernel.org, hughd@google.com,
	jlayton@redhat.com, viro@zeniv.linux.org.uk,
	Tavian Barnes <tavianator@tavianator.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 11:00:16 -0500	[thread overview]
Message-ID: <ZVOZkB2PcWvFOZBl@tissot.1015granger.net> (raw)
In-Reply-To: <ZVOYwikYNWMBg1bC@casper.infradead.org>

On Tue, Nov 14, 2023 at 03:56:50PM +0000, Matthew Wilcox wrote:
> On Tue, Nov 14, 2023 at 10:49:37AM -0500, Chuck Lever wrote:
> > -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;
> 
> Funny, you used the same bit pattern as ZERO_SIZE_PTR without using
> the macro ...

On purpose, it's an eye catcher because I didn't have a better idea.
It obviously worked!


> > @@ -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);
> >  	return 0;
> >  }
> 
> It might make more sense to use ERR_PTR(-ENOENT) or ERANGE or something
> that's a more understandable sentinel value?

Yes, thanks. That's a better idea.

-- 
Chuck Lever


  reply	other threads:[~2023-11-14 16:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 15:49 [PATCH RFC] libfs: getdents() should return 0 after reaching EOD Chuck Lever
2023-11-14 15:56 ` Matthew Wilcox
2023-11-14 16:00   ` Chuck Lever [this message]
2023-11-14 17:29 ` Christian Brauner
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=ZVOZkB2PcWvFOZBl@tissot.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=cel@kernel.org \
    --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 \
    --cc=willy@infradead.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