* Re* ext3: fix ext3_dx_readdir hash collision handling - Regression
[not found] ` <alpine.LFD.2.00.0810240853310.3287@nehalem.linux-foundation.org>
@ 2008-10-24 22:00 ` Junio C Hamano
2008-10-24 22:26 ` Linus Torvalds
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2008-10-24 22:00 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
Linus Torvalds <torvalds@linux-foundation.org> writes:
> The "git buglet" looks liek this:
>
> - build a kernel
>
> - do "git clean -dqfx". This fails with
>
> warning: failed to remove 'include/config/'
>
> - do "git clean -dqfx" again. And now it works - apparently because the
> first invocation deleted enough of the big directory.
>
> Doing an 'strace' to see what is going on, I see:
>
> ..
> getdents(3, /* 132 entries */, 4096) = 3888
> lstat("include/config/sgi", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
> open("include/config/sgi", O_RDONLY|O_NONBLOCK|O_DIRECTORY|0x80000) = 4
> fstat(4, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
> getdents(4, /* 3 entries */, 4096) = 80
> lstat("include/config/sgi/partition.h", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
> unlink("include/config/sgi/partition.h") = 0
> getdents(4, /* 0 entries */, 4096) = 0
> close(4) = 0
> rmdir("include/config/sgi") = 0
> lstat("include/config/sgi", 0x7fffdc4d2110) = -1 ENOENT (No such file or directory)
> close(3) = 0
> write(2, "warning: failed to remove \'include/config/\'\n", 44) = 44
> ..
>
> and notice how it does that
>
> lstat("include/config/sgi", ..
>
> _twice_. That, in turn (knowing the git implementation), implies that it
> was returned twice from that first "getdents(3, ...)" call.
>
> So what git clean does is to scan over the readdir() return values, see if
> it's a file it knows about, try to remove it if not, lstat() every entry,
> recurse into them if they are directories, and then remove it. If the
> lstat() fails, "git clean" will fail.
Hmm, interesting.
-- >8 --
Subject: allow readdir(3) to return the same entry twice
When removing a large directory recursively, repeatedly running unlink(2)
on what we read from readdir(3) can cause readdir(3) (or underlying
getdents(2)) to return the same entry twice. If we have already removed
it, running lstat() on the entry would fail with ENOENT, but there is no
harm if we ignore such an error.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
dir.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git i/dir.c w/dir.c
index 0131983..293df4e 100644
--- i/dir.c
+++ w/dir.c
@@ -800,8 +800,11 @@ int remove_dir_recursively(struct strbuf *path, int only_empty)
strbuf_setlen(path, len);
strbuf_addstr(path, e->d_name);
- if (lstat(path->buf, &st))
- ; /* fall thru */
+ if (lstat(path->buf, &st)) {
+ if (errno == ENOENT)
+ continue;
+ /* otherwise fall thru */
+ }
else if (S_ISDIR(st.st_mode)) {
if (!remove_dir_recursively(path, only_empty))
continue; /* happy */
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: Re* ext3: fix ext3_dx_readdir hash collision handling - Regression
2008-10-24 22:00 ` Re* ext3: fix ext3_dx_readdir hash collision handling - Regression Junio C Hamano
@ 2008-10-24 22:26 ` Linus Torvalds
2008-10-24 22:35 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2008-10-24 22:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Fri, 24 Oct 2008, Junio C Hamano wrote:
>
> Subject: allow readdir(3) to return the same entry twice
The thing is, this really is a kernel bug. We have even bisected it (and
it hasn't hit any released kernel). The original reporter showed it with a
simple "rm -r".
So it really isn't a git bug, even though I initially thought it might be,
before I looked closer.
That said, the git patch may be worth it just because two *concurrent*
invocations of "git clean" could then cause one (or both) to fail this
way.
Linus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Re* ext3: fix ext3_dx_readdir hash collision handling - Regression
2008-10-24 22:26 ` Linus Torvalds
@ 2008-10-24 22:35 ` Junio C Hamano
0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2008-10-24 22:35 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
Linus Torvalds <torvalds@linux-foundation.org> writes:
> On Fri, 24 Oct 2008, Junio C Hamano wrote:
>>
>> Subject: allow readdir(3) to return the same entry twice
>
> The thing is, this really is a kernel bug. We have even bisected it (and
> it hasn't hit any released kernel). The original reporter showed it with a
> simple "rm -r".
>
> So it really isn't a git bug, even though I initially thought it might be,
> before I looked closer.
>
> That said, the git patch may be worth it just because two *concurrent*
> invocations of "git clean" could then cause one (or both) to fail this
> way.
Yeah, or on perhaps a buggy implementation of readdir(3) on somebody
else's system. In either case, I just thought it might be a low impact
belt-and-suspenders fix that is worth considering.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-24 22:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20081022093201.GA2227@gentoox2.trippelsdorf.de>
[not found] ` <20081023032832.GE10369@mit.edu>
[not found] ` <20081023063740.GA2438@gentoox2.trippelsdorf.de>
[not found] ` <20081024000109.GD7842@mit.edu>
[not found] ` <20081024042851.GA2360@gentoox2.trippelsdorf.de>
[not found] ` <alpine.LFD.2.00.0810240853310.3287@nehalem.linux-foundation.org>
2008-10-24 22:00 ` Re* ext3: fix ext3_dx_readdir hash collision handling - Regression Junio C Hamano
2008-10-24 22:26 ` Linus Torvalds
2008-10-24 22:35 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).