aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/ialloc.c
diff options
context:
space:
mode:
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>2009-01-05 22:20:24 -0500
committerTheodore Ts'o <tytso@mit.edu>2009-01-05 22:20:24 -0500
commit560671a0d3c9ad2d647fa6d09375a262e1f19c4f (patch)
treea52673326726062d53b35643d51a16739cd804fc /fs/ext4/ialloc.c
parente8134b27e351e813414da3b95aa8eac6d3908088 (diff)
ext4: Use high 16 bits of the block group descriptor's free counts fields
Rename the lower bits with suffix _lo and add helper to access the values. Also rename bg_itable_unused_hi to bg_pad as in e2fsprogs. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/ialloc.c')
-rw-r--r--fs/ext4/ialloc.c83
1 files changed, 44 insertions, 39 deletions
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index cac3617ec780..11c4f6f5bd61 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -76,9 +76,9 @@ unsigned ext4_init_inode_bitmap(struct super_block *sb, struct buffer_head *bh,
76 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 76 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) {
77 ext4_error(sb, __func__, "Checksum bad for group %u", 77 ext4_error(sb, __func__, "Checksum bad for group %u",
78 block_group); 78 block_group);
79 gdp->bg_free_blocks_count = 0; 79 ext4_free_blks_set(sb, gdp, 0);
80 gdp->bg_free_inodes_count = 0; 80 ext4_free_inodes_set(sb, gdp, 0);
81 gdp->bg_itable_unused = 0; 81 ext4_itable_unused_set(sb, gdp, 0);
82 memset(bh->b_data, 0xff, sb->s_blocksize); 82 memset(bh->b_data, 0xff, sb->s_blocksize);
83 return 0; 83 return 0;
84 } 84 }
@@ -168,7 +168,7 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
168 struct ext4_group_desc *gdp; 168 struct ext4_group_desc *gdp;
169 struct ext4_super_block *es; 169 struct ext4_super_block *es;
170 struct ext4_sb_info *sbi; 170 struct ext4_sb_info *sbi;
171 int fatal = 0, err; 171 int fatal = 0, err, count;
172 ext4_group_t flex_group; 172 ext4_group_t flex_group;
173 173
174 if (atomic_read(&inode->i_count) > 1) { 174 if (atomic_read(&inode->i_count) > 1) {
@@ -236,9 +236,12 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
236 236
237 if (gdp) { 237 if (gdp) {
238 spin_lock(sb_bgl_lock(sbi, block_group)); 238 spin_lock(sb_bgl_lock(sbi, block_group));
239 le16_add_cpu(&gdp->bg_free_inodes_count, 1); 239 count = ext4_free_inodes_count(sb, gdp) + 1;
240 if (is_directory) 240 ext4_free_inodes_set(sb, gdp, count);
241 le16_add_cpu(&gdp->bg_used_dirs_count, -1); 241 if (is_directory) {
242 count = ext4_used_dirs_count(sb, gdp) - 1;
243 ext4_used_dirs_set(sb, gdp, count);
244 }
242 gdp->bg_checksum = ext4_group_desc_csum(sbi, 245 gdp->bg_checksum = ext4_group_desc_csum(sbi,
243 block_group, gdp); 246 block_group, gdp);
244 spin_unlock(sb_bgl_lock(sbi, block_group)); 247 spin_unlock(sb_bgl_lock(sbi, block_group));
@@ -291,13 +294,13 @@ static int find_group_dir(struct super_block *sb, struct inode *parent,
291 294
292 for (group = 0; group < ngroups; group++) { 295 for (group = 0; group < ngroups; group++) {
293 desc = ext4_get_group_desc(sb, group, NULL); 296 desc = ext4_get_group_desc(sb, group, NULL);
294 if (!desc || !desc->bg_free_inodes_count) 297 if (!desc || !ext4_free_inodes_count(sb, desc))
295 continue; 298 continue;
296 if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei) 299 if (ext4_free_inodes_count(sb, desc) < avefreei)
297 continue; 300 continue;
298 if (!best_desc || 301 if (!best_desc ||
299 (le16_to_cpu(desc->bg_free_blocks_count) > 302 (ext4_free_blks_count(sb, desc) >
300 le16_to_cpu(best_desc->bg_free_blocks_count))) { 303 ext4_free_blks_count(sb, best_desc))) {
301 *best_group = group; 304 *best_group = group;
302 best_desc = desc; 305 best_desc = desc;
303 ret = 0; 306 ret = 0;
@@ -369,7 +372,7 @@ found_flexbg:
369 for (i = best_flex * flex_size; i < ngroups && 372 for (i = best_flex * flex_size; i < ngroups &&
370 i < (best_flex + 1) * flex_size; i++) { 373 i < (best_flex + 1) * flex_size; i++) {
371 desc = ext4_get_group_desc(sb, i, &bh); 374 desc = ext4_get_group_desc(sb, i, &bh);
372 if (le16_to_cpu(desc->bg_free_inodes_count)) { 375 if (ext4_free_inodes_count(sb, desc)) {
373 *best_group = i; 376 *best_group = i;
374 goto out; 377 goto out;
375 } 378 }
@@ -443,17 +446,17 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
443 for (i = 0; i < ngroups; i++) { 446 for (i = 0; i < ngroups; i++) {
444 grp = (parent_group + i) % ngroups; 447 grp = (parent_group + i) % ngroups;
445 desc = ext4_get_group_desc(sb, grp, NULL); 448 desc = ext4_get_group_desc(sb, grp, NULL);
446 if (!desc || !desc->bg_free_inodes_count) 449 if (!desc || !ext4_free_inodes_count(sb, desc))
447 continue; 450 continue;
448 if (le16_to_cpu(desc->bg_used_dirs_count) >= best_ndir) 451 if (ext4_used_dirs_count(sb, desc) >= best_ndir)
449 continue; 452 continue;
450 if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei) 453 if (ext4_free_inodes_count(sb, desc) < avefreei)
451 continue; 454 continue;
452 if (le16_to_cpu(desc->bg_free_blocks_count) < avefreeb) 455 if (ext4_free_blks_count(sb, desc) < avefreeb)
453 continue; 456 continue;
454 *group = grp; 457 *group = grp;
455 ret = 0; 458 ret = 0;
456 best_ndir = le16_to_cpu(desc->bg_used_dirs_count); 459 best_ndir = ext4_used_dirs_count(sb, desc);
457 } 460 }
458 if (ret == 0) 461 if (ret == 0)
459 return ret; 462 return ret;
@@ -479,13 +482,13 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
479 for (i = 0; i < ngroups; i++) { 482 for (i = 0; i < ngroups; i++) {
480 *group = (parent_group + i) % ngroups; 483 *group = (parent_group + i) % ngroups;
481 desc = ext4_get_group_desc(sb, *group, NULL); 484 desc = ext4_get_group_desc(sb, *group, NULL);
482 if (!desc || !desc->bg_free_inodes_count) 485 if (!desc || !ext4_free_inodes_count(sb, desc))
483 continue; 486 continue;
484 if (le16_to_cpu(desc->bg_used_dirs_count) >= max_dirs) 487 if (ext4_used_dirs_count(sb, desc) >= max_dirs)
485 continue; 488 continue;
486 if (le16_to_cpu(desc->bg_free_inodes_count) < min_inodes) 489 if (ext4_free_inodes_count(sb, desc) < min_inodes)
487 continue; 490 continue;
488 if (le16_to_cpu(desc->bg_free_blocks_count) < min_blocks) 491 if (ext4_free_blks_count(sb, desc) < min_blocks)
489 continue; 492 continue;
490 return 0; 493 return 0;
491 } 494 }
@@ -494,8 +497,8 @@ fallback:
494 for (i = 0; i < ngroups; i++) { 497 for (i = 0; i < ngroups; i++) {
495 *group = (parent_group + i) % ngroups; 498 *group = (parent_group + i) % ngroups;
496 desc = ext4_get_group_desc(sb, *group, NULL); 499 desc = ext4_get_group_desc(sb, *group, NULL);
497 if (desc && desc->bg_free_inodes_count && 500 if (desc && ext4_free_inodes_count(sb, desc) &&
498 le16_to_cpu(desc->bg_free_inodes_count) >= avefreei) 501 ext4_free_inodes_count(sb, desc) >= avefreei)
499 return 0; 502 return 0;
500 } 503 }
501 504
@@ -524,8 +527,8 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
524 */ 527 */
525 *group = parent_group; 528 *group = parent_group;
526 desc = ext4_get_group_desc(sb, *group, NULL); 529 desc = ext4_get_group_desc(sb, *group, NULL);
527 if (desc && le16_to_cpu(desc->bg_free_inodes_count) && 530 if (desc && ext4_free_inodes_count(sb, desc) &&
528 le16_to_cpu(desc->bg_free_blocks_count)) 531 ext4_free_blks_count(sb, desc))
529 return 0; 532 return 0;
530 533
531 /* 534 /*
@@ -548,8 +551,8 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
548 if (*group >= ngroups) 551 if (*group >= ngroups)
549 *group -= ngroups; 552 *group -= ngroups;
550 desc = ext4_get_group_desc(sb, *group, NULL); 553 desc = ext4_get_group_desc(sb, *group, NULL);
551 if (desc && le16_to_cpu(desc->bg_free_inodes_count) && 554 if (desc && ext4_free_inodes_count(sb, desc) &&
552 le16_to_cpu(desc->bg_free_blocks_count)) 555 ext4_free_blks_count(sb, desc))
553 return 0; 556 return 0;
554 } 557 }
555 558
@@ -562,7 +565,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
562 if (++*group >= ngroups) 565 if (++*group >= ngroups)
563 *group = 0; 566 *group = 0;
564 desc = ext4_get_group_desc(sb, *group, NULL); 567 desc = ext4_get_group_desc(sb, *group, NULL);
565 if (desc && le16_to_cpu(desc->bg_free_inodes_count)) 568 if (desc && ext4_free_inodes_count(sb, desc))
566 return 0; 569 return 0;
567 } 570 }
568 571
@@ -591,7 +594,7 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode)
591 struct ext4_super_block *es; 594 struct ext4_super_block *es;
592 struct ext4_inode_info *ei; 595 struct ext4_inode_info *ei;
593 struct ext4_sb_info *sbi; 596 struct ext4_sb_info *sbi;
594 int ret2, err = 0; 597 int ret2, err = 0, count;
595 struct inode *ret; 598 struct inode *ret;
596 ext4_group_t i; 599 ext4_group_t i;
597 int free = 0; 600 int free = 0;
@@ -718,7 +721,7 @@ got:
718 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 721 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
719 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); 722 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
720 free = ext4_free_blocks_after_init(sb, group, gdp); 723 free = ext4_free_blocks_after_init(sb, group, gdp);
721 gdp->bg_free_blocks_count = cpu_to_le16(free); 724 ext4_free_blks_set(sb, gdp, free);
722 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, 725 gdp->bg_checksum = ext4_group_desc_csum(sbi, group,
723 gdp); 726 gdp);
724 } 727 }
@@ -753,7 +756,7 @@ got:
753 free = 0; 756 free = 0;
754 } else { 757 } else {
755 free = EXT4_INODES_PER_GROUP(sb) - 758 free = EXT4_INODES_PER_GROUP(sb) -
756 le16_to_cpu(gdp->bg_itable_unused); 759 ext4_itable_unused_count(sb, gdp);
757 } 760 }
758 761
759 /* 762 /*
@@ -763,13 +766,15 @@ got:
763 * 766 *
764 */ 767 */
765 if (ino > free) 768 if (ino > free)
766 gdp->bg_itable_unused = 769 ext4_itable_unused_set(sb, gdp,
767 cpu_to_le16(EXT4_INODES_PER_GROUP(sb) - ino); 770 (EXT4_INODES_PER_GROUP(sb) - ino));
768 } 771 }
769 772
770 le16_add_cpu(&gdp->bg_free_inodes_count, -1); 773 count = ext4_free_inodes_count(sb, gdp) - 1;
774 ext4_free_inodes_set(sb, gdp, count);
771 if (S_ISDIR(mode)) { 775 if (S_ISDIR(mode)) {
772 le16_add_cpu(&gdp->bg_used_dirs_count, 1); 776 count = ext4_used_dirs_count(sb, gdp) + 1;
777 ext4_used_dirs_set(sb, gdp, count);
773 } 778 }
774 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); 779 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp);
775 spin_unlock(sb_bgl_lock(sbi, group)); 780 spin_unlock(sb_bgl_lock(sbi, group));
@@ -987,7 +992,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)
987 gdp = ext4_get_group_desc(sb, i, NULL); 992 gdp = ext4_get_group_desc(sb, i, NULL);
988 if (!gdp) 993 if (!gdp)
989 continue; 994 continue;
990 desc_count += le16_to_cpu(gdp->bg_free_inodes_count); 995 desc_count += ext4_free_inodes_count(sb, gdp);
991 brelse(bitmap_bh); 996 brelse(bitmap_bh);
992 bitmap_bh = ext4_read_inode_bitmap(sb, i); 997 bitmap_bh = ext4_read_inode_bitmap(sb, i);
993 if (!bitmap_bh) 998 if (!bitmap_bh)
@@ -995,7 +1000,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)
995 1000
996 x = ext4_count_free(bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8); 1001 x = ext4_count_free(bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8);
997 printk(KERN_DEBUG "group %lu: stored = %d, counted = %lu\n", 1002 printk(KERN_DEBUG "group %lu: stored = %d, counted = %lu\n",
998 i, le16_to_cpu(gdp->bg_free_inodes_count), x); 1003 i, ext4_free_inodes_count(sb, gdp), x);
999 bitmap_count += x; 1004 bitmap_count += x;
1000 } 1005 }
1001 brelse(bitmap_bh); 1006 brelse(bitmap_bh);
@@ -1009,7 +1014,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)
1009 gdp = ext4_get_group_desc(sb, i, NULL); 1014 gdp = ext4_get_group_desc(sb, i, NULL);
1010 if (!gdp) 1015 if (!gdp)
1011 continue; 1016 continue;
1012 desc_count += le16_to_cpu(gdp->bg_free_inodes_count); 1017 desc_count += ext4_free_inodes_count(sb, gdp);
1013 cond_resched(); 1018 cond_resched();
1014 } 1019 }
1015 return desc_count; 1020 return desc_count;
@@ -1026,7 +1031,7 @@ unsigned long ext4_count_dirs(struct super_block * sb)
1026 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); 1031 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
1027 if (!gdp) 1032 if (!gdp)
1028 continue; 1033 continue;
1029 count += le16_to_cpu(gdp->bg_used_dirs_count); 1034 count += ext4_used_dirs_count(sb, gdp);
1030 } 1035 }
1031 return count; 1036 return count;
1032} 1037}