1 Date: Tue, 19 Sep 2006 15:33:04 -0500
2 From: Eric Sandeen <esandeen@redhat.com>
3 Subject: [RHEL5 Patch 3/3] (resend) Fix ext3 32-bit inodes
5 This one is in the -mm tree as ext3-inode-numbers-are-unsigned-long.patch,
6 resent to accomodate sct's request for uints instead; just pinged akpm
7 to pick up the ulonglong->uint change.
9 This is primarily format string fixes, with changes to ialloc.c where large
10 inode counts could overflow, and also pass around journal_inum as an
11 unsigned long, just to be pedantic about it....
13 Signed-off-by: Eric Sandeen <esandeen@redhat.com>
14 Cc: Mingming Cao <cmm@us.ibm.com>
15 Signed-off-by: Andrew Morton <akpm@osdl.org>
17 Index: linux-2.6.17-1.2654.el5/fs/ext3/ialloc.c
18 ===================================================================
19 --- linux-2.6.17-1.2654.el5.orig/fs/ext3/ialloc.c
20 +++ linux-2.6.17-1.2654.el5/fs/ext3/ialloc.c
21 @@ -202,7 +202,7 @@ error_return:
22 static int find_group_dir(struct super_block *sb, struct inode *parent)
24 int ngroups = EXT3_SB(sb)->s_groups_count;
25 - int freei, avefreei;
26 + unsigned int freei, avefreei;
27 struct ext3_group_desc *desc, *best_desc = NULL;
28 struct buffer_head *bh;
29 int group, best_group = -1;
30 @@ -261,10 +261,10 @@ static int find_group_orlov(struct super
31 struct ext3_super_block *es = sbi->s_es;
32 int ngroups = sbi->s_groups_count;
33 int inodes_per_group = EXT3_INODES_PER_GROUP(sb);
34 - int freei, avefreei;
35 + unsigned int freei, avefreei;
36 ext3_fsblk_t freeb, avefreeb;
37 ext3_fsblk_t blocks_per_dir;
40 int max_debt, max_dirs, min_inodes;
41 ext3_grpblk_t min_blocks;
43 Index: linux-2.6.17-1.2654.el5/fs/ext3/inode.c
44 ===================================================================
45 --- linux-2.6.17-1.2654.el5.orig/fs/ext3/inode.c
46 +++ linux-2.6.17-1.2654.el5/fs/ext3/inode.c
47 @@ -2115,7 +2115,7 @@ static void ext3_free_branches(handle_t
50 ext3_error(inode->i_sb, "ext3_free_branches",
51 - "Read failure, inode=%ld, block="E3FSBLK,
52 + "Read failure, inode=%lu, block="E3FSBLK,
56 Index: linux-2.6.17-1.2654.el5/fs/ext3/namei.c
57 ===================================================================
58 --- linux-2.6.17-1.2654.el5.orig/fs/ext3/namei.c
59 +++ linux-2.6.17-1.2654.el5/fs/ext3/namei.c
60 @@ -1919,8 +1919,8 @@ int ext3_orphan_add(handle_t *handle, st
62 list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan);
64 - jbd_debug(4, "superblock will point to %ld\n", inode->i_ino);
65 - jbd_debug(4, "orphan inode %ld will point to %d\n",
66 + jbd_debug(4, "superblock will point to %lu\n", inode->i_ino);
67 + jbd_debug(4, "orphan inode %lu will point to %d\n",
68 inode->i_ino, NEXT_ORPHAN(inode));
71 Index: linux-2.6.17-1.2654.el5/fs/ext3/super.c
72 ===================================================================
73 --- linux-2.6.17-1.2654.el5.orig/fs/ext3/super.c
74 +++ linux-2.6.17-1.2654.el5/fs/ext3/super.c
76 static int ext3_load_journal(struct super_block *, struct ext3_super_block *,
77 unsigned long journal_devnum);
78 static int ext3_create_journal(struct super_block *, struct ext3_super_block *,
81 static void ext3_commit_super (struct super_block * sb,
82 struct ext3_super_block * es,
84 @@ -376,7 +376,7 @@ static void dump_orphan_list(struct supe
85 list_for_each(l, &sbi->s_orphan) {
86 struct inode *inode = orphan_list_entry(l);
88 - "inode %s:%ld at %p: mode %o, nlink %d, next %d\n",
89 + "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
90 inode->i_sb->s_id, inode->i_ino, inode,
91 inode->i_mode, inode->i_nlink,
93 @@ -711,7 +711,7 @@ static ext3_fsblk_t get_sb_block(void **
96 static int parse_options (char *options, struct super_block *sb,
97 - unsigned long *inum, unsigned long *journal_devnum,
98 + unsigned int *inum, unsigned long *journal_devnum,
99 ext3_fsblk_t *n_blocks_count, int is_remount)
101 struct ext3_sb_info *sbi = EXT3_SB(sb);
102 @@ -1264,17 +1264,17 @@ static void ext3_orphan_cleanup (struct
104 if (inode->i_nlink) {
106 - "%s: truncating inode %ld to %Ld bytes\n",
107 + "%s: truncating inode %lu to %Ld bytes\n",
108 __FUNCTION__, inode->i_ino, inode->i_size);
109 - jbd_debug(2, "truncating inode %ld to %Ld bytes\n",
110 + jbd_debug(2, "truncating inode %lu to %Ld bytes\n",
111 inode->i_ino, inode->i_size);
112 ext3_truncate(inode);
116 - "%s: deleting unreferenced inode %ld\n",
117 + "%s: deleting unreferenced inode %lu\n",
118 __FUNCTION__, inode->i_ino);
119 - jbd_debug(2, "deleting unreferenced inode %ld\n",
120 + jbd_debug(2, "deleting unreferenced inode %lu\n",
124 @@ -1353,7 +1353,7 @@ static int ext3_fill_super (struct super
125 ext3_fsblk_t sb_block = get_sb_block(&data);
126 ext3_fsblk_t logic_sb_block;
127 unsigned long offset = 0;
128 - unsigned long journal_inum = 0;
129 + unsigned int journal_inum = 0;
130 unsigned long journal_devnum = 0;
131 unsigned long def_mount_opts;
133 @@ -1802,7 +1802,8 @@ static void ext3_init_journal_params(str
134 spin_unlock(&journal->j_state_lock);
137 -static journal_t *ext3_get_journal(struct super_block *sb, int journal_inum)
138 +static journal_t *ext3_get_journal(struct super_block *sb,
139 + unsigned int journal_inum)
141 struct inode *journal_inode;
143 @@ -1937,7 +1938,7 @@ static int ext3_load_journal(struct supe
144 unsigned long journal_devnum)
147 - int journal_inum = le32_to_cpu(es->s_journal_inum);
148 + unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
151 int really_read_only;
152 @@ -2023,7 +2024,7 @@ static int ext3_load_journal(struct supe
154 static int ext3_create_journal(struct super_block * sb,
155 struct ext3_super_block * es,
157 + unsigned int journal_inum)
161 @@ -2036,7 +2037,7 @@ static int ext3_create_journal(struct su
162 if (!(journal = ext3_get_journal(sb, journal_inum)))
165 - printk(KERN_INFO "EXT3-fs: creating new journal on inode %d\n",
166 + printk(KERN_INFO "EXT3-fs: creating new journal on inode %u\n",
169 if (journal_create(journal)) {
170 Index: linux-2.6.17-1.2654.el5/fs/ext3/xattr.c
171 ===================================================================
172 --- linux-2.6.17-1.2654.el5.orig/fs/ext3/xattr.c
173 +++ linux-2.6.17-1.2654.el5/fs/ext3/xattr.c
176 #ifdef EXT3_XATTR_DEBUG
177 # define ea_idebug(inode, f...) do { \
178 - printk(KERN_DEBUG "inode %s:%ld: ", \
179 + printk(KERN_DEBUG "inode %s:%lu: ", \
180 inode->i_sb->s_id, inode->i_ino); \
183 @@ -233,7 +233,7 @@ ext3_xattr_block_get(struct inode *inode
184 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
185 if (ext3_xattr_check_block(bh)) {
186 bad_block: ext3_error(inode->i_sb, __FUNCTION__,
187 - "inode %ld: bad block "E3FSBLK, inode->i_ino,
188 + "inode %lu: bad block "E3FSBLK, inode->i_ino,
189 EXT3_I(inode)->i_file_acl);
192 @@ -375,7 +375,7 @@ ext3_xattr_block_list(struct inode *inod
193 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
194 if (ext3_xattr_check_block(bh)) {
195 ext3_error(inode->i_sb, __FUNCTION__,
196 - "inode %ld: bad block "E3FSBLK, inode->i_ino,
197 + "inode %lu: bad block "E3FSBLK, inode->i_ino,
198 EXT3_I(inode)->i_file_acl);
201 @@ -647,7 +647,7 @@ ext3_xattr_block_find(struct inode *inod
202 le32_to_cpu(BHDR(bs->bh)->h_refcount));
203 if (ext3_xattr_check_block(bs->bh)) {
204 ext3_error(sb, __FUNCTION__,
205 - "inode %ld: bad block "E3FSBLK, inode->i_ino,
206 + "inode %lu: bad block "E3FSBLK, inode->i_ino,
207 EXT3_I(inode)->i_file_acl);
210 @@ -848,7 +848,7 @@ cleanup_dquot:
213 ext3_error(inode->i_sb, __FUNCTION__,
214 - "inode %ld: bad block "E3FSBLK, inode->i_ino,
215 + "inode %lu: bad block "E3FSBLK, inode->i_ino,
216 EXT3_I(inode)->i_file_acl);
219 @@ -1077,14 +1077,14 @@ ext3_xattr_delete_inode(handle_t *handle
220 bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl);
222 ext3_error(inode->i_sb, __FUNCTION__,
223 - "inode %ld: block "E3FSBLK" read error", inode->i_ino,
224 + "inode %lu: block "E3FSBLK" read error", inode->i_ino,
225 EXT3_I(inode)->i_file_acl);
228 if (BHDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) ||
229 BHDR(bh)->h_blocks != cpu_to_le32(1)) {
230 ext3_error(inode->i_sb, __FUNCTION__,
231 - "inode %ld: bad block "E3FSBLK, inode->i_ino,
232 + "inode %lu: bad block "E3FSBLK, inode->i_ino,
233 EXT3_I(inode)->i_file_acl);
236 @@ -1211,7 +1211,7 @@ again:
237 bh = sb_bread(inode->i_sb, ce->e_block);
239 ext3_error(inode->i_sb, __FUNCTION__,
240 - "inode %ld: block %lu read error",
241 + "inode %lu: block %lu read error",
242 inode->i_ino, (unsigned long) ce->e_block);
243 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >=
244 EXT3_XATTR_REFCOUNT_MAX) {
246 Date: Tue, 19 Sep 2006 15:32:02 -0500
247 From: Eric Sandeen <esandeen@redhat.com>
248 Subject: [RHEL5 Patch 1/3] (resend) Fix ext3 overflows at 16T
250 This one is in -mm as fix-ext3-mounts-at-16t.patch and
251 fix-ext3-mounts-at-16t-fix.patch
253 this gets things mounting for a 16T ext3 filesystem. (patched up
254 e2fsprogs will be needed too, working on that)
256 jarod wilson has been helping with testing.
258 This patch fixes these issues in the kernel:
260 o sbi->s_groups_count overflows in ext3_fill_super()
262 sbi->s_groups_count = (le32_to_cpu(es->s_blocks_count) -
263 le32_to_cpu(es->s_first_data_block) +
264 EXT3_BLOCKS_PER_GROUP(sb) - 1) /
265 EXT3_BLOCKS_PER_GROUP(sb);
267 at 16T, s_blocks_count is already maxed out; adding
268 EXT3_BLOCKS_PER_GROUP(sb) overflows it and groups_count comes out to 0.
269 Not really what we want, and causes a failed mount.
271 Changing it this way works & avoids the overflow:
273 (A + B - 1)/B changed to: ((A - 1)/B) + 1
275 o ext3_check_descriptors() overflows range checks
277 ext3_check_descriptors() iterates over all block groups making sure
278 that various bits are within the right block ranges... on the last pass
279 through, it is checking the error case
281 [item] >= block + EXT3_BLOCKS_PER_GROUP(sb)
283 where "block" is the first block in the last block group. The last
284 block in this group (and the last one that will fit in 32 bits) is block
285 + EXT3_BLOCKS_PER_GROUP(sb)- 1. block + EXT3_BLOCKS_PER_GROUP(sb) wraps
288 so, make things clearer with "first_block" and "last_block" where those
289 are first and last, inclusive, and use <, > rather than <, >=.
291 Finally, the last block group may be smaller than the rest, so account
292 for this on the last pass through: last_block = sb->s_blocks_count - 1;
294 Signed-off-by: Eric Sandeen <esandeen@redhat.com>
295 Cc: Mingming Cao <cmm@us.ibm.com>
296 Signed-off-by: Andrew Morton <akpm@osdl.org>
298 Index: linux-2.6.17-1.2654.el5/fs/ext3/super.c
299 ===================================================================
300 --- linux-2.6.17-1.2654.el5.orig/fs/ext3/super.c
301 +++ linux-2.6.17-1.2654.el5/fs/ext3/super.c
302 @@ -1132,7 +1132,8 @@ static int ext3_setup_super(struct super
303 static int ext3_check_descriptors (struct super_block * sb)
305 struct ext3_sb_info *sbi = EXT3_SB(sb);
306 - ext3_fsblk_t block = le32_to_cpu(sbi->s_es->s_first_data_block);
307 + ext3_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
308 + ext3_fsblk_t last_block;
309 struct ext3_group_desc * gdp = NULL;
312 @@ -1141,12 +1142,17 @@ static int ext3_check_descriptors (struc
314 for (i = 0; i < sbi->s_groups_count; i++)
316 + if (i == sbi->s_groups_count - 1)
317 + last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
319 + last_block = first_block +
320 + (EXT3_BLOCKS_PER_GROUP(sb) - 1);
322 if ((i % EXT3_DESC_PER_BLOCK(sb)) == 0)
323 gdp = (struct ext3_group_desc *)
324 sbi->s_group_desc[desc_block++]->b_data;
325 - if (le32_to_cpu(gdp->bg_block_bitmap) < block ||
326 - le32_to_cpu(gdp->bg_block_bitmap) >=
327 - block + EXT3_BLOCKS_PER_GROUP(sb))
328 + if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
329 + le32_to_cpu(gdp->bg_block_bitmap) > last_block)
331 ext3_error (sb, "ext3_check_descriptors",
332 "Block bitmap for group %d"
333 @@ -1155,9 +1161,8 @@ static int ext3_check_descriptors (struc
334 le32_to_cpu(gdp->bg_block_bitmap));
337 - if (le32_to_cpu(gdp->bg_inode_bitmap) < block ||
338 - le32_to_cpu(gdp->bg_inode_bitmap) >=
339 - block + EXT3_BLOCKS_PER_GROUP(sb))
340 + if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block ||
341 + le32_to_cpu(gdp->bg_inode_bitmap) > last_block)
343 ext3_error (sb, "ext3_check_descriptors",
344 "Inode bitmap for group %d"
345 @@ -1166,9 +1171,9 @@ static int ext3_check_descriptors (struc
346 le32_to_cpu(gdp->bg_inode_bitmap));
349 - if (le32_to_cpu(gdp->bg_inode_table) < block ||
350 - le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group >=
351 - block + EXT3_BLOCKS_PER_GROUP(sb))
352 + if (le32_to_cpu(gdp->bg_inode_table) < first_block ||
353 + le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group >
356 ext3_error (sb, "ext3_check_descriptors",
357 "Inode table for group %d"
358 @@ -1177,7 +1182,7 @@ static int ext3_check_descriptors (struc
359 le32_to_cpu(gdp->bg_inode_table));
362 - block += EXT3_BLOCKS_PER_GROUP(sb);
363 + first_block += EXT3_BLOCKS_PER_GROUP(sb);
367 @@ -1580,10 +1585,9 @@ static int ext3_fill_super (struct super
369 if (EXT3_BLOCKS_PER_GROUP(sb) == 0)
371 - sbi->s_groups_count = (le32_to_cpu(es->s_blocks_count) -
372 - le32_to_cpu(es->s_first_data_block) +
373 - EXT3_BLOCKS_PER_GROUP(sb) - 1) /
374 - EXT3_BLOCKS_PER_GROUP(sb);
375 + sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
376 + le32_to_cpu(es->s_first_data_block) - 1)
377 + / EXT3_BLOCKS_PER_GROUP(sb)) + 1;
378 db_count = (sbi->s_groups_count + EXT3_DESC_PER_BLOCK(sb) - 1) /
379 EXT3_DESC_PER_BLOCK(sb);
380 sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
382 Date: Tue, 19 Sep 2006 15:32:42 -0500
383 From: Eric Sandeen <esandeen@redhat.com>
384 Subject: [RHEL5 Patch 2/3] (resend) Fix more ext3 overflows at 16T
386 This is in akpm's tree as
387 more-ext3-16t-overflow-fixes.patch and more-ext3-16t-overflow-fixes-fix.patch
389 Some of the changes in balloc.c are just cosmetic -
390 if they overflow they'll then underflow and things are fine.
392 5th hunk actually fixes an overflow problem.
394 Also check for potential overflows in inode & block counts when resizing.
396 Signed-off-by: Eric Sandeen <esandeen@redhat.com>
397 Cc: Mingming Cao <cmm@us.ibm.com>
398 Signed-off-by: Andrew Morton <akpm@osdl.org>
400 Index: linux-2.6.17-1.2654.el5/fs/ext3/balloc.c
401 ===================================================================
402 --- linux-2.6.17-1.2654.el5.orig/fs/ext3/balloc.c
403 +++ linux-2.6.17-1.2654.el5/fs/ext3/balloc.c
404 @@ -168,7 +168,7 @@ goal_in_my_reservation(struct ext3_reser
405 ext3_fsblk_t group_first_block, group_last_block;
407 group_first_block = ext3_group_first_block_no(sb, group);
408 - group_last_block = group_first_block + EXT3_BLOCKS_PER_GROUP(sb) - 1;
409 + group_last_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1);
411 if ((rsv->_rsv_start > group_last_block) ||
412 (rsv->_rsv_end < group_first_block))
413 @@ -897,7 +897,7 @@ static int alloc_new_reservation(struct
414 spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock;
416 group_first_block = ext3_group_first_block_no(sb, group);
417 - group_end_block = group_first_block + EXT3_BLOCKS_PER_GROUP(sb) - 1;
418 + group_end_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1);
421 start_block = group_first_block;
422 @@ -1063,7 +1063,7 @@ ext3_try_to_allocate_with_rsv(struct sup
423 struct ext3_reserve_window_node * my_rsv,
424 unsigned long *count, int *errp)
426 - ext3_fsblk_t group_first_block;
427 + ext3_fsblk_t group_first_block, group_last_block;
428 ext3_grpblk_t ret = 0;
430 unsigned long num = *count;
431 @@ -1100,6 +1100,7 @@ ext3_try_to_allocate_with_rsv(struct sup
432 * first block is the block number of the first block in this group
434 group_first_block = ext3_group_first_block_no(sb, group);
435 + group_last_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1);
438 * Basically we will allocate a new block from inode's reservation
439 @@ -1132,8 +1133,8 @@ ext3_try_to_allocate_with_rsv(struct sup
440 try_to_extend_reservation(my_rsv, sb,
441 *count-my_rsv->rsv_end + grp_goal - 1);
443 - if ((my_rsv->rsv_start >= group_first_block + EXT3_BLOCKS_PER_GROUP(sb))
444 - || (my_rsv->rsv_end < group_first_block))
445 + if ((my_rsv->rsv_start > group_last_block) ||
446 + (my_rsv->rsv_end < group_first_block))
448 ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, grp_goal,
449 &num, &my_rsv->rsv_window);
450 Index: linux-2.6.17-1.2654.el5/fs/ext3/resize.c
451 ===================================================================
452 --- linux-2.6.17-1.2654.el5.orig/fs/ext3/resize.c
453 +++ linux-2.6.17-1.2654.el5/fs/ext3/resize.c
454 @@ -730,6 +730,18 @@ int ext3_group_add(struct super_block *s
458 + if (le32_to_cpu(es->s_blocks_count) + input->blocks_count <
459 + le32_to_cpu(es->s_blocks_count)) {
460 + ext3_warning(sb, __FUNCTION__, "blocks_count overflow\n");
464 + if (le32_to_cpu(es->s_inodes_count) + EXT3_INODES_PER_GROUP(sb) <
465 + le32_to_cpu(es->s_inodes_count)) {
466 + ext3_warning(sb, __FUNCTION__, "inodes_count overflow\n");
470 if (reserved_gdb || gdb_off == 0) {
471 if (!EXT3_HAS_COMPAT_FEATURE(sb,
472 EXT3_FEATURE_COMPAT_RESIZE_INODE)){
473 @@ -958,6 +970,11 @@ int ext3_group_extend(struct super_block
475 add = EXT3_BLOCKS_PER_GROUP(sb) - last;
477 + if (o_blocks_count + add < o_blocks_count) {
478 + ext3_warning(sb, __FUNCTION__, "blocks_count overflow");
482 if (o_blocks_count + add > n_blocks_count)
483 add = n_blocks_count - o_blocks_count;