|
|
e63663 |
From b9f9ed14bda93ecb407129b69e6476813c250046 Mon Sep 17 00:00:00 2001
|
|
|
e63663 |
From: Paul Eggert <eggert@cs.ucla.edu>
|
|
|
e63663 |
Date: Wed, 15 Apr 2020 20:50:32 -0700
|
|
|
e63663 |
Subject: [PATCH] fts: remove NOSTAT_LEAF_OPTIMIZATION
|
|
|
e63663 |
MIME-Version: 1.0
|
|
|
e63663 |
Content-Type: text/plain; charset=UTF-8
|
|
|
e63663 |
Content-Transfer-Encoding: 8bit
|
|
|
e63663 |
|
|
|
e63663 |
It caused ‘find’ and ‘du’ to dump core, and it was useful
|
|
|
e63663 |
only for obsolescent Linux filesystems anyway. Problem reported in:
|
|
|
e63663 |
https://lists.gnu.org/r/bug-gnulib/2020-04/msg00068.html
|
|
|
e63663 |
Quite possibly there is still a serious underlying fts bug with
|
|
|
e63663 |
tight-loop-check and mutating file systems, but if so this patch
|
|
|
e63663 |
should cause the bug to be triggered less often.
|
|
|
e63663 |
* lib/fts.c (enum leaf_optimization): Remove
|
|
|
e63663 |
NOSTAT_LEAF_OPTIMIZATION, as it’s problematic.
|
|
|
e63663 |
(S_MAGIC_REISERFS, S_MAGIC_XFS): Remove; no longer needed.
|
|
|
e63663 |
(leaf_optimization): Remove special cases for ReiserFS and XFS.
|
|
|
e63663 |
(fts_read): Remove NOSTAT_LEAF_OPTIMIZATION code.
|
|
|
e63663 |
* lib/fts_.h (struct _ftsent.fts_n_dirs_remaining):
|
|
|
e63663 |
Remove. All uses removed.
|
|
|
e63663 |
|
|
|
e63663 |
Upstream-commit: 47bf2cf3184027c1eb9c1dfeea5c5b8b2d69710d
|
|
|
e63663 |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
e63663 |
---
|
|
|
e63663 |
lib/fts.c | 56 ++++++++-------------------------------------------
|
|
|
e63663 |
lib/fts_.h | 5 -----
|
|
|
e63663 |
2 files changed, 8 insertions(+), 53 deletions(-)
|
|
|
e63663 |
|
|
|
e63663 |
diff --git a/lib/fts.c b/lib/fts.c
|
|
|
e63663 |
index 1093ce5..dfe3fef 100644
|
|
|
e63663 |
--- a/lib/fts.c
|
|
|
e63663 |
+++ b/lib/fts.c
|
|
|
e63663 |
@@ -445,7 +445,6 @@ fts_open (char * const *argv,
|
|
|
e63663 |
if ((parent = fts_alloc(sp, "", 0)) == NULL)
|
|
|
e63663 |
goto mem2;
|
|
|
e63663 |
parent->fts_level = FTS_ROOTPARENTLEVEL;
|
|
|
e63663 |
- parent->fts_n_dirs_remaining = -1;
|
|
|
e63663 |
}
|
|
|
e63663 |
|
|
|
e63663 |
/* The classic fts implementation would call fts_stat with
|
|
|
e63663 |
@@ -634,9 +633,8 @@ fts_close (FTS *sp)
|
|
|
e63663 |
}
|
|
|
e63663 |
|
|
|
e63663 |
/* Minimum link count of a traditional Unix directory. When leaf
|
|
|
e63663 |
- optimization is OK and MIN_DIR_NLINK <= st_nlink, then st_nlink is
|
|
|
e63663 |
- an upper bound on the number of subdirectories (counting "." and
|
|
|
e63663 |
- ".."). */
|
|
|
e63663 |
+ optimization is OK and a directory's st_nlink == MIN_DIR_NLINK,
|
|
|
e63663 |
+ then the directory has no subdirectories. */
|
|
|
e63663 |
enum { MIN_DIR_NLINK = 2 };
|
|
|
e63663 |
|
|
|
e63663 |
/* Whether leaf optimization is OK for a directory. */
|
|
|
e63663 |
@@ -645,12 +643,8 @@ enum leaf_optimization
|
|
|
e63663 |
/* st_nlink is not reliable for this directory's subdirectories. */
|
|
|
e63663 |
NO_LEAF_OPTIMIZATION,
|
|
|
e63663 |
|
|
|
e63663 |
- /* Leaf optimization is OK, but is not useful for avoiding stat calls. */
|
|
|
e63663 |
- OK_LEAF_OPTIMIZATION,
|
|
|
e63663 |
-
|
|
|
e63663 |
- /* Leaf optimization is not only OK: it is useful for avoiding
|
|
|
e63663 |
- stat calls, because dirent.d_type does not work. */
|
|
|
e63663 |
- NOSTAT_LEAF_OPTIMIZATION
|
|
|
e63663 |
+ /* st_nlink == 2 means the directory lacks subdirectories. */
|
|
|
e63663 |
+ OK_LEAF_OPTIMIZATION
|
|
|
e63663 |
};
|
|
|
e63663 |
|
|
|
e63663 |
#if (defined __linux__ || defined __ANDROID__) \
|
|
|
e63663 |
@@ -663,9 +657,7 @@ enum leaf_optimization
|
|
|
e63663 |
# define S_MAGIC_CIFS 0xFF534D42
|
|
|
e63663 |
# define S_MAGIC_NFS 0x6969
|
|
|
e63663 |
# define S_MAGIC_PROC 0x9FA0
|
|
|
e63663 |
-# define S_MAGIC_REISERFS 0x52654973
|
|
|
e63663 |
# define S_MAGIC_TMPFS 0x1021994
|
|
|
e63663 |
-# define S_MAGIC_XFS 0x58465342
|
|
|
e63663 |
|
|
|
e63663 |
# ifdef HAVE___FSWORD_T
|
|
|
e63663 |
typedef __fsword_t fsword;
|
|
|
e63663 |
@@ -786,23 +778,15 @@ dirent_inode_sort_may_be_useful (FTSENT const *p, int dir_fd)
|
|
|
e63663 |
}
|
|
|
e63663 |
|
|
|
e63663 |
/* Given an FTS entry P for a directory with descriptor DIR_FD,
|
|
|
e63663 |
- return true if it is both useful and valid to apply leaf optimization.
|
|
|
e63663 |
- The optimization is useful only for file systems that lack usable
|
|
|
e63663 |
- dirent.d_type info. The optimization is valid if an st_nlink value
|
|
|
e63663 |
- of at least MIN_DIR_NLINK is an upper bound on the number of
|
|
|
e63663 |
- subdirectories of D, counting "." and ".." as subdirectories.
|
|
|
e63663 |
+ return whether it is valid to apply leaf optimization.
|
|
|
e63663 |
+ The optimization is valid if a directory's st_nlink value equal
|
|
|
e63663 |
+ to MIN_DIR_NLINK means the directory has no subdirectories.
|
|
|
e63663 |
DIR_FD is negative if unavailable. */
|
|
|
e63663 |
static enum leaf_optimization
|
|
|
e63663 |
leaf_optimization (FTSENT const *p, int dir_fd)
|
|
|
e63663 |
{
|
|
|
e63663 |
switch (filesystem_type (p, dir_fd))
|
|
|
e63663 |
{
|
|
|
e63663 |
- /* List here the file system types that may lack usable dirent.d_type
|
|
|
e63663 |
- info, yet for which the optimization does apply. */
|
|
|
e63663 |
- case S_MAGIC_REISERFS:
|
|
|
e63663 |
- case S_MAGIC_XFS: /* XFS lacked it until 2013-08-22 commit. */
|
|
|
e63663 |
- return NOSTAT_LEAF_OPTIMIZATION;
|
|
|
e63663 |
-
|
|
|
e63663 |
case 0:
|
|
|
e63663 |
/* Leaf optimization is unsafe if the file system type is unknown. */
|
|
|
e63663 |
FALLTHROUGH;
|
|
|
e63663 |
@@ -1027,26 +1011,7 @@ check_for_dir:
|
|
|
e63663 |
if (p->fts_info == FTS_NSOK)
|
|
|
e63663 |
{
|
|
|
e63663 |
if (p->fts_statp->st_size == FTS_STAT_REQUIRED)
|
|
|
e63663 |
- {
|
|
|
e63663 |
- FTSENT *parent = p->fts_parent;
|
|
|
e63663 |
- if (parent->fts_n_dirs_remaining == 0
|
|
|
e63663 |
- && ISSET(FTS_NOSTAT)
|
|
|
e63663 |
- && ISSET(FTS_PHYSICAL)
|
|
|
e63663 |
- && (leaf_optimization (parent, sp->fts_cwd_fd)
|
|
|
e63663 |
- == NOSTAT_LEAF_OPTIMIZATION))
|
|
|
e63663 |
- {
|
|
|
e63663 |
- /* nothing more needed */
|
|
|
e63663 |
- }
|
|
|
e63663 |
- else
|
|
|
e63663 |
- {
|
|
|
e63663 |
- p->fts_info = fts_stat(sp, p, false);
|
|
|
e63663 |
- if (S_ISDIR(p->fts_statp->st_mode)
|
|
|
e63663 |
- && p->fts_level != FTS_ROOTLEVEL
|
|
|
e63663 |
- && 0 < parent->fts_n_dirs_remaining
|
|
|
e63663 |
- && parent->fts_n_dirs_remaining != (nlink_t) -1)
|
|
|
e63663 |
- parent->fts_n_dirs_remaining--;
|
|
|
e63663 |
- }
|
|
|
e63663 |
- }
|
|
|
e63663 |
+ p->fts_info = fts_stat(sp, p, false);
|
|
|
e63663 |
else
|
|
|
e63663 |
fts_assert (p->fts_statp->st_size == FTS_NO_STAT_REQUIRED);
|
|
|
e63663 |
}
|
|
|
e63663 |
@@ -1830,11 +1795,6 @@ err: memset(sbp, 0, sizeof(struct stat));
|
|
|
e63663 |
}
|
|
|
e63663 |
|
|
|
e63663 |
if (S_ISDIR(sbp->st_mode)) {
|
|
|
e63663 |
- p->fts_n_dirs_remaining
|
|
|
e63663 |
- = ((sbp->st_nlink < MIN_DIR_NLINK
|
|
|
e63663 |
- || p->fts_level <= FTS_ROOTLEVEL)
|
|
|
e63663 |
- ? -1
|
|
|
e63663 |
- : sbp->st_nlink - (ISSET (FTS_SEEDOT) ? 0 : MIN_DIR_NLINK));
|
|
|
e63663 |
if (ISDOT(p->fts_name)) {
|
|
|
e63663 |
/* Command-line "." and ".." are real directories. */
|
|
|
e63663 |
return (p->fts_level == FTS_ROOTLEVEL ? FTS_D : FTS_DOT);
|
|
|
e63663 |
diff --git a/lib/fts_.h b/lib/fts_.h
|
|
|
e63663 |
index d40a116..2e76cc4 100644
|
|
|
e63663 |
--- a/lib/fts_.h
|
|
|
e63663 |
+++ b/lib/fts_.h
|
|
|
e63663 |
@@ -227,11 +227,6 @@ typedef struct _ftsent {
|
|
|
e63663 |
|
|
|
e63663 |
size_t fts_namelen; /* strlen(fts_name) */
|
|
|
e63663 |
|
|
|
e63663 |
- /* If not (nlink_t) -1, an upper bound on the number of
|
|
|
e63663 |
- remaining subdirectories of interest. If this becomes
|
|
|
e63663 |
- zero, some work can be avoided. */
|
|
|
e63663 |
- nlink_t fts_n_dirs_remaining;
|
|
|
e63663 |
-
|
|
|
e63663 |
# define FTS_D 1 /* preorder directory */
|
|
|
e63663 |
# define FTS_DC 2 /* directory that causes cycles */
|
|
|
e63663 |
# define FTS_DEFAULT 3 /* none of the above */
|
|
|
e63663 |
--
|
|
|
e63663 |
2.21.1
|
|
|
e63663 |
|