balloc.c (0b832a4b93932103d73c0c3f35ef1153e288327b) | balloc.c (fd2d42912f9f09e5250cb3b024ee0625704e9cb7) |
---|---|
1/* 2 * linux/fs/ext4/balloc.c 3 * 4 * Copyright (C) 1992, 1993, 1994, 1995 5 * Remy Card (card@masi.ibp.fr) 6 * Laboratoire MASI - Institut Blaise Pascal 7 * Universite Pierre et Marie Curie (Paris VI) 8 * --- 15 unchanged lines hidden (view full) --- 24/* 25 * balloc.c contains the blocks allocation and deallocation routines 26 */ 27 28/* 29 * Calculate the block group number and offset, given a block number 30 */ 31void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr, | 1/* 2 * linux/fs/ext4/balloc.c 3 * 4 * Copyright (C) 1992, 1993, 1994, 1995 5 * Remy Card (card@masi.ibp.fr) 6 * Laboratoire MASI - Institut Blaise Pascal 7 * Universite Pierre et Marie Curie (Paris VI) 8 * --- 15 unchanged lines hidden (view full) --- 24/* 25 * balloc.c contains the blocks allocation and deallocation routines 26 */ 27 28/* 29 * Calculate the block group number and offset, given a block number 30 */ 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{ 34 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 35 ext4_grpblk_t offset; 36 37 blocknr = blocknr - le32_to_cpu(es->s_first_data_block); 38 offset = do_div(blocknr, EXT4_BLOCKS_PER_GROUP(sb)); 39 if (offsetp) 40 *offsetp = offset; 41 if (blockgrpp) 42 *blockgrpp = blocknr; 43 44} 45 46/* Initializes an uninitialized block bitmap if given, and returns the 47 * number of blocks free in the group. */ 48unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, | 33{ 34 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 35 ext4_grpblk_t offset; 36 37 blocknr = blocknr - le32_to_cpu(es->s_first_data_block); 38 offset = do_div(blocknr, EXT4_BLOCKS_PER_GROUP(sb)); 39 if (offsetp) 40 *offsetp = offset; 41 if (blockgrpp) 42 *blockgrpp = blocknr; 43 44} 45 46/* Initializes an uninitialized block bitmap if given, and returns the 47 * number of blocks free in the group. */ 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{ 51 unsigned long start; 52 int bit, bit_max; 53 unsigned free_blocks, group_blocks; 54 struct ext4_sb_info *sbi = EXT4_SB(sb); 55 56 if (bh) { 57 J_ASSERT_BH(bh, buffer_locked(bh)); 58 59 /* If checksum is bad mark all blocks used to prevent allocation 60 * essentially implementing a per-group read-only flag. */ 61 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 62 ext4_error(sb, __FUNCTION__, | 50{ 51 unsigned long start; 52 int bit, bit_max; 53 unsigned free_blocks, group_blocks; 54 struct ext4_sb_info *sbi = EXT4_SB(sb); 55 56 if (bh) { 57 J_ASSERT_BH(bh, buffer_locked(bh)); 58 59 /* If checksum is bad mark all blocks used to prevent allocation 60 * essentially implementing a per-group read-only flag. */ 61 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 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; 65 gdp->bg_free_inodes_count = 0; 66 gdp->bg_itable_unused = 0; 67 memset(bh->b_data, 0xff, sb->s_blocksize); 68 return 0; 69 } 70 memset(bh->b_data, 0, sb->s_blocksize); 71 } --- 76 unchanged lines hidden (view full) --- 148/** 149 * ext4_get_group_desc() -- load group descriptor from disk 150 * @sb: super block 151 * @block_group: given block group 152 * @bh: pointer to the buffer head to store the block 153 * group descriptor 154 */ 155struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb, | 64 gdp->bg_free_blocks_count = 0; 65 gdp->bg_free_inodes_count = 0; 66 gdp->bg_itable_unused = 0; 67 memset(bh->b_data, 0xff, sb->s_blocksize); 68 return 0; 69 } 70 memset(bh->b_data, 0, sb->s_blocksize); 71 } --- 76 unchanged lines hidden (view full) --- 148/** 149 * ext4_get_group_desc() -- load group descriptor from disk 150 * @sb: super block 151 * @block_group: given block group 152 * @bh: pointer to the buffer head to store the block 153 * group descriptor 154 */ 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) 158{ 159 unsigned long group_desc; 160 unsigned long offset; 161 struct ext4_group_desc * desc; 162 struct ext4_sb_info *sbi = EXT4_SB(sb); 163 164 if (block_group >= sbi->s_groups_count) { 165 ext4_error (sb, "ext4_get_group_desc", 166 "block_group >= groups_count - " | 157 struct buffer_head ** bh) 158{ 159 unsigned long group_desc; 160 unsigned long offset; 161 struct ext4_group_desc * desc; 162 struct ext4_sb_info *sbi = EXT4_SB(sb); 163 164 if (block_group >= sbi->s_groups_count) { 165 ext4_error (sb, "ext4_get_group_desc", 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); 169 170 return NULL; 171 } 172 smp_rmb(); 173 174 group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb); 175 offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1); 176 if (!sbi->s_group_desc[group_desc]) { 177 ext4_error (sb, "ext4_get_group_desc", 178 "Group descriptor not loaded - " | 168 block_group, sbi->s_groups_count); 169 170 return NULL; 171 } 172 smp_rmb(); 173 174 group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb); 175 offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1); 176 if (!sbi->s_group_desc[group_desc]) { 177 ext4_error (sb, "ext4_get_group_desc", 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); 181 return NULL; 182 } 183 184 desc = (struct ext4_group_desc *)( 185 (__u8 *)sbi->s_group_desc[group_desc]->b_data + 186 offset * EXT4_DESC_SIZE(sb)); 187 if (bh) --- 7 unchanged lines hidden (view full) --- 195 * @block_group: given block group 196 * 197 * Read the bitmap for a given block_group, reading into the specified 198 * slot in the superblock's bitmap cache. 199 * 200 * Return buffer_head on success or NULL in case of failure. 201 */ 202struct buffer_head * | 180 block_group, group_desc, offset); 181 return NULL; 182 } 183 184 desc = (struct ext4_group_desc *)( 185 (__u8 *)sbi->s_group_desc[group_desc]->b_data + 186 offset * EXT4_DESC_SIZE(sb)); 187 if (bh) --- 7 unchanged lines hidden (view full) --- 195 * @block_group: given block group 196 * 197 * Read the bitmap for a given block_group, reading into the specified 198 * slot in the superblock's bitmap cache. 199 * 200 * Return buffer_head on success or NULL in case of failure. 201 */ 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{ 205 struct ext4_group_desc * desc; 206 struct buffer_head * bh = NULL; 207 ext4_fsblk_t bitmap_blk; 208 209 desc = ext4_get_group_desc(sb, block_group, NULL); 210 if (!desc) 211 return NULL; --- 10 unchanged lines hidden (view full) --- 222 unlock_buffer(bh); 223 } 224 } else { 225 bh = sb_bread(sb, bitmap_blk); 226 } 227 if (!bh) 228 ext4_error (sb, __FUNCTION__, 229 "Cannot read block bitmap - " | 204{ 205 struct ext4_group_desc * desc; 206 struct buffer_head * bh = NULL; 207 ext4_fsblk_t bitmap_blk; 208 209 desc = ext4_get_group_desc(sb, block_group, NULL); 210 if (!desc) 211 return NULL; --- 10 unchanged lines hidden (view full) --- 222 unlock_buffer(bh); 223 } 224 } else { 225 bh = sb_bread(sb, bitmap_blk); 226 } 227 if (!bh) 228 ext4_error (sb, __FUNCTION__, 229 "Cannot read block bitmap - " |
230 "block_group = %d, block_bitmap = %llu", | 230 "block_group = %lu, block_bitmap = %llu", |
231 block_group, bitmap_blk); 232 return bh; 233} 234/* 235 * The reservation window structure operations 236 * -------------------------------------------- 237 * Operations include: 238 * dump, find, add, remove, is_empty, find_next_reservable_window, etc. --- 76 unchanged lines hidden (view full) --- 315 * If the reservation window is outside the goal allocation group, return 0; 316 * grp_goal (given goal block) could be -1, which means no specific 317 * goal block. In this case, always return 1. 318 * If the goal block is within the reservation window, return 1; 319 * otherwise, return 0; 320 */ 321static int 322goal_in_my_reservation(struct ext4_reserve_window *rsv, ext4_grpblk_t grp_goal, | 231 block_group, bitmap_blk); 232 return bh; 233} 234/* 235 * The reservation window structure operations 236 * -------------------------------------------- 237 * Operations include: 238 * dump, find, add, remove, is_empty, find_next_reservable_window, etc. --- 76 unchanged lines hidden (view full) --- 315 * If the reservation window is outside the goal allocation group, return 0; 316 * grp_goal (given goal block) could be -1, which means no specific 317 * goal block. In this case, always return 1. 318 * If the goal block is within the reservation window, return 1; 319 * otherwise, return 0; 320 */ 321static int 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{ 325 ext4_fsblk_t group_first_block, group_last_block; 326 327 group_first_block = ext4_group_first_block_no(sb, group); 328 group_last_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1); 329 330 if ((rsv->_rsv_start > group_last_block) || 331 (rsv->_rsv_end < group_first_block)) --- 203 unchanged lines hidden (view full) --- 535 * @pdquot_freed_blocks: pointer to quota 536 */ 537void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb, 538 ext4_fsblk_t block, unsigned long count, 539 unsigned long *pdquot_freed_blocks) 540{ 541 struct buffer_head *bitmap_bh = NULL; 542 struct buffer_head *gd_bh; | 324{ 325 ext4_fsblk_t group_first_block, group_last_block; 326 327 group_first_block = ext4_group_first_block_no(sb, group); 328 group_last_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1); 329 330 if ((rsv->_rsv_start > group_last_block) || 331 (rsv->_rsv_end < group_first_block)) --- 203 unchanged lines hidden (view full) --- 535 * @pdquot_freed_blocks: pointer to quota 536 */ 537void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb, 538 ext4_fsblk_t block, unsigned long count, 539 unsigned long *pdquot_freed_blocks) 540{ 541 struct buffer_head *bitmap_bh = NULL; 542 struct buffer_head *gd_bh; |
543 unsigned long block_group; | 543 ext4_group_t block_group; |
544 ext4_grpblk_t bit; 545 unsigned long i; 546 unsigned long overflow; 547 struct ext4_group_desc * desc; 548 struct ext4_super_block * es; 549 struct ext4_sb_info *sbi; 550 int err = 0, ret; 551 ext4_grpblk_t group_freed; --- 363 unchanged lines hidden (view full) --- 915 * Otherwise, the allocation range starts from the give goal block, ends at 916 * the block group's last block. 917 * 918 * If we failed to allocate the desired block then we may end up crossing to a 919 * new bitmap. In that case we must release write access to the old one via 920 * ext4_journal_release_buffer(), else we'll run out of credits. 921 */ 922static ext4_grpblk_t | 544 ext4_grpblk_t bit; 545 unsigned long i; 546 unsigned long overflow; 547 struct ext4_group_desc * desc; 548 struct ext4_super_block * es; 549 struct ext4_sb_info *sbi; 550 int err = 0, ret; 551 ext4_grpblk_t group_freed; --- 363 unchanged lines hidden (view full) --- 915 * Otherwise, the allocation range starts from the give goal block, ends at 916 * the block group's last block. 917 * 918 * If we failed to allocate the desired block then we may end up crossing to a 919 * new bitmap. In that case we must release write access to the old one via 920 * ext4_journal_release_buffer(), else we'll run out of credits. 921 */ 922static ext4_grpblk_t |
923ext4_try_to_allocate(struct super_block *sb, handle_t *handle, int group, 924 struct buffer_head *bitmap_bh, ext4_grpblk_t grp_goal, 925 unsigned long *count, struct ext4_reserve_window *my_rsv) | 923ext4_try_to_allocate(struct super_block *sb, handle_t *handle, 924 ext4_group_t group, struct buffer_head *bitmap_bh, 925 ext4_grpblk_t grp_goal, unsigned long *count, 926 struct ext4_reserve_window *my_rsv) |
926{ 927 ext4_fsblk_t group_first_block; 928 ext4_grpblk_t start, end; 929 unsigned long num = 0; 930 931 /* we do allocation within the reservation window if we have a window */ 932 if (my_rsv) { 933 group_first_block = ext4_group_first_block_no(sb, group); --- 217 unchanged lines hidden (view full) --- 1151 * 1152 * @sb: the super block 1153 * @group: the group we are trying to allocate in 1154 * @bitmap_bh: the block group block bitmap 1155 * 1156 */ 1157static int alloc_new_reservation(struct ext4_reserve_window_node *my_rsv, 1158 ext4_grpblk_t grp_goal, struct super_block *sb, | 927{ 928 ext4_fsblk_t group_first_block; 929 ext4_grpblk_t start, end; 930 unsigned long num = 0; 931 932 /* we do allocation within the reservation window if we have a window */ 933 if (my_rsv) { 934 group_first_block = ext4_group_first_block_no(sb, group); --- 217 unchanged lines hidden (view full) --- 1152 * 1153 * @sb: the super block 1154 * @group: the group we are trying to allocate in 1155 * @bitmap_bh: the block group block bitmap 1156 * 1157 */ 1158static int alloc_new_reservation(struct ext4_reserve_window_node *my_rsv, 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 struct ext4_reserve_window_node *search_head; 1162 ext4_fsblk_t group_first_block, group_end_block, start_block; 1163 ext4_grpblk_t first_free_block; 1164 struct rb_root *fs_rsv_root = &EXT4_SB(sb)->s_rsv_window_root; 1165 unsigned long size; 1166 int ret; 1167 spinlock_t *rsv_lock = &EXT4_SB(sb)->s_rsv_window_lock; --- 181 unchanged lines hidden (view full) --- 1349 * reservation), and there are lots of free blocks, but they are all 1350 * being reserved. 1351 * 1352 * We use a red-black tree for the per-filesystem reservation list. 1353 * 1354 */ 1355static ext4_grpblk_t 1356ext4_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle, | 1161{ 1162 struct ext4_reserve_window_node *search_head; 1163 ext4_fsblk_t group_first_block, group_end_block, start_block; 1164 ext4_grpblk_t first_free_block; 1165 struct rb_root *fs_rsv_root = &EXT4_SB(sb)->s_rsv_window_root; 1166 unsigned long size; 1167 int ret; 1168 spinlock_t *rsv_lock = &EXT4_SB(sb)->s_rsv_window_lock; --- 181 unchanged lines hidden (view full) --- 1350 * reservation), and there are lots of free blocks, but they are all 1351 * being reserved. 1352 * 1353 * We use a red-black tree for the per-filesystem reservation list. 1354 * 1355 */ 1356static ext4_grpblk_t 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 struct ext4_reserve_window_node * my_rsv, 1360 unsigned long *count, int *errp) 1361{ 1362 ext4_fsblk_t group_first_block, group_last_block; 1363 ext4_grpblk_t ret = 0; 1364 int fatal; 1365 unsigned long num = *count; --- 157 unchanged lines hidden (view full) --- 1523 * any specific goal block. 1524 * 1525 */ 1526ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, 1527 ext4_fsblk_t goal, unsigned long *count, int *errp) 1528{ 1529 struct buffer_head *bitmap_bh = NULL; 1530 struct buffer_head *gdp_bh; | 1359 ext4_grpblk_t grp_goal, 1360 struct ext4_reserve_window_node * my_rsv, 1361 unsigned long *count, int *errp) 1362{ 1363 ext4_fsblk_t group_first_block, group_last_block; 1364 ext4_grpblk_t ret = 0; 1365 int fatal; 1366 unsigned long num = *count; --- 157 unchanged lines hidden (view full) --- 1524 * any specific goal block. 1525 * 1526 */ 1527ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, 1528 ext4_fsblk_t goal, unsigned long *count, int *errp) 1529{ 1530 struct buffer_head *bitmap_bh = NULL; 1531 struct buffer_head *gdp_bh; |
1531 unsigned long group_no; 1532 int goal_group; | 1532 ext4_group_t group_no; 1533 ext4_group_t goal_group; |
1533 ext4_grpblk_t grp_target_blk; /* blockgroup relative goal block */ 1534 ext4_grpblk_t grp_alloc_blk; /* blockgroup-relative allocated block*/ 1535 ext4_fsblk_t ret_block; /* filesyetem-wide allocated block */ | 1534 ext4_grpblk_t grp_target_blk; /* blockgroup relative goal block */ 1535 ext4_grpblk_t grp_alloc_blk; /* blockgroup-relative 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 performed_allocation = 0; 1539 ext4_grpblk_t free_blocks; /* number of free blocks in a group */ 1540 struct super_block *sb; 1541 struct ext4_group_desc *gdp; 1542 struct ext4_super_block *es; 1543 struct ext4_sb_info *sbi; 1544 struct ext4_reserve_window_node *my_rsv = NULL; 1545 struct ext4_block_alloc_info *block_i; 1546 unsigned short windowsz = 0; | 1538 int fatal = 0, err; 1539 int performed_allocation = 0; 1540 ext4_grpblk_t free_blocks; /* number of free blocks in a group */ 1541 struct super_block *sb; 1542 struct ext4_group_desc *gdp; 1543 struct ext4_super_block *es; 1544 struct ext4_sb_info *sbi; 1545 struct ext4_reserve_window_node *my_rsv = NULL; 1546 struct ext4_block_alloc_info *block_i; 1547 unsigned short windowsz = 0; |
1547#ifdef EXT4FS_DEBUG 1548 static int goal_hits, goal_attempts; 1549#endif 1550 unsigned long ngroups; | 1548 ext4_group_t ngroups; |
1551 unsigned long num = *count; 1552 1553 *errp = -ENOSPC; 1554 sb = inode->i_sb; 1555 if (!sb) { 1556 printk("ext4_new_block: nonexistent device"); 1557 return 0; 1558 } --- 179 unchanged lines hidden (view full) --- 1738 goto out; 1739 } 1740 1741 /* 1742 * It is up to the caller to add the new buffer to a journal 1743 * list of some description. We don't know in advance whether 1744 * the caller wants to use it as metadata or data. 1745 */ | 1549 unsigned long num = *count; 1550 1551 *errp = -ENOSPC; 1552 sb = inode->i_sb; 1553 if (!sb) { 1554 printk("ext4_new_block: nonexistent device"); 1555 return 0; 1556 } --- 179 unchanged lines hidden (view full) --- 1736 goto out; 1737 } 1738 1739 /* 1740 * It is up to the caller to add the new buffer to a journal 1741 * list of some description. We don't know in advance whether 1742 * the caller wants to use it as metadata or data. 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)); 1750 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) 1751 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); 1752 gdp->bg_free_blocks_count = 1753 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)-num); 1754 gdp->bg_checksum = ext4_group_desc_csum(sbi, group_no, gdp); 1755 spin_unlock(sb_bgl_lock(sbi, group_no)); 1756 percpu_counter_sub(&sbi->s_freeblocks_counter, num); --- 42 unchanged lines hidden (view full) --- 1799 * @sb: superblock 1800 * 1801 * Adds up the number of free blocks from each block group. 1802 */ 1803ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb) 1804{ 1805 ext4_fsblk_t desc_count; 1806 struct ext4_group_desc *gdp; | 1744 spin_lock(sb_bgl_lock(sbi, group_no)); 1745 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) 1746 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); 1747 gdp->bg_free_blocks_count = 1748 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)-num); 1749 gdp->bg_checksum = ext4_group_desc_csum(sbi, group_no, gdp); 1750 spin_unlock(sb_bgl_lock(sbi, group_no)); 1751 percpu_counter_sub(&sbi->s_freeblocks_counter, num); --- 42 unchanged lines hidden (view full) --- 1794 * @sb: superblock 1795 * 1796 * Adds up the number of free blocks from each block group. 1797 */ 1798ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb) 1799{ 1800 ext4_fsblk_t desc_count; 1801 struct ext4_group_desc *gdp; |
1807 int i; 1808 unsigned long ngroups = EXT4_SB(sb)->s_groups_count; | 1802 ext4_group_t i; 1803 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; |
1809#ifdef EXT4FS_DEBUG 1810 struct ext4_super_block *es; 1811 ext4_fsblk_t bitmap_count; 1812 unsigned long x; 1813 struct buffer_head *bitmap_bh = NULL; 1814 1815 es = EXT4_SB(sb)->s_es; 1816 desc_count = 0; --- 7 unchanged lines hidden (view full) --- 1824 continue; 1825 desc_count += le16_to_cpu(gdp->bg_free_blocks_count); 1826 brelse(bitmap_bh); 1827 bitmap_bh = read_block_bitmap(sb, i); 1828 if (bitmap_bh == NULL) 1829 continue; 1830 1831 x = ext4_count_free(bitmap_bh, sb->s_blocksize); | 1804#ifdef EXT4FS_DEBUG 1805 struct ext4_super_block *es; 1806 ext4_fsblk_t bitmap_count; 1807 unsigned long x; 1808 struct buffer_head *bitmap_bh = NULL; 1809 1810 es = EXT4_SB(sb)->s_es; 1811 desc_count = 0; --- 7 unchanged lines hidden (view full) --- 1819 continue; 1820 desc_count += le16_to_cpu(gdp->bg_free_blocks_count); 1821 brelse(bitmap_bh); 1822 bitmap_bh = read_block_bitmap(sb, i); 1823 if (bitmap_bh == NULL) 1824 continue; 1825 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); 1834 bitmap_count += x; 1835 } 1836 brelse(bitmap_bh); 1837 printk("ext4_count_free_blocks: stored = %llu" 1838 ", computed = %llu, %llu\n", 1839 EXT4_FREE_BLOCKS_COUNT(es), 1840 desc_count, bitmap_count); --- 7 unchanged lines hidden (view full) --- 1848 continue; 1849 desc_count += le16_to_cpu(gdp->bg_free_blocks_count); 1850 } 1851 1852 return desc_count; 1853#endif 1854} 1855 | 1828 i, le16_to_cpu(gdp->bg_free_blocks_count), x); 1829 bitmap_count += x; 1830 } 1831 brelse(bitmap_bh); 1832 printk("ext4_count_free_blocks: stored = %llu" 1833 ", computed = %llu, %llu\n", 1834 EXT4_FREE_BLOCKS_COUNT(es), 1835 desc_count, bitmap_count); --- 7 unchanged lines hidden (view full) --- 1843 continue; 1844 desc_count += le16_to_cpu(gdp->bg_free_blocks_count); 1845 } 1846 1847 return desc_count; 1848#endif 1849} 1850 |
1856static inline int test_root(int a, int b) | 1851static inline int test_root(ext4_group_t a, int b) |
1857{ 1858 int num = b; 1859 1860 while (a > num) 1861 num *= b; 1862 return num == a; 1863} 1864 | 1852{ 1853 int num = b; 1854 1855 while (a > num) 1856 num *= b; 1857 return num == a; 1858} 1859 |
1865static int ext4_group_sparse(int group) | 1860static int ext4_group_sparse(ext4_group_t group) |
1866{ 1867 if (group <= 1) 1868 return 1; 1869 if (!(group & 1)) 1870 return 0; 1871 return (test_root(group, 7) || test_root(group, 5) || 1872 test_root(group, 3)); 1873} 1874 1875/** 1876 * ext4_bg_has_super - number of blocks used by the superblock in group 1877 * @sb: superblock for filesystem 1878 * @group: group number to check 1879 * 1880 * Return the number of blocks used by the superblock (primary or backup) 1881 * in this group. Currently this will be only 0 or 1. 1882 */ | 1861{ 1862 if (group <= 1) 1863 return 1; 1864 if (!(group & 1)) 1865 return 0; 1866 return (test_root(group, 7) || test_root(group, 5) || 1867 test_root(group, 3)); 1868} 1869 1870/** 1871 * ext4_bg_has_super - number of blocks used by the superblock in group 1872 * @sb: superblock for filesystem 1873 * @group: group number to check 1874 * 1875 * Return the number of blocks used by the superblock (primary or backup) 1876 * in this group. Currently this will be only 0 or 1. 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{ 1885 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 1886 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) && 1887 !ext4_group_sparse(group)) 1888 return 0; 1889 return 1; 1890} 1891 | 1879{ 1880 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 1881 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) && 1882 !ext4_group_sparse(group)) 1883 return 0; 1884 return 1; 1885} 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{ 1894 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb); | 1889{ 1890 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb); |
1895 unsigned long first = metagroup * EXT4_DESC_PER_BLOCK(sb); 1896 unsigned long last = first + EXT4_DESC_PER_BLOCK(sb) - 1; | 1891 ext4_group_t first = metagroup * EXT4_DESC_PER_BLOCK(sb); 1892 ext4_group_t last = first + EXT4_DESC_PER_BLOCK(sb) - 1; |
1897 1898 if (group == first || group == first + 1 || group == last) 1899 return 1; 1900 return 0; 1901} 1902 | 1893 1894 if (group == first || group == first + 1 || group == last) 1895 return 1; 1896 return 0; 1897} 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{ 1905 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 1906 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) && 1907 !ext4_group_sparse(group)) 1908 return 0; 1909 return EXT4_SB(sb)->s_gdb_count; 1910} 1911 1912/** 1913 * ext4_bg_num_gdb - number of blocks used by the group table in group 1914 * @sb: superblock for filesystem 1915 * @group: group number to check 1916 * 1917 * Return the number of blocks used by the group descriptor table 1918 * (primary or backup) in this group. In the future there may be a 1919 * different number of descriptor blocks in each group. 1920 */ | 1901{ 1902 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 1903 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) && 1904 !ext4_group_sparse(group)) 1905 return 0; 1906 return EXT4_SB(sb)->s_gdb_count; 1907} 1908 1909/** 1910 * ext4_bg_num_gdb - number of blocks used by the group table in group 1911 * @sb: superblock for filesystem 1912 * @group: group number to check 1913 * 1914 * Return the number of blocks used by the group descriptor table 1915 * (primary or backup) in this group. In the future there may be a 1916 * different number of descriptor blocks in each group. 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{ 1923 unsigned long first_meta_bg = 1924 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg); 1925 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb); 1926 1927 if (!EXT4_HAS_INCOMPAT_FEATURE(sb,EXT4_FEATURE_INCOMPAT_META_BG) || 1928 metagroup < first_meta_bg) 1929 return ext4_bg_num_gdb_nometa(sb,group); 1930 1931 return ext4_bg_num_gdb_meta(sb,group); 1932 1933} | 1919{ 1920 unsigned long first_meta_bg = 1921 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg); 1922 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb); 1923 1924 if (!EXT4_HAS_INCOMPAT_FEATURE(sb,EXT4_FEATURE_INCOMPAT_META_BG) || 1925 metagroup < first_meta_bg) 1926 return ext4_bg_num_gdb_nometa(sb,group); 1927 1928 return ext4_bg_num_gdb_meta(sb,group); 1929 1930} |