Whamcloud - gitweb
b=24214 Discard preallocation blocks after failed allocated.
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-misc-rhel5.patch
1 Index: linux-2.6.18.i386/fs/ext4/ext4_jbd2.h
2 ===================================================================
3 --- linux-2.6.18.i386.orig/fs/ext4/ext4_jbd2.h
4 +++ linux-2.6.18.i386/fs/ext4/ext4_jbd2.h
5 @@ -35,6 +35,11 @@
6         (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)   \
7                 || test_opt(sb, EXTENTS) ? 27U : 8U)
8  
9 +/* Indicate that EXT4_SINGLEDATA_TRANS_BLOCKS takes the sb as argument */
10 +#define EXT4_SINGLEDATA_TRANS_BLOCKS_HAS_SB
11 +
12 +#define ext4_journal_dirty_metadata(handle, bh)  \
13 +                ext4_handle_dirty_metadata(handle, NULL, bh)
14  /* Extended attribute operations touch at most two data buffers,
15   * two bitmap buffers, and two group summaries, in addition to the inode
16   * and the superblock, which are already accounted for. */
17 Index: linux-2.6.18.i386/fs/ext4/extents.c
18 ===================================================================
19 --- linux-2.6.18.i386.orig/fs/ext4/extents.c
20 +++ linux-2.6.18.i386/fs/ext4/extents.c
21 @@ -60,6 +60,17 @@ static ext4_fsblk_t ext_pblock(struct ex
22  }
23  
24  /*
25 + * ext4_ext_store_pblock:
26 + * stores a large physical block number into an extent struct,
27 + * breaking it into parts
28 + */
29 +void ext4_ext_store_pblock(struct ext4_extent *ex, ext4_fsblk_t pb)
30 +{
31 +       ex->ee_start_lo = cpu_to_le32((unsigned long) (pb & 0xffffffff));
32 +       ex->ee_start_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) & 0xffff);
33 +}
34 +
35 +/*
36   * idx_pblock:
37   * combine low and high parts of a leaf physical block number into ext4_fsblk_t
38   */
39 @@ -73,17 +84,6 @@ ext4_fsblk_t idx_pblock(struct ext4_exte
40  }
41  
42  /*
43 - * ext4_ext_store_pblock:
44 - * stores a large physical block number into an extent struct,
45 - * breaking it into parts
46 - */
47 -void ext4_ext_store_pblock(struct ext4_extent *ex, ext4_fsblk_t pb)
48 -{
49 -       ex->ee_start_lo = cpu_to_le32((unsigned long) (pb & 0xffffffff));
50 -       ex->ee_start_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) & 0xffff);
51 -}
52 -
53 -/*
54   * ext4_idx_store_pblock:
55   * stores a large physical block number into an index struct,
56   * breaking it into parts
57 @@ -1826,6 +1826,56 @@ static int ext4_ext_rm_idx(handle_t *han
58  }
59  
60  /*
61 + * This routine returns max. credits extent tree can consume.
62 + * It should be OK for low-performance paths like ->writepage()
63 + * To allow many writing process to fit a single transaction,
64 + * caller should calculate credits under truncate_mutex and
65 + * pass actual path.
66 + */
67 +int ext4_ext_calc_credits_for_insert(struct inode *inode,
68 +                                   struct ext4_ext_path *path)
69 +{
70 +       int depth, needed;
71 +
72 +       if (path) {
73 +               /* probably there is space in leaf? */
74 +               depth = ext_depth(inode);
75 +               if (le16_to_cpu(path[depth].p_hdr->eh_entries)
76 +                               < le16_to_cpu(path[depth].p_hdr->eh_max))
77 +                       return 1;
78 +       }
79 +
80 +       /*
81 +        * given 32bit logical block (4294967296 blocks), max. tree
82 +        * can be 4 levels in depth -- 4 * 340^4 == 53453440000.
83 +        * let's also add one more level for imbalance.
84 +        */
85 +       depth = 5;
86 +
87 +       /* allocation of new data block(s) */
88 +       needed = 2;
89 +
90 +       /*
91 +        * tree can be full, so it'd need to grow in depth:
92 +        * we need one credit to modify old root, credits for
93 +        * new root will be added in split accounting
94 +        */
95 +       needed += 1;
96 +
97 +       /*
98 +        * Index split can happen, we'd need:
99 +        *    allocate intermediate indexes (bitmap + group)
100 +        *  + change two blocks at each level, but root (already included)
101 +        */
102 +       needed += (depth * 2) + (depth * 2);
103 +
104 +       /* any allocation modifies superblock */
105 +       needed += 1;
106 +
107 +       return needed;
108 +}
109 +
110 +/*
111   * ext4_ext_calc_credits_for_single_extent:
112   * This routine returns max. credits that needed to insert an extent
113   * to the extent tree.
114 @@ -3157,4 +3207,14 @@ int ext4_fiemap(struct inode *inode, str
115  
116         return error;
117  }
118 +
119 +EXPORT_SYMBOL(ext4_ext_store_pblock);
120 +EXPORT_SYMBOL(ext4_ext_search_right);
121 +EXPORT_SYMBOL(ext4_ext_search_left);
122 +EXPORT_SYMBOL(ext_pblock);
123 +EXPORT_SYMBOL(ext4_ext_insert_extent);
124 +EXPORT_SYMBOL(ext4_mb_new_blocks);
125 +EXPORT_SYMBOL(ext4_ext_walk_space);
126 +EXPORT_SYMBOL(ext4_ext_calc_credits_for_insert);
127 +EXPORT_SYMBOL(ext4_mark_inode_dirty);
128  
129 Index: linux-2.6.18.i386/fs/ext4/ext4_extents.h
130 ===================================================================
131 --- linux-2.6.18.i386.orig/fs/ext4/ext4_extents.h
132 +++ linux-2.6.18.i386/fs/ext4/ext4_extents.h
133 @@ -59,6 +59,12 @@
134   */
135  #define EXT_STATS_
136  
137 +/*
138 + * define EXT4_ALLOC_NEEDED to 0 since block bitmap, group desc. and sb
139 + * are now accounted in ext4_ext_calc_credits_for_insert()
140 + */
141 +#define EXT4_ALLOC_NEEDED 0
142 +#define HAVE_EXT_PREPARE_CB_EXTENT
143  
144  /*
145   * ext4_inode has i_block array (60 bytes total).
146 @@ -124,6 +129,8 @@ struct ext4_ext_path {
147  #define EXT4_EXT_CACHE_GAP     1
148  #define EXT4_EXT_CACHE_EXTENT  2
149  
150 +#define EXT4_EXT_HAS_NO_TREE  /* ext4_extents_tree struct is not used*/
151 +#define EXT_INSERT_EXTENT_WITH_5ARGS
152  
153  #define EXT_MAX_BLOCK  0xffffffff
154  
155 @@ -228,6 +234,8 @@ static inline int ext4_ext_get_actual_le
156  extern ext4_fsblk_t idx_pblock(struct ext4_extent_idx *);
157  extern void ext4_ext_store_pblock(struct ext4_extent *, ext4_fsblk_t);
158  extern int ext4_extent_tree_init(handle_t *, struct inode *);
159 +extern int ext4_ext_calc_credits_for_insert(struct inode *,
160 +                                           struct ext4_ext_path *);
161  extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
162                                                    int num,
163                                                    struct ext4_ext_path *path);
164 Index: linux-2.6.18.i386/fs/ext4/mballoc.c
165 ===================================================================
166 --- linux-2.6.18.i386.orig/fs/ext4/mballoc.c
167 +++ linux-2.6.18.i386/fs/ext4/mballoc.c
168 @@ -4355,6 +4355,13 @@
169                 kmem_cache_free(ext4_ac_cachep, ac);
170  }
171  
172 +/* For backward compatibility, since Lustre uses this symbol */
173 +void ext4_mb_discard_inode_preallocations(struct inode *inode)
174 +{
175 +       ext4_discard_preallocations(inode);
176 +}
177 +EXPORT_SYMBOL(ext4_mb_discard_inode_preallocations);
178 +
179  /*
180   * finds all preallocated spaces and return blocks being freed to them
181   * if preallocated space becomes full (no block is used from the space)
182 @@ -4965,3 +4965,6 @@ error_return:
183                 kmem_cache_free(ext4_ac_cachep, ac);
184         return;
185  }
186 +
187 +EXPORT_SYMBOL(ext4_free_blocks);
188 +
189 Index: linux-2.6.18.i386/fs/ext4/ext4_jbd2.c
190 ===================================================================
191 --- linux-2.6.18.i386.orig/fs/ext4/ext4_jbd2.c
192 +++ linux-2.6.18.i386/fs/ext4/ext4_jbd2.c
193 @@ -21,6 +21,7 @@ int __ext4_journal_get_write_access(cons
194                 ext4_journal_abort_handle(where, __func__, bh, handle, err);
195         return err;
196  }
197 +EXPORT_SYMBOL(__ext4_journal_get_write_access);
198  
199  int __ext4_journal_forget(const char *where, handle_t *handle,
200                                 struct buffer_head *bh)
201 @@ -57,3 +58,4 @@ int __ext4_journal_dirty_metadata(const 
202                 ext4_journal_abort_handle(where, __func__, bh, handle, err);
203         return err;
204  }
205 +EXPORT_SYMBOL(__ext4_handle_dirty_metadata);
206 Index: linux-2.6.27.21-0.1/fs/ext4/ext4.h
207 ===================================================================
208 --- linux-2.6.27.21-0.1.orig/fs/ext4/ext4.h     2009-07-07 14:47:19.000000000 +0530
209 +++ linux-2.6.27.21-0.1/fs/ext4/ext4.h  2009-07-07 14:47:22.000000000 +0530
210 @@ -1123,6 +1128,8 @@
211  extern int ext4_mb_get_buddy_cache_lock(struct super_block *, ext4_group_t);
212  extern void ext4_mb_put_buddy_cache_lock(struct super_block *,
213                                                 ext4_group_t, int);
214 +extern void ext4_mb_discard_inode_preallocations(struct inode *);
215 +
216  /* inode.c */
217  int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
218                 struct buffer_head *bh, ext4_fsblk_t blocknr);
219 Index: linux-2.6.27.21-0.1/fs/ext4/inode.c
220 ===================================================================
221 --- linux-2.6.27.21-0.1.orig/fs/ext4/inode.c    2009-07-07 14:47:19.000000000 +0530
222 +++ linux-2.6.27.21-0.1/fs/ext4/inode.c 2009-07-07 14:47:22.000000000 +0530
223 @@ -4240,6 +4240,7 @@
224         iget_failed(inode);
225         return ERR_PTR(ret);
226  }
227 +EXPORT_SYMBOL(ext4_iget);
228  
229  static int ext4_inode_blocks_set(handle_t *handle,
230                                 struct ext4_inode *raw_inode,
231 Index: linux-2.6.27.21-0.1/fs/ext4/super.c
232 ===================================================================
233 --- linux-2.6.27.21-0.1.orig/fs/ext4/super.c    2009-07-07 14:47:19.000000000 +0530
234 +++ linux-2.6.27.21-0.1/fs/ext4/super.c 2009-07-07 14:48:53.000000000 +0530
235 @@ -91,6 +91,7 @@ ext4_fsblk_t ext4_inode_bitmap(struct su
236                 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
237                 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
238  }
239 +EXPORT_SYMBOL(ext4_inode_bitmap);
240  
241  ext4_fsblk_t ext4_inode_table(struct super_block *sb,
242                               struct ext4_group_desc *bg)
243 @@ -113,6 +118,7 @@
244                 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
245                 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
246  }
247 +EXPORT_SYMBOL(ext4_itable_unused_count);
248
249  void ext4_block_bitmap_set(struct super_block *sb,
250                            struct ext4_group_desc *bg, ext4_fsblk_t blk)
251 @@ -1286,6 +1287,7 @@
252         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
253         Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize,
254         Opt_usrquota, Opt_grpquota, Opt_i_version,
255 +       Opt_mballoc, Opt_extents,
256         Opt_stripe, Opt_delalloc, Opt_nodelalloc,
257         Opt_inode_readahead_blks, Opt_journal_ioprio,
258         Opt_iopen, Opt_noiopen, Opt_iopen_nopriv, Opt_bigendian_extents,
259 @@ -1346,6 +1348,8 @@
260         {Opt_barrier, "barrier"},
261         {Opt_nobarrier, "nobarrier"},
262         {Opt_i_version, "i_version"},
263 +       {Opt_mballoc, "mballoc"},
264 +       {Opt_extents, "extents"},
265         {Opt_stripe, "stripe=%u"},
266         {Opt_resize, "resize"},
267         {Opt_delalloc, "delalloc"},
268 @@ -1768,6 +1771,9 @@
269                 case Opt_bigendian_extents:
270                         bigendian_extents = 1;
271                         break;
272 +               case Opt_mballoc:
273 +               case Opt_extents:
274 +                       break;
275                 default:
276                         printk(KERN_ERR
277                                "EXT4-fs: Unrecognized mount option \"%s\" "
278 @@ -2768,7 +2771,7 @@
279                                               char *buf)
280  {
281         return snprintf(buf, PAGE_SIZE, "%llu\n",
282 -                       (s64) percpu_counter_sum(&sbi->s_dirtyblocks_counter));
283 +                       (unsigned long long) percpu_counter_sum(&sbi->s_dirtyblocks_counter));
284  }
285  
286  static ssize_t session_write_kbytes_show(struct ext4_attr *a,
287 @@ -2868,11 +2871,11 @@
288         struct super_block *sb = sbi->s_buddy_cache->i_sb;
289
290         return snprintf(buf, PAGE_SIZE, "%llu\n",
291 -                       sbi->s_kbytes_written + 
292 +                       (unsigned long long)(sbi->s_kbytes_written + 
293                         (sb->s_bdev->bd_part ?
294                         (part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
295                           EXT4_SB(sb)->s_sectors_written_start) >> 1
296 -                       : 0));
297 +                       : 0)));
298  }
299  
300  static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
301 @@ -3868,7 +3871,7 @@
302         if (blocks_count && ext4_blocks_count(es) > blocks_count) {
303                 ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
304                        "exceeds size of device (%llu blocks)",
305 -                      ext4_blocks_count(es), blocks_count);
306 +                      ext4_blocks_count(es), (unsigned long long)blocks_count);
307                 goto failed_mount;
308         }
309
310 Index: linux-2.6.27.21-0.1/fs/ext4/fsync.c
311 ===================================================================
312 --- linux-2.6.27.21-0.1.orig/fs/ext4/fsync.c    2009-07-07 14:47:19.000000000 +0530
313 +++ linux-2.6.27.21-0.1/fs/ext4/fsync.c 2009-07-07 14:48:53.000000000 +0530
314 @@ -1768,7 +1771,7 @@
315  
316         trace_mark(ext4_sync_file, "dev %s datasync %d ino %ld parent %ld",
317                    inode->i_sb->s_id, datasync, inode->i_ino,
318 -                  dentry->d_parent->d_inode->i_ino);
319 +                  0L);
320
321         /*
322          * data=writeback:
323 Index: linux-2.6.27.21-0.1/fs/ext4/move_extent.c
324 ===================================================================
325 --- linux-2.6.27.21-0.1.orig/fs/ext4/move_extent.c      2009-07-07 14:47:19.000000000 +0530
326 +++ linux-2.6.27.21-0.1/fs/ext4/move_extent.c   2009-07-07 14:48:53.000000000 +0530
327 @@ -1768,7 +1771,8 @@
328                                 ext4_error(orig_inode->i_sb, __func__,
329                                         "We replaced blocks too much! "
330                                         "sum of replaced: %llu requested: %llu",
331 -                                       *moved_len, len);
332 +                                       (unsigned long long)(*moved_len),
333 +                                       (unsigned long long)(len));
334                                 ret1 = -EIO;
335                                 goto out;
336                         }