Whamcloud - gitweb
Branch b1_6
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext3-mballoc3-2.6.22.patch
1 Index: linux-2.6.22.19/include/linux/ext3_fs_i.h
2 ===================================================================
3 --- linux-2.6.22.19.orig/include/linux/ext3_fs_i.h
4 +++ linux-2.6.22.19/include/linux/ext3_fs_i.h
5 @@ -154,6 +154,10 @@ struct ext3_inode_info {
6         struct inode vfs_inode;
7  
8         struct ext3_ext_cache i_cached_extent;
9 +
10 +       /* mballoc */
11 +       struct list_head i_prealloc_list;
12 +       spinlock_t i_prealloc_lock;
13  };
14  
15  #endif /* _LINUX_EXT3_FS_I */
16 Index: linux-2.6.22.19/include/linux/ext3_fs_sb.h
17 ===================================================================
18 --- linux-2.6.22.19.orig/include/linux/ext3_fs_sb.h
19 +++ linux-2.6.22.19/include/linux/ext3_fs_sb.h
20 @@ -21,8 +21,15 @@
21  #include <linux/wait.h>
22  #include <linux/blockgroup_lock.h>
23  #include <linux/percpu_counter.h>
24 +#include <linux/list.h>
25  #endif
26  #include <linux/rbtree.h>
27 +#include <linux/proc_fs.h>
28 +
29 +struct ext3_buddy_group_blocks;
30 +struct ext3_locality_group;
31 +struct ext3_mb_history;
32 +#define EXT3_BB_MAX_BLOCKS
33  
34  /*
35   * third extended-fs super-block data in memory
36 Index: linux-2.6.22.19/include/linux/ext3_fs.h
37 ===================================================================
38 --- linux-2.6.22.19.orig/include/linux/ext3_fs.h
39 +++ linux-2.6.22.19/include/linux/ext3_fs.h
40 @@ -17,6 +17,7 @@
41  #define _LINUX_EXT3_FS_H
42  
43  #include <linux/types.h>
44 +#include <linux/ext3_fs_i.h>
45  #include <linux/magic.h>
46  
47  /*
48 @@ -68,12 +69,12 @@
49  
50  struct ext3_allocation_request {
51         struct inode *inode;    /* target inode for block we're allocating */
52 -       unsigned long logical;  /* logical block in target inode */
53 -       unsigned long goal;     /* phys. target (a hint) */
54 -       unsigned long lleft;    /* the closest logical allocated block to the left */
55 -       unsigned long pleft;    /* phys. block for ^^^ */
56 -       unsigned long lright;   /* the closest logical allocated block to the right */
57 -       unsigned long pright;   /* phys. block for ^^^ */
58 +       ext3_fsblk_t logical;   /* logical block in target inode */
59 +       ext3_fsblk_t goal;      /* phys. target (a hint) */
60 +       ext3_fsblk_t lleft;     /* the closest logical allocated block to the left */
61 +       ext3_fsblk_t pleft;     /* phys. block for ^^^ */
62 +       ext3_fsblk_t lright;    /* the closest logical allocated block to the right */
63 +       ext3_fsblk_t pright;    /* phys. block for ^^^ */
64         unsigned long len;      /* how many blocks we want to allocate */
65         unsigned long flags;    /* flags. see above EXT3_MB_HINT_* */
66  };
67 @@ -414,6 +415,7 @@ struct ext3_inode {
68  #define EXT3_MOUNT_IOPEN_NOPRIV                0x800000/* Make iopen world-readable */
69  #define EXT3_MOUNT_EXTENTS             0x2000000/* Extents support */
70  #define EXT3_MOUNT_EXTDEBUG             0x4000000/* Extents debug */
71 +#define EXT3_MOUNT_MBALLOC             0x8000000/* Buddy allocation support */
72  
73  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
74  #ifndef clear_opt
75 @@ -801,12 +803,12 @@ ext3_group_first_block_no(struct super_b
76  /* balloc.c */
77  extern int ext3_bg_has_super(struct super_block *sb, int group);
78  extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group);
79 -extern ext3_fsblk_t ext3_new_block (handle_t *handle, struct inode *inode,
80 +extern ext3_fsblk_t ext3_new_block_old (handle_t *handle, struct inode *inode,
81                         ext3_fsblk_t goal, int *errp);
82 -extern ext3_fsblk_t ext3_new_blocks (handle_t *handle, struct inode *inode,
83 +extern ext3_fsblk_t ext3_new_blocks_old (handle_t *handle, struct inode *inode,
84                         ext3_fsblk_t goal, unsigned long *count, int *errp);
85  extern void ext3_free_blocks (handle_t *handle, struct inode *inode,
86 -                       ext3_fsblk_t block, unsigned long count);
87 +                       ext3_fsblk_t block, unsigned long count, int metadata);
88  extern void ext3_free_blocks_sb (handle_t *handle, struct super_block *sb,
89                                  ext3_fsblk_t block, unsigned long count,
90                                 unsigned long *pdquot_freed_blocks);
91 @@ -850,15 +852,45 @@ extern long ext3_mb_stats;
92  extern long ext3_mb_max_to_scan;
93  extern int ext3_mb_init(struct super_block *, int);
94  extern int ext3_mb_release(struct super_block *);
95 -extern unsigned long ext3_mb_new_blocks(handle_t *, struct ext3_allocation_request *, int *);
96 +extern ext3_fsblk_t ext3_new_block(handle_t *handle, struct inode *inode,
97 +                                  ext3_fsblk_t goal, int *errp);
98 +extern ext3_fsblk_t ext3_mb_new_blocks(handle_t *,
99 +                               struct ext3_allocation_request *, int *);
100  extern int ext3_mb_reserve_blocks(struct super_block *, int);
101  extern void ext3_mb_release_blocks(struct super_block *, int);
102  extern void ext3_mb_release_blocks(struct super_block *, int);
103  extern void ext3_mb_discard_inode_preallocations(struct inode *);
104  extern int __init init_ext3_mb_proc(void);
105  extern void exit_ext3_mb_proc(void);
106 -extern void ext3_mb_free_blocks(handle_t *, struct inode *, unsigned long, unsigned long, int, int *);
107 +extern void ext3_mb_free_blocks(handle_t *, struct inode *, unsigned long,
108 +                               unsigned long, int, unsigned long *);
109 +
110 +static inline ext3_fsblk_t ext3_new_blocks(handle_t *handle,
111 +                                          struct inode *inode,
112 +                                          ext3_fsblk_t goal,
113 +                                          unsigned long *count, int *errp)
114 +{
115 +       struct ext3_allocation_request ar;
116 +       ext3_fsblk_t ret;
117  
118 +       if (!test_opt(inode->i_sb, MBALLOC)) {
119 +               ret = ext3_new_blocks_old(handle, inode, goal, count, errp);
120 +               return ret;
121 +       }
122 +
123 +       ar.inode = inode;
124 +       ar.goal = goal;
125 +       ar.len = *count;
126 +       ar.logical = 0;
127 +       ar.lleft = 0;
128 +       ar.pleft = 0;
129 +       ar.lright = 0;
130 +       ar.pright = 0;
131 +       ar.flags = 0;
132 +       ret = ext3_mb_new_blocks(handle, &ar, errp);
133 +       *count = ar.len;
134 +       return ret;
135 +}
136  
137  /* inode.c */
138  int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
139 Index: linux-2.6.22.19/fs/ext3/super.c
140 ===================================================================
141 --- linux-2.6.22.19.orig/fs/ext3/super.c
142 +++ linux-2.6.22.19/fs/ext3/super.c
143 @@ -685,6 +685,7 @@ enum {
144         Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
145         Opt_grpquota,
146         Opt_extents, Opt_noextents, Opt_extdebug,
147 +       Opt_mballoc, Opt_nomballoc, Opt_stripe,
148  };
149  
150  static match_table_t tokens = {
151 @@ -740,6 +741,9 @@ static match_table_t tokens = {
152         {Opt_extents, "extents"},
153         {Opt_noextents, "noextents"},
154         {Opt_extdebug, "extdebug"},
155 +       {Opt_mballoc, "mballoc"},
156 +       {Opt_nomballoc, "nomballoc"},
157 +       {Opt_stripe, "stripe=%u"},
158         {Opt_err, NULL},
159         {Opt_resize, "resize"},
160  };
161 @@ -1093,6 +1097,19 @@ clear_qf_name:
162                 case Opt_extdebug:
163                         set_opt (sbi->s_mount_opt, EXTDEBUG);
164                         break;
165 +               case Opt_mballoc:
166 +                       set_opt(sbi->s_mount_opt, MBALLOC);
167 +                       break;
168 +               case Opt_nomballoc:
169 +                       clear_opt(sbi->s_mount_opt, MBALLOC);
170 +                       break;
171 +               case Opt_stripe:
172 +                       if (match_int(&args[0], &option))
173 +                               return 0;
174 +                       if (option < 0)
175 +                               return 0;
176 +                       sbi->s_stripe = option;
177 +                       break;
178                 default:
179                         printk (KERN_ERR
180                                 "EXT3-fs: Unrecognized mount option \"%s\" "
181 @@ -1832,6 +1849,7 @@ static int ext3_fill_super (struct super
182                 "writeback");
183  
184         ext3_ext_init(sb);
185 +       ext3_mb_init(sb, needs_recovery);
186  
187         lock_kernel();
188         return 0;
189 Index: linux-2.6.22.19/fs/ext3/extents.c
190 ===================================================================
191 --- linux-2.6.22.19.orig/fs/ext3/extents.c
192 +++ linux-2.6.22.19/fs/ext3/extents.c
193 @@ -801,7 +801,7 @@ cleanup:
194                 for (i = 0; i < depth; i++) {
195                         if (!ablocks[i])
196                                 continue;
197 -                       ext3_free_blocks(handle, inode, ablocks[i], 1);
198 +                       ext3_free_blocks(handle, inode, ablocks[i], 1, 1);
199                 }
200         }
201         kfree(ablocks);
202 @@ -1619,7 +1619,7 @@ int ext3_ext_rm_idx(handle_t *handle, st
203         ext_debug(inode, "index is empty, remove it, free block %lu\n", leaf);
204         bh = sb_find_get_block(inode->i_sb, leaf);
205         ext3_forget(handle, 1, inode, bh, leaf);
206 -       ext3_free_blocks(handle, inode, leaf, 1);
207 +       ext3_free_blocks(handle, inode, leaf, 1, 1);
208         return err;
209  }
210  
211 @@ -1678,7 +1678,7 @@ static int ext3_remove_blocks(handle_t *
212                                 unsigned long from, unsigned long to)
213  {
214         struct buffer_head *bh;
215 -       int i;
216 +       int i, metadata = 0;
217  
218  #ifdef EXTENTS_STATS
219         {
220 @@ -1696,6 +1696,8 @@ static int ext3_remove_blocks(handle_t *
221                 spin_unlock(&sbi->s_ext_stats_lock);
222         }
223  #endif
224 +       if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
225 +               metadata = 1;
226         if (from >= le32_to_cpu(ex->ee_block)
227             && to == le32_to_cpu(ex->ee_block) + le16_to_cpu(ex->ee_len) - 1) {
228                 /* tail removal */
229 @@ -1707,7 +1709,7 @@ static int ext3_remove_blocks(handle_t *
230                         bh = sb_find_get_block(inode->i_sb, start + i);
231                         ext3_forget(handle, 0, inode, bh, start + i);
232                 }
233 -               ext3_free_blocks(handle, inode, start, num);
234 +               ext3_free_blocks(handle, inode, start, num, metadata);
235         } else if (from == le32_to_cpu(ex->ee_block)
236                    && to <= le32_to_cpu(ex->ee_block) + le16_to_cpu(ex->ee_len) - 1) {
237                 printk("strange request: removal %lu-%lu from %u:%u\n",
238 @@ -2040,7 +2042,7 @@ int ext3_ext_get_blocks(handle_t *handle
239         struct ext3_extent newex, *ex;
240         int goal, newblock, err = 0, depth;
241         unsigned long allocated = 0;
242 -       unsigned long next;
243 +       struct ext3_allocation_request ar;
244  
245         __clear_bit(BH_New, &bh_result->b_state);
246         ext_debug(inode, "blocks %d/%lu requested for inode %u\n", (int) iblock,
247 @@ -2122,18 +2124,36 @@ int ext3_ext_get_blocks(handle_t *handle
248         if (S_ISREG(inode->i_mode) && (!EXT3_I(inode)->i_block_alloc_info))
249                 ext3_init_block_alloc_info(inode);
250  
251 +       /* find neighbour allocated blocks */
252 +       ar.lleft = iblock;
253 +       err = ext3_ext_search_left(inode, path, &ar.lleft, &ar.pleft);
254 +       if (err)
255 +               goto out2;
256 +       ar.lright = iblock;
257 +       err = ext3_ext_search_right(inode, path, &ar.lright, &ar.pright);
258 +       if (err)
259 +               goto out2;
260 +
261         /* find next allocated block so that we know how many
262          * blocks we can allocate without ovelapping next extent */
263 -       BUG_ON(iblock < le32_to_cpu(ex->ee_block) + le16_to_cpu(ex->ee_len));
264 -       next = ext3_ext_next_allocated_block(path);
265 -       BUG_ON(next <= iblock);
266 -       allocated = next - iblock;
267 +       BUG_ON(ar.pright != 0 && ar.lright <= iblock);
268 +       if (ar.pright == 0)
269 +               allocated = EXT_MAX_BLOCK - iblock;
270 +       else
271 +               allocated = ar.lright - iblock;
272         if (allocated > max_blocks)
273                 allocated = max_blocks;
274  
275         /* allocate new block */
276 -       goal = ext3_ext_find_goal(inode, path, iblock);
277 -       newblock = ext3_new_blocks(handle, inode, goal, &allocated, &err);
278 +       ar.inode = inode;
279 +       ar.goal = ext3_ext_find_goal(inode, path, iblock);
280 +       ar.logical = iblock;
281 +       ar.len = allocated;
282 +       if (S_ISREG(inode->i_mode))
283 +               ar.flags = EXT3_MB_HINT_DATA;
284 +       else
285 +               ar.flags = 0;
286 +       newblock = ext3_mb_new_blocks(handle, &ar, &err);
287         if (!newblock)
288                 goto out2;
289         ext_debug(inode, "allocate new block: goal %d, found %d/%lu\n",
290 @@ -2143,12 +2163,16 @@ int ext3_ext_get_blocks(handle_t *handle
291         newex.ee_block = cpu_to_le32(iblock);
292         newex.ee_start = cpu_to_le32(newblock);
293         newex.ee_start_hi = 0;
294 -       newex.ee_len = cpu_to_le16(allocated);
295 +       newex.ee_len = cpu_to_le16(ar.len);
296         err = ext3_ext_insert_extent(handle, inode, path, &newex);
297         if (err) {
298                 /* free data blocks we just allocated */
299 -               ext3_free_blocks(handle, inode, le32_to_cpu(newex.ee_start),
300 -                               le16_to_cpu(newex.ee_len));
301 +               /* not a good idea to call discard here directly,
302 +                * but otherwise we'd need to call it every free() */
303 +               ext3_mb_discard_inode_preallocations(inode);
304 +               ext3_free_blocks(handle, inode, newex.ee_start,
305 +                                newex.ee_len, 0);
306 +
307                 goto out2;
308         }
309  
310 @@ -2157,6 +2181,7 @@ int ext3_ext_get_blocks(handle_t *handle
311  
312         /* previous routine could use block we allocated */
313         newblock = le32_to_cpu(newex.ee_start);
314 +       allocated = le16_to_cpu(newex.ee_len);
315         __set_bit(BH_New, &bh_result->b_state);
316  
317         ext3_ext_put_in_cache(inode, iblock, allocated, newblock,
318 @@ -2208,6 +2233,9 @@ void ext3_ext_truncate(struct inode * in
319         mutex_lock(&EXT3_I(inode)->truncate_mutex);
320         ext3_ext_invalidate_cache(inode);
321  
322 +       /* it's important to discard preallocations under truncate_mutex */
323 +       ext3_mb_discard_inode_preallocations(inode);
324 +
325         /*
326          * TODO: optimization is possible here
327          * probably we need not scaning at all,
328 Index: linux-2.6.22.19/fs/ext3/Makefile
329 ===================================================================
330 --- linux-2.6.22.19.orig/fs/ext3/Makefile
331 +++ linux-2.6.22.19/fs/ext3/Makefile
332 @@ -6,7 +6,7 @@ obj-$(CONFIG_EXT3_FS) += ext3.o
333  
334  ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
335            ioctl.o namei.o super.o symlink.o hash.o resize.o ext3_jbd.o \
336 -          extents.o
337 +          extents.o mballoc.o
338  
339  ext3-$(CONFIG_EXT3_FS_XATTR)    += xattr.o xattr_user.o xattr_trusted.o
340  ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
341 Index: linux-2.6.22.19/fs/ext3/xattr.c
342 ===================================================================
343 --- linux-2.6.22.19.orig/fs/ext3/xattr.c
344 +++ linux-2.6.22.19/fs/ext3/xattr.c
345 @@ -488,7 +488,7 @@ ext3_xattr_release_block(handle_t *handl
346                 ea_bdebug(bh, "refcount now=0; freeing");
347                 if (ce)
348                         mb_cache_entry_free(ce);
349 -               ext3_free_blocks(handle, inode, bh->b_blocknr, 1);
350 +               ext3_free_blocks(handle, inode, bh->b_blocknr, 1, 1);
351                 get_bh(bh);
352                 ext3_forget(handle, 1, inode, bh, bh->b_blocknr);
353         } else {
354 @@ -813,7 +813,7 @@ inserted:
355                         new_bh = sb_getblk(sb, block);
356                         if (!new_bh) {
357  getblk_failed:
358 -                               ext3_free_blocks(handle, inode, block, 1);
359 +                               ext3_free_blocks(handle, inode, block, 1, 1);
360                                 error = -EIO;
361                                 goto cleanup;
362                         }
363 Index: linux-2.6.22.19/fs/ext3/balloc.c
364 ===================================================================
365 --- linux-2.6.22.19.orig/fs/ext3/balloc.c
366 +++ linux-2.6.22.19/fs/ext3/balloc.c
367 @@ -90,7 +90,7 @@ struct ext3_group_desc * ext3_get_group_
368   *
369   * Return buffer_head on success or NULL in case of failure.
370   */
371 -static struct buffer_head *
372 +struct buffer_head *
373  read_block_bitmap(struct super_block *sb, unsigned int block_group)
374  {
375         struct ext3_group_desc * desc;
376 @@ -391,6 +391,8 @@ void ext3_discard_reservation(struct ino
377         struct ext3_reserve_window_node *rsv;
378         spinlock_t *rsv_lock = &EXT3_SB(inode->i_sb)->s_rsv_window_lock;
379  
380 +       ext3_mb_discard_inode_preallocations(inode);
381 +
382         if (!block_i)
383                 return;
384  
385 @@ -602,19 +604,24 @@ error_return:
386   * @count:             number of blocks to count
387   */
388  void ext3_free_blocks(handle_t *handle, struct inode *inode,
389 -                       ext3_fsblk_t block, unsigned long count)
390 +                       ext3_fsblk_t block, unsigned long count, int metadata)
391  {
392 -       struct super_block * sb;
393 -       unsigned long dquot_freed_blocks;
394 +       struct super_block *sb;
395 +       unsigned long freed;
396 +
397 +       /* this isn't the right place to decide whether block is metadata
398 +        * inode.c/extents.c knows better, but for safety ... */
399 +       if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode) ||
400 +                       ext3_should_journal_data(inode))
401 +               metadata = 1;
402  
403         sb = inode->i_sb;
404 -       if (!sb) {
405 -               printk ("ext3_free_blocks: nonexistent device");
406 -               return;
407 -       }
408 -       ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
409 -       if (dquot_freed_blocks)
410 -               DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
411 +       if (!test_opt(sb, MBALLOC) || !EXT3_SB(sb)->s_group_info)
412 +               ext3_free_blocks_sb(handle, sb, block, count, &freed);
413 +       else
414 +               ext3_mb_free_blocks(handle, inode, block, count, metadata, &freed);
415 +       if (freed)
416 +               DQUOT_FREE_BLOCK(inode, freed);
417         return;
418  }
419  
420 @@ -1403,7 +1410,7 @@ int ext3_should_retry_alloc(struct super
421   * any specific goal block.
422   *
423   */
424 -ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
425 +ext3_fsblk_t ext3_new_blocks_old(handle_t *handle, struct inode *inode,
426                         ext3_fsblk_t goal, unsigned long *count, int *errp)
427  {
428         struct buffer_head *bitmap_bh = NULL;
429 @@ -1666,7 +1673,7 @@ out:
430         return 0;
431  }
432  
433 -ext3_fsblk_t ext3_new_block(handle_t *handle, struct inode *inode,
434 +ext3_fsblk_t ext3_new_block_old(handle_t *handle, struct inode *inode,
435                         ext3_fsblk_t goal, int *errp)
436  {
437         unsigned long count = 1;
438 Index: linux-2.6.22.19/fs/ext3/inode.c
439 ===================================================================
440 --- linux-2.6.22.19.orig/fs/ext3/inode.c
441 +++ linux-2.6.22.19/fs/ext3/inode.c
442 @@ -560,7 +560,7 @@ static int ext3_alloc_blocks(handle_t *h
443         return ret;
444  failed_out:
445         for (i = 0; i <index; i++)
446 -               ext3_free_blocks(handle, inode, new_blocks[i], 1);
447 +               ext3_free_blocks(handle, inode, new_blocks[i], 1, 0);
448         return ret;
449  }
450  
451 @@ -659,9 +659,9 @@ failed:
452                 ext3_journal_forget(handle, branch[i].bh);
453         }
454         for (i = 0; i <indirect_blks; i++)
455 -               ext3_free_blocks(handle, inode, new_blocks[i], 1);
456 +               ext3_free_blocks(handle, inode, new_blocks[i], 1, 0);
457  
458 -       ext3_free_blocks(handle, inode, new_blocks[i], num);
459 +       ext3_free_blocks(handle, inode, new_blocks[i], num, 0);
460  
461         return err;
462  }
463 @@ -758,9 +758,10 @@ err_out:
464         for (i = 1; i <= num; i++) {
465                 BUFFER_TRACE(where[i].bh, "call journal_forget");
466                 ext3_journal_forget(handle, where[i].bh);
467 -               ext3_free_blocks(handle,inode,le32_to_cpu(where[i-1].key),1);
468 +               ext3_free_blocks(handle,inode,le32_to_cpu(where[i-1].key), 1,
469 +                                0);
470         }
471 -       ext3_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks);
472 +       ext3_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks, 0);
473  
474         return err;
475  }
476 @@ -1988,7 +1989,7 @@ static void ext3_clear_blocks(handle_t *
477                 }
478         }
479  
480 -       ext3_free_blocks(handle, inode, block_to_free, count);
481 +       ext3_free_blocks(handle, inode, block_to_free, count, 0);
482  }
483  
484  /**
485 @@ -2161,7 +2162,7 @@ static void ext3_free_branches(handle_t 
486                                 ext3_journal_test_restart(handle, inode);
487                         }
488  
489 -                       ext3_free_blocks(handle, inode, nr, 1);
490 +                       ext3_free_blocks(handle, inode, nr, 1, 1);
491  
492                         if (parent_bh) {
493                                 /*
494 Index: linux-2.6.22.19/fs/ext3/mballoc.c
495 ===================================================================
496 --- linux-2.6.22.19.orig/fs/ext3/mballoc.c
497 +++ linux-2.6.22.19/fs/ext3/mballoc.c
498 @@ -305,7 +305,7 @@
499   */
500  #define MB_DEFAULT_STRIPE              256
501  
502 -static kmem_cache_t *ext3_pspace_cachep = NULL;
503 +static struct kmem_cache *ext3_pspace_cachep = NULL;
504  
505  #ifdef EXT3_BB_MAX_BLOCKS
506  #undef EXT3_BB_MAX_BLOCKS
507 @@ -350,8 +350,8 @@ struct ext3_prealloc_space {
508         spinlock_t              pa_lock;
509         atomic_t                pa_count;
510         unsigned                pa_deleted;
511 -       unsigned long           pa_pstart;      /* phys. block */
512 -       unsigned long           pa_lstart;      /* log. block */
513 +       ext3_fsblk_t            pa_pstart;      /* phys. block */
514 +       ext3_fsblk_t            pa_lstart;      /* log. block */
515         unsigned short          pa_len;         /* len of preallocated chunk */
516         unsigned short          pa_free;        /* how many blocks are free */
517         unsigned short          pa_linear;      /* consumed in one direction
518 @@ -460,8 +460,8 @@ static struct proc_dir_entry *proc_root_
519  
520  int ext3_create (struct inode *, struct dentry *, int, struct nameidata *);
521  struct buffer_head * read_block_bitmap(struct super_block *, unsigned int);
522 -unsigned long ext3_new_blocks_old(handle_t *handle, struct inode *inode,
523 -                       unsigned long goal, unsigned long *count, int *errp);
524 +ext3_fsblk_t ext3_new_blocks_old(handle_t *handle, struct inode *inode,
525 +                       ext3_fsblk_t goal, unsigned long *count, int *errp);
526  void ext3_mb_release_blocks(struct super_block *, int);
527  void ext3_mb_poll_new_transaction(struct super_block *, handle_t *);
528  void ext3_mb_free_committed_blocks(struct super_block *);
529 @@ -479,7 +479,7 @@ int ext3_mb_destroy_per_dev_proc(struct 
530   * Calculate the block group number and offset, given a block number
531   */
532  static void ext3_get_group_no_and_offset(struct super_block *sb,
533 -                                       unsigned long blocknr,
534 +                                       ext3_fsblk_t blocknr,
535                                         unsigned long *blockgrpp,
536                                         unsigned long *offsetp)
537  {
538 @@ -517,12 +517,12 @@ ext3_is_group_locked(struct super_block 
539                                         &EXT3_GROUP_INFO(sb, group)->bb_state);
540  }
541  
542 -unsigned long ext3_grp_offs_to_block(struct super_block *sb,
543 +ext3_fsblk_t ext3_grp_offs_to_block(struct super_block *sb,
544                                         struct ext3_free_extent *fex)
545  {
546 -       unsigned long block;
547 +       ext3_fsblk_t block;
548  
549 -       block = (unsigned long) fex->fe_group * EXT3_BLOCKS_PER_GROUP(sb)
550 +       block = (ext3_fsblk_t) fex->fe_group * EXT3_BLOCKS_PER_GROUP(sb)
551                         + fex->fe_start
552                         + le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block);
553         return block;
554 @@ -3202,7 +3202,7 @@ void ext3_mb_collect_stats(struct ext3_a
555  void ext3_mb_use_inode_pa(struct ext3_allocation_context *ac,
556                                 struct ext3_prealloc_space *pa)
557  {
558 -       unsigned long start, len;
559 +       ext3_fsblk_t start, len;
560  
561         /* found preallocated blocks, use them */
562         start = pa->pa_pstart + (ac->ac_o_ex.fe_logical - pa->pa_lstart);
563 @@ -4053,13 +4053,13 @@ int ext3_mb_discard_preallocations(struc
564   * it tries to use preallocation first, then falls back
565   * to usual allocation
566   */
567 -unsigned long ext3_mb_new_blocks(handle_t *handle,
568 +ext3_fsblk_t ext3_mb_new_blocks(handle_t *handle,
569                                  struct ext3_allocation_request *ar, int *errp)
570  {
571         struct ext3_allocation_context ac;
572         struct ext3_sb_info *sbi;
573         struct super_block *sb;
574 -       unsigned long block = 0;
575 +       ext3_fsblk_t block = 0;
576         int freed, inquota;
577  
578         sb = ar->inode->i_sb;
579 @@ -4070,8 +4070,8 @@ unsigned long ext3_mb_new_blocks(handle_
580                 if (ext3_mballoc_warning++ == 0)
581                         printk(KERN_ERR "EXT3-fs: multiblock request with "
582                                         "mballoc disabled!\n");
583 -               ar->len = 1;
584 -               block = ext3_new_block_old(handle, ar->inode, ar->goal, errp);
585 +               block = ext3_new_blocks_old(handle, ar->inode, ar->goal,
586 +                                           &ar->len, errp);
587                 return block;
588         }
589  
590 @@ -4135,11 +4135,11 @@ out:
591  }
592  EXPORT_SYMBOL(ext3_mb_new_blocks);
593  
594 -int ext3_new_block(handle_t *handle, struct inode *inode,
595 -                  unsigned long goal, int *errp)
596 +ext3_fsblk_t ext3_new_block(handle_t *handle, struct inode *inode,
597 +                  ext3_fsblk_t goal, int *errp)
598  {
599         struct ext3_allocation_request ar;
600 -       unsigned long ret;
601 +       ext3_fsblk_t ret;
602  
603         if (!test_opt(inode->i_sb, MBALLOC)) {
604                 ret = ext3_new_block_old(handle, inode, goal, errp);
605 @@ -4254,8 +4254,8 @@ int ext3_mb_free_metadata(handle_t *hand
606   * Main entry point into mballoc to free blocks
607   */
608  void ext3_mb_free_blocks(handle_t *handle, struct inode *inode,
609 -                       unsigned long block, unsigned long count,
610 -                       int metadata, int *freed)
611 +                       ext3_fsblk_t block, unsigned long count,
612 +                       int metadata, unsigned long *freed)
613  {
614         struct buffer_head *bitmap_bh = NULL;
615         struct super_block *sb = inode->i_sb;