Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: Change unsigned long to unsigned int

Convert the unsigned longs that are most responsible for bloating the
stack usage on 64-bit systems.

Nearly all places in the ext3/4 code which uses "unsigned long" is
probably a bug, since on 32-bit systems a ulong a 32-bits, which means
we are wasting stack space on 64-bit systems.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

+77 -79
+7 -7
fs/ext4/balloc.c
··· 205 205 ext4_group_t block_group, 206 206 struct buffer_head **bh) 207 207 { 208 - unsigned long group_desc; 209 - unsigned long offset; 208 + unsigned int group_desc; 209 + unsigned int offset; 210 210 struct ext4_group_desc *desc; 211 211 struct ext4_sb_info *sbi = EXT4_SB(sb); 212 212 ··· 225 225 if (!sbi->s_group_desc[group_desc]) { 226 226 ext4_error(sb, "ext4_get_group_desc", 227 227 "Group descriptor not loaded - " 228 - "block_group = %u, group_desc = %lu, desc = %lu", 228 + "block_group = %u, group_desc = %u, desc = %u", 229 229 block_group, group_desc, offset); 230 230 return NULL; 231 231 } ··· 372 372 struct buffer_head *gd_bh; 373 373 ext4_group_t block_group; 374 374 ext4_grpblk_t bit; 375 - unsigned long i; 376 - unsigned long overflow; 375 + unsigned int i; 376 + unsigned int overflow; 377 377 struct ext4_group_desc *desc; 378 378 struct ext4_super_block *es; 379 379 struct ext4_sb_info *sbi; ··· 720 720 #ifdef EXT4FS_DEBUG 721 721 struct ext4_super_block *es; 722 722 ext4_fsblk_t bitmap_count; 723 - unsigned long x; 723 + unsigned int x; 724 724 struct buffer_head *bitmap_bh = NULL; 725 725 726 726 es = EXT4_SB(sb)->s_es; ··· 740 740 continue; 741 741 742 742 x = ext4_count_free(bitmap_bh, sb->s_blocksize); 743 - printk(KERN_DEBUG "group %lu: stored = %d, counted = %lu\n", 743 + printk(KERN_DEBUG "group %lu: stored = %d, counted = %u\n", 744 744 i, le16_to_cpu(gdp->bg_free_blocks_count), x); 745 745 bitmap_count += x; 746 746 }
+2 -3
fs/ext4/bitmap.c
··· 15 15 16 16 static const int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0}; 17 17 18 - unsigned long ext4_count_free(struct buffer_head *map, unsigned int numchars) 18 + unsigned int ext4_count_free(struct buffer_head *map, unsigned int numchars) 19 19 { 20 - unsigned int i; 21 - unsigned long sum = 0; 20 + unsigned int i, sum = 0; 22 21 23 22 if (!map) 24 23 return 0;
+4 -4
fs/ext4/dir.c
··· 64 64 int ext4_check_dir_entry(const char *function, struct inode *dir, 65 65 struct ext4_dir_entry_2 *de, 66 66 struct buffer_head *bh, 67 - unsigned long offset) 67 + unsigned int offset) 68 68 { 69 69 const char *error_msg = NULL; 70 70 const int rlen = ext4_rec_len_from_disk(de->rec_len); ··· 84 84 if (error_msg != NULL) 85 85 ext4_error(dir->i_sb, function, 86 86 "bad entry in directory #%lu: %s - " 87 - "offset=%lu, inode=%lu, rec_len=%d, name_len=%d", 87 + "offset=%u, inode=%u, rec_len=%d, name_len=%d", 88 88 dir->i_ino, error_msg, offset, 89 - (unsigned long) le32_to_cpu(de->inode), 89 + le32_to_cpu(de->inode), 90 90 rlen, de->name_len); 91 91 return error_msg == NULL ? 1 : 0; 92 92 } ··· 95 95 void *dirent, filldir_t filldir) 96 96 { 97 97 int error = 0; 98 - unsigned long offset; 98 + unsigned int offset; 99 99 int i, stored; 100 100 struct ext4_dir_entry_2 *de; 101 101 struct super_block *sb;
+10 -12
fs/ext4/ext4.h
··· 94 94 /* phys. block for ^^^ */ 95 95 ext4_fsblk_t pright; 96 96 /* how many blocks we want to allocate */ 97 - unsigned long len; 97 + unsigned int len; 98 98 /* flags. see above EXT4_MB_HINT_* */ 99 - unsigned long flags; 99 + unsigned int flags; 100 100 }; 101 101 102 102 /* ··· 997 997 # define ATTRIB_NORET __attribute__((noreturn)) 998 998 # define NORET_AND noreturn, 999 999 1000 + /* bitmap.c */ 1001 + extern unsigned int ext4_count_free(struct buffer_head *, unsigned); 1002 + 1000 1003 /* balloc.c */ 1001 1004 extern unsigned int ext4_block_group(struct super_block *sb, 1002 1005 ext4_fsblk_t blocknr); ··· 1027 1024 /* dir.c */ 1028 1025 extern int ext4_check_dir_entry(const char *, struct inode *, 1029 1026 struct ext4_dir_entry_2 *, 1030 - struct buffer_head *, unsigned long); 1027 + struct buffer_head *, unsigned int); 1031 1028 extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, 1032 1029 __u32 minor_hash, 1033 1030 struct ext4_dir_entry_2 *dirent); ··· 1047 1044 extern unsigned long ext4_count_free_inodes(struct super_block *); 1048 1045 extern unsigned long ext4_count_dirs(struct super_block *); 1049 1046 extern void ext4_check_inodes_bitmap(struct super_block *); 1050 - extern unsigned long ext4_count_free(struct buffer_head *, unsigned); 1051 1047 1052 1048 /* mballoc.c */ 1053 1049 extern long ext4_mb_stats; ··· 1076 1074 ext4_lblk_t, int, int *); 1077 1075 int ext4_get_block(struct inode *inode, sector_t iblock, 1078 1076 struct buffer_head *bh_result, int create); 1079 - int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, 1080 - ext4_lblk_t iblock, unsigned long maxblocks, 1081 - struct buffer_head *bh_result, 1082 - int create, int extend_disksize); 1083 1077 1084 1078 extern struct inode *ext4_iget(struct super_block *, unsigned long); 1085 1079 extern int ext4_write_inode(struct inode *, int); ··· 1274 1276 extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks, 1275 1277 int chunk); 1276 1278 extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, 1277 - ext4_lblk_t iblock, 1278 - unsigned long max_blocks, struct buffer_head *bh_result, 1279 - int create, int extend_disksize); 1279 + ext4_lblk_t iblock, unsigned int max_blocks, 1280 + struct buffer_head *bh_result, 1281 + int create, int extend_disksize); 1280 1282 extern void ext4_ext_truncate(struct inode *); 1281 1283 extern void ext4_ext_init(struct super_block *); 1282 1284 extern void ext4_ext_release(struct super_block *); 1283 1285 extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset, 1284 1286 loff_t len); 1285 1287 extern int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, 1286 - sector_t block, unsigned long max_blocks, 1288 + sector_t block, unsigned int max_blocks, 1287 1289 struct buffer_head *bh, int create, 1288 1290 int extend_disksize, int flag); 1289 1291 #endif /* __KERNEL__ */
+7 -6
fs/ext4/ext4_i.h
··· 100 100 */ 101 101 loff_t i_disksize; 102 102 103 - /* on-disk additional length */ 104 - __u16 i_extra_isize; 105 - 106 103 /* 107 104 * i_data_sem is for serialising ext4_truncate() against 108 105 * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's ··· 126 129 spinlock_t i_prealloc_lock; 127 130 128 131 /* allocation reservation info for delalloc */ 129 - unsigned long i_reserved_data_blocks; 130 - unsigned long i_reserved_meta_blocks; 131 - unsigned long i_allocated_meta_blocks; 132 + unsigned int i_reserved_data_blocks; 133 + unsigned int i_reserved_meta_blocks; 134 + unsigned int i_allocated_meta_blocks; 132 135 unsigned short i_delalloc_reserved_flag; 136 + 137 + /* on-disk additional length */ 138 + __u16 i_extra_isize; 139 + 133 140 spinlock_t i_block_reservation_lock; 134 141 }; 135 142
+12 -12
fs/ext4/extents.c
··· 2377 2377 struct inode *inode, 2378 2378 struct ext4_ext_path *path, 2379 2379 ext4_lblk_t iblock, 2380 - unsigned long max_blocks) 2380 + unsigned int max_blocks) 2381 2381 { 2382 2382 struct ext4_extent *ex, newex, orig_ex; 2383 2383 struct ext4_extent *ex1 = NULL; ··· 2675 2675 */ 2676 2676 int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, 2677 2677 ext4_lblk_t iblock, 2678 - unsigned long max_blocks, struct buffer_head *bh_result, 2678 + unsigned int max_blocks, struct buffer_head *bh_result, 2679 2679 int create, int extend_disksize) 2680 2680 { 2681 2681 struct ext4_ext_path *path = NULL; 2682 2682 struct ext4_extent_header *eh; 2683 2683 struct ext4_extent newex, *ex; 2684 - ext4_fsblk_t goal, newblock; 2685 - int err = 0, depth, ret; 2686 - unsigned long allocated = 0; 2684 + ext4_fsblk_t newblock; 2685 + int err = 0, depth, ret, cache_type; 2686 + unsigned int allocated = 0; 2687 2687 struct ext4_allocation_request ar; 2688 2688 loff_t disksize; 2689 2689 2690 2690 __clear_bit(BH_New, &bh_result->b_state); 2691 - ext_debug("blocks %u/%lu requested for inode %u\n", 2691 + ext_debug("blocks %u/%u requested for inode %u\n", 2692 2692 iblock, max_blocks, inode->i_ino); 2693 2693 2694 2694 /* check in cache */ 2695 - goal = ext4_ext_in_cache(inode, iblock, &newex); 2696 - if (goal) { 2697 - if (goal == EXT4_EXT_CACHE_GAP) { 2695 + cache_type = ext4_ext_in_cache(inode, iblock, &newex); 2696 + if (cache_type) { 2697 + if (cache_type == EXT4_EXT_CACHE_GAP) { 2698 2698 if (!create) { 2699 2699 /* 2700 2700 * block isn't allocated yet and ··· 2703 2703 goto out2; 2704 2704 } 2705 2705 /* we should allocate requested block */ 2706 - } else if (goal == EXT4_EXT_CACHE_EXTENT) { 2706 + } else if (cache_type == EXT4_EXT_CACHE_EXTENT) { 2707 2707 /* block is already allocated */ 2708 2708 newblock = iblock 2709 2709 - le32_to_cpu(newex.ee_block) ··· 2851 2851 if (!newblock) 2852 2852 goto out2; 2853 2853 ext_debug("allocate new block: goal %llu, found %llu/%lu\n", 2854 - goal, newblock, allocated); 2854 + ar.goal, newblock, allocated); 2855 2855 2856 2856 /* try to insert new extent into found leaf and return */ 2857 2857 ext4_ext_store_pblock(&newex, newblock); ··· 3001 3001 handle_t *handle; 3002 3002 ext4_lblk_t block; 3003 3003 loff_t new_size; 3004 - unsigned long max_blocks; 3004 + unsigned int max_blocks; 3005 3005 int ret = 0; 3006 3006 int ret2 = 0; 3007 3007 int retries = 0;
+13 -12
fs/ext4/inode.c
··· 514 514 * return the total number of blocks to be allocate, including the 515 515 * direct and indirect blocks. 516 516 */ 517 - static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned long blks, 517 + static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned int blks, 518 518 int blocks_to_boundary) 519 519 { 520 - unsigned long count = 0; 520 + unsigned int count = 0; 521 521 522 522 /* 523 523 * Simple case, [t,d]Indirect block(s) has not allocated yet ··· 856 856 * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block 857 857 * (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem) 858 858 */ 859 - int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, 860 - ext4_lblk_t iblock, unsigned long maxblocks, 861 - struct buffer_head *bh_result, 862 - int create, int extend_disksize) 859 + static int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, 860 + ext4_lblk_t iblock, unsigned int maxblocks, 861 + struct buffer_head *bh_result, 862 + int create, int extend_disksize) 863 863 { 864 864 int err = -EIO; 865 865 ext4_lblk_t offsets[4]; ··· 1061 1061 * It returns the error in case of allocation failure. 1062 1062 */ 1063 1063 int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, 1064 - unsigned long max_blocks, struct buffer_head *bh, 1064 + unsigned int max_blocks, struct buffer_head *bh, 1065 1065 int create, int extend_disksize, int flag) 1066 1066 { 1067 1067 int retval; ··· 1641 1641 get_block_t *get_block; 1642 1642 struct writeback_control *wbc; 1643 1643 int io_done; 1644 - long pages_written; 1644 + int pages_written; 1645 1645 int retval; 1646 1646 }; 1647 1647 ··· 1855 1855 printk(KERN_EMERG "dirty_blocks=%lld\n", 1856 1856 (long long)percpu_counter_sum(&sbi->s_dirtyblocks_counter)); 1857 1857 printk(KERN_EMERG "Block reservation details\n"); 1858 - printk(KERN_EMERG "i_reserved_data_blocks=%lu\n", 1858 + printk(KERN_EMERG "i_reserved_data_blocks=%u\n", 1859 1859 EXT4_I(inode)->i_reserved_data_blocks); 1860 - printk(KERN_EMERG "i_reserved_meta_blocks=%lu\n", 1860 + printk(KERN_EMERG "i_reserved_meta_blocks=%u\n", 1861 1861 EXT4_I(inode)->i_reserved_meta_blocks); 1862 1862 return; 1863 1863 } ··· 2307 2307 { 2308 2308 int ret = 0; 2309 2309 loff_t size; 2310 - unsigned long len; 2310 + unsigned int len; 2311 2311 struct buffer_head *page_bufs; 2312 2312 struct inode *inode = page->mapping->host; 2313 2313 ··· 2416 2416 struct mpage_da_data mpd; 2417 2417 struct inode *inode = mapping->host; 2418 2418 int no_nrwrite_index_update; 2419 - long pages_written = 0, pages_skipped; 2419 + int pages_written = 0; 2420 + long pages_skipped; 2420 2421 int needed_blocks, ret = 0, nr_to_writebump = 0; 2421 2422 struct ext4_sb_info *sbi = EXT4_SB(mapping->host->i_sb); 2422 2423
+10 -10
fs/ext4/mballoc.c
··· 2796 2796 */ 2797 2797 static noinline_for_stack int 2798 2798 ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, 2799 - handle_t *handle, unsigned long reserv_blks) 2799 + handle_t *handle, unsigned int reserv_blks) 2800 2800 { 2801 2801 struct buffer_head *bitmap_bh = NULL; 2802 2802 struct ext4_super_block *es; ··· 3036 3036 /* check we don't cross already preallocated blocks */ 3037 3037 rcu_read_lock(); 3038 3038 list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { 3039 - unsigned long pa_end; 3039 + ext4_lblk_t pa_end; 3040 3040 3041 3041 if (pa->pa_deleted) 3042 3042 continue; ··· 3080 3080 /* XXX: extra loop to check we really don't overlap preallocations */ 3081 3081 rcu_read_lock(); 3082 3082 list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { 3083 - unsigned long pa_end; 3083 + ext4_lblk_t pa_end; 3084 3084 spin_lock(&pa->pa_lock); 3085 3085 if (pa->pa_deleted == 0) { 3086 3086 pa_end = pa->pa_lstart + pa->pa_len; ··· 3584 3584 { 3585 3585 struct super_block *sb = e4b->bd_sb; 3586 3586 struct ext4_sb_info *sbi = EXT4_SB(sb); 3587 - unsigned long end; 3588 - unsigned long next; 3587 + unsigned int end; 3588 + unsigned int next; 3589 3589 ext4_group_t group; 3590 3590 ext4_grpblk_t bit; 3591 3591 sector_t start; ··· 4029 4029 struct ext4_sb_info *sbi = EXT4_SB(sb); 4030 4030 struct ext4_super_block *es = sbi->s_es; 4031 4031 ext4_group_t group; 4032 - unsigned long len; 4033 - unsigned long goal; 4032 + unsigned int len; 4033 + ext4_fsblk_t goal; 4034 4034 ext4_grpblk_t block; 4035 4035 4036 4036 /* we can't allocate > group size */ ··· 4291 4291 struct ext4_sb_info *sbi; 4292 4292 struct super_block *sb; 4293 4293 ext4_fsblk_t block = 0; 4294 - unsigned long inquota; 4295 - unsigned long reserv_blks = 0; 4294 + unsigned int inquota; 4295 + unsigned int reserv_blks = 0; 4296 4296 4297 4297 sb = ar->inode->i_sb; 4298 4298 sbi = EXT4_SB(sb); ··· 4504 4504 struct ext4_allocation_context *ac = NULL; 4505 4505 struct ext4_group_desc *gdp; 4506 4506 struct ext4_super_block *es; 4507 - unsigned long overflow; 4507 + unsigned int overflow; 4508 4508 ext4_grpblk_t bit; 4509 4509 struct buffer_head *gd_bh; 4510 4510 ext4_group_t block_group;
+12 -13
fs/ext4/namei.c
··· 811 811 static inline int search_dirblock(struct buffer_head *bh, 812 812 struct inode *dir, 813 813 const struct qstr *d_name, 814 - unsigned long offset, 814 + unsigned int offset, 815 815 struct ext4_dir_entry_2 ** res_dir) 816 816 { 817 817 struct ext4_dir_entry_2 * de; ··· 1048 1048 bh = ext4_find_entry(dir, &dentry->d_name, &de); 1049 1049 inode = NULL; 1050 1050 if (bh) { 1051 - unsigned long ino = le32_to_cpu(de->inode); 1051 + __u32 ino = le32_to_cpu(de->inode); 1052 1052 brelse(bh); 1053 1053 if (!ext4_valid_inum(dir->i_sb, ino)) { 1054 1054 ext4_error(dir->i_sb, "ext4_lookup", 1055 - "bad inode number: %lu", ino); 1055 + "bad inode number: %u", ino); 1056 1056 return ERR_PTR(-EIO); 1057 1057 } 1058 1058 inode = ext4_iget(dir->i_sb, ino); ··· 1065 1065 1066 1066 struct dentry *ext4_get_parent(struct dentry *child) 1067 1067 { 1068 - unsigned long ino; 1068 + __u32 ino; 1069 1069 struct inode *inode; 1070 1070 static const struct qstr dotdot = { 1071 1071 .name = "..", ··· 1083 1083 1084 1084 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) { 1085 1085 ext4_error(child->d_inode->i_sb, "ext4_get_parent", 1086 - "bad inode number: %lu", ino); 1086 + "bad inode number: %u", ino); 1087 1087 return ERR_PTR(-EIO); 1088 1088 } 1089 1089 ··· 1271 1271 struct inode *dir = dentry->d_parent->d_inode; 1272 1272 const char *name = dentry->d_name.name; 1273 1273 int namelen = dentry->d_name.len; 1274 - unsigned long offset = 0; 1274 + unsigned int offset = 0; 1275 1275 unsigned short reclen; 1276 1276 int nlen, rlen, err; 1277 1277 char *top; ··· 1444 1444 struct inode *inode) 1445 1445 { 1446 1446 struct inode *dir = dentry->d_parent->d_inode; 1447 - unsigned long offset; 1448 1447 struct buffer_head *bh; 1449 1448 struct ext4_dir_entry_2 *de; 1450 1449 struct super_block *sb; ··· 1465 1466 ext4_mark_inode_dirty(handle, dir); 1466 1467 } 1467 1468 blocks = dir->i_size >> sb->s_blocksize_bits; 1468 - for (block = 0, offset = 0; block < blocks; block++) { 1469 + for (block = 0; block < blocks; block++) { 1469 1470 bh = ext4_bread(handle, dir, block, 0, &retval); 1470 1471 if(!bh) 1471 1472 return retval; ··· 1860 1861 */ 1861 1862 static int empty_dir(struct inode *inode) 1862 1863 { 1863 - unsigned long offset; 1864 + unsigned int offset; 1864 1865 struct buffer_head *bh; 1865 1866 struct ext4_dir_entry_2 *de, *de1; 1866 1867 struct super_block *sb; ··· 1905 1906 if (err) 1906 1907 ext4_error(sb, __func__, 1907 1908 "error %d reading directory" 1908 - " #%lu offset %lu", 1909 + " #%lu offset %u", 1909 1910 err, inode->i_ino, offset); 1910 1911 offset += sb->s_blocksize; 1911 1912 continue; ··· 2008 2009 struct list_head *prev; 2009 2010 struct ext4_inode_info *ei = EXT4_I(inode); 2010 2011 struct ext4_sb_info *sbi; 2011 - unsigned long ino_next; 2012 + __u32 ino_next; 2012 2013 struct ext4_iloc iloc; 2013 2014 int err = 0; 2014 2015 ··· 2041 2042 goto out_err; 2042 2043 2043 2044 if (prev == &sbi->s_orphan) { 2044 - jbd_debug(4, "superblock will point to %lu\n", ino_next); 2045 + jbd_debug(4, "superblock will point to %u\n", ino_next); 2045 2046 BUFFER_TRACE(sbi->s_sbh, "get_write_access"); 2046 2047 err = ext4_journal_get_write_access(handle, sbi->s_sbh); 2047 2048 if (err) ··· 2053 2054 struct inode *i_prev = 2054 2055 &list_entry(prev, struct ext4_inode_info, i_orphan)->vfs_inode; 2055 2056 2056 - jbd_debug(4, "orphan inode %lu will point to %lu\n", 2057 + jbd_debug(4, "orphan inode %lu will point to %u\n", 2057 2058 i_prev->i_ino, ino_next); 2058 2059 err = ext4_reserve_inode_write(handle, i_prev, &iloc2); 2059 2060 if (err)