2009-08-30 15:13:02

by Andreas Schlick

[permalink] [raw]
Subject: [PATCH 0/2] Fix wrong name_len and file_type in intermediate htree nodes

Hello,

while testing the dirshrink patch, I found that sometimes intermediate htree
nodes end up with their fake_dirent's name_len and file_type not being zero.
e2fsck will then consider the htree to be corrupted as it doesn't recognise
that these blocks contain dx_nodes.

As far as I understand it, this happens sometimes when ext4_dx_add_entry() has
to create a new index node and calls ext4_append(). In the end ext4_getblk()
is called and it might get a buffer that has BH_Uptodate set, causing
ext4_getblk() to not zero it out and leave the old content intact.

I can reproduce this with plain linux-2.6.30.5. To produce this I use a nearly
full filesystem and continuously create new files in one directory while
removing other directories/files at the same time.

Do I understand it correctly, that it happens when the newly allocated block
(for the new index node) was very recently used by another file/directory, so
that it is still in the buffer cache? But it surprises me that it doesn't
happen more often.

Andreas Schlick



2009-08-30 15:13:03

by Andreas Schlick

[permalink] [raw]
Subject: [PATCH 1/2] ext4: Always set dx_node's fake_dirent explicitly.

When ext4_dx_add_entry() has to split an index node, it has to ensure that
name_len of dx_node's fake_dirent is also zero, because otherwise e2fsck
won't recognise it as an intermediate htree node and consider the htree to
be corrupted.

Signed-off-by: Andreas Schlick <[email protected]>
---
fs/ext4/namei.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 22098e1..682a488 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1590,9 +1590,9 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
goto cleanup;
node2 = (struct dx_node *)(bh2->b_data);
entries2 = node2->entries;
+ memset(&node2->fake, 0, sizeof(struct fake_dirent));
node2->fake.rec_len = ext4_rec_len_to_disk(sb->s_blocksize,
sb->s_blocksize);
- node2->fake.inode = 0;
BUFFER_TRACE(frame->bh, "get_write_access");
err = ext4_journal_get_write_access(handle, frame->bh);
if (err)
--
1.6.4



2009-08-30 15:13:03

by Andreas Schlick

[permalink] [raw]
Subject: [PATCH 2/2] ext3: Always set dx_node's fake_dirent explicitly.

When ext3_dx_add_entry() has to split an index node, it has to ensure that
name_len of dx_node's fake_dirent is also zero, because otherwise e2fsck
won't recognise it as an intermediate htree node and consider the htree to
be corrupted.

Signed-off-by: Andreas Schlick <[email protected]>
---
fs/ext3/namei.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 6ff7b97..877dd2b 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -1550,8 +1550,8 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
goto cleanup;
node2 = (struct dx_node *)(bh2->b_data);
entries2 = node2->entries;
+ memset(&node2->fake, 0, sizeof(struct fake_dirent));
node2->fake.rec_len = ext3_rec_len_to_disk(sb->s_blocksize);
- node2->fake.inode = 0;
BUFFER_TRACE(frame->bh, "get_write_access");
err = ext3_journal_get_write_access(handle, frame->bh);
if (err)
--
1.6.4



2009-09-11 03:19:35

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 1/2] ext4: Always set dx_node's fake_dirent explicitly.

On Sun, Aug 30, 2009 at 04:57:50PM +0200, Andreas Schlick wrote:
> When ext4_dx_add_entry() has to split an index node, it has to ensure that
> name_len of dx_node's fake_dirent is also zero, because otherwise e2fsck
> won't recognise it as an intermediate htree node and consider the htree to
> be corrupted.
>
> Signed-off-by: Andreas Schlick <[email protected]>

Added to the ext4 patch queue, thanks.

- Ted