aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/inode.c
diff options
context:
space:
mode:
authorValerie Clement <valerie.clement@bull.net>2008-02-15 13:43:07 -0500
committerTheodore Ts'o <tytso@mit.edu>2008-02-15 13:43:07 -0500
commit74d3487fc8aa58cec16dff7239dea1ca59bdab0e (patch)
treee7f2e3b107bc7ff98ae4a02d0deb44809ae53394 /fs/ext4/inode.c
parente56eb6590693a5a340e8f596db2768a6e1b9e236 (diff)
ext4: modify block allocation algorithm for the last group
When a directory inode is allocated in the last group and the last group contains less than s_blocks_per_group blocks, the initial block allocated for the directory is not always allocated in the same group as the directory inode, but in one of the first groups of the filesystem (group 1 for example). Depending on the current process's pid, ext4_find_near() and ext4_ext_find_goal() can return a block number greater than the maximum blocks count in the filesystem and in that case the block will be not allocated in the same group as the inode. The following patch fixes the problem. Should the modification also be done in ext2/3 code? Signed-off-by: Valerie Clement <valerie.clement@bull.net> Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r--fs/ext4/inode.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index d3c6f58a9def..34f3eb615fd5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -403,6 +403,7 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
403 __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data; 403 __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data;
404 __le32 *p; 404 __le32 *p;
405 ext4_fsblk_t bg_start; 405 ext4_fsblk_t bg_start;
406 ext4_fsblk_t last_block;
406 ext4_grpblk_t colour; 407 ext4_grpblk_t colour;
407 408
408 /* Try to find previous block */ 409 /* Try to find previous block */
@@ -420,8 +421,13 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
420 * into the same cylinder group then. 421 * into the same cylinder group then.
421 */ 422 */
422 bg_start = ext4_group_first_block_no(inode->i_sb, ei->i_block_group); 423 bg_start = ext4_group_first_block_no(inode->i_sb, ei->i_block_group);
423 colour = (current->pid % 16) * 424 last_block = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es) - 1;
425
426 if (bg_start + EXT4_BLOCKS_PER_GROUP(inode->i_sb) <= last_block)
427 colour = (current->pid % 16) *
424 (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16); 428 (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16);
429 else
430 colour = (current->pid % 16) * ((last_block - bg_start) / 16);
425 return bg_start + colour; 431 return bg_start + colour;
426} 432}
427 433