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

ext4: Make ext4_group_t be an unsigned int

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>

+49 -49
+5 -5
fs/ext4/balloc.c
··· 100 100 * essentially implementing a per-group read-only flag. */ 101 101 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 102 102 ext4_error(sb, __func__, 103 - "Checksum bad for group %lu", block_group); 103 + "Checksum bad for group %u", block_group); 104 104 gdp->bg_free_blocks_count = 0; 105 105 gdp->bg_free_inodes_count = 0; 106 106 gdp->bg_itable_unused = 0; ··· 213 213 if (block_group >= sbi->s_groups_count) { 214 214 ext4_error(sb, "ext4_get_group_desc", 215 215 "block_group >= groups_count - " 216 - "block_group = %lu, groups_count = %lu", 216 + "block_group = %u, groups_count = %u", 217 217 block_group, sbi->s_groups_count); 218 218 219 219 return NULL; ··· 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 = %lu, group_desc = %lu, desc = %lu", 228 + "block_group = %u, group_desc = %lu, desc = %lu", 229 229 block_group, group_desc, offset); 230 230 return NULL; 231 231 } ··· 315 315 if (unlikely(!bh)) { 316 316 ext4_error(sb, __func__, 317 317 "Cannot read block bitmap - " 318 - "block_group = %lu, block_bitmap = %llu", 318 + "block_group = %u, block_bitmap = %llu", 319 319 block_group, bitmap_blk); 320 320 return NULL; 321 321 } ··· 337 337 put_bh(bh); 338 338 ext4_error(sb, __func__, 339 339 "Cannot read block bitmap - " 340 - "block_group = %lu, block_bitmap = %llu", 340 + "block_group = %u, block_bitmap = %llu", 341 341 block_group, bitmap_blk); 342 342 return NULL; 343 343 }
+1 -1
fs/ext4/ext4.h
··· 965 965 #define ERR_BAD_DX_DIR -75000 966 966 967 967 void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr, 968 - unsigned long *blockgrpp, ext4_grpblk_t *offsetp); 968 + ext4_group_t *blockgrpp, ext4_grpblk_t *offsetp); 969 969 970 970 extern struct proc_dir_entry *ext4_proc_root; 971 971
+1 -1
fs/ext4/ext4_i.h
··· 31 31 typedef __u32 ext4_lblk_t; 32 32 33 33 /* data type for block group number */ 34 - typedef unsigned long ext4_group_t; 34 + typedef unsigned int ext4_group_t; 35 35 36 36 #define rsv_start rsv_window._rsv_start 37 37 #define rsv_end rsv_window._rsv_end
+4 -4
fs/ext4/ialloc.c
··· 74 74 /* If checksum is bad mark all blocks and inodes use to prevent 75 75 * allocation, essentially implementing a per-group read-only flag. */ 76 76 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 77 - ext4_error(sb, __func__, "Checksum bad for group %lu", 77 + ext4_error(sb, __func__, "Checksum bad for group %u", 78 78 block_group); 79 79 gdp->bg_free_blocks_count = 0; 80 80 gdp->bg_free_inodes_count = 0; ··· 111 111 if (unlikely(!bh)) { 112 112 ext4_error(sb, __func__, 113 113 "Cannot read inode bitmap - " 114 - "block_group = %lu, inode_bitmap = %llu", 114 + "block_group = %u, inode_bitmap = %llu", 115 115 block_group, bitmap_blk); 116 116 return NULL; 117 117 } ··· 133 133 put_bh(bh); 134 134 ext4_error(sb, __func__, 135 135 "Cannot read inode bitmap - " 136 - "block_group = %lu, inode_bitmap = %llu", 136 + "block_group = %u, inode_bitmap = %llu", 137 137 block_group, bitmap_blk); 138 138 return NULL; 139 139 } ··· 690 690 ino > EXT4_INODES_PER_GROUP(sb)) { 691 691 ext4_error(sb, __func__, 692 692 "reserved inode or inode > inodes count - " 693 - "block_group = %lu, inode=%lu", group, 693 + "block_group = %u, inode=%lu", group, 694 694 ino + group * EXT4_INODES_PER_GROUP(sb)); 695 695 err = -EIO; 696 696 goto fail;
+29 -29
fs/ext4/mballoc.c
··· 447 447 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 448 448 449 449 ext4_error(sb, __func__, "double-free of inode" 450 - " %lu's block %llu(bit %u in group %lu)", 450 + " %lu's block %llu(bit %u in group %u)", 451 451 inode ? inode->i_ino : 0, blocknr, 452 452 first + i, e4b->bd_group); 453 453 } ··· 477 477 b2 = (unsigned char *) bitmap; 478 478 for (i = 0; i < e4b->bd_sb->s_blocksize; i++) { 479 479 if (b1[i] != b2[i]) { 480 - printk(KERN_ERR "corruption in group %lu " 480 + printk(KERN_ERR "corruption in group %u " 481 481 "at byte %u(%u): %x in copy != %x " 482 482 "on disk/prealloc\n", 483 483 e4b->bd_group, i, i * 8, b1[i], b2[i]); ··· 691 691 692 692 if (free != grp->bb_free) { 693 693 ext4_error(sb, __func__, 694 - "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd", 694 + "EXT4-fs: group %u: %u blocks in bitmap, %u in gd", 695 695 group, free, grp->bb_free); 696 696 /* 697 697 * If we intent to continue, we consider group descritor ··· 800 800 get_bh(bh[i]); 801 801 bh[i]->b_end_io = end_buffer_read_sync; 802 802 submit_bh(READ, bh[i]); 803 - mb_debug("read bitmap for group %lu\n", first_group + i); 803 + mb_debug("read bitmap for group %u\n", first_group + i); 804 804 } 805 805 806 806 /* wait for I/O completion */ ··· 895 895 struct page *page; 896 896 int ret; 897 897 898 - mb_debug("load group %lu\n", group); 898 + mb_debug("load group %u\n", group); 899 899 900 900 blocks_per_page = PAGE_CACHE_SIZE / sb->s_blocksize; 901 901 ··· 1096 1096 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 1097 1097 ext4_unlock_group(sb, e4b->bd_group); 1098 1098 ext4_error(sb, __func__, "double-free of inode" 1099 - " %lu's block %llu(bit %u in group %lu)", 1099 + " %lu's block %llu(bit %u in group %u)", 1100 1100 inode ? inode->i_ino : 0, blocknr, block, 1101 1101 e4b->bd_group); 1102 1102 ext4_lock_group(sb, e4b->bd_group); ··· 1934 1934 if (hs->op == EXT4_MB_HISTORY_ALLOC) { 1935 1935 fmt = "%-5u %-8u %-23s %-23s %-23s %-5u %-5u %-2u " 1936 1936 "%-5u %-5s %-5u %-6u\n"; 1937 - sprintf(buf2, "%lu/%d/%u@%u", hs->result.fe_group, 1937 + sprintf(buf2, "%u/%d/%u@%u", hs->result.fe_group, 1938 1938 hs->result.fe_start, hs->result.fe_len, 1939 1939 hs->result.fe_logical); 1940 - sprintf(buf, "%lu/%d/%u@%u", hs->orig.fe_group, 1940 + sprintf(buf, "%u/%d/%u@%u", hs->orig.fe_group, 1941 1941 hs->orig.fe_start, hs->orig.fe_len, 1942 1942 hs->orig.fe_logical); 1943 - sprintf(buf3, "%lu/%d/%u@%u", hs->goal.fe_group, 1943 + sprintf(buf3, "%u/%d/%u@%u", hs->goal.fe_group, 1944 1944 hs->goal.fe_start, hs->goal.fe_len, 1945 1945 hs->goal.fe_logical); 1946 1946 seq_printf(seq, fmt, hs->pid, hs->ino, buf, buf3, buf2, ··· 1949 1949 hs->buddy ? 1 << hs->buddy : 0); 1950 1950 } else if (hs->op == EXT4_MB_HISTORY_PREALLOC) { 1951 1951 fmt = "%-5u %-8u %-23s %-23s %-23s\n"; 1952 - sprintf(buf2, "%lu/%d/%u@%u", hs->result.fe_group, 1952 + sprintf(buf2, "%u/%d/%u@%u", hs->result.fe_group, 1953 1953 hs->result.fe_start, hs->result.fe_len, 1954 1954 hs->result.fe_logical); 1955 - sprintf(buf, "%lu/%d/%u@%u", hs->orig.fe_group, 1955 + sprintf(buf, "%u/%d/%u@%u", hs->orig.fe_group, 1956 1956 hs->orig.fe_start, hs->orig.fe_len, 1957 1957 hs->orig.fe_logical); 1958 1958 seq_printf(seq, fmt, hs->pid, hs->ino, buf, "", buf2); 1959 1959 } else if (hs->op == EXT4_MB_HISTORY_DISCARD) { 1960 - sprintf(buf2, "%lu/%d/%u", hs->result.fe_group, 1960 + sprintf(buf2, "%u/%d/%u", hs->result.fe_group, 1961 1961 hs->result.fe_start, hs->result.fe_len); 1962 1962 seq_printf(seq, "%-5u %-8u %-23s discard\n", 1963 1963 hs->pid, hs->ino, buf2); 1964 1964 } else if (hs->op == EXT4_MB_HISTORY_FREE) { 1965 - sprintf(buf2, "%lu/%d/%u", hs->result.fe_group, 1965 + sprintf(buf2, "%u/%d/%u", hs->result.fe_group, 1966 1966 hs->result.fe_start, hs->result.fe_len); 1967 1967 seq_printf(seq, "%-5u %-8u %-23s free\n", 1968 1968 hs->pid, hs->ino, buf2); ··· 2075 2075 return NULL; 2076 2076 2077 2077 group = *pos + 1; 2078 - return (void *) group; 2078 + return (void *) ((unsigned long) group); 2079 2079 } 2080 2080 2081 2081 static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos) ··· 2088 2088 if (*pos < 0 || *pos >= sbi->s_groups_count) 2089 2089 return NULL; 2090 2090 group = *pos + 1; 2091 - return (void *) group;; 2091 + return (void *) ((unsigned long) group); 2092 2092 } 2093 2093 2094 2094 static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v) 2095 2095 { 2096 2096 struct super_block *sb = seq->private; 2097 - long group = (long) v; 2097 + ext4_group_t group = (ext4_group_t) ((unsigned long) v); 2098 2098 int i; 2099 2099 int err; 2100 2100 struct ext4_buddy e4b; ··· 2116 2116 sizeof(struct ext4_group_info); 2117 2117 err = ext4_mb_load_buddy(sb, group, &e4b); 2118 2118 if (err) { 2119 - seq_printf(seq, "#%-5lu: I/O error\n", group); 2119 + seq_printf(seq, "#%-5u: I/O error\n", group); 2120 2120 return 0; 2121 2121 } 2122 2122 ext4_lock_group(sb, group); ··· 2124 2124 ext4_unlock_group(sb, group); 2125 2125 ext4_mb_release_desc(&e4b); 2126 2126 2127 - seq_printf(seq, "#%-5lu: %-5u %-5u %-5u [", group, sg.info.bb_free, 2127 + seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free, 2128 2128 sg.info.bb_fragments, sg.info.bb_first_free); 2129 2129 for (i = 0; i <= 13; i++) 2130 2130 seq_printf(seq, " %-5u", i <= sb->s_blocksize_bits + 1 ? ··· 2459 2459 desc = ext4_get_group_desc(sb, i, NULL); 2460 2460 if (desc == NULL) { 2461 2461 printk(KERN_ERR 2462 - "EXT4-fs: can't read descriptor %lu\n", i); 2462 + "EXT4-fs: can't read descriptor %u\n", i); 2463 2463 goto err_freebuddy; 2464 2464 } 2465 2465 if (ext4_mb_add_groupinfo(sb, i, desc) != 0) ··· 2657 2657 list_for_each_safe(l, ltmp, &txn->t_private_list) { 2658 2658 entry = list_entry(l, struct ext4_free_data, list); 2659 2659 2660 - mb_debug("gonna free %u blocks in group %lu (0x%p):", 2660 + mb_debug("gonna free %u blocks in group %u (0x%p):", 2661 2661 entry->count, entry->group, entry); 2662 2662 2663 2663 err = ext4_mb_load_buddy(sb, entry->group, &e4b); ··· 2829 2829 if (!gdp) 2830 2830 goto out_err; 2831 2831 2832 - ext4_debug("using block group %lu(%d)\n", ac->ac_b_ex.fe_group, 2832 + ext4_debug("using block group %u(%d)\n", ac->ac_b_ex.fe_group, 2833 2833 gdp->bg_free_blocks_count); 2834 2834 2835 2835 err = ext4_journal_get_write_access(handle, gdp_bh); ··· 3351 3351 preallocated += len; 3352 3352 count++; 3353 3353 } 3354 - mb_debug("prellocated %u for group %lu\n", preallocated, group); 3354 + mb_debug("prellocated %u for group %u\n", preallocated, group); 3355 3355 } 3356 3356 3357 3357 static void ext4_mb_pa_callback(struct rcu_head *head) ··· 3368 3368 static void ext4_mb_put_pa(struct ext4_allocation_context *ac, 3369 3369 struct super_block *sb, struct ext4_prealloc_space *pa) 3370 3370 { 3371 - unsigned long grp; 3371 + ext4_group_t grp; 3372 3372 3373 3373 if (!atomic_dec_and_test(&pa->pa_count) || pa->pa_free != 0) 3374 3374 return; ··· 3697 3697 int busy = 0; 3698 3698 int free = 0; 3699 3699 3700 - mb_debug("discard preallocation for group %lu\n", group); 3700 + mb_debug("discard preallocation for group %u\n", group); 3701 3701 3702 3702 if (list_empty(&grp->bb_prealloc_list)) 3703 3703 return 0; ··· 3705 3705 bitmap_bh = ext4_read_block_bitmap(sb, group); 3706 3706 if (bitmap_bh == NULL) { 3707 3707 ext4_error(sb, __func__, "Error in reading block " 3708 - "bitmap for %lu", group); 3708 + "bitmap for %u", group); 3709 3709 return 0; 3710 3710 } 3711 3711 3712 3712 err = ext4_mb_load_buddy(sb, group, &e4b); 3713 3713 if (err) { 3714 3714 ext4_error(sb, __func__, "Error in loading buddy " 3715 - "information for %lu", group); 3715 + "information for %u", group); 3716 3716 put_bh(bitmap_bh); 3717 3717 return 0; 3718 3718 } ··· 3879 3879 err = ext4_mb_load_buddy(sb, group, &e4b); 3880 3880 if (err) { 3881 3881 ext4_error(sb, __func__, "Error in loading buddy " 3882 - "information for %lu", group); 3882 + "information for %u", group); 3883 3883 continue; 3884 3884 } 3885 3885 3886 3886 bitmap_bh = ext4_read_block_bitmap(sb, group); 3887 3887 if (bitmap_bh == NULL) { 3888 3888 ext4_error(sb, __func__, "Error in reading block " 3889 - "bitmap for %lu", group); 3889 + "bitmap for %u", group); 3890 3890 ext4_mb_release_desc(&e4b); 3891 3891 continue; 3892 3892 } ··· 4151 4151 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL); 4152 4152 if (ext4_mb_load_buddy(sb, group, &e4b)) { 4153 4153 ext4_error(sb, __func__, "Error in loading buddy " 4154 - "information for %lu", group); 4154 + "information for %u", group); 4155 4155 continue; 4156 4156 } 4157 4157 ext4_lock_group(sb, group);
+2 -2
fs/ext4/resize.c
··· 50 50 ext4_get_group_no_and_offset(sb, start, NULL, &offset); 51 51 if (group != sbi->s_groups_count) 52 52 ext4_warning(sb, __func__, 53 - "Cannot add at group %u (only %lu groups)", 53 + "Cannot add at group %u (only %u groups)", 54 54 input->group, sbi->s_groups_count); 55 55 else if (offset != 0) 56 56 ext4_warning(sb, __func__, "Last group not full"); ··· 716 716 exit_err: 717 717 if (err) { 718 718 ext4_warning(sb, __func__, 719 - "can't update backup for group %lu (err %d), " 719 + "can't update backup for group %u (err %d), " 720 720 "forcing fsck on next reboot", group, err); 721 721 sbi->s_mount_state &= ~EXT4_VALID_FS; 722 722 sbi->s_es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
+7 -7
fs/ext4/super.c
··· 1470 1470 1471 1471 ext4_commit_super(sb, es, 1); 1472 1472 if (test_opt(sb, DEBUG)) 1473 - printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%lu, " 1473 + printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " 1474 1474 "bpg=%lu, ipg=%lu, mo=%04lx]\n", 1475 1475 sb->s_blocksize, 1476 1476 sbi->s_groups_count, ··· 1514 1514 sizeof(struct flex_groups), GFP_KERNEL); 1515 1515 if (sbi->s_flex_groups == NULL) { 1516 1516 printk(KERN_ERR "EXT4-fs: not enough memory for " 1517 - "%lu flex groups\n", flex_group_count); 1517 + "%u flex groups\n", flex_group_count); 1518 1518 goto failed; 1519 1519 } 1520 1520 ··· 1599 1599 block_bitmap = ext4_block_bitmap(sb, gdp); 1600 1600 if (block_bitmap < first_block || block_bitmap > last_block) { 1601 1601 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1602 - "Block bitmap for group %lu not in group " 1602 + "Block bitmap for group %u not in group " 1603 1603 "(block %llu)!\n", i, block_bitmap); 1604 1604 return 0; 1605 1605 } 1606 1606 inode_bitmap = ext4_inode_bitmap(sb, gdp); 1607 1607 if (inode_bitmap < first_block || inode_bitmap > last_block) { 1608 1608 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1609 - "Inode bitmap for group %lu not in group " 1609 + "Inode bitmap for group %u not in group " 1610 1610 "(block %llu)!\n", i, inode_bitmap); 1611 1611 return 0; 1612 1612 } ··· 1614 1614 if (inode_table < first_block || 1615 1615 inode_table + sbi->s_itb_per_group - 1 > last_block) { 1616 1616 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1617 - "Inode table for group %lu not in group " 1617 + "Inode table for group %u not in group " 1618 1618 "(block %llu)!\n", i, inode_table); 1619 1619 return 0; 1620 1620 } 1621 1621 spin_lock(sb_bgl_lock(sbi, i)); 1622 1622 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 1623 1623 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1624 - "Checksum for group %lu failed (%u!=%u)\n", 1624 + "Checksum for group %u failed (%u!=%u)\n", 1625 1625 i, le16_to_cpu(ext4_group_desc_csum(sbi, i, 1626 1626 gdp)), le16_to_cpu(gdp->bg_checksum)); 1627 1627 if (!(sb->s_flags & MS_RDONLY)) { ··· 3154 3154 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { 3155 3155 printk(KERN_ERR 3156 3156 "EXT4-fs: ext4_remount: " 3157 - "Checksum for group %lu failed (%u!=%u)\n", 3157 + "Checksum for group %u failed (%u!=%u)\n", 3158 3158 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), 3159 3159 le16_to_cpu(gdp->bg_checksum)); 3160 3160 err = -EINVAL;