Thomas Trauner | 1 Aug 2008 11:43

duplicate entries on ext3 when using readdir/readdir64

Hello,

I have a problem with directories that contain more than 10000 entries
(Ubuntu 8.04.1) or with more than 70000 entries (RHEL 5.2). If you use
readdir(3) or readdir64(3) you get one entry twice, with same name and
inode.

Some analyzing showed that disabling dir_index solves this problem, but
I think that this is a bug in the ext3 code, as no other file-system
shows this behavior.

I've found the following regarding this bug, but nothing about whether
if it is fixed nor if a back-port for older 2.6 kernels exists.

<https://www.redhat.com/archives/ext3-users/2007-December/msg00004.html>
and
<http://episteme.arstechnica.com/eve/forums/a/tpc/f/96509133/m/199007643931?r=494000843931#494000843931>

On linux-fsdevel I've found the following, but they delete directory
entries in between multiple readdir calls.

<http://kerneltrap.org/mailarchive/linux-fsdevel/2005/9/15/310258>

Does anyone know where I could find more information or report this bug?

Thanks in advance!
Regards.
Tom Trauner
Theodore Tso | 1 Aug 2008 14:16
Picon
Picon
Favicon
Gravatar

Re: duplicate entries on ext3 when using readdir/readdir64

On Fri, Aug 01, 2008 at 11:43:40AM +0200, Thomas Trauner wrote:
> 
> I have a problem with directories that contain more than 10000 entries
> (Ubuntu 8.04.1) or with more than 70000 entries (RHEL 5.2). If you use
> readdir(3) or readdir64(3) you get one entry twice, with same name and
> inode.
> 

How reproducible is this; can you reproduce it on this one filesystem?
Can you reproduce it on multiple filesystems?  What sort of file names
are you using?

Also, are you testing by using "ls", or do you have your own program
getting the names of the files.  If the latter, are you using
telldir()/seekdir() in any way?

						- Ted
Thomas Trauner | 1 Aug 2008 16:00

Re: duplicate entries on ext3 when using readdir/readdir64

On Fri, 2008-08-01 at 08:16 -0400, Theodore Tso wrote:
> On Fri, Aug 01, 2008 at 11:43:40AM +0200, Thomas Trauner wrote:
> > 
> > I have a problem with directories that contain more than 10000 entries
> > (Ubuntu 8.04.1) or with more than 70000 entries (RHEL 5.2). If you use
> > readdir(3) or readdir64(3) you get one entry twice, with same name and
> > inode.
> > 
> 
> How reproducible is this; can you reproduce it on this one filesystem?
> Can you reproduce it on multiple filesystems?  What sort of file names
> are you using?

Every time I tried. It is reproducible on the same filesystem, and also on other
systems with different filesystem sizes and usage patterns.
It showed up when on of our own script working through a Subversion directory failed.

File names are numbers, starting with "0" counting up.

> Also, are you testing by using "ls", or do you have your own program
> getting the names of the files.  If the latter, are you using
> telldir()/seekdir() in any way?

I'm testing with 'ls|sort -n|uniq -d' and also with a simple program
that simply counts how often readdir can be called.

> 						- Ted
> 

Tom
(Continue reading)

Eric Sandeen | 1 Aug 2008 16:47
Picon
Favicon
Gravatar

Re: duplicate entries on ext3 when using readdir/readdir64

Thomas Trauner wrote:
> On Fri, 2008-08-01 at 08:16 -0400, Theodore Tso wrote:
>> On Fri, Aug 01, 2008 at 11:43:40AM +0200, Thomas Trauner wrote:
>>> I have a problem with directories that contain more than 10000 entries
>>> (Ubuntu 8.04.1) or with more than 70000 entries (RHEL 5.2). If you use
>>> readdir(3) or readdir64(3) you get one entry twice, with same name and
>>> inode.
>>>
>> How reproducible is this; can you reproduce it on this one filesystem?
>> Can you reproduce it on multiple filesystems?  What sort of file names
>> are you using?
> 
> Every time I tried. It is reproducible on the same filesystem, and also on other
> systems with different filesystem sizes and usage patterns.
> It showed up when on of our own script working through a Subversion directory failed.
> 
> File names are numbers, starting with "0" counting up.
> 
>> Also, are you testing by using "ls", or do you have your own program
>> getting the names of the files.  If the latter, are you using
>> telldir()/seekdir() in any way?
> 
> I'm testing with 'ls|sort -n|uniq -d' and also with a simple program
> that simply counts how often readdir can be called.
> 

Hm, a bog-simple test here doesn't show any trouble:

[root <at> inode dirtest]# for I in `seq 0 10500`; do touch $I; done
[root <at> inode dirtest]# ls | sort -n | uniq -d
(Continue reading)

Thomas Trauner | 4 Aug 2008 09:48

Re: duplicate entries on ext3 when using readdir/readdir64

On Fri, 2008-08-01 at 09:47 -0500, Eric Sandeen wrote:
> Hm, a bog-simple test here doesn't show any trouble:
> 
> [root <at> inode dirtest]# for I in `seq 0 10500`; do touch $I; done
> [root <at> inode dirtest]# ls | sort -n | uniq -d
> [root <at> inode dirtest]# ls | wc -l
> 10501
> 
> does that reflect what you're doing?  Do you have a testcase you can share?

Yes, but I've written incorrect values, sorry. It's a little bit higher,
a run of my program outputs this on 2.6.24-19-generic (ubuntu 8.04.1):

expected 11778 files, but readdir reports 11779
expected 11862 files, but readdir64 reports 11863

And on 2.6.18-92.1.6.el5 (rhel 5.2):
expected 72922 files, but readdir reports 72923
expected 73131 files, but readdir64 reports 73132

The testcase is here: <http://www.unet.univie.ac.at/~a9100884/readdir.c>
> -Eric

Tom
Thomas Trauner | 5 Aug 2008 12:53

Re: duplicate entries on ext3 when using readdir/readdir64

On Fri, 2008-08-01 at 08:16 -0400, Theodore Tso wrote:
> On Fri, Aug 01, 2008 at 11:43:40AM +0200, Thomas Trauner wrote:
> > 
> > I have a problem with directories that contain more than 10000 entries
> > (Ubuntu 8.04.1) or with more than 70000 entries (RHEL 5.2). If you use
> > readdir(3) or readdir64(3) you get one entry twice, with same name and
> > inode.
> > 
> 
> How reproducible is this; can you reproduce it on this one filesystem?
> Can you reproduce it on multiple filesystems?  What sort of file names
> are you using?

I made new tests with the code under
<http://www.unet.univie.ac.at/~a9100884/readdir.c> on a bunch of freshly
generated and empty filesystems, every about 38GB large, of type fat
(aborted after about 22000 entries because it took to long), ext2, xfs,
jfs and again ext3. All tests made with 2.6.24-19-generic (ubuntu
8.04.1).

I also tried minix fs, just for fun, but I could only create 126 files.

Ext3 shows the same effect as before, but at 103033 entries (readdir)
and 104136 entries (readdir64). 'ls|sort -n|uniq -d' output (ls uses
getdents64, so I asume it uses readdir64, but I don't checked the ls
source):

        root <at> darfnix:/readdir/ext3/testdir# ls|sort -n|uniq -d
        102456
        root <at> darfnix:/readdir/ext3/testdir# 
(Continue reading)

Theodore Tso | 6 Aug 2008 06:46
Picon
Picon
Favicon
Gravatar

Re: duplicate entries on ext3 when using readdir/readdir64

On Tue, Aug 05, 2008 at 12:53:51PM +0200, Thomas Trauner wrote:
> > How reproducible is this; can you reproduce it on this one filesystem?
> > Can you reproduce it on multiple filesystems?  What sort of file names
> > are you using?
> 
> I made new tests with the code under
> <http://www.unet.univie.ac.at/~a9100884/readdir.c> on a bunch of freshly
> generated and empty filesystems, every about 38GB large, of type fat
> (aborted after about 22000 entries because it took to long), ext2, xfs,
> jfs and again ext3. All tests made with 2.6.24-19-generic (ubuntu
> 8.04.1).

I was able to reproduce using ext3.  It looks like it's caused by a
hash collision; but ext3 has code that's supposed to avoid returning a
directory entry doubled in this fashion.  I'll have to look into it.

	  		   		       - Ted
Thomas Trauner | 6 Aug 2008 15:33

Re: duplicate entries on ext3 when using readdir/readdir64

On Wed, 2008-08-06 at 00:46 -0400, Theodore Tso wrote:
> I was able to reproduce using ext3.  It looks like it's caused by a
> hash collision; but ext3 has code that's supposed to avoid returning a
> directory entry doubled in this fashion.  I'll have to look into it.
> 
> 	  		   		       - Ted

Thank you.

Tom
Theodore Tso | 6 Aug 2008 16:07
Picon
Picon
Favicon

Re: duplicate entries on ext3 when using readdir/readdir64

On Tue, Aug 05, 2008 at 12:53:51PM +0200, Thomas Trauner wrote:
> On Fri, 2008-08-01 at 08:16 -0400, Theodore Tso wrote:
> > On Fri, Aug 01, 2008 at 11:43:40AM +0200, Thomas Trauner wrote:
> > > 
> > > I have a problem with directories that contain more than 10000 entries
> > > (Ubuntu 8.04.1) or with more than 70000 entries (RHEL 5.2). If you use
> > > readdir(3) or readdir64(3) you get one entry twice, with same name and
> > > inode.
> > > 
> I made new tests with the code under
> <http://www.unet.univie.ac.at/~a9100884/readdir.c> on a bunch of freshly
> generated and empty filesystems, every about 38GB large, of type fat
> (aborted after about 22000 entries because it took to long), ext2, xfs,
> jfs and again ext3....

OK, I have a workaroud for you.  It appears there's a kernel bug
hiding here, since there shouldn't be duplicates returned by readdir()
even if we have hash collisions.  

It turns out though that the TEA hash we are currently using as the
default is a really sucky hash.  I can't remember who suggested it; I
may go looking in the archives just out of curiosity.  My fault,
though, I should have tested it much more thoroughly, although it
*looked* good, and it was take from the core of an encryption
algorithm, so I thought it would be OK.

The claim was that it was just as good for our purposes as the
cut-down md4 hash we were using, but it was faster (so it would burn
less cpu cycles).  Unfortunately, (a) at least on modern hardware (I
tested on an X61s laptop) the TEA hash is in fact a little slower, and
(Continue reading)

Theodore Tso | 6 Aug 2008 16:45
Picon
Picon
Favicon

Re: duplicate entries on ext3 when using readdir/readdir64

On Mon, Aug 04, 2008 at 09:48:39AM +0200, Thomas Trauner wrote:
> Yes, but I've written incorrect values, sorry. It's a little bit higher,
> a run of my program outputs this on 2.6.24-19-generic (ubuntu 8.04.1):
> 
> expected 11778 files, but readdir reports 11779
> expected 11862 files, but readdir64 reports 11863
> 
> And on 2.6.18-92.1.6.el5 (rhel 5.2):
> expected 72922 files, but readdir reports 72923
> expected 73131 files, but readdir64 reports 73132

BTW, I doubt the difference in what you had on your Ubuntu and RHEL
system has anything to do with the kernel version or the distribution,
but just the luck of the draw.  If you run "dumpe2fs -h /dev/sdXX |
grep "Hash Seed" from both systms, and then take that uuid and feed it
to the tst_hash program via the -s option, you'll probably see it was
simply the different directory hash seed which is changing when the
first collision happened:

%./tst_hash -s 27e0ed94-069c-44c0-bea0-044b1a8d7bcc 
hash collision: 142886, 142987: 7104d654:131c0700
hash collision: 188030, 188131: aefe1dc2:f7517103
hash collision: 14020, 14031: fc717efa:87ce3eaa
hash collision: 120336, 120732: 34c3f1b6:cee72d50
4 collisions

vs.

% ./tst_hash -s 7089e459-07c2-43cc-b25f-bafdcce9cd05
hash collision: 167469, 167568: 4de08834:3fa2a17a
(Continue reading)


Gmane