Fix wrong name_len and file_type in intermediate htree nodes
cover 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
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.
--- fs/ext4/namei.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ext4/namei.c +1 -1
@@ -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)
Signature · 1 line
1.6.4
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.
--- fs/ext3/namei.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ext3/namei.c +1 -1
@@ -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)
Signature · 1 line
1.6.4
Theodore Tso
maintainerRe: [PATCH 1/2] ext4: Always set dx_node's fake_dirent explicitly.
In reply to Andreas SchlickQuoted 6 lines · Andreas Schlick
When
ext4_dx_add_entry()has to split an index node, it has to ensure thatname_lenof dx_node'sfake_direntis 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