aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/balloc.c
diff options
context:
space:
mode:
authorAvantika Mathur <mathur@us.ibm.com>2008-01-28 23:58:27 -0500
committerTheodore Ts'o <tytso@mit.edu>2008-01-28 23:58:27 -0500
commitfd2d42912f9f09e5250cb3b024ee0625704e9cb7 (patch)
tree23e85123e8cc06d518fd7cff665f93429e19e4e2 /fs/ext4/balloc.c
parentbba907433b85ba2adae1bb3b6fd29b4e5f35c468 (diff)
ext4: add ext4_group_t, and change all group variables to this type.
In many places variables for block group are of type int, which limits the maximum number of block groups to 2^31. Each block group can have up to 2^15 blocks, with a 4K block size, and the max filesystem size is limited to 2^31 * (2^15 * 2^12) = 2^58 -- or 256 PB This patch introduces a new type ext4_group_t, of type unsigned long, to represent block group numbers in ext4. All occurrences of block group variables are converted to type ext4_group_t. Signed-off-by: Avantika Mathur <mathur@us.ibm.com>
Diffstat (limited to 'fs/ext4/balloc.c')
-rw-r--r--fs/ext4/balloc.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 71ee95e534fd..9568a57c607c 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -29,7 +29,7 @@
29 * Calculate the block group number and offset, given a block number 29 * Calculate the block group number and offset, given a block number
30 */ 30 */
31void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr, 31void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
32 unsigned long *blockgrpp, ext4_grpblk_t *offsetp) 32 ext4_group_t *blockgrpp, ext4_grpblk_t *offsetp)
33{ 33{
34 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 34 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
35 ext4_grpblk_t offset; 35 ext4_grpblk_t offset;
@@ -46,7 +46,7 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
46/* Initializes an uninitialized block bitmap if given, and returns the 46/* Initializes an uninitialized block bitmap if given, and returns the
47 * number of blocks free in the group. */ 47 * number of blocks free in the group. */
48unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, 48unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
49 int block_group, struct ext4_group_desc *gdp) 49 ext4_group_t block_group, struct ext4_group_desc *gdp)
50{ 50{
51 unsigned long start; 51 unsigned long start;
52 int bit, bit_max; 52 int bit, bit_max;
@@ -60,7 +60,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
60 * essentially implementing a per-group read-only flag. */ 60 * essentially implementing a per-group read-only flag. */
61 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 61 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) {
62 ext4_error(sb, __FUNCTION__, 62 ext4_error(sb, __FUNCTION__,
63 "Checksum bad for group %u\n", block_group); 63 "Checksum bad for group %lu\n", block_group);
64 gdp->bg_free_blocks_count = 0; 64 gdp->bg_free_blocks_count = 0;
65 gdp->bg_free_inodes_count = 0; 65 gdp->bg_free_inodes_count = 0;
66 gdp->bg_itable_unused = 0; 66 gdp->bg_itable_unused = 0;
@@ -153,7 +153,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
153 * group descriptor 153 * group descriptor
154 */ 154 */
155struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb, 155struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
156 unsigned int block_group, 156 ext4_group_t block_group,
157 struct buffer_head ** bh) 157 struct buffer_head ** bh)
158{ 158{
159 unsigned long group_desc; 159 unsigned long group_desc;
@@ -164,7 +164,7 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
164 if (block_group >= sbi->s_groups_count) { 164 if (block_group >= sbi->s_groups_count) {
165 ext4_error (sb, "ext4_get_group_desc", 165 ext4_error (sb, "ext4_get_group_desc",
166 "block_group >= groups_count - " 166 "block_group >= groups_count - "
167 "block_group = %d, groups_count = %lu", 167 "block_group = %lu, groups_count = %lu",
168 block_group, sbi->s_groups_count); 168 block_group, sbi->s_groups_count);
169 169
170 return NULL; 170 return NULL;
@@ -176,7 +176,7 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
176 if (!sbi->s_group_desc[group_desc]) { 176 if (!sbi->s_group_desc[group_desc]) {
177 ext4_error (sb, "ext4_get_group_desc", 177 ext4_error (sb, "ext4_get_group_desc",
178 "Group descriptor not loaded - " 178 "Group descriptor not loaded - "
179 "block_group = %d, group_desc = %lu, desc = %lu", 179 "block_group = %lu, group_desc = %lu, desc = %lu",
180 block_group, group_desc, offset); 180 block_group, group_desc, offset);
181 return NULL; 181 return NULL;
182 } 182 }
@@ -200,7 +200,7 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
200 * Return buffer_head on success or NULL in case of failure. 200 * Return buffer_head on success or NULL in case of failure.
201 */ 201 */
202struct buffer_head * 202struct buffer_head *
203read_block_bitmap(struct super_block *sb, unsigned int block_group) 203read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
204{ 204{
205 struct ext4_group_desc * desc; 205 struct ext4_group_desc * desc;
206 struct buffer_head * bh = NULL; 206 struct buffer_head * bh = NULL;
@@ -227,7 +227,7 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)
227 if (!bh) 227 if (!bh)
228 ext4_error (sb, __FUNCTION__, 228 ext4_error (sb, __FUNCTION__,
229 "Cannot read block bitmap - " 229 "Cannot read block bitmap - "
230 "block_group = %d, block_bitmap = %llu", 230 "block_group = %lu, block_bitmap = %llu",
231 block_group, bitmap_blk); 231 block_group, bitmap_blk);
232 return bh; 232 return bh;
233} 233}
@@ -320,7 +320,7 @@ restart:
320 */ 320 */
321static int 321static int
322goal_in_my_reservation(struct ext4_reserve_window *rsv, ext4_grpblk_t grp_goal, 322goal_in_my_reservation(struct ext4_reserve_window *rsv, ext4_grpblk_t grp_goal,
323 unsigned int group, struct super_block * sb) 323 ext4_group_t group, struct super_block *sb)
324{ 324{
325 ext4_fsblk_t group_first_block, group_last_block; 325 ext4_fsblk_t group_first_block, group_last_block;
326 326
@@ -540,7 +540,7 @@ void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb,
540{ 540{
541 struct buffer_head *bitmap_bh = NULL; 541 struct buffer_head *bitmap_bh = NULL;
542 struct buffer_head *gd_bh; 542 struct buffer_head *gd_bh;
543 unsigned long block_group; 543 ext4_group_t block_group;
544 ext4_grpblk_t bit; 544 ext4_grpblk_t bit;
545 unsigned long i; 545 unsigned long i;
546 unsigned long overflow; 546 unsigned long overflow;
@@ -920,9 +920,10 @@ claim_block(spinlock_t *lock, ext4_grpblk_t block, struct buffer_head *bh)
920 * ext4_journal_release_buffer(), else we'll run out of credits. 920 * ext4_journal_release_buffer(), else we'll run out of credits.
921 */ 921 */
922static ext4_grpblk_t 922static ext4_grpblk_t
923ext4_try_to_allocate(struct super_block *sb, handle_t *handle, int group, 923ext4_try_to_allocate(struct super_block *sb, handle_t *handle,
924 struct buffer_head *bitmap_bh, ext4_grpblk_t grp_goal, 924 ext4_group_t group, struct buffer_head *bitmap_bh,
925 unsigned long *count, struct ext4_reserve_window *my_rsv) 925 ext4_grpblk_t grp_goal, unsigned long *count,
926 struct ext4_reserve_window *my_rsv)
926{ 927{
927 ext4_fsblk_t group_first_block; 928 ext4_fsblk_t group_first_block;
928 ext4_grpblk_t start, end; 929 ext4_grpblk_t start, end;
@@ -1156,7 +1157,7 @@ static int find_next_reservable_window(
1156 */ 1157 */
1157static int alloc_new_reservation(struct ext4_reserve_window_node *my_rsv, 1158static int alloc_new_reservation(struct ext4_reserve_window_node *my_rsv,
1158 ext4_grpblk_t grp_goal, struct super_block *sb, 1159 ext4_grpblk_t grp_goal, struct super_block *sb,
1159 unsigned int group, struct buffer_head *bitmap_bh) 1160 ext4_group_t group, struct buffer_head *bitmap_bh)
1160{ 1161{
1161 struct ext4_reserve_window_node *search_head; 1162 struct ext4_reserve_window_node *search_head;
1162 ext4_fsblk_t group_first_block, group_end_block, start_block; 1163 ext4_fsblk_t group_first_block, group_end_block, start_block;
@@ -1354,7 +1355,7 @@ static void try_to_extend_reservation(struct ext4_reserve_window_node *my_rsv,
1354 */ 1355 */
1355static ext4_grpblk_t 1356static ext4_grpblk_t
1356ext4_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle, 1357ext4_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
1357 unsigned int group, struct buffer_head *bitmap_bh, 1358 ext4_group_t group, struct buffer_head *bitmap_bh,
1358 ext4_grpblk_t grp_goal, 1359 ext4_grpblk_t grp_goal,
1359 struct ext4_reserve_window_node * my_rsv, 1360 struct ext4_reserve_window_node * my_rsv,
1360 unsigned long *count, int *errp) 1361 unsigned long *count, int *errp)
@@ -1528,12 +1529,12 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
1528{ 1529{
1529 struct buffer_head *bitmap_bh = NULL; 1530 struct buffer_head *bitmap_bh = NULL;
1530 struct buffer_head *gdp_bh; 1531 struct buffer_head *gdp_bh;
1531 unsigned long group_no; 1532 ext4_group_t group_no;
1532 int goal_group; 1533 ext4_group_t goal_group;
1533 ext4_grpblk_t grp_target_blk; /* blockgroup relative goal block */ 1534 ext4_grpblk_t grp_target_blk; /* blockgroup relative goal block */
1534 ext4_grpblk_t grp_alloc_blk; /* blockgroup-relative allocated block*/ 1535 ext4_grpblk_t grp_alloc_blk; /* blockgroup-relative allocated block*/
1535 ext4_fsblk_t ret_block; /* filesyetem-wide allocated block */ 1536 ext4_fsblk_t ret_block; /* filesyetem-wide allocated block */
1536 int bgi; /* blockgroup iteration index */ 1537 ext4_group_t bgi; /* blockgroup iteration index */
1537 int fatal = 0, err; 1538 int fatal = 0, err;
1538 int performed_allocation = 0; 1539 int performed_allocation = 0;
1539 ext4_grpblk_t free_blocks; /* number of free blocks in a group */ 1540 ext4_grpblk_t free_blocks; /* number of free blocks in a group */
@@ -1544,10 +1545,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
1544 struct ext4_reserve_window_node *my_rsv = NULL; 1545 struct ext4_reserve_window_node *my_rsv = NULL;
1545 struct ext4_block_alloc_info *block_i; 1546 struct ext4_block_alloc_info *block_i;
1546 unsigned short windowsz = 0; 1547 unsigned short windowsz = 0;
1547#ifdef EXT4FS_DEBUG 1548 ext4_group_t ngroups;
1548 static int goal_hits, goal_attempts;
1549#endif
1550 unsigned long ngroups;
1551 unsigned long num = *count; 1549 unsigned long num = *count;
1552 1550
1553 *errp = -ENOSPC; 1551 *errp = -ENOSPC;
@@ -1743,9 +1741,6 @@ allocated:
1743 * list of some description. We don't know in advance whether 1741 * list of some description. We don't know in advance whether
1744 * the caller wants to use it as metadata or data. 1742 * the caller wants to use it as metadata or data.
1745 */ 1743 */
1746 ext4_debug("allocating block %lu. Goal hits %d of %d.\n",
1747 ret_block, goal_hits, goal_attempts);
1748
1749 spin_lock(sb_bgl_lock(sbi, group_no)); 1744 spin_lock(sb_bgl_lock(sbi, group_no));
1750 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) 1745 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))
1751 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); 1746 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
@@ -1804,8 +1799,8 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
1804{ 1799{
1805 ext4_fsblk_t desc_count; 1800 ext4_fsblk_t desc_count;
1806 struct ext4_group_desc *gdp; 1801 struct ext4_group_desc *gdp;
1807 int i; 1802 ext4_group_t i;
1808 unsigned long ngroups = EXT4_SB(sb)->s_groups_count; 1803 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
1809#ifdef EXT4FS_DEBUG 1804#ifdef EXT4FS_DEBUG
1810 struct ext4_super_block *es; 1805 struct ext4_super_block *es;
1811 ext4_fsblk_t bitmap_count; 1806 ext4_fsblk_t bitmap_count;
@@ -1829,7 +1824,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
1829 continue; 1824 continue;
1830 1825
1831 x = ext4_count_free(bitmap_bh, sb->s_blocksize); 1826 x = ext4_count_free(bitmap_bh, sb->s_blocksize);
1832 printk("group %d: stored = %d, counted = %lu\n", 1827 printk(KERN_DEBUG "group %lu: stored = %d, counted = %lu\n",
1833 i, le16_to_cpu(gdp->bg_free_blocks_count), x); 1828 i, le16_to_cpu(gdp->bg_free_blocks_count), x);
1834 bitmap_count += x; 1829 bitmap_count += x;
1835 } 1830 }
@@ -1853,7 +1848,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
1853#endif 1848#endif
1854} 1849}
1855 1850
1856static inline int test_root(int a, int b) 1851static inline int test_root(ext4_group_t a, int b)
1857{ 1852{
1858 int num = b; 1853 int num = b;
1859 1854
@@ -1862,7 +1857,7 @@ static inline int test_root(int a, int b)
1862 return num == a; 1857 return num == a;
1863} 1858}
1864 1859
1865static int ext4_group_sparse(int group) 1860static int ext4_group_sparse(ext4_group_t group)
1866{ 1861{
1867 if (group <= 1) 1862 if (group <= 1)
1868 return 1; 1863 return 1;
@@ -1880,7 +1875,7 @@ static int ext4_group_sparse(int group)
1880 * Return the number of blocks used by the superblock (primary or backup) 1875 * Return the number of blocks used by the superblock (primary or backup)
1881 * in this group. Currently this will be only 0 or 1. 1876 * in this group. Currently this will be only 0 or 1.
1882 */ 1877 */
1883int ext4_bg_has_super(struct super_block *sb, int group) 1878int ext4_bg_has_super(struct super_block *sb, ext4_group_t group)
1884{ 1879{
1885 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 1880 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
1886 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) && 1881 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
@@ -1889,18 +1884,20 @@ int ext4_bg_has_super(struct super_block *sb, int group)
1889 return 1; 1884 return 1;
1890} 1885}
1891 1886
1892static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb, int group) 1887static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb,
1888 ext4_group_t group)
1893{ 1889{
1894 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb); 1890 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb);
1895 unsigned long first = metagroup * EXT4_DESC_PER_BLOCK(sb); 1891 ext4_group_t first = metagroup * EXT4_DESC_PER_BLOCK(sb);
1896 unsigned long last = first + EXT4_DESC_PER_BLOCK(sb) - 1; 1892 ext4_group_t last = first + EXT4_DESC_PER_BLOCK(sb) - 1;
1897 1893
1898 if (group == first || group == first + 1 || group == last) 1894 if (group == first || group == first + 1 || group == last)
1899 return 1; 1895 return 1;
1900 return 0; 1896 return 0;
1901} 1897}
1902 1898
1903static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb, int group) 1899static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb,
1900 ext4_group_t group)
1904{ 1901{
1905 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 1902 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
1906 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) && 1903 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
@@ -1918,7 +1915,7 @@ static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb, int group)
1918 * (primary or backup) in this group. In the future there may be a 1915 * (primary or backup) in this group. In the future there may be a
1919 * different number of descriptor blocks in each group. 1916 * different number of descriptor blocks in each group.
1920 */ 1917 */
1921unsigned long ext4_bg_num_gdb(struct super_block *sb, int group) 1918unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group)
1922{ 1919{
1923 unsigned long first_meta_bg = 1920 unsigned long first_meta_bg =
1924 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg); 1921 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);