Hello,

we've discussed with Jim the issue with mounts triggered during directory
tree traversal and we've decided to make a trade-off for now - enable the 
extra stat call only if the FTS_TIGHT_CYCLE_CHECK is set. This means it only 
affects find and du for now and leaves other utilities to work as they used
to work before (failing on the triggered mount). I think this is a good
enough temporary solution since we are still waiting for reply from the
kernel guys.

As for the indentation, I've attempted to do my best. Indentation of the 
fts_build() has been already broken completely. So please don't shout at me
I screwed it up :-)

Kamil
From 239d400abe783ad297b547e4e5a281cc1613ef70 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdu...@redhat.com>
Date: Tue, 10 Nov 2009 14:26:56 +0100
Subject: [PATCH] fts: do not fail on a submount during traversal

* lib/fts.c (fts_build): Read the stat info again after opening
a directory if the FTS_TIGHT_CYCLE_CHECK flag is set.
Original report at http://bugzilla.redhat.com/501848.
---
 ChangeLog |    7 +++++++
 lib/fts.c |   14 ++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 599a2ab..2ecd268 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-11-10  Kamil Dudka  <kdu...@redhat.com>
+
+	fts: do not fail on a submount during traversal
+	* lib/fts.c (fts_build): Read the stat info again after opening
+	a directory if the FTS_TIGHT_CYCLE_CHECK flag is set.
+	Original report at http://bugzilla.redhat.com/501848.
+
 2009-11-09  Eric Blake  <e...@byu.net>
 
 	rename: detect FreeBSD bug
diff --git a/lib/fts.c b/lib/fts.c
index 40a837e..6720946 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1268,6 +1268,20 @@ fts_build (register FTS *sp, int type)
 	  opening it.  */
        if (cur->fts_info == FTS_NSOK)
 	 cur->fts_info = fts_stat(sp, cur, false);
+       else if (sp->fts_options & FTS_TIGHT_CYCLE_CHECK) {
+		/* Now read the stat info again after opening a directory to
+		 * reveal eventual changes caused by a submount triggered by
+		 * the traverse.  But do it only for utilities which use
+		 * FTS_TIGHT_CYCLE_CHECK.  Therefore only find and du can
+		 * benefit from this feature for now.
+		 */
+		LEAVE_DIR (sp, cur, "4");
+		fts_stat (sp, cur, false);
+		if (! enter_dir (sp, cur)) {
+			 __set_errno (ENOMEM);
+			 return NULL;
+		}
+	}
 
 	/*
 	 * Nlinks is the number of possible entries of type directory in the
-- 
1.6.2.5

Reply via email to