Whamcloud - gitweb
8e258d2ea513904334547f775aaf365c3818688b
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext3-block-bitmap-validation-2.6-SLES10.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.16.46-0.14/fs/ext3/balloc.c
4 ===================================================================
5 --- linux-2.6.16.46-0.14.orig/fs/ext3/balloc.c
6 +++ linux-2.6.16.46-0.14/fs/ext3/balloc.c
7 @@ -144,6 +144,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 @@ -153,33 +161,52 @@ 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 -       if (desc->bg_flags & cpu_to_le16(EXT3_BG_BLOCK_UNINIT)) {
35 -               bh = sb_getblk(sb, le32_to_cpu(desc->bg_block_bitmap));
36 -               if (!buffer_uptodate(bh)) {
37 -                       lock_buffer(bh);
38 -                       if (!buffer_uptodate(bh)) {
39 -                               ext3_init_block_bitmap(sb, bh,block_group,desc);
40 -                               set_buffer_uptodate(bh);
41 -                       }
42 -                       unlock_buffer(bh);
43 -               }
44 -       } else {
45 -               bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
46 -       }
47 +               return NULL;
48 +       bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
49 +       bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
50         if (!bh)
51 -               ext3_error (sb, "read_block_bitmap",
52 -                           "Cannot read block bitmap - "
53 -                           "block_group = %d, block_bitmap = %u",
54 -                           block_group, le32_to_cpu(desc->bg_block_bitmap));
55 +               ext3_error (sb, __FUNCTION__,
56 +                               "Cannot read block bitmap - "
57 +                               "block_group = %d, block_bitmap = %lu",
58 +                               block_group, bitmap_blk);
59 +       /* check whether block bitmap block number is set */
60 +          if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
61 +                  /* bad block bitmap */
62 +                  goto error_out;
63 +          }
64 +
65 +          /* check whether the inode bitmap block number is set */
66 +          bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
67 +          if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
68 +                  /* bad block bitmap */
69 +                  goto error_out;
70 +          }
71 +          /* check whether the inode table block number is set */
72 +          bitmap_blk = le32_to_cpu(desc->bg_inode_table);
73 +          for (i = 0; i < EXT3_SB(sb)->s_itb_per_group; i++, bitmap_blk++) {
74 +                  if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
75 +                          /* bad block bitmap */
76 +                          goto error_out;
77 +                  }
78 +          }
79 +          return bh;
80 +
81  error_out:
82 -       return bh;
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   * --------------------------------------------
94 @@ -1548,14 +1575,6 @@ unsigned long ext3_count_free_blocks(str
95  #endif
96  }
97  
98 -static inline int
99 -block_in_use(unsigned long block, struct super_block *sb, unsigned char *map)
100 -{
101 -       return ext3_test_bit ((block -
102 -               le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) %
103 -                        EXT3_BLOCKS_PER_GROUP(sb), map);
104 -}
105 -
106  static inline int test_root(int a, int b)
107  {
108         int num = b;