All of lore.kernel.org
 help / color / mirror / Atom feed
From: bugzilla-daemon@bugzilla.kernel.org
To: linux-ext4@kernel.org
Subject: [Bug 196405] mkdir mishandles st_nlink in ext4 directory with 64997 subdirectories
Date: Tue, 25 Jul 2017 08:56:05 +0000	[thread overview]
Message-ID: <bug-196405-13602-oUQg4Y8Vvz@https.bugzilla.kernel.org/> (raw)
In-Reply-To: <bug-196405-13602@https.bugzilla.kernel.org/>

https://bugzilla.kernel.org/show_bug.cgi?id=196405

--- Comment #26 from Paul Eggert (eggert@cs.ucla.edu) ---
(In reply to Theodore Tso from comment #18)
> One of the things which confuses me is why you think there's so much
> code which tries to use the st_nlink hack.  It's ***much*** simpler to
> just rely on d_type if it exists (and it does on most systems).

This is true only for one particular optimization; it is not true for others.
For example, Gnulib takes advantage of the fact a directory with st_nlink==2
has no subdirectories, if the directory is in a file system where this
optimizatino is known to work. One can't easily use d_type for this.

> 1) The assumption that st_nlink always has the property that it is >2
>    and can be used to derive the number of subdirectories was never
>    valid across all file system types

Yes, and Gnulib exploits the st_nlink assumption only on file systems where it
is useful and/or known to work.

> 2) If you did descend into a file system which didn't support d_type,
>    d_type would be DT_UNKNOWN instead of DT_REG or DT_DIR

Yes, and Gnulib doesn't use the optimization if d_type is DT_UNKNOWN.

> 3) Using DT_DIR is means you can skip the stat check for all directory
>    entries.  If you are doing a recursive descent where you care about
>    the name, you need to call readdir() on all of the directory
>    entries anyway, so you will have access to d_type.  If you are
>    doing a recursive descent where you are checking on file ownership,
>    you are doing the stat(2) anyway, so why not check
>    S_ISDIR(st.st_mode) instead of blindly using the st_nlink hack?

No, you can do even better than that in some cases, if st_nlink works. Suppose
we are implementing the equivalent of 'find . -type d'. If we come across a
directory whose st_nlink == 2, then we don't need to readdir from the directory
at all, much less stat its entries.

> 4) ... if your argument is what about legacy Unix code

There is more of that floating around than I'd like, yes. But I'm mostly
worried about GNU code.

> Can you give me a pointer to the original bug report?  I'm curious how
> things were misbehaving.

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27739

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

  parent reply	other threads:[~2017-07-25  8:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-17 21:23 [Bug 196405] New: mkdir mishandles st_nlink in ext4 directory with 64997 subdirectories bugzilla-daemon
2017-07-18 19:41 ` [Bug 196405] " bugzilla-daemon
2017-07-18 21:07 ` bugzilla-daemon
2017-07-18 21:37 ` bugzilla-daemon
2017-07-18 21:54 ` bugzilla-daemon
2017-07-18 21:57 ` bugzilla-daemon
2017-07-18 22:19 ` bugzilla-daemon
2017-07-18 23:12 ` bugzilla-daemon
2017-07-18 23:15 ` bugzilla-daemon
2017-07-19  5:35 ` bugzilla-daemon
2017-07-19  8:02 ` bugzilla-daemon
2017-07-19 14:49 ` bugzilla-daemon
2017-07-19 19:44 ` bugzilla-daemon
2017-07-19 19:59 ` bugzilla-daemon
2017-07-19 22:22 ` bugzilla-daemon
2017-07-20  0:59 ` bugzilla-daemon
2017-07-21  7:48 ` bugzilla-daemon
2017-07-21  8:22 ` bugzilla-daemon
2017-07-21 15:25 ` bugzilla-daemon
2017-07-21 18:34 ` bugzilla-daemon
2017-07-21 21:14 ` bugzilla-daemon
2017-07-21 21:47 ` bugzilla-daemon
2017-07-22 14:41 ` bugzilla-daemon
2017-07-23 16:23 ` bugzilla-daemon
2017-07-23 22:55 ` bugzilla-daemon
2017-07-24 18:48 ` bugzilla-daemon
2017-07-25  8:56 ` bugzilla-daemon [this message]
2017-07-25  9:05 ` bugzilla-daemon

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=bug-196405-13602-oUQg4Y8Vvz@https.bugzilla.kernel.org/ \
    --to=bugzilla-daemon@bugzilla.kernel.org \
    --cc=linux-ext4@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.