Whamcloud - gitweb
f76289e93163e8fcaa32a875d98c33c1d2a25e0a
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext3-block-bitmap-validation-2.6-rhel5.patch
1 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2 Signed-off-by: Andreas Dilger <adilger@clusterfs.com>
3 Index: linux-2.6.18-8.1.8/fs/ext3/balloc.c
4 ===================================================================
5 --- linux-2.6.18-8.1.8.orig/fs/ext3/balloc.c
6 +++ linux-2.6.18-8.1.8/fs/ext3/balloc.c
7 @@ -143,6 +143,14 @@ unsigned ext3_init_block_bitmap(struct s
8         return free_blocks - sbi->s_itb_per_group - 2;
9  }
10  
11 +static inline int
12 +block_in_use(unsigned long block, struct super_block *sb, unsigned char *map)
13 +{
14 +       return ext3_test_bit ((block -
15 +               le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) %
16 +                       EXT3_BLOCKS_PER_GROUP(sb), map);
17 +}
18 +
19  /*
20   * Read the bitmap for a given block_group, reading into the specified 
21   * slot in the superblock's bitmap cache.
22 @@ -152,14 +160,18 @@ unsigned ext3_init_block_bitmap(struct s
23  struct buffer_head *
24  read_block_bitmap(struct super_block *sb, unsigned int block_group)
25  {
26 +       int i;
27         struct ext3_group_desc * desc;
28         struct buffer_head * bh = NULL;
29 +       unsigned long bitmap_blk;
30  
31         desc = ext3_get_group_desc (sb, block_group, NULL);
32         if (!desc)
33 -               goto error_out;
34 +               return NULL;
35 +
36 +       bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
37         if (desc->bg_flags & cpu_to_le16(EXT3_BG_BLOCK_UNINIT)) {
38 -               bh = sb_getblk(sb, le32_to_cpu(desc->bg_block_bitmap));
39 +               bh = sb_getblk(sb, bitmap_blk);
40                 if (!buffer_uptodate(bh)) {
41                         lock_buffer(bh);
42                         if (!buffer_uptodate(bh)) {
43 @@ -169,15 +181,44 @@ read_block_bitmap(struct super_block *sb
44                         unlock_buffer(bh);
45                 }
46         } else {
47 -               bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
48 +               bh = sb_bread(sb, bitmap_blk);
49         }
50         if (!bh)
51 -               ext3_error (sb, "read_block_bitmap",
52 +               ext3_error (sb, __FUNCTION__,
53                             "Cannot read block bitmap - "
54 -                           "block_group = %d, block_bitmap = %u",
55 -                           block_group, le32_to_cpu(desc->bg_block_bitmap));
56 -error_out:
57 +                           "block_group = %d, block_bitmap = %lu",
58 +                           block_group, bitmap_blk);
59 +
60 +       /* check whether block bitmap block number is set */
61 +       if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
62 +               /* bad block bitmap */
63 +               goto error_out;
64 +       }
65 +
66 +       /* check whether the inode bitmap block number is set */
67 +       bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
68 +       if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
69 +       /* bad block bitmap */
70 +               goto error_out;
71 +       }
72 +       /* check whether the inode table block number is set */
73 +       bitmap_blk = le32_to_cpu(desc->bg_inode_table);
74 +       for (i = 0; i < EXT3_SB(sb)->s_itb_per_group; i++, bitmap_blk++) {
75 +               if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
76 +                       /* bad block bitmap */
77 +                       goto error_out;
78 +               }
79 +       }
80         return bh;
81 +
82 +error_out:
83 +       brelse(bh);
84 +       ext3_error(sb, __FUNCTION__,
85 +                       "Invalid block bitmap - "
86 +                       "block_group = %d, block = %lu",
87 +                       block_group, bitmap_blk);
88 +       return NULL;
89 +
90  }
91  /*
92   * The reservation window structure operations
93 @@ -1617,14 +1658,6 @@ ext3_fsblk_t ext3_count_free_blocks(stru
94  #endif
95  }
96  
97 -static inline int
98 -block_in_use(ext3_fsblk_t block, struct super_block *sb, unsigned char *map)
99 -{
100 -       return ext3_test_bit ((block -
101 -               le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) %
102 -                        EXT3_BLOCKS_PER_GROUP(sb), map);
103 -}
104 -
105  static inline int test_root(int a, int b)
106  {
107         int num = b;