1 Index: linux-2.6.9-42.0.10.EL_lustre.1.4.10/fs/ext3/extents.c
2 ===================================================================
3 --- linux-2.6.9-42.0.10.EL_lustre.1.4.10.orig/fs/ext3/extents.c 2007-06-14 11:42:34.000000000 +0200
4 +++ linux-2.6.9-42.0.10.EL_lustre.1.4.10/fs/ext3/extents.c 2007-06-14 13:59:49.000000000 +0200
6 #include <asm/uaccess.h>
9 -static inline int ext3_ext_check_header(struct ext3_extent_header *eh)
11 - if (eh->eh_magic != EXT3_EXT_MAGIC) {
12 - printk(KERN_ERR "EXT3-fs: invalid magic = 0x%x\n",
13 - (unsigned)eh->eh_magic);
16 - if (eh->eh_max == 0) {
17 - printk(KERN_ERR "EXT3-fs: invalid eh_max = %u\n",
18 - (unsigned)eh->eh_max);
21 - if (eh->eh_entries > eh->eh_max) {
22 - printk(KERN_ERR "EXT3-fs: invalid eh_entries = %u\n",
23 - (unsigned)eh->eh_entries);
25 +static int __ext3_ext_check_header(const char *function, struct inode *inode,
26 + struct ext3_extent_header *eh, int depth,
29 + const char *error_msg = NULL;
31 + if (unlikely(eh->eh_magic != EXT3_EXT_MAGIC)) {
32 + error_msg = "invalid magic";
35 + if (unlikely(eh->eh_depth != depth)) {
36 + error_msg = "unexpected eh_depth";
39 + if (unlikely(eh->eh_max == 0)) {
40 + error_msg = "too small eh_max";
43 + if (unlikely(eh->eh_max > max)) {
44 + error_msg = "too large eh_max";
47 + if (unlikely(eh->eh_entries > eh->eh_max)) {
48 + error_msg = "invalid eh_entries";
54 + ext3_error(inode->i_sb, function,
55 + "bad header in inode #%lu: %s - magic %x, "
56 + "entries %u, max %u(%u), depth %u(%u)",
57 + inode->i_ino, error_msg, eh->eh_magic,
58 + eh->eh_entries, eh->eh_max, max,
59 + eh->eh_depth, depth);
64 +#define ext3_ext_check_header(inode,eh,depth,max) \
65 + __ext3_ext_check_header(__FUNCTION__,inode,eh,depth,max)
68 static handle_t *ext3_ext_journal_restart(handle_t *handle, int needed)
71 @@ -227,6 +250,26 @@ static inline int ext3_ext_space_root_id
76 +ext3_ext_max_entries(struct ext3_extents_tree *tree, int root, int depth)
82 + max = ext3_ext_space_root(tree);
84 + max = ext3_ext_space_root_idx(tree);
87 + max = ext3_ext_space_block(tree);
89 + max = ext3_ext_space_block_idx(tree);
95 static void ext3_ext_show_path(struct ext3_extents_tree *tree,
96 struct ext3_ext_path *path)
98 @@ -297,10 +340,6 @@ ext3_ext_binsearch_idx(struct ext3_exten
99 struct ext3_extent_idx *ix;
102 - EXT_ASSERT(eh->eh_magic == EXT3_EXT_MAGIC);
103 - EXT_ASSERT(eh->eh_entries <= eh->eh_max);
104 - EXT_ASSERT(eh->eh_entries > 0);
106 ext_debug(tree, "binsearch for %d(idx): ", block);
108 path->p_idx = ix = EXT_FIRST_INDEX(eh);
109 @@ -360,9 +399,6 @@ ext3_ext_binsearch(struct ext3_extents_t
110 struct ext3_extent *ex;
113 - EXT_ASSERT(eh->eh_magic == EXT3_EXT_MAGIC);
114 - EXT_ASSERT(eh->eh_entries <= eh->eh_max);
116 if (eh->eh_entries == 0) {
118 * this leaf is empty yet:
119 @@ -437,6 +473,7 @@ ext3_ext_find_extent(struct ext3_extents
120 struct ext3_extent_header *eh;
121 struct buffer_head *bh;
122 int depth, i, ppos = 0;
126 EXT_ASSERT(tree->inode);
127 @@ -444,17 +481,15 @@ ext3_ext_find_extent(struct ext3_extents
129 eh = EXT_ROOT_HDR(tree);
131 - if (ext3_ext_check_header(eh)) {
132 + i = depth = EXT_DEPTH(tree);
133 + max = ext3_ext_max_entries(tree, 1, i);
134 + if (ext3_ext_check_header(tree->inode, eh, i, max)) {
135 /* don't free previously allocated path
136 * -- caller should take care */
141 - i = depth = EXT_DEPTH(tree);
142 - EXT_ASSERT(eh->eh_max);
143 - EXT_ASSERT(eh->eh_magic == EXT3_EXT_MAGIC);
145 /* account possible depth increase */
147 path = kmalloc(sizeof(struct ext3_ext_path) * (depth + 2),
148 @@ -485,7 +520,8 @@ ext3_ext_find_extent(struct ext3_extents
149 path[ppos].p_hdr = eh;
152 - if (ext3_ext_check_header(eh))
153 + max = ext3_ext_max_entries(tree, 0, i);
154 + if (ext3_ext_check_header(tree->inode, eh, i, max))
158 @@ -494,9 +530,6 @@ ext3_ext_find_extent(struct ext3_extents
159 path[ppos].p_ext = NULL;
160 path[ppos].p_idx = NULL;
162 - if (ext3_ext_check_header(eh))
166 ext3_ext_binsearch(tree, path + ppos, block);
168 @@ -993,7 +1026,7 @@ ext3_ext_search_right(struct ext3_extent
169 struct ext3_extent_idx *ix;
170 struct ext3_extent *ex;
175 BUG_ON(path == NULL);
176 depth = path->p_depth;
177 @@ -1051,7 +1084,8 @@ ext3_ext_search_right(struct ext3_extent
180 eh = EXT_BLOCK_HDR(bh);
181 - if (ext3_ext_check_header(eh)) {
182 + max = ext3_ext_max_entries(tree, 0, depth);
183 + if (ext3_ext_check_header(tree->inode, eh, depth, max)) {
187 @@ -1064,7 +1098,8 @@ ext3_ext_search_right(struct ext3_extent
190 eh = EXT_BLOCK_HDR(bh);
191 - if (ext3_ext_check_header(eh)) {
192 + max = ext3_ext_max_entries(tree, 0, depth);
193 + if (ext3_ext_check_header(tree->inode, eh, depth, max)) {
197 @@ -1694,6 +1729,8 @@ ext3_ext_rm_leaf(handle_t *handle, struc
198 ext_debug(tree, "remove [%lu:%lu] in leaf\n", start, end);
199 if (!path[depth].p_hdr)
200 path[depth].p_hdr = EXT_BLOCK_HDR(path[depth].p_bh);
202 + /* the header must be checked already in ext3_ext_remove_space() */
203 eh = path[depth].p_hdr;
205 EXT_ASSERT(eh->eh_entries <= eh->eh_max);
206 @@ -1856,7 +1893,7 @@ int ext3_ext_remove_space(struct ext3_ex
207 int depth = EXT_DEPTH(tree);
208 struct ext3_ext_path *path;
210 - int i = 0, err = 0;
211 + int i = 0, err = 0, max;
213 ext_debug(tree, "space to be removed: %lu:%lu\n", start, end);
215 @@ -1879,7 +1916,13 @@ int ext3_ext_remove_space(struct ext3_ex
217 memset(path, 0, sizeof(struct ext3_ext_path) * (depth + 1));
218 path[i].p_hdr = EXT_ROOT_HDR(tree);
221 + max = ext3_ext_max_entries(tree, 1, depth);
222 + if (ext3_ext_check_header(inode, path[i].p_hdr, depth, max)) {
227 while (i >= 0 && err == 0) {
229 /* this is leaf block */
230 @@ -1889,16 +1932,13 @@ int ext3_ext_remove_space(struct ext3_ex
236 /* this is index block */
237 if (!path[i].p_hdr) {
238 ext_debug(tree, "initialize header\n");
239 path[i].p_hdr = EXT_BLOCK_HDR(path[i].p_bh);
242 - EXT_ASSERT(path[i].p_hdr->eh_entries <= path[i].p_hdr->eh_max);
243 - EXT_ASSERT(path[i].p_hdr->eh_magic == EXT3_EXT_MAGIC);
245 if (!path[i].p_idx) {
246 /* this level hasn't touched yet */
248 @@ -1925,6 +1965,14 @@ int ext3_ext_remove_space(struct ext3_ex
252 + BUG_ON(i + 1 > depth);
253 + max = ext3_ext_max_entries(tree, 0, depth - i - 1);
254 + if (ext3_ext_check_header(inode,
255 + EXT_BLOCK_HDR(path[i+1].p_bh),
256 + depth - i - 1, max)) {
260 /* put actual number of indexes to know is this
261 * number got changed at the next iteration */
262 path[i].p_block = path[i].p_hdr->eh_entries;
263 @@ -1945,7 +1993,7 @@ int ext3_ext_remove_space(struct ext3_ex
266 /* TODO: flexible tree reduction should be here */
267 - if (path->p_hdr->eh_entries == 0) {
268 + if (err == 0 && path->p_hdr->eh_entries == 0) {
270 * truncate to zero freed all the tree
271 * so, we need to correct eh_depth
272 @@ -1959,6 +2007,7 @@ int ext3_ext_remove_space(struct ext3_ex
274 ext3_ext_tree_changed(tree);
278 ext3_journal_stop(handle);