2008-02-12 12:36:35

by Aneesh Kumar K.V

[permalink] [raw]
Subject: EXT4_FEATURE_RO_COMPAT_DIR_NLINK and the directory size.

Steps:
[root]# more /root/largedir
i=65000
mkdir /mnt/tmp/test/
cd /mnt/tmp/test/
while [ $i -gt 0 ]
do
mkdir $i
i=$(expr $i - 1)
done

# /root/largedir
# cd /mnt/tmp/test
# rm -rf *
# cd ..
# ls -al
drwxr-xr-x 1 root root 1380352 Feb 12 07:15 test
# e2fsck -fv /dev/sda7
# ls -al
drwxr-xr-x 2 root root 1380352 Feb 12 07:15 test


So e2fsck fix the link count. But the size is not updated. If i try to
run the script again, i get

EXT4-fs error (device sda7): ext4_find_entry: reading directory #187681
offset 0
attempt to access beyond end of device
sda7: rw=32, want=17582522464, limit=19551042
attempt to access beyond end of device
sda7: rw=32, want=32620150800, limit=19551042
attempt to access beyond end of device
sda7: rw=32, want=32620150800, limit=19551042



Also after running fsstress fsck fails with zero size directory on
powerpc. I am finding directories with

i_links_count == 1
i_blocks == 0

I missed to check whether the l_i_blocks_hi was having some value.

-aneesh


2008-02-12 13:53:57

by Aneesh Kumar K.V

[permalink] [raw]
Subject: Re: EXT4_FEATURE_RO_COMPAT_DIR_NLINK and the directory size.

On Tue, Feb 12, 2008 at 06:06:32PM +0530, Aneesh Kumar K.V wrote:
> Also after running fsstress fsck fails with zero size directory on
> powerpc. I am finding directories with
>
> i_links_count == 1
> i_blocks == 0
>
> I missed to check whether the l_i_blocks_hi was having some value.

Ok this is what i have in ext4_inode and super block

(gdb) p *inode
$1 = {i_mode = 16895, i_uid = 0, i_size = 4096, i_atime = 1202822535, i_ctime = 1202822535, i_mtime = 1202822535, i_dtime = 0,
i_gid = 0, i_links_count = 1, i_blocks = 0, i_flags = 524288, osd1 = {linux1 = {l_i_version = 1}, hurd1 = {h_i_translator = 1},
masix1 = {m_i_reserved1 = 1}}, i_block = {4077518848, 262144, 0 <repeats 13 times>}, i_generation = 2950864834, i_file_acl = 0,
i_dir_acl = 0, i_faddr = 0, osd2 = {linux2 = {l_i_blocks_hi = 0, i_pad1 = 0, l_i_uid_high = 0, l_i_gid_high = 0, l_i_reserved2 = 0},
hurd2 = {h_i_frag = 0 '\0', h_i_fsize = 0 '\0', h_i_mode_high = 0, h_i_uid_high = 0, h_i_gid_high = 0, h_i_author = 0}, masix2 = {
m_i_frag = 0 '\0', m_i_fsize = 0 '\0', m_pad1 = 0, m_i_reserved2 = {0, 0}}}}



(gdb) p *(struct ext2_super_block *)0x10081088
$3 = {s_inodes_count = 612000, s_blocks_count = 2443880, s_r_blocks_count = 122194, s_free_blocks_count = 2367290,
s_free_inodes_count = 597740, s_first_data_block = 0, s_log_block_size = 2, s_log_frag_size = 2, s_blocks_per_group = 32768,
s_frags_per_group = 32768, s_inodes_per_group = 8160, s_mtime = 1202819872, s_wtime = 1202822940, s_mnt_count = 1,
s_max_mnt_count = 31, s_magic = 61267, s_state = 1, s_errors = 1, s_minor_rev_level = 0, s_lastcheck = 1202819860,
s_checkinterval = 15552000, s_creator_os = 0, s_rev_level = 1, s_def_resuid = 0, s_def_resgid = 0, s_first_ino = 11,
s_inode_size = 256, s_block_group_nr = 0, s_feature_compat = 60, s_feature_incompat = 66, s_feature_ro_compat = 3,
s_uuid = "\017�K\n�\[email protected]\211\2106\210Q\006���", s_volume_name = '\0' <repeats 15 times>, s_last_mounted = '\0' <repeats 63 times>,
s_algorithm_usage_bitmap = 0, s_prealloc_blocks = 0 '\0', s_prealloc_dir_blocks = 0 '\0', s_reserved_gdt_blocks = 596,
s_journal_uuid = '\0' <repeats 15 times>, s_journal_inum = 8, s_journal_dev = 0, s_last_orphan = 0, s_hash_seed = {3431749423,
287196506, 2183301643, 2777289977}, s_def_hash_version = 2 '\002', s_jnl_backup_type = 1 '\001', s_desc_size = 0,
s_default_mount_opts = 0, s_first_meta_bg = 0, s_mkfs_time = 1202819860, s_jnl_blocks = {1116, 1117, 1118, 1119, 1120, 1121, 1122,
1123, 1124, 1125, 1126, 1127, 1128, 2153, 0, 0, 134217728}, s_blocks_count_hi = 0, s_r_blocks_count_hi = 0, s_free_blocks_hi = 0,
s_min_extra_isize = 0, s_want_extra_isize = 0, s_flags = 6, s_raid_stride = 0, s_mmp_update_interval = 0, s_mmp_block = 0,
s_raid_stripe_width = 0, s_reserve

2008-02-12 15:05:18

by Aneesh Kumar K.V

[permalink] [raw]
Subject: Re: EXT4_FEATURE_RO_COMPAT_DIR_NLINK and the directory size.

On Tue, Feb 12, 2008 at 07:23:42PM +0530, Aneesh Kumar K.V wrote:
> On Tue, Feb 12, 2008 at 06:06:32PM +0530, Aneesh Kumar K.V wrote:
> > Also after running fsstress fsck fails with zero size directory on
> > powerpc. I am finding directories with
> >
> > i_links_count == 1
> > i_blocks == 0
> >
> > I missed to check whether the l_i_blocks_hi was having some value.
>
> Ok this is what i have in ext4_inode and super block
>
> (gdb) p *inode
> $1 = {i_mode = 16895, i_uid = 0, i_size = 4096, i_atime = 1202822535, i_ctime = 1202822535, i_mtime = 1202822535, i_dtime = 0,
> i_gid = 0, i_links_count = 1, i_blocks = 0, i_flags = 524288, osd1 = {linux1 = {l_i_version = 1}, hurd1 = {h_i_translator = 1},
> masix1 = {m_i_reserved1 = 1}}, i_block = {4077518848, 262144, 0 <repeats 13 times>}, i_generation = 2950864834, i_file_acl = 0,
> i_dir_acl = 0, i_faddr = 0, osd2 = {linux2 = {l_i_blocks_hi = 0, i_pad1 = 0, l_i_uid_high = 0, l_i_gid_high = 0, l_i_reserved2 = 0},
> hurd2 = {h_i_frag = 0 '\0', h_i_fsize = 0 '\0', h_i_mode_high = 0, h_i_uid_high = 0, h_i_gid_high = 0, h_i_author = 0}, masix2 = {
> m_i_frag = 0 '\0', m_i_fsize = 0 '\0', m_pad1 = 0, m_i_reserved2 = {0, 0}}}}
>
>
>
> (gdb) p *(struct ext2_super_block *)0x10081088
> $3 = {s_inodes_count = 612000, s_blocks_count = 2443880, s_r_blocks_count = 122194, s_free_blocks_count = 2367290,
> s_free_inodes_count = 597740, s_first_data_block = 0, s_log_block_size = 2, s_log_frag_size = 2, s_blocks_per_group = 32768,
> s_frags_per_group = 32768, s_inodes_per_group = 8160, s_mtime = 1202819872, s_wtime = 1202822940, s_mnt_count = 1,
> s_max_mnt_count = 31, s_magic = 61267, s_state = 1, s_errors = 1, s_minor_rev_level = 0, s_lastcheck = 1202819860,
> s_checkinterval = 15552000, s_creator_os = 0, s_rev_level = 1, s_def_resuid = 0, s_def_resgid = 0, s_first_ino = 11,
> s_inode_size = 256, s_block_group_nr = 0, s_feature_compat = 60, s_feature_incompat = 66, s_feature_ro_compat = 3,
> s_uuid = "\017�K\n�\[email protected]\211\2106\210Q\006���", s_volume_name = '\0' <repeats 15 times>, s_last_mounted = '\0' <repeats 63 times>,
> s_algorithm_usage_bitmap = 0, s_prealloc_blocks = 0 '\0', s_prealloc_dir_blocks = 0 '\0', s_reserved_gdt_blocks = 596,
> s_journal_uuid = '\0' <repeats 15 times>, s_journal_inum = 8, s_journal_dev = 0, s_last_orphan = 0, s_hash_seed = {3431749423,
> 287196506, 2183301643, 2777289977}, s_def_hash_version = 2 '\002', s_jnl_backup_type = 1 '\001', s_desc_size = 0,
> s_default_mount_opts = 0, s_first_meta_bg = 0, s_mkfs_time = 1202819860, s_jnl_blocks = {1116, 1117, 1118, 1119, 1120, 1121, 1122,
> 1123, 1124, 1125, 1126, 1127, 1128, 2153, 0, 0, 134217728}, s_blocks_count_hi = 0, s_r_blocks_count_hi = 0, s_free_blocks_hi = 0,
> s_min_extra_isize = 0, s_want_extra_isize = 0, s_flags = 6, s_raid_stride = 0, s_mmp_update_interval = 0, s_mmp_block = 0,
> s_raid_stripe_width = 0, s_reserve
> -

Right now waiting for the test to finish with this change.

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index a9347fb..fd3b031 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1805,7 +1805,7 @@ retry:
inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
dir_block = ext4_bread (handle, inode, 0, 1, &err);
if (!dir_block) {
- ext4_dec_count(handle, inode); /* is this nlink == 0? */
+ drop_nlink(inode);
ext4_mark_inode_dirty(handle, inode);
iput (inode);
goto out_stop;

2008-02-12 22:57:10

by Andreas Dilger

[permalink] [raw]
Subject: Re: EXT4_FEATURE_RO_COMPAT_DIR_NLINK and the directory size.

On Feb 12, 2008 20:35 +0530, Aneesh Kumar K.V wrote:
> On Tue, Feb 12, 2008 at 07:23:42PM +0530, Aneesh Kumar K.V wrote:
> > On Tue, Feb 12, 2008 at 06:06:32PM +0530, Aneesh Kumar K.V wrote:
> > > Also after running fsstress fsck fails with zero size directory on
> > > powerpc. I am finding directories with
> > >
> > > i_links_count == 1
> > > i_blocks == 0

Is this after some failure to create a subdirectory (e.g. ENOSPC)?

> > (gdb) p *inode
> > $1 = {i_mode = 16895, i_uid = 0, i_size = 4096, i_atime = 1202822535, i_ctime = 1202822535, i_mtime = 1202822535, i_dtime = 0,
> > i_gid = 0, i_links_count = 1, i_blocks = 0, i_flags = 524288, osd1 = {linux1 = {l_i_version = 1}, hurd1 = {h_i_translator = 1},
> > masix1 = {m_i_reserved1 = 1}}, i_block = {4077518848, 262144, 0 <repeats 13 times>}, i_generation = 2950864834, i_file_acl = 0,
> > i_dir_acl = 0, i_faddr = 0, osd2 = {linux2 = {l_i_blocks_hi = 0, i_pad1 = 0, l_i_uid_high = 0, l_i_gid_high = 0, l_i_reserved2 = 0},
> > hurd2 = {h_i_frag = 0 '\0', h_i_fsize = 0 '\0', h_i_mode_high = 0, h_i_uid_high = 0, h_i_gid_high = 0, h_i_author = 0}, masix2 = {
> > m_i_frag = 0 '\0', m_i_fsize = 0 '\0', m_pad1 = 0, m_i_reserved2 = {0, 0}}}}

This is the subdirectory inode? The i_block values are the extent magic,
and i_flags = EXTENT_FL it appears (which is fine).

> Right now waiting for the test to finish with this change.
>
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index a9347fb..fd3b031 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -1805,7 +1805,7 @@ retry:
> inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
> dir_block = ext4_bread (handle, inode, 0, 1, &err);
> if (!dir_block) {
> - ext4_dec_count(handle, inode); /* is this nlink == 0? */
> + drop_nlink(inode);
> ext4_mark_inode_dirty(handle, inode);
> iput (inode);
> goto out_stop;

It's entirely possible this is the right fix. The code was changed for
all directory inodes replacing drop_nlink() (or its predecessor) with
ext4_dec_count(). In most cases this is correct, but it seems here it
isn't very clear (even with the useless comment) that the intention is
to drop the nlinks to 0 for the new directory inode.

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.