1 Add support for the uninit_groups feature to the kernel.
3 Keep a high water mark of used inodes for each group to improve e2fsck time.
4 Block and inode bitmaps can be uninitialized on disk via a flag in the
5 group descriptor to avoid reading or scanning them at e2fsck time.
6 A checksum of each group descriptor is used to ensure that corruption in
7 the group descriptor's bit flags does not cause incorrect operation.
9 Index: linux-2.6.5-7.311/include/linux/ext3_fs.h
10 ===================================================================
11 --- linux-2.6.5-7.311.orig/include/linux/ext3_fs.h
12 +++ linux-2.6.5-7.311/include/linux/ext3_fs.h
13 @@ -153,16 +153,22 @@ struct ext3_allocation_request {
15 struct ext3_group_desc
17 - __u32 bg_block_bitmap; /* Blocks bitmap block */
18 - __u32 bg_inode_bitmap; /* Inodes bitmap block */
19 + __u32 bg_block_bitmap; /* Blocks bitmap block */
20 + __u32 bg_inode_bitmap; /* Inodes bitmap block */
21 __u32 bg_inode_table; /* Inodes table block */
22 __u16 bg_free_blocks_count; /* Free blocks count */
23 __u16 bg_free_inodes_count; /* Free inodes count */
24 __u16 bg_used_dirs_count; /* Directories count */
26 - __u32 bg_reserved[3];
27 + __u16 bg_flags; /* EXT3_BG_flags (UNINIT, etc) */
28 + __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */
29 + __u16 bg_itable_unused; /* Unused inodes count */
30 + __u16 bg_checksum; /* crc16(sb_uuid+group+desc) */
33 +#define EXT3_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */
34 +#define EXT3_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */
35 +#define EXT3_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */
38 * Macro-instructions used to manage group descriptors
40 @@ -466,7 +472,7 @@ struct ext3_super_block {
42 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
43 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
45 + __u16 s_reserved_gdt_blocks; /* Per group desc for online growth */
47 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
49 @@ -554,6 +560,7 @@ static inline struct ext3_inode_info *EX
50 #define EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
51 #define EXT3_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
52 #define EXT3_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
53 +#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
54 #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
56 #define EXT3_FEATURE_INCOMPAT_COMPRESSION 0x0001
57 @@ -570,6 +577,7 @@ static inline struct ext3_inode_info *EX
58 EXT3_FEATURE_INCOMPAT_EXTENTS)
59 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
60 EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
61 + EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
62 EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \
63 EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
65 Index: linux-2.6.5-7.311/fs/ext3/super.c
66 ===================================================================
67 --- linux-2.6.5-7.311.orig/fs/ext3/super.c
68 +++ linux-2.6.5-7.311/fs/ext3/super.c
70 #include <linux/quotaops.h>
75 static int ext3_load_journal(struct super_block *, struct ext3_super_block *);
76 static int ext3_create_journal(struct super_block *, struct ext3_super_block *,
77 @@ -998,6 +999,90 @@ static int ext3_setup_super(struct super
81 +#if !defined(CONFIG_CRC16) && !defined(CONFIG_CRC16_MODULE)
82 +/** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */
83 +__u16 const crc16_table[256] = {
84 + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
85 + 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
86 + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
87 + 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
88 + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
89 + 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
90 + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
91 + 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
92 + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
93 + 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
94 + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
95 + 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
96 + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
97 + 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
98 + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
99 + 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
100 + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
101 + 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
102 + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
103 + 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
104 + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
105 + 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
106 + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
107 + 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
108 + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
109 + 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
110 + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
111 + 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
112 + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
113 + 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
114 + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
115 + 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
118 +static inline __u16 crc16_byte(__u16 crc, const __u8 data)
120 + return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff];
123 +__u16 crc16(__u16 crc, __u8 const *buffer, size_t len)
126 + crc = crc16_byte(crc, *buffer++);
131 +__le16 ext3_group_desc_csum(struct ext3_sb_info *sbi, __u32 block_group,
132 + struct ext3_group_desc *gdp)
136 + if (sbi->s_es->s_feature_ro_compat &
137 + cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
138 + int offset = offsetof(struct ext3_group_desc, bg_checksum);
139 + __le32 le_group = cpu_to_le32(block_group);
141 + crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
142 + crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
143 + crc = crc16(crc, (__u8 *)gdp, offset);
144 + offset += sizeof(gdp->bg_checksum); /* skip checksum */
145 + BUG_ON(offset != sizeof(*gdp)); /* XXX handle s_desc_size */
146 + /* for checksum of struct ext4_group_desc do the rest...
147 + if (offset < sbi->s_es->s_desc_size) {
148 + crc = crc16(crc, (__u8 *)gdp + offset,
149 + sbi->s_es->s_desc_size - offset);
153 + return cpu_to_le16(crc);
156 +int ext3_group_desc_csum_verify(struct ext3_sb_info *sbi, __u32 block_group,
157 + struct ext3_group_desc *gdp)
159 + if (gdp->bg_checksum != ext3_group_desc_csum(sbi, block_group, gdp))
165 static int ext3_check_descriptors (struct super_block * sb)
167 struct ext3_sb_info *sbi = EXT3_SB(sb);
168 @@ -1046,6 +1131,13 @@ static int ext3_check_descriptors (struc
169 le32_to_cpu(gdp->bg_inode_table));
172 + if (!ext3_group_desc_csum_verify(sbi, i, gdp)) {
173 + ext3_error(sb, __FUNCTION__,
174 + "Checksum for group %d failed (%u!=%u)\n", i,
175 + le16_to_cpu(ext3_group_desc_csum(sbi,i,gdp)),
176 + le16_to_cpu(gdp->bg_checksum));
179 block += EXT3_BLOCKS_PER_GROUP(sb);
182 Index: linux-2.6.5-7.311/fs/ext3/group.h
183 ===================================================================
185 +++ linux-2.6.5-7.311/fs/ext3/group.h
188 + * linux/fs/ext3/group.h
190 + * Copyright 2008 Sun Microsystems, Inc.
192 + * Author: Andreas Dilger <adilger@clusterfs.com>
195 +#ifndef _LINUX_EXT3_GROUP_H
196 +#define _LINUX_EXT3_GROUP_H
197 +#if defined(CONFIG_CRC16) || defined(CONFIG_CRC16_MODULE)
198 +#include <linux/crc16.h>
201 +extern __le16 ext3_group_desc_csum(struct ext3_sb_info *sbi, __u32 group,
202 + struct ext3_group_desc *gdp);
203 +extern int ext3_group_desc_csum_verify(struct ext3_sb_info *sbi, __u32 group,
204 + struct ext3_group_desc *gdp);
205 +struct buffer_head *read_block_bitmap(struct super_block *sb,
206 + unsigned int block_group);
207 +extern unsigned ext3_init_block_bitmap(struct super_block *sb,
208 + struct buffer_head *bh, int group,
209 + struct ext3_group_desc *desc);
210 +#define ext3_free_blocks_after_init(sb, group, desc) \
211 + ext3_init_block_bitmap(sb, NULL, group, desc)
212 +extern unsigned ext3_init_inode_bitmap(struct super_block *sb,
213 + struct buffer_head *bh, int group,
214 + struct ext3_group_desc *desc);
215 +extern void mark_bitmap_end(int start_bit, int end_bit, char *bitmap);
216 +#endif /* _LINUX_EXT3_GROUP_H */
217 Index: linux-2.6.5-7.311/fs/ext3/ialloc.c
218 ===================================================================
219 --- linux-2.6.5-7.311.orig/fs/ext3/ialloc.c
220 +++ linux-2.6.5-7.311/fs/ext3/ialloc.c
228 * ialloc.c contains the inodes allocation and deallocation routines
230 * the free blocks count in the block.
234 + * To avoid calling the atomic setbit hundreds or thousands of times, we only
235 + * need to use it within a single byte (to ensure we get endianness right).
236 + * We can use memset for the rest of the bitmap as there are no other users.
238 +void mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
242 + if (start_bit >= end_bit)
245 + ext3_debug("mark end bits +%d through +%d used\n", start_bit, end_bit);
246 + for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++)
247 + ext3_set_bit(i, bitmap);
249 + memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
252 +/* Initializes an uninitialized inode bitmap */
253 +unsigned ext3_init_inode_bitmap(struct super_block *sb,
254 + struct buffer_head *bh, int block_group,
255 + struct ext3_group_desc *gdp)
257 + struct ext3_sb_info *sbi = EXT3_SB(sb);
259 + J_ASSERT_BH(bh, buffer_locked(bh));
261 + /* If checksum is bad mark all blocks and inodes use to prevent
262 + * allocation, essentially implementing a per-group read-only flag. */
263 + if (!ext3_group_desc_csum_verify(sbi, block_group, gdp)) {
264 + ext3_error(sb, __FUNCTION__, "Checksum bad for group %u\n",
266 + gdp->bg_free_blocks_count = 0;
267 + gdp->bg_free_inodes_count = 0;
268 + gdp->bg_itable_unused = 0;
269 + memset(bh->b_data, 0xff, sb->s_blocksize);
273 + memset(bh->b_data, 0, (EXT3_INODES_PER_GROUP(sb) + 7) / 8);
274 + mark_bitmap_end(EXT3_INODES_PER_GROUP(sb), EXT3_BLOCKS_PER_GROUP(sb),
277 + return EXT3_INODES_PER_GROUP(sb);
281 * Read the inode allocation bitmap for a given block_group, reading
282 @@ -59,8 +106,19 @@ read_inode_bitmap(struct super_block * s
283 desc = ext3_get_group_desc(sb, block_group, NULL);
287 - bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap));
288 + if (desc->bg_flags & cpu_to_le16(EXT3_BG_INODE_UNINIT)) {
289 + bh = sb_getblk(sb, le32_to_cpu(desc->bg_inode_bitmap));
290 + if (!buffer_uptodate(bh)) {
292 + if (!buffer_uptodate(bh)) {
293 + ext3_init_inode_bitmap(sb, bh,block_group,desc);
294 + set_buffer_uptodate(bh);
299 + bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap));
302 ext3_error(sb, "read_inode_bitmap",
303 "Cannot read inode bitmap - "
304 @@ -168,6 +226,8 @@ void ext3_free_inode (handle_t *handle,
306 gdp->bg_used_dirs_count = cpu_to_le16(
307 le16_to_cpu(gdp->bg_used_dirs_count) - 1);
308 + gdp->bg_checksum = ext3_group_desc_csum(sbi,block_group,
310 spin_unlock(sb_bgl_lock(sbi, block_group));
311 percpu_counter_inc(&sbi->s_freeinodes_counter);
313 @@ -453,7 +513,7 @@ struct inode *ext3_new_inode(handle_t *h
314 struct ext3_sb_info *sbi;
320 /* Cannot create files in a deleted directory */
321 if (!dir || !dir->i_nlink)
322 @@ -569,11 +629,13 @@ repeat_in_this_group:
326 - ino += group * EXT3_INODES_PER_GROUP(sb) + 1;
327 - if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
328 - ext3_error (sb, "ext3_new_inode",
329 - "reserved inode or inode > inodes count - "
330 - "block_group = %d, inode=%lu", group, ino);
332 + if ((group == 0 && ino < EXT3_FIRST_INO(sb)) ||
333 + ino > EXT3_INODES_PER_GROUP(sb)) {
334 + ext3_error(sb, __FUNCTION__,
335 + "reserved inode or inode > inodes count - "
336 + "block_group = %d, inode=%lu", group,
337 + ino + group * EXT3_INODES_PER_GROUP(sb));
341 @@ -581,13 +643,65 @@ got:
342 BUFFER_TRACE(bh2, "get_write_access");
343 err = ext3_journal_get_write_access(handle, bh2);
346 + /* We may have to initialize the block bitmap if it isn't already */
347 + if (EXT3_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM) &&
348 + gdp->bg_flags & cpu_to_le16(EXT3_BG_BLOCK_UNINIT)) {
349 + struct buffer_head *block_bh = read_block_bitmap(sb, group);
351 + BUFFER_TRACE(block_bh, "get block bitmap access");
352 + err = ext3_journal_get_write_access(handle, block_bh);
359 + spin_lock(sb_bgl_lock(sbi, group));
360 + /* recheck and clear flag under lock if we still need to */
361 + if (gdp->bg_flags & cpu_to_le16(EXT3_BG_BLOCK_UNINIT)) {
362 + gdp->bg_flags &= cpu_to_le16(~EXT3_BG_BLOCK_UNINIT);
363 + free = ext3_free_blocks_after_init(sb, group, gdp);
364 + gdp->bg_free_blocks_count = cpu_to_le16(free);
366 + spin_unlock(sb_bgl_lock(sbi, group));
368 + /* Don't need to dirty bitmap block if we didn't change it */
370 + BUFFER_TRACE(block_bh, "dirty block bitmap");
371 + err = ext3_journal_dirty_metadata(handle, block_bh);
379 spin_lock(sb_bgl_lock(sbi, group));
380 + /* If we didn't allocate from within the initialized part of the inode
381 + * table then we need to initialize up to this inode. */
382 + if (EXT3_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
383 + if (gdp->bg_flags & cpu_to_le16(EXT3_BG_INODE_UNINIT)) {
384 + gdp->bg_flags &= cpu_to_le16(~EXT3_BG_INODE_UNINIT);
387 + free = EXT3_INODES_PER_GROUP(sb) -
388 + le16_to_cpu(gdp->bg_itable_unused);
392 + gdp->bg_itable_unused =
393 + cpu_to_le16(EXT3_INODES_PER_GROUP(sb) - ino);
397 gdp->bg_free_inodes_count =
398 cpu_to_le16(le16_to_cpu(gdp->bg_free_inodes_count) - 1);
400 gdp->bg_used_dirs_count =
401 cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
403 + gdp->bg_checksum = ext3_group_desc_csum(sbi, group, gdp);
404 spin_unlock(sb_bgl_lock(sbi, group));
405 BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata");
406 err = ext3_journal_dirty_metadata(handle, bh2);
407 @@ -609,7 +723,7 @@ got:
408 inode->i_gid = current->fsgid;
409 inode->i_mode = mode;
411 - inode->i_ino = ino;
412 + inode->i_ino = ino + group * EXT3_INODES_PER_GROUP(sb);
413 /* This is the optimal IO size (for stat), not the fs block size */
414 inode->i_blksize = PAGE_SIZE;
416 Index: linux-2.6.5-7.311/fs/ext3/mballoc.c
417 ===================================================================
418 --- linux-2.6.5-7.311.orig/fs/ext3/mballoc.c
419 +++ linux-2.6.5-7.311/fs/ext3/mballoc.c
421 #include <linux/seq_file.h>
422 #include <linux/version.h>
428 * - test ext3_ext_search_left() and ext3_ext_search_right()
429 @@ -323,6 +325,7 @@ struct ext3_group_info {
430 unsigned long bb_state;
431 unsigned long bb_tid;
432 struct ext3_free_metadata *bb_md_cur;
433 + struct ext3_group_desc *bb_gdp;
434 unsigned short bb_first_free;
435 unsigned short bb_free;
436 unsigned short bb_fragments;
437 @@ -943,10 +946,7 @@ static int ext3_mb_init_cache(struct pag
438 if (first_group + i >= EXT3_SB(sb)->s_groups_count)
442 - desc = ext3_get_group_desc(sb, first_group + i, NULL);
445 + desc = EXT3_GROUP_INFO(sb, first_group + i)->bb_gdp;
448 bh[i] = sb_getblk(sb, le32_to_cpu(desc->bg_block_bitmap));
449 @@ -961,7 +961,12 @@ static int ext3_mb_init_cache(struct pag
450 unlock_buffer(bh[i]);
454 + if (desc->bg_flags & cpu_to_le16(EXT3_BG_BLOCK_UNINIT)) {
455 + ext3_init_block_bitmap(sb, bh[i], first_group + i,desc);
456 + set_buffer_uptodate(bh[i]);
457 + unlock_buffer(bh[i]);
461 bh[i]->b_end_io = end_buffer_read_sync;
462 submit_bh(READ, bh[i]);
463 @@ -1733,6 +1738,10 @@ static int ext3_mb_good_group(struct ext
466 BUG_ON(ac->ac_2order == 0);
467 + /* If this group is uninitialized, skip it initially */
468 + if (grp->bb_gdp->bg_flags &
469 + cpu_to_le16(EXT3_BG_BLOCK_UNINIT))
471 bits = ac->ac_sb->s_blocksize_bits + 1;
472 for (i = ac->ac_2order; i <= bits; i++)
473 if (grp->bb_counters[i] > 0)
474 @@ -1826,7 +1835,9 @@ repeat:
477 ac->ac_groups_scanned++;
479 + if (cr == 0 || (e3b.bd_info->bb_gdp->bg_flags &
480 + cpu_to_le16(EXT3_BG_BLOCK_UNINIT) &&
481 + ac->ac_2order != 0))
482 ext3_mb_simple_scan_group(ac, &e3b);
483 else if (cr == 1 && ac->ac_g_ex.fe_len == sbi->s_stripe)
484 ext3_mb_scan_aligned(ac, &e3b);
485 @@ -2306,12 +2317,13 @@ int ext3_mb_init_backend(struct super_bl
489 + memset(meta_group_info[j], 0, len);
490 desc = ext3_get_group_desc(sb, i, NULL);
491 + meta_group_info[j]->bb_gdp = desc;
493 printk(KERN_ERR"EXT3-fs: can't read descriptor %u\n",i);
496 - memset(meta_group_info[j], 0, len);
497 set_bit(EXT3_GROUP_INFO_NEED_INIT_BIT,
498 &meta_group_info[j]->bb_state);
500 @@ -2945,9 +2957,17 @@ int ext3_mb_mark_diskspace_used(struct e
501 mb_set_bits(NULL, bitmap_bh->b_data,
502 ac->ac_b_ex.fe_start, ac->ac_b_ex.fe_len);
504 + if (gdp->bg_flags & cpu_to_le16(EXT3_BG_BLOCK_UNINIT)) {
505 + gdp->bg_flags &= cpu_to_le16(~EXT3_BG_BLOCK_UNINIT);
506 + gdp->bg_free_blocks_count =
507 + cpu_to_le16(ext3_free_blocks_after_init(sb,
508 + ac->ac_b_ex.fe_group,
511 gdp->bg_free_blocks_count =
512 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)
513 - ac->ac_b_ex.fe_len);
514 + gdp->bg_checksum = ext3_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp);
515 spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group));
516 percpu_counter_mod(&sbi->s_freeblocks_counter, - ac->ac_b_ex.fe_len);
518 @@ -4357,6 +4377,7 @@ do_more:
519 spin_lock(sb_bgl_lock(sbi, block_group));
520 gdp->bg_free_blocks_count =
521 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) + count);
522 + gdp->bg_checksum = ext3_group_desc_csum(sbi, block_group, gdp);
523 spin_unlock(sb_bgl_lock(sbi, block_group));
524 percpu_counter_mod(&sbi->s_freeblocks_counter, count);
526 Index: linux-2.6.5-7.311/fs/ext3/balloc.c
527 ===================================================================
528 --- linux-2.6.5-7.311.orig/fs/ext3/balloc.c
529 +++ linux-2.6.5-7.311/fs/ext3/balloc.c
531 #include <linux/quotaops.h>
532 #include <linux/buffer_head.h>
536 * balloc.c contains the blocks allocation and deallocation routines
538 @@ -72,6 +73,83 @@ struct ext3_group_desc * ext3_get_group_
542 +/* Initializes an uninitialized block bitmap if given, and returns the
543 + * number of blocks free in the group. */
544 +unsigned ext3_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
545 + int block_group, struct ext3_group_desc *gdp)
547 + unsigned long start;
549 + unsigned free_blocks;
550 + struct ext3_sb_info *sbi = EXT3_SB(sb);
553 + J_ASSERT_BH(bh, buffer_locked(bh));
555 + /* If checksum is bad mark all blocks use to prevent allocation,
556 + * essentially implementing a per-group read-only flag. */
557 + if (!ext3_group_desc_csum_verify(sbi, block_group, gdp)) {
558 + ext3_error(sb, __FUNCTION__,
559 + "Checksum bad for group %u\n", block_group);
560 + gdp->bg_free_blocks_count = 0;
561 + gdp->bg_free_inodes_count = 0;
562 + gdp->bg_itable_unused = 0;
563 + memset(bh->b_data, 0xff, sb->s_blocksize);
566 + memset(bh->b_data, 0, sb->s_blocksize);
569 + /* Check for superblock and gdt backups in this group */
570 + bit_max = ext3_bg_has_super(sb, block_group);
572 + if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_META_BG) ||
573 + block_group < le32_to_cpu(sbi->s_es->s_first_meta_bg) *
574 + sbi->s_desc_per_block) {
576 + bit_max += ext3_bg_num_gdb(sb, block_group);
577 + bit_max +=le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks);
579 + } else { /* For META_BG_BLOCK_GROUPS */
580 + int group_rel = (block_group -
581 + le32_to_cpu(sbi->s_es->s_first_meta_bg)) %
582 + EXT3_DESC_PER_BLOCK(sb);
583 + if (group_rel == 0 || group_rel == 1 ||
584 + (group_rel == EXT3_DESC_PER_BLOCK(sb) - 1))
588 + /* Last and first groups are always initialized */
589 + free_blocks = EXT3_BLOCKS_PER_GROUP(sb) - bit_max;
592 + for (bit = 0; bit < bit_max; bit++)
593 + ext3_set_bit(bit, bh->b_data);
595 + start = block_group * EXT3_BLOCKS_PER_GROUP(sb) +
596 + le32_to_cpu(sbi->s_es->s_first_data_block);
598 + /* Set bits for block and inode bitmaps, and inode table */
599 + ext3_set_bit(le32_to_cpu(gdp->bg_block_bitmap) - start,
601 + ext3_set_bit(le32_to_cpu(gdp->bg_inode_bitmap) - start,
603 + for (bit = le32_to_cpu(gdp->bg_inode_table) - start,
604 + bit_max = bit + sbi->s_itb_per_group; bit < bit_max; bit++)
605 + ext3_set_bit(bit, bh->b_data);
608 + * Also if the number of blocks within the group is
609 + * less than the blocksize * 8 ( which is the size
610 + * of bitmap ), set rest of the block bitmap to 1
612 + mark_bitmap_end(EXT3_BLOCKS_PER_GROUP(sb), sb->s_blocksize * 8,
616 + return free_blocks - sbi->s_itb_per_group - 2;
620 * Read the bitmap for a given block_group, reading into the specified
621 * slot in the superblock's bitmap cache.
622 @@ -87,7 +165,19 @@ read_block_bitmap(struct super_block *sb
623 desc = ext3_get_group_desc (sb, block_group, NULL);
626 - bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
627 + if (desc->bg_flags & cpu_to_le16(EXT3_BG_BLOCK_UNINIT)) {
628 + bh = sb_getblk(sb, le32_to_cpu(desc->bg_block_bitmap));
629 + if (!buffer_uptodate(bh)) {
631 + if (!buffer_uptodate(bh)) {
632 + ext3_init_block_bitmap(sb, bh,block_group,desc);
633 + set_buffer_uptodate(bh);
638 + bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
641 ext3_error (sb, "read_block_bitmap",
642 "Cannot read block bitmap - "
643 @@ -432,6 +522,7 @@ do_more:
644 gdp->bg_free_blocks_count =
645 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) +
647 + gdp->bg_checksum = ext3_group_desc_csum(sbi, block_group, gdp);
648 spin_unlock(sb_bgl_lock(sbi, block_group));
649 percpu_counter_mod(&sbi->s_freeblocks_counter, count);
651 @@ -1372,8 +1463,11 @@ allocated:
652 ret_block, goal_hits, goal_attempts);
654 spin_lock(sb_bgl_lock(sbi, group_no));
655 + if (gdp->bg_flags & cpu_to_le16(EXT3_BG_BLOCK_UNINIT))
656 + gdp->bg_flags &= cpu_to_le16(~EXT3_BG_BLOCK_UNINIT);
657 gdp->bg_free_blocks_count =
658 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) - 1);
659 + gdp->bg_checksum = ext3_group_desc_csum(sbi, group_no, gdp);
660 spin_unlock(sb_bgl_lock(sbi, group_no));
661 percpu_counter_mod(&sbi->s_freeblocks_counter, -1);