mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Hengyu Liang <hengyul@cs.unc.edu>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	Yangtao Li <frank.li@vivo.com>,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 2/2] hfsplus: do not end readdir at i_size after an unlink
Date: Mon, 16 Nov 2026 14:30:29 -0800	[thread overview]
Message-ID: <446748647839fd554246a78d72be728069b44b7a.camel@dubeyko.com> (raw)
In-Reply-To: <20261114125045.466604-1-hengyul@cs.unc.edu>

On Sat, 2026-11-14 at 07:50 -0500, Hengyu Liang wrote:
> On Thu, 2026-11-12 at 12:44 -0800, Viacheslav Dubeyko wrote:
> > Frankly speaking, I don't quite follow what is the issue of the
> > fix. Do
> > you mean that we create and delete folder in one thread and execute
> > the
> > readdir in another one? Or do you mean that application has several
> > threads and one thread do readdir but another one delete file by
> > file?
> > How this deletion is executed? I mean which files are deleted?
> 
> Sorry, the commit message was too short. There is only one thread. It
> reads a part of the directory with getdents64(), deletes the files
> that
> this call returned, and then calls getdents64() again on the same fd.
> This is what "rm -r" of BusyBox does.
> 
> > Even if we delete files in folder then i_size is dropping
> > gradually. If
> > we traversing the folder's content and ctx->pos >= inode->i_size,
> > then
> > it sounds that we already showed the existing content. Do you mean
> > that
> > if we deleted the range that we already processed, then we miss the
> > rest of undeleted items?
> 
> Yes, exactly. ctx->pos counts the entries returned since the start,
> and
> i_size is the number of entries that exist now (valence + 2). When
> the
> entries that were already returned are deleted, ctx->pos stays and
> i_size drops, so ctx->pos can reach i_size while entries are still
> unread.
> 
> A small example is a directory with 4 files and a buffer that takes 4
> entries:
> 
>   getdents64() returns ".", "..", f1, f2   ctx->pos = 4, i_size = 6
>                                            rd->pos = 4, rd->key = f3
>   unlink(f1)                               i_size = 5
>   unlink(f2)                               i_size = 4
>   getdents64() returns 0                   f_pos (4) >= i_size (4)
> 
> f3 and f4 were never returned. Before commit 4b0496432844,
> hfsplus_delete_cat() moved f_pos back for every deleted entry before
> the saved key, so the second call started with f_pos = 2 and returned
> f3 and f4.
> 
> With 1500 files and a 32768 byte buffer, the first call returns 1022
> files. After they are deleted, i_size is 480 and f_pos is 1024, so
> the
> second call returns 0 and 478 files are left.
> 
> > > +	bool resume = rd && rd->pos == file->f_pos;
> > 
> > Is it possible that rd is NULL here?
> 
> Yes. file->private_data is allocated at the end of the first
> hfsplus_readdir() call that stops in the middle of the directory, so
> it
> is NULL before that. The current code has the same check
> ("if (rd && rd->pos == ctx->pos)").
> 
> > I don't really follow how the resume variable can help at all.
> > Probably, I am missing the case. Could you please explain the issue
> > at
> > first?
> 
> resume tells apart the two ways the function finds the next record:
> from the key that the previous call saved (rd->key), or by counting
> records from the start of the directory with ctx->pos. It is the
> condition the current code already uses to choose between them, only
> computed at the start of the function.
> 
> When the call continues from the saved key, ctx->pos no longer says
> where the walk is in the directory, because entries returned by
> earlier calls may have been deleted. So comparing it with i_size
> cannot tell if the directory has ended. The patch skips the three
> i_size checks for such a call, and ends the walk when the next record
> belongs to another parent or the catalog has no more records.
> 
> A call that finds its position with ctx->pos (the first call, or a
> call after lseek()) keeps the i_size checks and the "walked past end
> of dir" error as they are.
> 
> 

Frankly speaking, I dislike the resume variable way. It looks really
confusing. And, as far as I can see, you used it in two/three different
contexts. If I understood correctly, we are checking three conditions:
(1) Is current position correct? -> rd->pos == file->f_pos;
(2) Has directory content processed? -> ctx->pos >= inode->i_size;
(3) Is it last directory's item? -> err == -ENOENT.
Could we introduce dedicated inline functions for these checks? The
code will be more clear and easy to understand then. What do you think?

And, please, explain the problem with more details in the commit
message.

Thanks,
Slava.

      reply	other threads:[~2026-11-16 22:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 11:17 [PATCH 0/2] hfs, hfsplus: do not end readdir early " Hengyu Liang
2026-11-12 11:17 ` [PATCH 1/2] hfs: do not end readdir at i_size " Hengyu Liang
2026-11-12 20:45   ` Viacheslav Dubeyko
2026-11-14 12:50     ` Hengyu Liang
2026-11-12 11:17 ` [PATCH 2/2] hfsplus: " Hengyu Liang
2026-11-12 20:44   ` Viacheslav Dubeyko
2026-11-14 12:50     ` Hengyu Liang
2026-11-16 22:30       ` Viacheslav Dubeyko [this message]

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=446748647839fd554246a78d72be728069b44b7a.camel@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=hengyul@cs.unc.edu \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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

all inboxes | Powered by JetHome®