Commit 2ef0192c authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] ext2_new_block cleanups and fixes

The general error logic handling in there is:

	*errp = -EFOO;
	<lots of code>
	if (some_error)
		goto out;

this is fragile and unmaintainable, because the setting of the error code is
"far away" from the site where the error was detected.

And the code was actually wrong - we're returning ENOSPC in places where fs
metadata inconsistency was detected.  We traditionally return -EIO in this
case.

So change it all to do, effectively:

	if (some_error) {
		*errp = -EFOO;
		goto out;
	}
parent 359ae811
......@@ -334,22 +334,23 @@ int ext2_new_block (struct inode * inode, unsigned long goal,
if (!prealloc_count || *prealloc_count)
prealloc_goal = 0;
*err = -EDQUOT;
if (DQUOT_ALLOC_BLOCK(inode, 1))
if (DQUOT_ALLOC_BLOCK(inode, 1)) {
*err = -EDQUOT;
goto out;
}
while (prealloc_goal && DQUOT_PREALLOC_BLOCK(inode, prealloc_goal))
prealloc_goal--;
dq_alloc = prealloc_goal + 1;
*err = -ENOSPC;
lock_super (sb);
es_alloc = reserve_blocks(sb, dq_alloc);
if (!es_alloc)
if (!es_alloc) {
*err = -ENOSPC;
goto out_unlock;
}
ext2_debug ("goal=%lu.\n", goal);
......@@ -396,8 +397,10 @@ int ext2_new_block (struct inode * inode, unsigned long goal,
goto io_error;
group_alloc = group_reserve_blocks(desc, gdp_bh, es_alloc);
}
if (bit >= sbi->s_groups_count)
if (bit >= sbi->s_groups_count) {
*err = -ENOSPC;
goto out_release;
}
brelse(bitmap_bh);
bitmap_bh = read_block_bitmap(sb, group_no);
if (!bitmap_bh)
......@@ -409,7 +412,7 @@ int ext2_new_block (struct inode * inode, unsigned long goal,
"Free blocks count corrupted for block group %d",
group_no);
group_alloc = 0;
goto out_release;
goto io_error;
}
got_block:
......@@ -432,7 +435,7 @@ int ext2_new_block (struct inode * inode, unsigned long goal,
"block(%d) >= blocks count(%d) - "
"block_group = %d, es == %p ", ret_block,
le32_to_cpu(es->s_blocks_count), group_no, es);
goto out_release;
goto io_error;
}
block = target_block;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment