Skip to content

Commit 8e33fad

Browse files
zhangyi089tytso
authored andcommitted
ext4: remove an unnecessary if statement in __ext4_get_inode_loc()
The "if (!buffer_uptodate(bh))" hunk covered almost the whole code after getting buffer in __ext4_get_inode_loc() which seems unnecessary, remove it and switch to check ext4_buffer_uptodate(), it simplify code and make it more readable. Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0904c9a commit 8e33fad

File tree

1 file changed

+78
-84
lines changed

1 file changed

+78
-84
lines changed

fs/ext4/inode.c

Lines changed: 78 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4337,99 +4337,93 @@ static int __ext4_get_inode_loc(struct super_block *sb, unsigned long ino,
43374337
bh = sb_getblk(sb, block);
43384338
if (unlikely(!bh))
43394339
return -ENOMEM;
4340-
if (!buffer_uptodate(bh)) {
4341-
lock_buffer(bh);
4342-
4343-
if (ext4_buffer_uptodate(bh)) {
4344-
/* someone brought it uptodate while we waited */
4345-
unlock_buffer(bh);
4346-
goto has_buffer;
4347-
}
4340+
if (ext4_buffer_uptodate(bh))
4341+
goto has_buffer;
43484342

4349-
/*
4350-
* If we have all information of the inode in memory and this
4351-
* is the only valid inode in the block, we need not read the
4352-
* block.
4353-
*/
4354-
if (in_mem) {
4355-
struct buffer_head *bitmap_bh;
4356-
int i, start;
4343+
lock_buffer(bh);
4344+
/*
4345+
* If we have all information of the inode in memory and this
4346+
* is the only valid inode in the block, we need not read the
4347+
* block.
4348+
*/
4349+
if (in_mem) {
4350+
struct buffer_head *bitmap_bh;
4351+
int i, start;
43574352

4358-
start = inode_offset & ~(inodes_per_block - 1);
4353+
start = inode_offset & ~(inodes_per_block - 1);
43594354

4360-
/* Is the inode bitmap in cache? */
4361-
bitmap_bh = sb_getblk(sb, ext4_inode_bitmap(sb, gdp));
4362-
if (unlikely(!bitmap_bh))
4363-
goto make_io;
4355+
/* Is the inode bitmap in cache? */
4356+
bitmap_bh = sb_getblk(sb, ext4_inode_bitmap(sb, gdp));
4357+
if (unlikely(!bitmap_bh))
4358+
goto make_io;
43644359

4365-
/*
4366-
* If the inode bitmap isn't in cache then the
4367-
* optimisation may end up performing two reads instead
4368-
* of one, so skip it.
4369-
*/
4370-
if (!buffer_uptodate(bitmap_bh)) {
4371-
brelse(bitmap_bh);
4372-
goto make_io;
4373-
}
4374-
for (i = start; i < start + inodes_per_block; i++) {
4375-
if (i == inode_offset)
4376-
continue;
4377-
if (ext4_test_bit(i, bitmap_bh->b_data))
4378-
break;
4379-
}
4360+
/*
4361+
* If the inode bitmap isn't in cache then the
4362+
* optimisation may end up performing two reads instead
4363+
* of one, so skip it.
4364+
*/
4365+
if (!buffer_uptodate(bitmap_bh)) {
43804366
brelse(bitmap_bh);
4381-
if (i == start + inodes_per_block) {
4382-
/* all other inodes are free, so skip I/O */
4383-
memset(bh->b_data, 0, bh->b_size);
4384-
set_buffer_uptodate(bh);
4385-
unlock_buffer(bh);
4386-
goto has_buffer;
4387-
}
4367+
goto make_io;
4368+
}
4369+
for (i = start; i < start + inodes_per_block; i++) {
4370+
if (i == inode_offset)
4371+
continue;
4372+
if (ext4_test_bit(i, bitmap_bh->b_data))
4373+
break;
43884374
}
4375+
brelse(bitmap_bh);
4376+
if (i == start + inodes_per_block) {
4377+
/* all other inodes are free, so skip I/O */
4378+
memset(bh->b_data, 0, bh->b_size);
4379+
set_buffer_uptodate(bh);
4380+
unlock_buffer(bh);
4381+
goto has_buffer;
4382+
}
4383+
}
43894384

43904385
make_io:
4391-
/*
4392-
* If we need to do any I/O, try to pre-readahead extra
4393-
* blocks from the inode table.
4394-
*/
4395-
blk_start_plug(&plug);
4396-
if (EXT4_SB(sb)->s_inode_readahead_blks) {
4397-
ext4_fsblk_t b, end, table;
4398-
unsigned num;
4399-
__u32 ra_blks = EXT4_SB(sb)->s_inode_readahead_blks;
4400-
4401-
table = ext4_inode_table(sb, gdp);
4402-
/* s_inode_readahead_blks is always a power of 2 */
4403-
b = block & ~((ext4_fsblk_t) ra_blks - 1);
4404-
if (table > b)
4405-
b = table;
4406-
end = b + ra_blks;
4407-
num = EXT4_INODES_PER_GROUP(sb);
4408-
if (ext4_has_group_desc_csum(sb))
4409-
num -= ext4_itable_unused_count(sb, gdp);
4410-
table += num / inodes_per_block;
4411-
if (end > table)
4412-
end = table;
4413-
while (b <= end)
4414-
ext4_sb_breadahead_unmovable(sb, b++);
4415-
}
4386+
/*
4387+
* If we need to do any I/O, try to pre-readahead extra
4388+
* blocks from the inode table.
4389+
*/
4390+
blk_start_plug(&plug);
4391+
if (EXT4_SB(sb)->s_inode_readahead_blks) {
4392+
ext4_fsblk_t b, end, table;
4393+
unsigned num;
4394+
__u32 ra_blks = EXT4_SB(sb)->s_inode_readahead_blks;
4395+
4396+
table = ext4_inode_table(sb, gdp);
4397+
/* s_inode_readahead_blks is always a power of 2 */
4398+
b = block & ~((ext4_fsblk_t) ra_blks - 1);
4399+
if (table > b)
4400+
b = table;
4401+
end = b + ra_blks;
4402+
num = EXT4_INODES_PER_GROUP(sb);
4403+
if (ext4_has_group_desc_csum(sb))
4404+
num -= ext4_itable_unused_count(sb, gdp);
4405+
table += num / inodes_per_block;
4406+
if (end > table)
4407+
end = table;
4408+
while (b <= end)
4409+
ext4_sb_breadahead_unmovable(sb, b++);
4410+
}
44164411

4417-
/*
4418-
* There are other valid inodes in the buffer, this inode
4419-
* has in-inode xattrs, or we don't have this inode in memory.
4420-
* Read the block from disk.
4421-
*/
4422-
trace_ext4_load_inode(sb, ino);
4423-
ext4_read_bh_nowait(bh, REQ_META | REQ_PRIO, NULL);
4424-
blk_finish_plug(&plug);
4425-
wait_on_buffer(bh);
4426-
ext4_simulate_fail_bh(sb, bh, EXT4_SIM_INODE_EIO);
4427-
if (!buffer_uptodate(bh)) {
4428-
if (ret_block)
4429-
*ret_block = block;
4430-
brelse(bh);
4431-
return -EIO;
4432-
}
4412+
/*
4413+
* There are other valid inodes in the buffer, this inode
4414+
* has in-inode xattrs, or we don't have this inode in memory.
4415+
* Read the block from disk.
4416+
*/
4417+
trace_ext4_load_inode(sb, ino);
4418+
ext4_read_bh_nowait(bh, REQ_META | REQ_PRIO, NULL);
4419+
blk_finish_plug(&plug);
4420+
wait_on_buffer(bh);
4421+
ext4_simulate_fail_bh(sb, bh, EXT4_SIM_INODE_EIO);
4422+
if (!buffer_uptodate(bh)) {
4423+
if (ret_block)
4424+
*ret_block = block;
4425+
brelse(bh);
4426+
return -EIO;
44334427
}
44344428
has_buffer:
44354429
iloc->bh = bh;

0 commit comments

Comments
 (0)