Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 143223
b: refs/heads/master
c: 316cb4e
h: refs/heads/master
i:
  143221: f55f35d
  143219: f808d60
  143215: 25ca25f
v: v3
  • Loading branch information
Jan Kara authored and Linus Torvalds committed Apr 13, 2009
1 parent efed20a commit 23badc7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: caefba1740d8016e6dfe8fda84f85bdcb8f8c85d
refs/heads/master: 316cb4ef3eb2ad6e35e15cc56d39c6cda58c093a
44 changes: 33 additions & 11 deletions trunk/fs/ext2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,8 @@ static int ext2_get_blocks(struct inode *inode,

if (depth == 0)
return (err);
reread:
partial = ext2_get_branch(inode, depth, offsets, chain, &err);

partial = ext2_get_branch(inode, depth, offsets, chain, &err);
/* Simplest case - block found, no allocation needed */
if (!partial) {
first_block = le32_to_cpu(chain[depth - 1].key);
Expand All @@ -602,30 +601,59 @@ static int ext2_get_blocks(struct inode *inode,
while (count < maxblocks && count <= blocks_to_boundary) {
ext2_fsblk_t blk;

if (!verify_chain(chain, partial)) {
if (!verify_chain(chain, chain + depth - 1)) {
/*
* Indirect block might be removed by
* truncate while we were reading it.
* Handling of that case: forget what we've
* got now, go to reread.
*/
err = -EAGAIN;
count = 0;
goto changed;
break;
}
blk = le32_to_cpu(*(chain[depth-1].p + count));
if (blk == first_block + count)
count++;
else
break;
}
goto got_it;
if (err != -EAGAIN)
goto got_it;
}

/* Next simple case - plain lookup or failed read of indirect block */
if (!create || err == -EIO)
goto cleanup;

mutex_lock(&ei->truncate_mutex);
/*
* If the indirect block is missing while we are reading
* the chain(ext3_get_branch() returns -EAGAIN err), or
* if the chain has been changed after we grab the semaphore,
* (either because another process truncated this branch, or
* another get_block allocated this branch) re-grab the chain to see if
* the request block has been allocated or not.
*
* Since we already block the truncate/other get_block
* at this point, we will have the current copy of the chain when we
* splice the branch into the tree.
*/
if (err == -EAGAIN || !verify_chain(chain, partial)) {
while (partial > chain) {
brelse(partial->bh);
partial--;
}
partial = ext2_get_branch(inode, depth, offsets, chain, &err);
if (!partial) {
count++;
mutex_unlock(&ei->truncate_mutex);
if (err)
goto cleanup;
clear_buffer_new(bh_result);
goto got_it;
}
}

/*
* Okay, we need to do block allocation. Lazily initialize the block
Expand Down Expand Up @@ -683,12 +711,6 @@ static int ext2_get_blocks(struct inode *inode,
partial--;
}
return err;
changed:
while (partial > chain) {
brelse(partial->bh);
partial--;
}
goto reread;
}

int ext2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create)
Expand Down

0 comments on commit 23badc7

Please sign in to comment.