Skip to content

Commit 1c2bf37

Browse files
Mingming CaoLinus Torvalds
authored andcommitted
[PATCH] ext3_fsblk_t: filesystem, group blocks and bug fixes
Some of the in-kernel ext3 block variable type are treated as signed 4 bytes int type, thus limited ext3 filesystem to 8TB (4kblock size based). While trying to fix them, it seems quite confusing in the ext3 code where some blocks are filesystem-wide blocks, some are group relative offsets that need to be signed value (as -1 has special meaning). So it seem saner to define two types of physical blocks: one is filesystem wide blocks, another is group-relative blocks. The following patches clarify these two types of blocks in the ext3 code, and fix the type bugs which limit current 32 bit ext3 filesystem limit to 8TB. With this series of patches and the percpu counter data type changes in the mm tree, we are able to extend exts filesystem limit to 16TB. This work is also a pre-request for the recent >32 bit ext3 work, and makes the kernel to able to address 48 bit ext3 block a lot easier: Simply redefine ext3_fsblk_t from unsigned long to sector_t and redefine the format string for ext3 filesystem block corresponding. Two RFC with a series patches have been posted to ext2-devel list and have been reviewed and discussed: http://marc.theaimsgroup.com/?l=ext2-devel&m=114722190816690&w=2 http://marc.theaimsgroup.com/?l=ext2-devel&m=114784919525942&w=2 Patches are tested on both 32 bit machine and 64 bit machine, <8TB ext3 and >8TB ext3 filesystem(with the latest to be released e2fsprogs-1.39). Tests includes overnight fsx, tiobench, dbench and fsstress. This patch: Defines ext3_fsblk_t and ext3_grpblk_t, and the printk format string for filesystem wide blocks. This patch classifies all block group relative blocks, and ext3_fsblk_t blocks occurs in the same function where used to be confusing before. Also include kernel bug fixes for filesystem wide in-kernel block variables. There are some fileystem wide blocks are treated as int/unsigned int type in the kernel currently, especially in ext3 block allocation and reservation code. This patch fixed those bugs by converting those variables to ext3_fsblk_t(unsigned long) type. Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent cedfb17 commit 1c2bf37

8 files changed

Lines changed: 177 additions & 149 deletions

File tree

‎fs/ext3/balloc.c‎

Lines changed: 112 additions & 103 deletions
Large diffs are not rendered by default.

‎fs/ext3/ialloc.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
262262
int ngroups = sbi->s_groups_count;
263263
int inodes_per_group = EXT3_INODES_PER_GROUP(sb);
264264
int freei, avefreei;
265-
int freeb, avefreeb;
266-
int blocks_per_dir, ndirs;
267-
int max_debt, max_dirs, min_blocks, min_inodes;
265+
ext3_fsblk_t freeb, avefreeb;
266+
ext3_fsblk_t blocks_per_dir;
267+
int ndirs;
268+
int max_debt, max_dirs, min_inodes;
269+
ext3_grpblk_t min_blocks;
268270
int group = -1, i;
269271
struct ext3_group_desc *desc;
270272
struct buffer_head *bh;
@@ -307,7 +309,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
307309
min_inodes = avefreei - inodes_per_group / 4;
308310
min_blocks = avefreeb - EXT3_BLOCKS_PER_GROUP(sb) / 4;
309311

310-
max_debt = EXT3_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, BLOCK_COST);
312+
max_debt = EXT3_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext3_fsblk_t)BLOCK_COST);
311313
if (max_debt * INODE_COST > inodes_per_group)
312314
max_debt = inodes_per_group / INODE_COST;
313315
if (max_debt > 255)

‎fs/ext3/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int ext3_inode_is_fast_symlink(struct inode *inode)
6262
* still needs to be revoked.
6363
*/
6464
int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
65-
struct buffer_head *bh, int blocknr)
65+
struct buffer_head *bh, ext3_fsblk_t blocknr)
6666
{
6767
int err;
6868

‎fs/ext3/resize.c‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ static int verify_group_input(struct super_block *sb,
2828
{
2929
struct ext3_sb_info *sbi = EXT3_SB(sb);
3030
struct ext3_super_block *es = sbi->s_es;
31-
unsigned start = le32_to_cpu(es->s_blocks_count);
32-
unsigned end = start + input->blocks_count;
31+
ext3_fsblk_t start = le32_to_cpu(es->s_blocks_count);
32+
ext3_fsblk_t end = start + input->blocks_count;
3333
unsigned group = input->group;
34-
unsigned itend = input->inode_table + sbi->s_itb_per_group;
34+
ext3_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
3535
unsigned overhead = ext3_bg_has_super(sb, group) ?
3636
(1 + ext3_bg_num_gdb(sb, group) +
3737
le16_to_cpu(es->s_reserved_gdt_blocks)) : 0;
38-
unsigned metaend = start + overhead;
38+
ext3_fsblk_t metaend = start + overhead;
3939
struct buffer_head *bh = NULL;
40-
int free_blocks_count;
40+
ext3_grpblk_t free_blocks_count;
4141
int err = -EINVAL;
4242

4343
input->free_blocks_count = free_blocks_count =
@@ -64,7 +64,8 @@ static int verify_group_input(struct super_block *sb,
6464
ext3_warning(sb, __FUNCTION__, "Bad blocks count %u",
6565
input->blocks_count);
6666
else if (!(bh = sb_bread(sb, end - 1)))
67-
ext3_warning(sb, __FUNCTION__, "Cannot read last block (%u)",
67+
ext3_warning(sb, __FUNCTION__,
68+
"Cannot read last block ("E3FSBLK")",
6869
end - 1);
6970
else if (outside(input->block_bitmap, start, end))
7071
ext3_warning(sb, __FUNCTION__,
@@ -77,32 +78,35 @@ static int verify_group_input(struct super_block *sb,
7778
else if (outside(input->inode_table, start, end) ||
7879
outside(itend - 1, start, end))
7980
ext3_warning(sb, __FUNCTION__,
80-
"Inode table not in group (blocks %u-%u)",
81+
"Inode table not in group (blocks %u-"E3FSBLK")",
8182
input->inode_table, itend - 1);
8283
else if (input->inode_bitmap == input->block_bitmap)
8384
ext3_warning(sb, __FUNCTION__,
8485
"Block bitmap same as inode bitmap (%u)",
8586
input->block_bitmap);
8687
else if (inside(input->block_bitmap, input->inode_table, itend))
8788
ext3_warning(sb, __FUNCTION__,
88-
"Block bitmap (%u) in inode table (%u-%u)",
89+
"Block bitmap (%u) in inode table (%u-"E3FSBLK")",
8990
input->block_bitmap, input->inode_table, itend-1);
9091
else if (inside(input->inode_bitmap, input->inode_table, itend))
9192
ext3_warning(sb, __FUNCTION__,
92-
"Inode bitmap (%u) in inode table (%u-%u)",
93+
"Inode bitmap (%u) in inode table (%u-"E3FSBLK")",
9394
input->inode_bitmap, input->inode_table, itend-1);
9495
else if (inside(input->block_bitmap, start, metaend))
9596
ext3_warning(sb, __FUNCTION__,
96-
"Block bitmap (%u) in GDT table (%u-%u)",
97+
"Block bitmap (%u) in GDT table"
98+
" ("E3FSBLK"-"E3FSBLK")",
9799
input->block_bitmap, start, metaend - 1);
98100
else if (inside(input->inode_bitmap, start, metaend))
99101
ext3_warning(sb, __FUNCTION__,
100-
"Inode bitmap (%u) in GDT table (%u-%u)",
102+
"Inode bitmap (%u) in GDT table"
103+
" ("E3FSBLK"-"E3FSBLK")",
101104
input->inode_bitmap, start, metaend - 1);
102105
else if (inside(input->inode_table, start, metaend) ||
103106
inside(itend - 1, start, metaend))
104107
ext3_warning(sb, __FUNCTION__,
105-
"Inode table (%u-%u) overlaps GDT table (%u-%u)",
108+
"Inode table (%u-"E3FSBLK") overlaps"
109+
"GDT table ("E3FSBLK"-"E3FSBLK")",
106110
input->inode_table, itend - 1, start, metaend - 1);
107111
else
108112
err = 0;
@@ -171,7 +175,7 @@ static int setup_new_group_blocks(struct super_block *sb,
171175
struct buffer_head *bh;
172176
handle_t *handle;
173177
unsigned long block;
174-
int bit;
178+
ext3_grpblk_t bit;
175179
int i;
176180
int err = 0, err2;
177181

@@ -340,7 +344,7 @@ static int verify_reserved_gdb(struct super_block *sb,
340344
while ((grp = ext3_list_backups(sb, &three, &five, &seven)) < end) {
341345
if (le32_to_cpu(*p++) != grp * EXT3_BLOCKS_PER_GROUP(sb) + blk){
342346
ext3_warning(sb, __FUNCTION__,
343-
"reserved GDT %ld missing grp %d (%ld)",
347+
"reserved GDT %lu missing grp %d (%lu)",
344348
blk, grp,
345349
grp * EXT3_BLOCKS_PER_GROUP(sb) + blk);
346350
return -EINVAL;
@@ -906,11 +910,12 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
906910
{
907911
unsigned long o_blocks_count;
908912
unsigned long o_groups_count;
909-
unsigned long last;
910-
int add;
913+
ext3_grpblk_t last;
914+
ext3_grpblk_t add;
911915
struct buffer_head * bh;
912916
handle_t *handle;
913-
int err, freed_blocks;
917+
int err;
918+
unsigned long freed_blocks;
914919

915920
/* We don't need to worry about locking wrt other resizers just
916921
* yet: we're going to revalidate es->s_blocks_count after
@@ -1001,10 +1006,10 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
10011006
ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
10021007
sb->s_dirt = 1;
10031008
unlock_super(sb);
1004-
ext3_debug("freeing blocks %ld through %ld\n", o_blocks_count,
1009+
ext3_debug("freeing blocks %lu through %lu\n", o_blocks_count,
10051010
o_blocks_count + add);
10061011
ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks);
1007-
ext3_debug("freed blocks %ld through %ld\n", o_blocks_count,
1012+
ext3_debug("freed blocks %lu through %lu\n", o_blocks_count,
10081013
o_blocks_count + add);
10091014
if ((err = ext3_journal_stop(handle)))
10101015
goto exit_put;

‎fs/ext3/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
18411841
struct buffer_head * bh;
18421842
journal_t *journal;
18431843
int start;
1844-
int len;
1844+
ext3_fsblk_t len;
18451845
int hblock, blocksize;
18461846
unsigned long sb_block;
18471847
unsigned long offset;

‎fs/ext3/xattr.c‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,15 @@ ext3_xattr_block_get(struct inode *inode, int name_index, const char *name,
225225
error = -ENODATA;
226226
if (!EXT3_I(inode)->i_file_acl)
227227
goto cleanup;
228-
ea_idebug(inode, "reading block %d", EXT3_I(inode)->i_file_acl);
228+
ea_idebug(inode, "reading block %u", EXT3_I(inode)->i_file_acl);
229229
bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl);
230230
if (!bh)
231231
goto cleanup;
232232
ea_bdebug(bh, "b_count=%d, refcount=%d",
233233
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
234234
if (ext3_xattr_check_block(bh)) {
235235
bad_block: ext3_error(inode->i_sb, __FUNCTION__,
236-
"inode %ld: bad block %d", inode->i_ino,
236+
"inode %ld: bad block %u", inode->i_ino,
237237
EXT3_I(inode)->i_file_acl);
238238
error = -EIO;
239239
goto cleanup;
@@ -366,7 +366,7 @@ ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
366366
error = 0;
367367
if (!EXT3_I(inode)->i_file_acl)
368368
goto cleanup;
369-
ea_idebug(inode, "reading block %d", EXT3_I(inode)->i_file_acl);
369+
ea_idebug(inode, "reading block %u", EXT3_I(inode)->i_file_acl);
370370
bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl);
371371
error = -EIO;
372372
if (!bh)
@@ -375,7 +375,7 @@ ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
375375
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
376376
if (ext3_xattr_check_block(bh)) {
377377
ext3_error(inode->i_sb, __FUNCTION__,
378-
"inode %ld: bad block %d", inode->i_ino,
378+
"inode %ld: bad block %u", inode->i_ino,
379379
EXT3_I(inode)->i_file_acl);
380380
error = -EIO;
381381
goto cleanup;
@@ -647,7 +647,7 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i,
647647
le32_to_cpu(BHDR(bs->bh)->h_refcount));
648648
if (ext3_xattr_check_block(bs->bh)) {
649649
ext3_error(sb, __FUNCTION__,
650-
"inode %ld: bad block %d", inode->i_ino,
650+
"inode %ld: bad block %u", inode->i_ino,
651651
EXT3_I(inode)->i_file_acl);
652652
error = -EIO;
653653
goto cleanup;
@@ -792,11 +792,12 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
792792
get_bh(new_bh);
793793
} else {
794794
/* We need to allocate a new block */
795-
int goal = le32_to_cpu(
795+
ext3_fsblk_t goal = le32_to_cpu(
796796
EXT3_SB(sb)->s_es->s_first_data_block) +
797-
EXT3_I(inode)->i_block_group *
797+
(ext3_fsblk_t)EXT3_I(inode)->i_block_group *
798798
EXT3_BLOCKS_PER_GROUP(sb);
799-
int block = ext3_new_block(handle, inode, goal, &error);
799+
ext3_fsblk_t block = ext3_new_block(handle, inode,
800+
goal, &error);
800801
if (error)
801802
goto cleanup;
802803
ea_idebug(inode, "creating block %d", block);
@@ -847,7 +848,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
847848

848849
bad_block:
849850
ext3_error(inode->i_sb, __FUNCTION__,
850-
"inode %ld: bad block %d", inode->i_ino,
851+
"inode %ld: bad block %u", inode->i_ino,
851852
EXT3_I(inode)->i_file_acl);
852853
goto cleanup;
853854

@@ -1076,14 +1077,14 @@ ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
10761077
bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl);
10771078
if (!bh) {
10781079
ext3_error(inode->i_sb, __FUNCTION__,
1079-
"inode %ld: block %d read error", inode->i_ino,
1080+
"inode %ld: block %u read error", inode->i_ino,
10801081
EXT3_I(inode)->i_file_acl);
10811082
goto cleanup;
10821083
}
10831084
if (BHDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
10841085
BHDR(bh)->h_blocks != cpu_to_le32(1)) {
10851086
ext3_error(inode->i_sb, __FUNCTION__,
1086-
"inode %ld: bad block %d", inode->i_ino,
1087+
"inode %ld: bad block %u", inode->i_ino,
10871088
EXT3_I(inode)->i_file_acl);
10881089
goto cleanup;
10891090
}
@@ -1210,11 +1211,11 @@ ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header,
12101211
bh = sb_bread(inode->i_sb, ce->e_block);
12111212
if (!bh) {
12121213
ext3_error(inode->i_sb, __FUNCTION__,
1213-
"inode %ld: block %ld read error",
1214+
"inode %ld: block %lu read error",
12141215
inode->i_ino, (unsigned long) ce->e_block);
12151216
} else if (le32_to_cpu(BHDR(bh)->h_refcount) >=
12161217
EXT3_XATTR_REFCOUNT_MAX) {
1217-
ea_idebug(inode, "block %ld refcount %d>=%d",
1218+
ea_idebug(inode, "block %lu refcount %d>=%d",
12181219
(unsigned long) ce->e_block,
12191220
le32_to_cpu(BHDR(bh)->h_refcount),
12201221
EXT3_XATTR_REFCOUNT_MAX);

‎include/linux/ext3_fs.h‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,15 @@ struct dir_private_info {
730730
/* balloc.c */
731731
extern int ext3_bg_has_super(struct super_block *sb, int group);
732732
extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group);
733-
extern int ext3_new_block (handle_t *, struct inode *, unsigned long, int *);
734-
extern int ext3_new_blocks (handle_t *, struct inode *, unsigned long,
735-
unsigned long *, int *);
736-
extern void ext3_free_blocks (handle_t *, struct inode *, unsigned long,
737-
unsigned long);
738-
extern void ext3_free_blocks_sb (handle_t *, struct super_block *,
739-
unsigned long, unsigned long, int *);
733+
extern ext3_fsblk_t ext3_new_block (handle_t *handle, struct inode *inode,
734+
ext3_fsblk_t goal, int *errp);
735+
extern ext3_fsblk_t ext3_new_blocks (handle_t *handle, struct inode *inode,
736+
ext3_fsblk_t goal, unsigned long *count, int *errp);
737+
extern void ext3_free_blocks (handle_t *handle, struct inode *inode,
738+
ext3_fsblk_t block, unsigned long count);
739+
extern void ext3_free_blocks_sb (handle_t *handle, struct super_block *sb,
740+
ext3_fsblk_t block, unsigned long count,
741+
unsigned long *pdquot_freed_blocks);
740742
extern unsigned long ext3_count_free_blocks (struct super_block *);
741743
extern void ext3_check_blocks_bitmap (struct super_block *);
742744
extern struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
@@ -773,7 +775,8 @@ extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
773775

774776

775777
/* inode.c */
776-
int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
778+
int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
779+
struct buffer_head *bh, ext3_fsblk_t blocknr);
777780
struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
778781
struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
779782
int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,

‎include/linux/ext3_fs_i.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
#include <linux/seqlock.h>
2222
#include <linux/mutex.h>
2323

24+
/* data type for block offset of block group */
25+
typedef int ext3_grpblk_t;
26+
27+
/* data type for filesystem-wide blocks number */
28+
typedef unsigned long ext3_fsblk_t;
29+
30+
#define E3FSBLK "%lu"
31+
2432
struct ext3_reserve_window {
2533
__u32 _rsv_start; /* First byte reserved */
2634
__u32 _rsv_end; /* Last byte reserved or 0 */

0 commit comments

Comments
 (0)