Commit fb823ed3 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] ext2 block allocation race fix

If this CPU decides that an ext2 block group has a free block it will then go
in and try to acquire it.  No locks are held, so another CPU can come in and
steal the last block.

In this case we will bogusly report a corrupted filessytem.

Fix it by just restarting the scan - this will choose a different blockgroup
or will generate -ENOSPC.
parent 410257b5
...@@ -402,6 +402,7 @@ int ext2_new_block(struct inode *inode, unsigned long goal, ...@@ -402,6 +402,7 @@ int ext2_new_block(struct inode *inode, unsigned long goal,
* Now search the rest of the groups. We assume that * Now search the rest of the groups. We assume that
* i and desc correctly point to the last group visited. * i and desc correctly point to the last group visited.
*/ */
retry:
for (bit = 0; !group_alloc && for (bit = 0; !group_alloc &&
bit < sbi->s_groups_count; bit++) { bit < sbi->s_groups_count; bit++) {
group_no++; group_no++;
...@@ -425,11 +426,12 @@ int ext2_new_block(struct inode *inode, unsigned long goal, ...@@ -425,11 +426,12 @@ int ext2_new_block(struct inode *inode, unsigned long goal,
ret_block = grab_block(sb_bgl_lock(sbi, group_no), bitmap_bh->b_data, ret_block = grab_block(sb_bgl_lock(sbi, group_no), bitmap_bh->b_data,
group_size, 0); group_size, 0);
if (ret_block < 0) { if (ret_block < 0) {
ext2_error (sb, "ext2_new_block", /*
"Free blocks count corrupted for block group %d", * Someone else grabbed the last free block in this blockgroup
group_no); * before us. Retry the scan.
*/
group_alloc = 0; group_alloc = 0;
goto io_error; goto retry;
} }
got_block: got_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