Whamcloud - gitweb
04eb2a2e30c320ba6a42980acfccc8364be4b6c1
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext3-mballoc3-2.6.18.patch
1 Index: linux-2.6.18.8/include/linux/ext3_fs_i.h
2 ===================================================================
3 --- linux-2.6.18.8.orig/include/linux/ext3_fs_i.h       2007-06-21 14:20:14.000000000 +0200
4 +++ linux-2.6.18.8/include/linux/ext3_fs_i.h    2007-06-21 14:20:15.000000000 +0200
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.18.8/include/linux/ext3_fs_sb.h
17 ===================================================================
18 --- linux-2.6.18.8.orig/include/linux/ext3_fs_sb.h      2007-06-21 14:20:15.000000000 +0200
19 +++ linux-2.6.18.8/include/linux/ext3_fs_sb.h   2007-06-21 14:20:15.000000000 +0200
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.18.8/include/linux/ext3_fs.h
37 ===================================================================
38 --- linux-2.6.18.8.orig/include/linux/ext3_fs.h 2007-06-21 14:20:15.000000000 +0200
39 +++ linux-2.6.18.8/include/linux/ext3_fs.h      2007-06-21 14:20:15.000000000 +0200
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  
46  /*
47   * The second extended filesystem constants/structures
48 @@ -67,12 +68,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 @@ -400,6 +401,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 @@ -787,12 +789,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 @@ -836,15 +838,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_proc(void);
105  extern void exit_ext3_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.18.8/fs/ext3/super.c
140 ===================================================================
141 --- linux-2.6.18.8.orig/fs/ext3/super.c 2007-06-21 14:20:15.000000000 +0200
142 +++ linux-2.6.18.8/fs/ext3/super.c      2007-06-21 14:20:15.000000000 +0200
143 @@ -688,6 +688,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 @@ -743,6 +744,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 @@ -1096,6 +1100,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 @@ -1826,6 +1843,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.18.8/fs/ext3/extents.c
190 ===================================================================
191 --- linux-2.6.18.8.orig/fs/ext3/extents.c       2007-06-21 14:20:14.000000000 +0200
192 +++ linux-2.6.18.8/fs/ext3/extents.c    2007-06-21 14:20:15.000000000 +0200
193 @@ -795,7 +795,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 @@ -1613,7 +1613,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 @@ -1672,7 +1672,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 @@ -1690,6 +1690,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 @@ -1701,7 +1703,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 @@ -2034,7 +2036,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 @@ -2116,18 +2118,33 @@ 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 +       ar.flags = EXT3_MB_HINT_DATA;
283 +       newblock = ext3_mb_new_blocks(handle, &ar, &err);
284         if (!newblock)
285                 goto out2;
286         ext_debug(inode, "allocate new block: goal %d, found %d/%lu\n",
287 @@ -2137,12 +2154,16 @@ int ext3_ext_get_blocks(handle_t *handle
288         newex.ee_block = cpu_to_le32(iblock);
289         newex.ee_start = cpu_to_le32(newblock);
290         newex.ee_start_hi = 0;
291 -       newex.ee_len = cpu_to_le16(allocated);
292 +       newex.ee_len = cpu_to_le16(ar.len);
293         err = ext3_ext_insert_extent(handle, inode, path, &newex);
294         if (err) {
295                 /* free data blocks we just allocated */
296 -               ext3_free_blocks(handle, inode, le32_to_cpu(newex.ee_start),
297 -                               le16_to_cpu(newex.ee_len));
298 +               /* not a good idea to call discard here directly,
299 +                * but otherwise we'd need to call it every free() */
300 +               ext3_mb_discard_inode_preallocations(inode);
301 +               ext3_free_blocks(handle, inode, newex.ee_start,
302 +                                newex.ee_len, 0);
303 +
304                 goto out2;
305         }
306  
307 @@ -2151,6 +2172,7 @@ int ext3_ext_get_blocks(handle_t *handle
308  
309         /* previous routine could use block we allocated */
310         newblock = le32_to_cpu(newex.ee_start);
311 +       allocated = le16_to_cpu(newex.ee_len);
312         __set_bit(BH_New, &bh_result->b_state);
313  
314         ext3_ext_put_in_cache(inode, iblock, allocated, newblock,
315 @@ -2202,6 +2224,9 @@ void ext3_ext_truncate(struct inode * in
316         mutex_lock(&EXT3_I(inode)->truncate_mutex);
317         ext3_ext_invalidate_cache(inode);
318  
319 +       /* it's important to discard preallocations under truncate_mutex */
320 +       ext3_mb_discard_inode_preallocations(inode);
321 +
322         /*
323          * TODO: optimization is possible here
324          * probably we need not scaning at all,
325 Index: linux-2.6.18.8/fs/ext3/Makefile
326 ===================================================================
327 --- linux-2.6.18.8.orig/fs/ext3/Makefile        2007-06-21 14:20:14.000000000 +0200
328 +++ linux-2.6.18.8/fs/ext3/Makefile     2007-06-21 14:20:15.000000000 +0200
329 @@ -5,7 +5,7 @@
330  obj-$(CONFIG_EXT3_FS) += ext3.o
331  
332  ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
333 -          ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o
334 +          ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o mballoc.o
335  
336  ext3-$(CONFIG_EXT3_FS_XATTR)    += xattr.o xattr_user.o xattr_trusted.o
337  ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
338 Index: linux-2.6.18.8/fs/ext3/xattr.c
339 ===================================================================
340 --- linux-2.6.18.8.orig/fs/ext3/xattr.c 2007-06-21 10:31:07.000000000 +0200
341 +++ linux-2.6.18.8/fs/ext3/xattr.c      2007-06-21 14:20:15.000000000 +0200
342 @@ -484,7 +484,7 @@ ext3_xattr_release_block(handle_t *handl
343                 ea_bdebug(bh, "refcount now=0; freeing");
344                 if (ce)
345                         mb_cache_entry_free(ce);
346 -               ext3_free_blocks(handle, inode, bh->b_blocknr, 1);
347 +               ext3_free_blocks(handle, inode, bh->b_blocknr, 1, 1);
348                 get_bh(bh);
349                 ext3_forget(handle, 1, inode, bh, bh->b_blocknr);
350         } else {
351 @@ -805,7 +805,7 @@ inserted:
352                         new_bh = sb_getblk(sb, block);
353                         if (!new_bh) {
354  getblk_failed:
355 -                               ext3_free_blocks(handle, inode, block, 1);
356 +                               ext3_free_blocks(handle, inode, block, 1, 1);
357                                 error = -EIO;
358                                 goto cleanup;
359                         }
360 Index: linux-2.6.18.8/fs/ext3/balloc.c
361 ===================================================================
362 --- linux-2.6.18.8.orig/fs/ext3/balloc.c        2007-06-21 10:31:07.000000000 +0200
363 +++ linux-2.6.18.8/fs/ext3/balloc.c     2007-06-21 14:20:15.000000000 +0200
364 @@ -79,7 +79,7 @@ struct ext3_group_desc * ext3_get_group_
365   *
366   * Return buffer_head on success or NULL in case of failure.
367   */
368 -static struct buffer_head *
369 +struct buffer_head *
370  read_block_bitmap(struct super_block *sb, unsigned int block_group)
371  {
372         struct ext3_group_desc * desc;
373 @@ -294,6 +294,8 @@ void ext3_discard_reservation(struct ino
374         struct ext3_reserve_window_node *rsv;
375         spinlock_t *rsv_lock = &EXT3_SB(inode->i_sb)->s_rsv_window_lock;
376  
377 +       ext3_mb_discard_inode_preallocations(inode);
378 +
379         if (!block_i)
380                 return;
381  
382 @@ -490,21 +492,25 @@ error_return:
383         return;
384  }
385  
386 -/* Free given blocks, update quota and i_blocks field */
387  void ext3_free_blocks(handle_t *handle, struct inode *inode,
388 -                       ext3_fsblk_t block, unsigned long count)
389 +                       ext3_fsblk_t block, unsigned long count, int metadata)
390  {
391 -       struct super_block * sb;
392 -       unsigned long dquot_freed_blocks;
393 +       struct super_block *sb;
394 +       unsigned long freed;
395 +
396 +       /* this isn't the right place to decide whether block is metadata
397 +        * inode.c/extents.c knows better, but for safety ... */
398 +       if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode) ||
399 +                       ext3_should_journal_data(inode))
400 +               metadata = 1;
401  
402         sb = inode->i_sb;
403 -       if (!sb) {
404 -               printk ("ext3_free_blocks: nonexistent device");
405 -               return;
406 -       }
407 -       ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
408 -       if (dquot_freed_blocks)
409 -               DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
410 +       if (!test_opt(sb, MBALLOC) || !EXT3_SB(sb)->s_group_info)
411 +               ext3_free_blocks_sb(handle, sb, block, count, &freed);
412 +       else
413 +               ext3_mb_free_blocks(handle, inode, block, count, metadata, &freed);
414 +       if (freed)
415 +               DQUOT_FREE_BLOCK(inode, freed);
416         return;
417  }
418  
419 @@ -1199,7 +1205,7 @@ int ext3_should_retry_alloc(struct super
420   * bitmap, and then for any free bit if that fails.
421   * This function also updates quota and i_blocks field.
422   */
423 -ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
424 +ext3_fsblk_t ext3_new_blocks_old(handle_t *handle, struct inode *inode,
425                         ext3_fsblk_t goal, unsigned long *count, int *errp)
426  {
427         struct buffer_head *bitmap_bh = NULL;
428 @@ -1463,7 +1469,7 @@ out:
429         return 0;
430  }
431  
432 -ext3_fsblk_t ext3_new_block(handle_t *handle, struct inode *inode,
433 +ext3_fsblk_t ext3_new_block_old(handle_t *handle, struct inode *inode,
434                         ext3_fsblk_t goal, int *errp)
435  {
436         unsigned long count = 1;
437 Index: linux-2.6.18.8/fs/ext3/inode.c
438 ===================================================================
439 --- linux-2.6.18.8.orig/fs/ext3/inode.c 2007-06-21 14:20:14.000000000 +0200
440 +++ linux-2.6.18.8/fs/ext3/inode.c      2007-06-21 14:20:15.000000000 +0200
441 @@ -560,7 +560,7 @@ static int ext3_alloc_blocks(handle_t *h
442         return ret;
443  failed_out:
444         for (i = 0; i <index; i++)
445 -               ext3_free_blocks(handle, inode, new_blocks[i], 1);
446 +               ext3_free_blocks(handle, inode, new_blocks[i], 1, 0);
447         return ret;
448  }
449  
450 @@ -659,9 +659,9 @@ failed:
451                 ext3_journal_forget(handle, branch[i].bh);
452         }
453         for (i = 0; i <indirect_blks; i++)
454 -               ext3_free_blocks(handle, inode, new_blocks[i], 1);
455 +               ext3_free_blocks(handle, inode, new_blocks[i], 1, 0);
456  
457 -       ext3_free_blocks(handle, inode, new_blocks[i], num);
458 +       ext3_free_blocks(handle, inode, new_blocks[i], num, 0);
459  
460         return err;
461  }
462 @@ -758,9 +758,10 @@ err_out:
463         for (i = 1; i <= num; i++) {
464                 BUFFER_TRACE(where[i].bh, "call journal_forget");
465                 ext3_journal_forget(handle, where[i].bh);
466 -               ext3_free_blocks(handle,inode,le32_to_cpu(where[i-1].key),1);
467 +               ext3_free_blocks(handle,inode,le32_to_cpu(where[i-1].key), 1,
468 +                                0);
469         }
470 -       ext3_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks);
471 +       ext3_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks, 0);
472  
473         return err;
474  }
475 @@ -1996,7 +1997,7 @@ static void ext3_clear_blocks(handle_t *
476                 }
477         }
478  
479 -       ext3_free_blocks(handle, inode, block_to_free, count);
480 +       ext3_free_blocks(handle, inode, block_to_free, count, 0);
481  }
482  
483  /**
484 @@ -2169,7 +2170,7 @@ static void ext3_free_branches(handle_t 
485                                 ext3_journal_test_restart(handle, inode);
486                         }
487  
488 -                       ext3_free_blocks(handle, inode, nr, 1);
489 +                       ext3_free_blocks(handle, inode, nr, 1, 1);
490  
491                         if (parent_bh) {
492                                 /*
493 Index: linux-2.6.18.8/fs/ext3/mballoc.c
494 ===================================================================
495 --- linux-2.6.18.8.orig/fs/ext3/mballoc.c       2007-06-21 14:20:15.000000000 +0200
496 +++ linux-2.6.18.8/fs/ext3/mballoc.c    2007-06-21 14:24:19.000000000 +0200
497 @@ -350,8 +350,8 @@ struct ext3_prealloc_space {
498         spinlock_t              pa_lock;
499         atomic_t                pa_count;
500         unsigned                pa_deleted;
501 -       unsigned long           pa_pstart;      /* phys. block */
502 -       unsigned long           pa_lstart;      /* log. block */
503 +       ext3_fsblk_t            pa_pstart;      /* phys. block */
504 +       ext3_fsblk_t            pa_lstart;      /* log. block */
505         unsigned short          pa_len;         /* len of preallocated chunk */
506         unsigned short          pa_free;        /* how many blocks are free */
507         unsigned short          pa_linear;      /* consumed in one direction
508 @@ -460,8 +460,8 @@ static struct proc_dir_entry *proc_root_
509  
510  int ext3_create (struct inode *, struct dentry *, int, struct nameidata *);
511  struct buffer_head * read_block_bitmap(struct super_block *, unsigned int);
512 -unsigned long ext3_new_blocks_old(handle_t *handle, struct inode *inode,
513 -                       unsigned long goal, unsigned long *count, int *errp);
514 +ext3_fsblk_t ext3_new_blocks_old(handle_t *handle, struct inode *inode,
515 +                       ext3_fsblk_t goal, unsigned long *count, int *errp);
516  void ext3_mb_release_blocks(struct super_block *, int);
517  void ext3_mb_poll_new_transaction(struct super_block *, handle_t *);
518  void ext3_mb_free_committed_blocks(struct super_block *);
519 @@ -479,7 +479,7 @@ int ext3_mb_destroy_per_dev_proc(struct 
520   * Calculate the block group number and offset, given a block number
521   */
522  static void ext3_get_group_no_and_offset(struct super_block *sb,
523 -                                       unsigned long blocknr,
524 +                                       ext3_fsblk_t blocknr,
525                                         unsigned long *blockgrpp,
526                                         unsigned long *offsetp)
527  {
528 @@ -517,12 +517,12 @@ ext3_is_group_locked(struct super_block 
529                                         &EXT3_GROUP_INFO(sb, group)->bb_state);
530  }
531  
532 -unsigned long ext3_grp_offs_to_block(struct super_block *sb,
533 +ext3_fsblk_t ext3_grp_offs_to_block(struct super_block *sb,
534                                         struct ext3_free_extent *fex)
535  {
536 -       unsigned long block;
537 +       ext3_fsblk_t block;
538  
539 -       block = (unsigned long) fex->fe_group * EXT3_BLOCKS_PER_GROUP(sb)
540 +       block = (ext3_fsblk_t) fex->fe_group * EXT3_BLOCKS_PER_GROUP(sb)
541                         + fex->fe_start
542                         + le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block);
543         return block;
544 @@ -3188,7 +3188,7 @@ void ext3_mb_collect_stats(struct ext3_a
545  void ext3_mb_use_inode_pa(struct ext3_allocation_context *ac,
546                                 struct ext3_prealloc_space *pa)
547  {
548 -       unsigned long start, len;
549 +       ext3_fsblk_t start, len;
550  
551         /* found preallocated blocks, use them */
552         start = pa->pa_pstart + (ac->ac_o_ex.fe_logical - pa->pa_lstart);
553 @@ -4041,13 +4041,13 @@ int ext3_mb_discard_preallocations(struc
554   * it tries to use preallocation first, then falls back
555   * to usual allocation
556   */
557 -unsigned long ext3_mb_new_blocks(handle_t *handle,
558 +ext3_fsblk_t ext3_mb_new_blocks(handle_t *handle,
559                                  struct ext3_allocation_request *ar, int *errp)
560  {
561         struct ext3_allocation_context ac;
562         struct ext3_sb_info *sbi;
563         struct super_block *sb;
564 -       unsigned long block;
565 +       ext3_fsblk_t block;
566         int err, freed;
567  
568         sb = ar->inode->i_sb;
569 @@ -4058,9 +4058,8 @@ unsigned long ext3_mb_new_blocks(handle_
570                 if (ext3_mballoc_warning++ == 0)
571                         printk(KERN_ERR "EXT3-fs: multiblock request with "
572                                         "mballoc disabled!\n");
573 -               ar->len = 1;
574 -               err = ext3_new_block_old(handle, ar->inode, ar->goal, errp);
575 -               return err;
576 +               return ext3_new_blocks_old(handle, ar->inode, ar->goal,
577 +                                          &ar->len, errp);
578         }
579  
580         ext3_mb_poll_new_transaction(sb, handle);
581 @@ -4107,11 +4106,11 @@ repeat:
582  }
583  EXPORT_SYMBOL(ext3_mb_new_blocks);
584  
585 -int ext3_new_block(handle_t *handle, struct inode *inode,
586 -                  unsigned long goal, int *errp)
587 +ext3_fsblk_t ext3_new_block(handle_t *handle, struct inode *inode,
588 +                  ext3_fsblk_t goal, int *errp)
589  {
590         struct ext3_allocation_request ar;
591 -       unsigned long ret;
592 +       ext3_fsblk_t ret;
593  
594         if (!test_opt(inode->i_sb, MBALLOC)) {
595                 ret = ext3_new_block_old(handle, inode, goal, errp);
596 @@ -4226,8 +4225,8 @@ int ext3_mb_free_metadata(handle_t *hand
597   * Main entry point into mballoc to free blocks
598   */
599  void ext3_mb_free_blocks(handle_t *handle, struct inode *inode,
600 -                       unsigned long block, unsigned long count,
601 -                       int metadata, int *freed)
602 +                       ext3_fsblk_t block, unsigned long count,
603 +                       int metadata, unsigned long *freed)
604  {
605         struct buffer_head *bitmap_bh = NULL;
606         struct super_block *sb = inode->i_sb;