aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>2008-07-11 19:27:31 -0400
committerTheodore Ts'o <tytso@mit.edu>2008-07-11 19:27:31 -0400
commit654b4908bc17a6318d18f3036fecc5155de92f55 (patch)
treea77264435aa5ed0386334653fae7624ee423f8cf /fs/ext4
parent7061eba75ceb0835ba61e7cbd757a6f9c1e4af92 (diff)
ext4: cleanup block allocator
Move the code related to block allocation to a single function and add helper funtions to differient allocation for data and meta data blocks Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/balloc.c127
-rw-r--r--fs/ext4/ext4.h2
-rw-r--r--fs/ext4/extents.c10
-rw-r--r--fs/ext4/inode.c2
-rw-r--r--fs/ext4/mballoc.c2
5 files changed, 84 insertions, 59 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 816f1dbaeb3c..48787e86d438 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -1640,20 +1640,24 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries)
1640} 1640}
1641 1641
1642/** 1642/**
1643 * ext4_new_blocks_old() -- core block(s) allocation function 1643 * ext4_old_new_blocks() -- core block bitmap based block allocation function
1644 *
1644 * @handle: handle to this transaction 1645 * @handle: handle to this transaction
1645 * @inode: file inode 1646 * @inode: file inode
1646 * @goal: given target block(filesystem wide) 1647 * @goal: given target block(filesystem wide)
1647 * @count: target number of blocks to allocate 1648 * @count: target number of blocks to allocate
1648 * @errp: error code 1649 * @errp: error code
1649 * 1650 *
1650 * ext4_new_blocks uses a goal block to assist allocation. It tries to 1651 * ext4_old_new_blocks uses a goal block to assist allocation and look up
1651 * allocate block(s) from the block group contains the goal block first. If that 1652 * the block bitmap directly to do block allocation. It tries to
1652 * fails, it will try to allocate block(s) from other block groups without 1653 * allocate block(s) from the block group contains the goal block first. If
1653 * any specific goal block. 1654 * that fails, it will try to allocate block(s) from other block groups
1655 * without any specific goal block.
1656 *
1657 * This function is called when -o nomballoc mount option is enabled
1654 * 1658 *
1655 */ 1659 */
1656ext4_fsblk_t ext4_new_blocks_old(handle_t *handle, struct inode *inode, 1660ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode,
1657 ext4_fsblk_t goal, unsigned long *count, int *errp) 1661 ext4_fsblk_t goal, unsigned long *count, int *errp)
1658{ 1662{
1659 struct buffer_head *bitmap_bh = NULL; 1663 struct buffer_head *bitmap_bh = NULL;
@@ -1923,78 +1927,95 @@ out:
1923 return 0; 1927 return 0;
1924} 1928}
1925 1929
1926ext4_fsblk_t ext4_new_meta_block(handle_t *handle, struct inode *inode, 1930#define EXT4_META_BLOCK 0x1
1927 ext4_fsblk_t goal, int *errp)
1928{
1929 struct ext4_allocation_request ar;
1930 ext4_fsblk_t ret;
1931
1932 if (!test_opt(inode->i_sb, MBALLOC)) {
1933 unsigned long count = 1;
1934 ret = ext4_new_blocks_old(handle, inode, goal, &count, errp);
1935 return ret;
1936 }
1937 1931
1938 memset(&ar, 0, sizeof(ar)); 1932static ext4_fsblk_t do_blk_alloc(handle_t *handle, struct inode *inode,
1939 ar.inode = inode;
1940 ar.goal = goal;
1941 ar.len = 1;
1942 ret = ext4_mb_new_blocks(handle, &ar, errp);
1943 return ret;
1944}
1945ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
1946 ext4_fsblk_t goal, unsigned long *count, int *errp)
1947{
1948 struct ext4_allocation_request ar;
1949 ext4_fsblk_t ret;
1950
1951 if (!test_opt(inode->i_sb, MBALLOC)) {
1952 ret = ext4_new_blocks_old(handle, inode, goal, count, errp);
1953 return ret;
1954 }
1955
1956 memset(&ar, 0, sizeof(ar));
1957 ar.inode = inode;
1958 ar.goal = goal;
1959 ar.len = *count;
1960 ret = ext4_mb_new_blocks(handle, &ar, errp);
1961 *count = ar.len;
1962 return ret;
1963}
1964
1965ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
1966 ext4_lblk_t iblock, ext4_fsblk_t goal, 1933 ext4_lblk_t iblock, ext4_fsblk_t goal,
1967 unsigned long *count, int *errp) 1934 unsigned long *count, int *errp, int flags)
1968{ 1935{
1969 struct ext4_allocation_request ar; 1936 struct ext4_allocation_request ar;
1970 ext4_fsblk_t ret; 1937 ext4_fsblk_t ret;
1971 1938
1972 if (!test_opt(inode->i_sb, MBALLOC)) { 1939 if (!test_opt(inode->i_sb, MBALLOC)) {
1973 ret = ext4_new_blocks_old(handle, inode, goal, count, errp); 1940 return ext4_old_new_blocks(handle, inode, goal, count, errp);
1974 return ret;
1975 } 1941 }
1976 1942
1977 memset(&ar, 0, sizeof(ar)); 1943 memset(&ar, 0, sizeof(ar));
1978 /* Fill with neighbour allocated blocks */ 1944 /* Fill with neighbour allocated blocks */
1979 ar.lleft = 0;
1980 ar.pleft = 0;
1981 ar.lright = 0;
1982 ar.pright = 0;
1983 1945
1984 ar.inode = inode; 1946 ar.inode = inode;
1985 ar.goal = goal; 1947 ar.goal = goal;
1986 ar.len = *count; 1948 ar.len = *count;
1987 ar.logical = iblock; 1949 ar.logical = iblock;
1988 if (S_ISREG(inode->i_mode)) 1950
1951 if (S_ISREG(inode->i_mode) && !(flags & EXT4_META_BLOCK))
1952 /* enable in-core preallocation for data block allocation */
1989 ar.flags = EXT4_MB_HINT_DATA; 1953 ar.flags = EXT4_MB_HINT_DATA;
1990 else 1954 else
1991 /* disable in-core preallocation for non-regular files */ 1955 /* disable in-core preallocation for non-regular files */
1992 ar.flags = 0; 1956 ar.flags = 0;
1957
1993 ret = ext4_mb_new_blocks(handle, &ar, errp); 1958 ret = ext4_mb_new_blocks(handle, &ar, errp);
1994 *count = ar.len; 1959 *count = ar.len;
1995 return ret; 1960 return ret;
1996} 1961}
1997 1962
1963/*
1964 * ext4_new_meta_block() -- allocate block for meta data (indexing) blocks
1965 *
1966 * @handle: handle to this transaction
1967 * @inode: file inode
1968 * @goal: given target block(filesystem wide)
1969 * @errp: error code
1970 *
1971 * Return allocated block number on success
1972 */
1973ext4_fsblk_t ext4_new_meta_block(handle_t *handle, struct inode *inode,
1974 ext4_fsblk_t goal, int *errp)
1975{
1976 unsigned long count = 1;
1977 return do_blk_alloc(handle, inode, 0, goal,
1978 &count, errp, EXT4_META_BLOCK);
1979}
1980
1981/*
1982 * ext4_new_meta_blocks() -- allocate block for meta data (indexing) blocks
1983 *
1984 * @handle: handle to this transaction
1985 * @inode: file inode
1986 * @goal: given target block(filesystem wide)
1987 * @count: total number of blocks need
1988 * @errp: error code
1989 *
1990 * Return 1st allocated block numberon success, *count stores total account
1991 * error stores in errp pointer
1992 */
1993ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
1994 ext4_fsblk_t goal, unsigned long *count, int *errp)
1995{
1996 return do_blk_alloc(handle, inode, 0, goal,
1997 count, errp, EXT4_META_BLOCK);
1998}
1999
2000/*
2001 * ext4_new_blocks() -- allocate data blocks
2002 *
2003 * @handle: handle to this transaction
2004 * @inode: file inode
2005 * @goal: given target block(filesystem wide)
2006 * @count: total number of blocks need
2007 * @errp: error code
2008 *
2009 * Return 1st allocated block numberon success, *count stores total account
2010 * error stores in errp pointer
2011 */
2012
2013ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
2014 ext4_lblk_t iblock, ext4_fsblk_t goal,
2015 unsigned long *count, int *errp)
2016{
2017 return do_blk_alloc(handle, inode, iblock, goal, count, errp, 0);
2018}
1998 2019
1999/** 2020/**
2000 * ext4_count_free_blocks() -- count filesystem free blocks 2021 * ext4_count_free_blocks() -- count filesystem free blocks
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index d44a7fb6a7b1..e622ade69d5c 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -977,7 +977,7 @@ extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
977extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, 977extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
978 ext4_lblk_t iblock, ext4_fsblk_t goal, 978 ext4_lblk_t iblock, ext4_fsblk_t goal,
979 unsigned long *count, int *errp); 979 unsigned long *count, int *errp);
980extern ext4_fsblk_t ext4_new_blocks_old(handle_t *handle, struct inode *inode, 980extern ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode,
981 ext4_fsblk_t goal, unsigned long *count, int *errp); 981 ext4_fsblk_t goal, unsigned long *count, int *errp);
982extern void ext4_free_blocks (handle_t *handle, struct inode *inode, 982extern void ext4_free_blocks (handle_t *handle, struct inode *inode,
983 ext4_fsblk_t block, unsigned long count, int metadata); 983 ext4_fsblk_t block, unsigned long count, int metadata);
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index c729b3507b46..555155d239df 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -179,8 +179,11 @@ static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode,
179 return bg_start + colour + block; 179 return bg_start + colour + block;
180} 180}
181 181
182/*
183 * Allocation for a meta data block
184 */
182static ext4_fsblk_t 185static ext4_fsblk_t
183ext4_ext_new_block(handle_t *handle, struct inode *inode, 186ext4_ext_new_meta_block(handle_t *handle, struct inode *inode,
184 struct ext4_ext_path *path, 187 struct ext4_ext_path *path,
185 struct ext4_extent *ex, int *err) 188 struct ext4_extent *ex, int *err)
186{ 189{
@@ -690,7 +693,8 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
690 /* allocate all needed blocks */ 693 /* allocate all needed blocks */
691 ext_debug("allocate %d blocks for indexes/leaf\n", depth - at); 694 ext_debug("allocate %d blocks for indexes/leaf\n", depth - at);
692 for (a = 0; a < depth - at; a++) { 695 for (a = 0; a < depth - at; a++) {
693 newblock = ext4_ext_new_block(handle, inode, path, newext, &err); 696 newblock = ext4_ext_new_meta_block(handle, inode, path,
697 newext, &err);
694 if (newblock == 0) 698 if (newblock == 0)
695 goto cleanup; 699 goto cleanup;
696 ablocks[a] = newblock; 700 ablocks[a] = newblock;
@@ -886,7 +890,7 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
886 ext4_fsblk_t newblock; 890 ext4_fsblk_t newblock;
887 int err = 0; 891 int err = 0;
888 892
889 newblock = ext4_ext_new_block(handle, inode, path, newext, &err); 893 newblock = ext4_ext_new_meta_block(handle, inode, path, newext, &err);
890 if (newblock == 0) 894 if (newblock == 0)
891 return err; 895 return err;
892 896
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index bc950562b5ba..c5d506dce8c5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -561,7 +561,7 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode,
561 goto allocated; 561 goto allocated;
562 /* Now allocate data blocks */ 562 /* Now allocate data blocks */
563 count = target; 563 count = target;
564 /* allocating blocks for indirect blocks and direct blocks */ 564 /* allocating blocks for data blocks */
565 current_block = ext4_new_blocks(handle, inode, iblock, 565 current_block = ext4_new_blocks(handle, inode, iblock,
566 goal, &count, err); 566 goal, &count, err);
567 if (*err && (target == blks)) { 567 if (*err && (target == blks)) {
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index cde232bdaed0..816ba8cce79a 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4041,7 +4041,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4041 sbi = EXT4_SB(sb); 4041 sbi = EXT4_SB(sb);
4042 4042
4043 if (!test_opt(sb, MBALLOC)) { 4043 if (!test_opt(sb, MBALLOC)) {
4044 block = ext4_new_blocks_old(handle, ar->inode, ar->goal, 4044 block = ext4_old_new_blocks(handle, ar->inode, ar->goal,
4045 &(ar->len), errp); 4045 &(ar->len), errp);
4046 return block; 4046 return block;
4047 } 4047 }