Whamcloud - gitweb
8ee9ad5a0b212083cbdcc43d53c94cb1f9953571
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-update-sles11-rhel6.patch
1 diff -urpN linux-stage.orig/fs/ext4/balloc.c linux-stage/fs/ext4/balloc.c
2 --- linux-stage.orig/fs/ext4/balloc.c   2012-07-02 12:07:23.000000000 -0400
3 +++ linux-stage/fs/ext4/balloc.c        2012-07-02 12:07:57.000000000 -0400
4 @@ -97,7 +97,7 @@ unsigned ext4_init_block_bitmap(struct s
5                 /* If checksum is bad mark all blocks used to prevent allocation
6                  * essentially implementing a per-group read-only flag. */
7                 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) {
8 -                       ext4_error(sb, __func__,
9 +                       ext4_error(sb,
10                                   "Checksum bad for group %u", block_group);
11                         ext4_free_blks_set(sb, gdp, 0);
12                         ext4_free_inodes_set(sb, gdp, 0);
13 @@ -207,10 +207,8 @@ struct ext4_group_desc * ext4_get_group_
14         struct ext4_sb_info *sbi = EXT4_SB(sb);
15  
16         if (block_group >= ngroups) {
17 -               ext4_error(sb, "ext4_get_group_desc",
18 -                          "block_group >= groups_count - "
19 -                          "block_group = %u, groups_count = %u",
20 -                          block_group, ngroups);
21 +               ext4_error(sb, "block_group >= groups_count - block_group = %u,"
22 +                          " groups_count = %u", block_group, ngroups);
23  
24                 return NULL;
25         }
26 @@ -218,8 +216,7 @@ struct ext4_group_desc * ext4_get_group_
27         group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb);
28         offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1);
29         if (!sbi->s_group_desc[group_desc]) {
30 -               ext4_error(sb, "ext4_get_group_desc",
31 -                          "Group descriptor not loaded - "
32 +               ext4_error(sb, "Group descriptor not loaded - "
33                            "block_group = %u, group_desc = %u, desc = %u",
34                            block_group, group_desc, offset);
35                 return NULL;
36 @@ -280,7 +277,7 @@ static int ext4_valid_block_bitmap(struc
37                 return 1;
38  
39  err_out:
40 -       ext4_error(sb, __func__,
41 +       ext4_error(sb,
42                         "Invalid block bitmap - "
43                         "block_group = %d, block = %llu",
44                         block_group, bitmap_blk);
45 @@ -309,7 +306,7 @@ ext4_read_block_bitmap(struct super_bloc
46         bitmap_blk = ext4_block_bitmap(sb, desc);
47         bh = sb_getblk(sb, bitmap_blk);
48         if (unlikely(!bh)) {
49 -               ext4_error(sb, __func__,
50 +               ext4_error(sb,
51                             "Cannot read block bitmap - "
52                             "block_group = %u, block_bitmap = %llu",
53                             block_group, bitmap_blk);
54 @@ -352,7 +349,7 @@ ext4_read_block_bitmap(struct super_bloc
55         set_bitmap_uptodate(bh);
56         if (bh_submit_read(bh) < 0) {
57                 put_bh(bh);
58 -               ext4_error(sb, __func__,
59 +               ext4_error(sb,
60                             "Cannot read block bitmap - "
61                             "block_group = %u, block_bitmap = %llu",
62                             block_group, bitmap_blk);
63 @@ -417,7 +414,7 @@ void ext4_add_groupblocks(handle_t *hand
64             in_range(block, ext4_inode_table(sb, desc), sbi->s_itb_per_group) ||
65             in_range(block + count - 1, ext4_inode_table(sb, desc),
66                      sbi->s_itb_per_group)) {
67 -               ext4_error(sb, __func__,
68 +               ext4_error(sb,
69                            "Adding blocks in system zones - "
70                            "Block = %llu, count = %lu",
71                            block, count);
72 @@ -451,7 +448,7 @@ void ext4_add_groupblocks(handle_t *hand
73                 BUFFER_TRACE(bitmap_bh, "clear bit");
74                 if (!ext4_clear_bit_atomic(ext4_group_lock_ptr(sb, block_group),
75                                                 bit + i, bitmap_bh->b_data)) {
76 -                       ext4_error(sb, __func__,
77 +                       ext4_error(sb,
78                                    "bit already cleared for block %llu",
79                                    (ext4_fsblk_t)(block + i));
80                         BUFFER_TRACE(bitmap_bh, "bit already cleared");
81 diff -urpN linux-stage.orig/fs/ext4/dir.c linux-stage/fs/ext4/dir.c
82 --- linux-stage.orig/fs/ext4/dir.c      2012-07-02 12:07:23.000000000 -0400
83 +++ linux-stage/fs/ext4/dir.c   2012-07-02 12:07:57.000000000 -0400
84 @@ -70,28 +70,29 @@ int ext4_check_dir_entry(const char *fun
85         const int rlen = ext4_rec_len_from_disk(de->rec_len,
86                                                 dir->i_sb->s_blocksize);
87  
88 -       if (rlen < EXT4_DIR_REC_LEN(1))
89 +       if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
90                 error_msg = "rec_len is smaller than minimal";
91 -       else if (rlen % 4 != 0)
92 +       else if (unlikely(rlen % 4 != 0))
93                 error_msg = "rec_len % 4 != 0";
94 -       else if (rlen < EXT4_DIR_REC_LEN(de->name_len))
95 +       else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
96                 error_msg = "rec_len is too small for name_len";
97 -       else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)
98 +       else if (unlikely(((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize))
99                 error_msg = "directory entry across blocks";
100 -       else if (le32_to_cpu(de->inode) >
101 -                       le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count))
102 +       else if (unlikely(le32_to_cpu(de->inode) >
103 +                       le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count)))
104                 error_msg = "inode out of bounds";
105 +       else
106 +               return 1;
107  
108 -       if (error_msg != NULL)
109 -               ext4_error(dir->i_sb, function,
110 -                       "bad entry in directory #%lu: %s - block=%llu"
111 -                       "offset=%u(%u), inode=%u, rec_len=%d, name_len=%d",
112 -                       dir->i_ino, error_msg,
113 -                       (unsigned long long) bh->b_blocknr,
114 -                       (unsigned) (offset%bh->b_size), offset,
115 -                       le32_to_cpu(de->inode),
116 -                       rlen, de->name_len);
117 -       return error_msg == NULL ? 1 : 0;
118 +       ext4_error(dir->i_sb,
119 +               "bad entry in directory #%lu: %s - block=%llu"
120 +               "offset=%u(%u), inode=%u, rec_len=%d, name_len=%d",
121 +               dir->i_ino, error_msg,
122 +               (unsigned long long) bh->b_blocknr,
123 +               (unsigned) (offset%bh->b_size), offset,
124 +               le32_to_cpu(de->inode),
125 +               rlen, de->name_len);
126 +       return 0;
127  }
128  
129  static int ext4_readdir(struct file *filp,
130 @@ -152,7 +153,7 @@ static int ext4_readdir(struct file *fil
131                  */
132                 if (!bh) {
133                         if (!dir_has_error) {
134 -                               ext4_error(sb, __func__, "directory #%lu "
135 +                               ext4_error(sb, "directory #%lu "
136                                            "contains a hole at offset %Lu",
137                                            inode->i_ino,
138                                            (unsigned long long) filp->f_pos);
139 diff -urpN linux-stage.orig/fs/ext4/ext4_extents.h linux-stage/fs/ext4/ext4_extents.h
140 --- linux-stage.orig/fs/ext4/ext4_extents.h     2012-07-02 12:07:23.000000000 -0400
141 +++ linux-stage/fs/ext4/ext4_extents.h  2012-07-02 12:07:57.000000000 -0400
142 @@ -138,7 +138,7 @@ typedef int (*ext_prepare_callback)(stru
143  #define EXT_REPEAT     2
144  
145  /* Maximum logical block in a file; ext4_extent's ee_block is __le32 */
146 -#define EXT_MAX_BLOCK  0xffffffff
147 +#define EXT_MAX_BLOCKS 0xffffffff
148  
149  /*
150   * EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an
151 diff -urpN linux-stage.orig/fs/ext4/ext4.h linux-stage/fs/ext4/ext4.h
152 --- linux-stage.orig/fs/ext4/ext4.h     2012-07-02 12:07:23.000000000 -0400
153 +++ linux-stage/fs/ext4/ext4.h  2012-07-02 12:10:15.000000000 -0400
154 @@ -23,6 +23,7 @@
155  #include <linux/quota.h>
156  #include <linux/rwsem.h>
157  #include <linux/rbtree.h>
158 +#include <linux/kernel.h>
159  #include <linux/seqlock.h>
160  #include <linux/mutex.h>
161  #include <linux/timer.h>
162 @@ -56,6 +57,12 @@
163  #define ext4_debug(f, a...)    do {} while (0)
164  #endif
165  
166 +#define EXT4_ERROR_INODE(inode, fmt, a...) \
167 +       ext4_error_inode(__func__, (inode), (fmt), ## a);
168 +
169 +#define EXT4_ERROR_FILE(file, fmt, a...)        \
170 +       ext4_error_file(__func__, (file), (fmt), ## a);
171 +
172  /* data type for block offset of block group */
173  typedef int ext4_grpblk_t;
174  
175 @@ -970,7 +977,27 @@ struct ext4_super_block {
176         __u8    s_reserved_char_pad2;
177         __le16  s_reserved_pad;
178         __le64  s_kbytes_written;       /* nr of lifetime kilobytes written */
179 -       __u32   s_reserved[160];        /* Padding to the end of the block */
180 +       __le32  s_snapshot_inum;        /* Inode number of active snapshot */
181 +       __le32  s_snapshot_id;          /* sequential ID of active snapshot */
182 +       __le64  s_snapshot_r_blocks_count; /* reserved blocks for active
183 +                                             snapshot's future use */
184 +       __le32  s_snapshot_list;        /* inode number of the head of the
185 +                                          on-disk snapshot list */
186 +#define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count)
187 +       __le32  s_error_count;          /* number of fs errors */
188 +       __le32  s_first_error_time;     /* first time an error happened */
189 +       __le32  s_first_error_ino;      /* inode involved in first error */
190 +       __le64  s_first_error_block;    /* block involved of first error */
191 +       __u8    s_first_error_func[32]; /* function where the error happened */
192 +       __le32  s_first_error_line;     /* line number where error happened */
193 +       __le32  s_last_error_time;      /* most recent time of an error */
194 +       __le32  s_last_error_ino;       /* inode involved in last error */
195 +       __le32  s_last_error_line;      /* line number where error happened */
196 +       __le64  s_last_error_block;     /* block involved of last error */
197 +       __u8    s_last_error_func[32];  /* function where the error happened */
198 +#define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts)
199 +       __u8    s_mount_opts[64];
200 +       __le32  s_reserved[112];        /* Padding to the end of the block */
201  };
202  
203  #ifdef __KERNEL__
204 @@ -1110,6 +1137,9 @@ struct ext4_sb_info {
205  
206         /* workqueue for dio unwritten */
207         struct workqueue_struct *dio_unwritten_wq;
208 +
209 +       /* Lazy inode table initialization info */
210 +       struct ext4_li_request *s_li_request;
211  };
212  
213  static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
214 @@ -1431,6 +1461,23 @@ void ext4_get_group_no_and_offset(struct
215  extern struct proc_dir_entry *ext4_proc_root;
216  
217  /*
218 + * Timeout and state flag for lazy initialization inode thread.
219 + */
220 +#define EXT4_DEF_LI_WAIT_MULT                  10
221 +#define EXT4_DEF_LI_MAX_START_DELAY            5
222 +#define EXT4_LAZYINIT_QUIT                     0x0001
223 +#define EXT4_LAZYINIT_RUNNING                  0x0002
224 +
225 +/*
226 + * Lazy inode table initialization info
227 + */
228 +struct ext4_lazy_init {
229 +       unsigned long           li_state;
230 +       struct list_head        li_request_list;
231 +       struct mutex            li_list_mtx;
232 +};
233 +
234 +/*
235   * Function prototypes
236   */
237  
238 @@ -1509,6 +1556,7 @@ extern struct buffer_head *ext4_read_ino
239  extern void mark_bitmap_end(int start_bit, int end_bit, char *bitmap);
240  
241  /* mballoc.c */
242 +struct fstrim_range;
243  extern long ext4_mb_stats;
244  extern long ext4_mb_max_to_scan;
245  extern int ext4_mb_init(struct super_block *, int);
246 @@ -1526,6 +1574,8 @@ extern int ext4_mb_add_groupinfo(struct 
247  extern int ext4_mb_get_buddy_cache_lock(struct super_block *, ext4_group_t);
248  extern void ext4_mb_put_buddy_cache_lock(struct super_block *,
249                                                 ext4_group_t, int);
250 +extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
251 +
252  /* inode.c */
253  int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
254                 struct buffer_head *bh, ext4_fsblk_t blocknr);
255 @@ -1586,13 +1636,17 @@ extern int ext4_group_extend(struct supe
256                                 ext4_fsblk_t n_blocks_count);
257  
258  /* super.c */
259 -extern void ext4_error(struct super_block *, const char *, const char *, ...)
260 +extern void __ext4_error(struct super_block *, const char *, const char *, ...)
261 +       __attribute__ ((format (printf, 3, 4)));
262 +#define ext4_error(sb, message...)     __ext4_error(sb, __func__, ## message)
263 +extern void ext4_error_inode(const char *, struct inode *, const char *, ...)
264         __attribute__ ((format (printf, 3, 4)));
265  extern void __ext4_std_error(struct super_block *, const char *, int);
266  extern void ext4_abort(struct super_block *, const char *, const char *, ...)
267         __attribute__ ((format (printf, 3, 4)));
268 -extern void ext4_warning(struct super_block *, const char *, const char *, ...)
269 +extern void __ext4_warning(struct super_block *, const char *, const char *, ...)
270         __attribute__ ((format (printf, 3, 4)));
271 +#define ext4_warning(sb, message...)   __ext4_warning(sb, __func__, ## message)
272  extern void ext4_msg(struct super_block *, const char *, const char *, ...)
273         __attribute__ ((format (printf, 3, 4)));
274  extern void ext4_grp_locked_error(struct super_block *, ext4_group_t,
275 @@ -1774,11 +1828,19 @@ struct ext4_group_info {
276                                          * 5 free 8-block regions. */
277  };
278  
279 -#define EXT4_GROUP_INFO_NEED_INIT_BIT  0
280 +#define EXT4_GROUP_INFO_NEED_INIT_BIT          0
281 +#define EXT4_GROUP_INFO_WAS_TRIMMED_BIT                1
282  
283  #define EXT4_MB_GRP_NEED_INIT(grp)     \
284         (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
285  
286 +#define EXT4_MB_GRP_WAS_TRIMMED(grp)    \
287 +       (test_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
288 +#define EXT4_MB_GRP_SET_TRIMMED(grp)    \
289 +       (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
290 +#define EXT4_MB_GRP_CLEAR_TRIMMED(grp)  \
291 +       (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
292 +
293  #define EXT4_MAX_CONTENTION            8
294  #define EXT4_CONTENTION_THRESHOLD      2
295  
296 diff -urpN linux-stage.orig/fs/ext4/ext4_jbd2.c linux-stage/fs/ext4/ext4_jbd2.c
297 --- linux-stage.orig/fs/ext4/ext4_jbd2.c        2012-07-02 12:07:23.000000000 -0400
298 +++ linux-stage/fs/ext4/ext4_jbd2.c     2012-07-02 12:07:57.000000000 -0400
299 @@ -96,7 +96,7 @@ int __ext4_handle_dirty_metadata(const c
300                 if (inode && inode_needs_sync(inode)) {
301                         sync_dirty_buffer(bh);
302                         if (buffer_req(bh) && !buffer_uptodate(bh)) {
303 -                               ext4_error(inode->i_sb, __func__,
304 +                               ext4_error(inode->i_sb,
305                                            "IO error syncing inode, "
306                                            "inode=%lu, block=%llu",
307                                            inode->i_ino,
308 diff -urpN linux-stage.orig/fs/ext4/extents.c linux-stage/fs/ext4/extents.c
309 --- linux-stage.orig/fs/ext4/extents.c  2012-07-02 12:07:23.000000000 -0400
310 +++ linux-stage/fs/ext4/extents.c       2012-07-02 12:07:57.000000000 -0400
311 @@ -437,7 +437,7 @@ static int __ext4_ext_check(const char *
312         return 0;
313  
314  corrupted:
315 -       ext4_error(inode->i_sb, function,
316 +       ext4_error(inode->i_sb,
317                         "bad header/extent in inode #%lu: %s - magic %x, "
318                         "entries %u, max %u(%u), depth %u(%u)",
319                         inode->i_ino, error_msg, le16_to_cpu(eh->eh_magic),
320 @@ -1329,7 +1329,7 @@ got_index:
321  
322  /*
323   * ext4_ext_next_allocated_block:
324 - * returns allocated block in subsequent extent or EXT_MAX_BLOCK.
325 + * returns allocated block in subsequent extent or EXT_MAX_BLOCKS.
326   * NOTE: it considers block number from index entry as
327   * allocated block. Thus, index entries have to be consistent
328   * with leaves.
329 @@ -1343,7 +1343,7 @@ ext4_ext_next_allocated_block(struct ext
330         depth = path->p_depth;
331  
332         if (depth == 0 && path->p_ext == NULL)
333 -               return EXT_MAX_BLOCK;
334 +               return EXT_MAX_BLOCKS;
335  
336         while (depth >= 0) {
337                 if (depth == path->p_depth) {
338 @@ -1360,12 +1360,12 @@ ext4_ext_next_allocated_block(struct ext
339                 depth--;
340         }
341  
342 -       return EXT_MAX_BLOCK;
343 +       return EXT_MAX_BLOCKS;
344  }
345  
346  /*
347   * ext4_ext_next_leaf_block:
348 - * returns first allocated block from next leaf or EXT_MAX_BLOCK
349 + * returns first allocated block from next leaf or EXT_MAX_BLOCKS
350   */
351  static ext4_lblk_t ext4_ext_next_leaf_block(struct inode *inode,
352                                         struct ext4_ext_path *path)
353 @@ -1377,7 +1377,7 @@ static ext4_lblk_t ext4_ext_next_leaf_bl
354  
355         /* zero-tree has no leaf blocks at all */
356         if (depth == 0)
357 -               return EXT_MAX_BLOCK;
358 +               return EXT_MAX_BLOCKS;
359  
360         /* go to index block */
361         depth--;
362 @@ -1390,7 +1390,7 @@ static ext4_lblk_t ext4_ext_next_leaf_bl
363                 depth--;
364         }
365  
366 -       return EXT_MAX_BLOCK;
367 +       return EXT_MAX_BLOCKS;
368  }
369  
370  /*
371 @@ -1534,7 +1534,7 @@ int ext4_ext_try_to_merge(struct inode *
372                 merge_done = 1;
373                 WARN_ON(eh->eh_entries == 0);
374                 if (!eh->eh_entries)
375 -                       ext4_error(inode->i_sb, "ext4_ext_try_to_merge",
376 +                       ext4_error(inode->i_sb,
377                            "inode#%lu, eh->eh_entries = 0!", inode->i_ino);
378         }
379  
380 @@ -1570,13 +1570,13 @@ unsigned int ext4_ext_check_overlap(stru
381          */
382         if (b2 < b1) {
383                 b2 = ext4_ext_next_allocated_block(path);
384 -               if (b2 == EXT_MAX_BLOCK)
385 +               if (b2 == EXT_MAX_BLOCKS)
386                         goto out;
387         }
388  
389         /* check for wrap through zero on extent logical start block*/
390         if (b1 + len1 < b1) {
391 -               len1 = EXT_MAX_BLOCK - b1;
392 +               len1 = EXT_MAX_BLOCKS - b1;
393                 newext->ee_len = cpu_to_le16(len1);
394                 ret = 1;
395         }
396 @@ -1652,7 +1652,7 @@ repeat:
397         fex = EXT_LAST_EXTENT(eh);
398         next = ext4_ext_next_leaf_block(inode, path);
399         if (le32_to_cpu(newext->ee_block) > le32_to_cpu(fex->ee_block)
400 -           && next != EXT_MAX_BLOCK) {
401 +           && next != EXT_MAX_BLOCKS) {
402                 ext_debug("next leaf block - %d\n", next);
403                 BUG_ON(npath != NULL);
404                 npath = ext4_ext_find_extent(inode, next, NULL);
405 @@ -1771,7 +1771,7 @@ int ext4_ext_walk_space(struct inode *in
406         BUG_ON(func == NULL);
407         BUG_ON(inode == NULL);
408  
409 -       while (block < last && block != EXT_MAX_BLOCK) {
410 +       while (block < last && block != EXT_MAX_BLOCKS) {
411                 num = last - block;
412                 /* find extent for this block */
413                 down_read(&EXT4_I(inode)->i_data_sem);
414 @@ -1784,7 +1784,11 @@ int ext4_ext_walk_space(struct inode *in
415                 }
416  
417                 depth = ext_depth(inode);
418 -               BUG_ON(path[depth].p_hdr == NULL);
419 +               if (unlikely(path[depth].p_hdr == NULL)) {
420 +                       EXT4_ERROR_INODE(inode, "path[%d].p_hdr == NULL", depth);
421 +                       err = -EIO;
422 +                       break;
423 +               }
424                 ex = path[depth].p_ext;
425                 next = ext4_ext_next_allocated_block(path);
426  
427 @@ -1835,7 +1839,11 @@ int ext4_ext_walk_space(struct inode *in
428                         cbex.ec_type = EXT4_EXT_CACHE_EXTENT;
429                 }
430  
431 -               BUG_ON(cbex.ec_len == 0);
432 +               if (unlikely(cbex.ec_len == 0)) {
433 +                       EXT4_ERROR_INODE(inode, "cbex.ec_len == 0");
434 +                       err = -EIO;
435 +                       break;
436 +               }
437                 err = func(inode, path, &cbex, ex, cbdata);
438                 ext4_ext_drop_refs(path);
439  
440 @@ -1899,7 +1907,7 @@ ext4_ext_put_gap_in_cache(struct inode *
441         if (ex == NULL) {
442                 /* there is no extent yet, so gap is [0;-] */
443                 lblock = 0;
444 -               len = EXT_MAX_BLOCK;
445 +               len = EXT_MAX_BLOCKS;
446                 ext_debug("cache gap(whole file):");
447         } else if (block < le32_to_cpu(ex->ee_block)) {
448                 lblock = block;
449 @@ -2144,8 +2152,8 @@ ext4_ext_rm_leaf(handle_t *handle, struc
450                 path[depth].p_ext = ex;
451  
452                 a = ex_ee_block > start ? ex_ee_block : start;
453 -               b = ex_ee_block + ex_ee_len - 1 < EXT_MAX_BLOCK ?
454 -                       ex_ee_block + ex_ee_len - 1 : EXT_MAX_BLOCK;
455 +               b = ex_ee_block + ex_ee_len - 1 < EXT_MAX_BLOCKS ?
456 +                       ex_ee_block + ex_ee_len - 1 : EXT_MAX_BLOCKS;
457  
458                 ext_debug("  border %u:%u\n", a, b);
459  
460 @@ -3284,7 +3292,7 @@ int ext4_ext_get_blocks(handle_t *handle
461          * this is why assert can't be put in ext4_ext_find_extent()
462          */
463         if (path[depth].p_ext == NULL && depth != 0) {
464 -               ext4_error(inode->i_sb, __func__, "bad extent address "
465 +               ext4_error(inode->i_sb, "bad extent address "
466                            "inode: %lu, iblock: %lu, depth: %d",
467                            inode->i_ino, (unsigned long) iblock, depth);
468                 err = -EIO;
469 @@ -3415,7 +3423,7 @@ int ext4_ext_get_blocks(handle_t *handle
470  
471         if (unlikely(ext4_test_inode_flag(inode, EXT4_INODE_EOFBLOCKS))) {
472                 if (unlikely(!eh->eh_entries)) {
473 -                       ext4_error(inode->i_sb, __func__,
474 +                       ext4_error(inode->i_sb,
475                                    "inode#%lu, eh->eh_entries = 0 and "
476                                    "EOFBLOCKS_FL set", inode->i_ino);
477                         err = -EIO;
478 @@ -3782,15 +3790,15 @@ static int ext4_ext_fiemap_cb(struct ino
479                 flags |= FIEMAP_EXTENT_UNWRITTEN;
480  
481         /*
482 -        * If this extent reaches EXT_MAX_BLOCK, it must be last.
483 +        * If this extent reaches EXT_MAX_BLOCKS, it must be last.
484          *
485 -        * Or if ext4_ext_next_allocated_block is EXT_MAX_BLOCK,
486 +        * Or if ext4_ext_next_allocated_block is EXT_MAX_BLOCKS,
487          * this also indicates no more allocated blocks.
488          *
489 -        * XXX this might miss a single-block extent at EXT_MAX_BLOCK
490 +        * XXX this might miss a single-block extent at EXT_MAX_BLOCKS
491          */
492 -       if (ext4_ext_next_allocated_block(path) == EXT_MAX_BLOCK ||
493 -           newex->ec_block + newex->ec_len - 1 == EXT_MAX_BLOCK) {
494 +       if (ext4_ext_next_allocated_block(path) == EXT_MAX_BLOCKS ||
495 +           newex->ec_block + newex->ec_len - 1 == EXT_MAX_BLOCKS) {
496                 loff_t size = i_size_read(inode);
497                 loff_t bs = EXT4_BLOCK_SIZE(inode->i_sb);
498  
499 @@ -3870,8 +3878,8 @@ int ext4_fiemap(struct inode *inode, str
500  
501                 start_blk = start >> inode->i_sb->s_blocksize_bits;
502                 last_blk = (start + len - 1) >> inode->i_sb->s_blocksize_bits;
503 -               if (last_blk >= EXT_MAX_BLOCK)
504 -                       last_blk = EXT_MAX_BLOCK-1;
505 +               if (last_blk >= EXT_MAX_BLOCKS)
506 +                       last_blk = EXT_MAX_BLOCKS-1;
507                 len_blks = ((ext4_lblk_t) last_blk) - start_blk + 1;
508  
509                 /*
510 diff -urpN linux-stage.orig/fs/ext4/ialloc.c linux-stage/fs/ext4/ialloc.c
511 --- linux-stage.orig/fs/ext4/ialloc.c   2012-07-02 12:07:23.000000000 -0400
512 +++ linux-stage/fs/ext4/ialloc.c        2012-07-02 12:07:57.000000000 -0400
513 @@ -76,7 +76,7 @@ unsigned ext4_init_inode_bitmap(struct s
514         /* If checksum is bad mark all blocks and inodes use to prevent
515          * allocation, essentially implementing a per-group read-only flag. */
516         if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) {
517 -               ext4_error(sb, __func__, "Checksum bad for group %u",
518 +               ext4_error(sb, "Checksum bad for group %u",
519                            block_group);
520                 ext4_free_blks_set(sb, gdp, 0);
521                 ext4_free_inodes_set(sb, gdp, 0);
522 @@ -111,7 +111,7 @@ ext4_read_inode_bitmap(struct super_bloc
523         bitmap_blk = ext4_inode_bitmap(sb, desc);
524         bh = sb_getblk(sb, bitmap_blk);
525         if (unlikely(!bh)) {
526 -               ext4_error(sb, __func__,
527 +               ext4_error(sb,
528                             "Cannot read inode bitmap - "
529                             "block_group = %u, inode_bitmap = %llu",
530                             block_group, bitmap_blk);
531 @@ -153,7 +153,7 @@ ext4_read_inode_bitmap(struct super_bloc
532         set_bitmap_uptodate(bh);
533         if (bh_submit_read(bh) < 0) {
534                 put_bh(bh);
535 -               ext4_error(sb, __func__,
536 +               ext4_error(sb,
537                             "Cannot read inode bitmap - "
538                             "block_group = %u, inode_bitmap = %llu",
539                             block_group, bitmap_blk);
540 @@ -230,8 +230,7 @@ void ext4_free_inode(handle_t *handle, s
541  
542         es = EXT4_SB(sb)->s_es;
543         if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
544 -               ext4_error(sb, "ext4_free_inode",
545 -                          "reserved or nonexistent inode %lu", ino);
546 +               ext4_error(sb, "reserved or nonexistent inode %lu", ino);
547                 goto error_return;
548         }
549         block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
550 @@ -286,11 +285,10 @@ out:
551                         fatal = err;
552                 sb->s_dirt = 1;
553         } else
554 -               ext4_error(sb, "ext4_free_inode",
555 -                          "bit already cleared for inode %lu", ino);
556 +               ext4_error(sb, "bit already cleared for inode %lu", ino);
557  
558  error_return:
559 -       brelse(bitmap_bh);
560 +       brelse(bitmap_bh); 
561         ext4_std_error(sb, fatal);
562  }
563  
564 @@ -730,7 +728,7 @@ static int ext4_claim_inode(struct super
565         if ((group == 0 && ino < EXT4_FIRST_INO(sb)) ||
566                         ino > EXT4_INODES_PER_GROUP(sb)) {
567                 ext4_unlock_group(sb, group);
568 -               ext4_error(sb, __func__,
569 +               ext4_error(sb,
570                            "reserved inode or inode > inodes count - "
571                            "block_group = %u, inode=%lu", group,
572                            ino + group * EXT4_INODES_PER_GROUP(sb));
573 @@ -1094,7 +1092,7 @@ struct inode *ext4_orphan_get(struct sup
574  
575         /* Error cases - e2fsck has already cleaned up for us */
576         if (ino > max_ino) {
577 -               ext4_warning(sb, __func__,
578 +               ext4_warning(sb,
579                              "bad orphan ino %lu!  e2fsck was run?", ino);
580                 goto error;
581         }
582 @@ -1103,7 +1101,7 @@ struct inode *ext4_orphan_get(struct sup
583         bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
584         bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
585         if (!bitmap_bh) {
586 -               ext4_warning(sb, __func__,
587 +               ext4_warning(sb,
588                              "inode bitmap error for orphan %lu", ino);
589                 goto error;
590         }
591 @@ -1136,7 +1134,7 @@ iget_failed:
592         err = PTR_ERR(inode);
593         inode = NULL;
594  bad_orphan:
595 -       ext4_warning(sb, __func__,
596 +       ext4_warning(sb,
597                      "bad orphan inode %lu!  e2fsck was run?", ino);
598         printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
599                bit, (unsigned long long)bitmap_bh->b_blocknr,
600 diff -urpN linux-stage.orig/fs/ext4/inode.c linux-stage/fs/ext4/inode.c
601 --- linux-stage.orig/fs/ext4/inode.c    2012-07-02 12:07:23.000000000 -0400
602 +++ linux-stage/fs/ext4/inode.c 2012-07-02 12:07:57.000000000 -0400
603 @@ -246,7 +246,7 @@ void ext4_delete_inode(struct inode *ino
604         inode->i_size = 0;
605         err = ext4_mark_inode_dirty(handle, inode);
606         if (err) {
607 -               ext4_warning(inode->i_sb, __func__,
608 +               ext4_warning(inode->i_sb,
609                              "couldn't mark inode dirty (err %d)", err);
610                 goto stop_handle;
611         }
612 @@ -264,7 +264,7 @@ void ext4_delete_inode(struct inode *ino
613                 if (err > 0)
614                         err = ext4_journal_restart(handle, 3);
615                 if (err != 0) {
616 -                       ext4_warning(inode->i_sb, __func__,
617 +                       ext4_warning(inode->i_sb,
618                                      "couldn't extend journal (err %d)", err);
619                 stop_handle:
620                         ext4_journal_stop(handle);
621 @@ -375,8 +375,7 @@ static int ext4_block_to_path(struct ino
622                 offsets[n++] = i_block & (ptrs - 1);
623                 final = ptrs;
624         } else {
625 -               ext4_warning(inode->i_sb, "ext4_block_to_path",
626 -                            "block %lu > max in inode %lu",
627 +               ext4_warning(inode->i_sb, "block %lu > max in inode %lu",
628                              i_block + direct_blocks +
629                              indirect_blocks + double_blocks, inode->i_ino);
630         }
631 @@ -396,7 +395,7 @@ static int __ext4_check_blockref(const c
632                 if (blk &&
633                     unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb),
634                                                     blk, 1))) {
635 -                       ext4_error(inode->i_sb, function,
636 +                       ext4_error(inode->i_sb,
637                                    "invalid block reference %u "
638                                    "in inode #%lu", blk, inode->i_ino);
639                         return -EIO;
640 @@ -1167,7 +1166,7 @@ static int check_block_validity(struct i
641                                 sector_t logical, sector_t phys, int len)
642  {
643         if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), phys, len)) {
644 -               ext4_error(inode->i_sb, msg,
645 +               ext4_error(inode->i_sb,
646                            "inode #%lu logical block %llu mapped to %llu "
647                            "(size %d)", inode->i_ino,
648                            (unsigned long long) logical,
649 @@ -4316,7 +4315,7 @@ static void ext4_free_data(handle_t *han
650                 if ((EXT4_JOURNAL(inode) == NULL) || bh2jh(this_bh))
651                         ext4_handle_dirty_metadata(handle, inode, this_bh);
652                 else
653 -                       ext4_error(inode->i_sb, __func__,
654 +                       ext4_error(inode->i_sb,
655                                    "circular indirect block detected, "
656                                    "inode=%lu, block=%llu",
657                                    inode->i_ino,
658 @@ -4364,7 +4363,7 @@ static void ext4_free_branches(handle_t 
659                          * (should be rare).
660                          */
661                         if (!bh) {
662 -                               ext4_error(inode->i_sb, "ext4_free_branches",
663 +                               ext4_error(inode->i_sb,
664                                            "Read failure, inode=%lu, block=%llu",
665                                            inode->i_ino, nr);
666                                 continue;
667 @@ -4680,9 +4679,8 @@ static int __ext4_get_inode_loc(struct i
668  
669         bh = sb_getblk(sb, block);
670         if (!bh) {
671 -               ext4_error(sb, "ext4_get_inode_loc", "unable to read "
672 -                          "inode block - inode=%lu, block=%llu",
673 -                          inode->i_ino, block);
674 +               ext4_error(sb, "unable to read inode block - "
675 +                          "inode=%lu, block=%llu", inode->i_ino, block);
676                 return -EIO;
677         }
678         if (!buffer_uptodate(bh)) {
679 @@ -4780,7 +4778,7 @@ make_io:
680                 submit_bh(READ_META, bh);
681                 wait_on_buffer(bh);
682                 if (!buffer_uptodate(bh)) {
683 -                       ext4_error(sb, __func__,
684 +                       ext4_error(sb,
685                                    "unable to read inode block - inode=%lu, "
686                                    "block=%llu", inode->i_ino, block);
687                         brelse(bh);
688 @@ -4999,7 +4997,7 @@ struct inode *ext4_iget(struct super_blo
689         ret = 0;
690         if (ei->i_file_acl &&
691             !ext4_data_block_valid(EXT4_SB(sb), ei->i_file_acl, 1)) {
692 -               ext4_error(sb, __func__,
693 +               ext4_error(sb,
694                            "bad extended attribute block %llu in inode #%lu",
695                            ei->i_file_acl, inode->i_ino);
696                 ret = -EIO;
697 @@ -5046,7 +5044,7 @@ struct inode *ext4_iget(struct super_blo
698                            new_decode_dev(le32_to_cpu(raw_inode->i_block[1])));
699         } else {
700                 ret = -EIO;
701 -               ext4_error(inode->i_sb, __func__,
702 +               ext4_error(inode->i_sb,
703                            "bogus i_mode (%o) for inode=%lu",
704                            inode->i_mode, inode->i_ino);
705                 goto bad_inode;
706 @@ -5286,7 +5284,7 @@ int ext4_write_inode(struct inode *inode
707                 if (wait)
708                         sync_dirty_buffer(iloc.bh);
709                 if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
710 -                       ext4_error(inode->i_sb, __func__,
711 +                       ext4_error(inode->i_sb,
712                                    "IO error syncing inode, "
713                                    "inode=%lu, block=%llu",
714                                    inode->i_ino,
715 @@ -5707,7 +5705,7 @@ int ext4_mark_inode_dirty(handle_t *hand
716                                                      EXT4_STATE_NO_EXPAND);
717                                 if (mnt_count !=
718                                         le16_to_cpu(sbi->s_es->s_mnt_count)) {
719 -                                       ext4_warning(inode->i_sb, __func__,
720 +                                       ext4_warning(inode->i_sb,
721                                         "Unable to expand inode %lu. Delete"
722                                         " some EAs or run e2fsck.",
723                                         inode->i_ino);
724 diff -urpN linux-stage.orig/fs/ext4/mballoc.c linux-stage/fs/ext4/mballoc.c
725 --- linux-stage.orig/fs/ext4/mballoc.c  2012-07-02 12:07:23.000000000 -0400
726 +++ linux-stage/fs/ext4/mballoc.c       2012-07-02 12:07:57.000000000 -0400
727 @@ -862,8 +862,6 @@ static int ext4_mb_init_cache(struct pag
728  
729         err = 0;
730         first_block = page->index * blocks_per_page;
731 -       /* init the page  */
732 -       memset(page_address(page), 0xff, PAGE_CACHE_SIZE);
733         for (i = 0; i < blocks_per_page; i++) {
734                 int group;
735                 struct ext4_group_info *grinfo;
736 @@ -899,6 +897,8 @@ static int ext4_mb_init_cache(struct pag
737                          * incore got set to the group block bitmap below
738                          */
739                         ext4_lock_group(sb, group);
740 +                       /* init the page  */
741 +                       memset(data, 0xff, blocksize);
742                         ext4_mb_generate_buddy(sb, data, incore, group);
743                         ext4_unlock_group(sb, group);
744                         incore = NULL;
745 @@ -1862,7 +1862,6 @@ void ext4_mb_scan_aligned(struct ext4_al
746         }
747  }
748  
749 -/* This is now called BEFORE we load the buddy bitmap. */
750  static int ext4_mb_good_group(struct ext4_allocation_context *ac,
751                                 ext4_group_t group, int cr)
752  {
753 @@ -2162,6 +2161,11 @@ static void *ext4_mb_seq_groups_next(str
754         return (void *) ((unsigned long) group);
755  }
756  
757 +static inline void ext4_mb_release_desc(struct ext4_buddy *e4b)
758 +{
759 +       ext4_mb_unload_buddy(e4b);
760 +}
761 +
762  static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
763  {
764         struct super_block *sb = seq->private;
765 @@ -2193,7 +2197,7 @@ static int ext4_mb_seq_groups_show(struc
766         ext4_lock_group(sb, group);
767         memcpy(&sg, ext4_get_group_info(sb, group), i);
768         ext4_unlock_group(sb, group);
769 -       ext4_mb_unload_buddy(&e4b);
770 +       ext4_mb_release_desc(&e4b);
771  
772         seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free,
773                         sg.info.bb_fragments, sg.info.bb_first_free);
774 @@ -2562,6 +2566,17 @@ int ext4_mb_release(struct super_block *
775         return 0;
776  }
777  
778 +static inline int ext4_issue_discard(struct super_block *sb,
779 +               ext4_group_t block_group, ext4_grpblk_t block, int count)
780 +{
781 +       ext4_fsblk_t discard_block;
782 +
783 +       discard_block = block + ext4_group_first_block_no(sb, block_group);
784 +       trace_ext4_discard_blocks(sb,
785 +                       (unsigned long long) discard_block, count);
786 +       return sb_issue_discard(sb, discard_block, count);
787 +}
788 +
789  /*
790   * This function is called by the jbd2 layer once the commit has finished,
791   * so we know we can free the blocks that were released with that commit.
792 @@ -2581,22 +2596,9 @@ static void release_blocks_on_commit(jou
793                 mb_debug(1, "gonna free %u blocks in group %u (0x%p):",
794                          entry->count, entry->group, entry);
795  
796 -               if (test_opt(sb, DISCARD)) {
797 -                       int ret;
798 -                       ext4_fsblk_t discard_block;
799 -
800 -                       discard_block = entry->start_blk +
801 -                               ext4_group_first_block_no(sb, entry->group);
802 -                       trace_ext4_discard_blocks(sb,
803 -                                       (unsigned long long)discard_block,
804 -                                       entry->count);
805 -                       ret = sb_issue_discard(sb, discard_block, entry->count);
806 -                       if (ret == EOPNOTSUPP) {
807 -                               ext4_warning(sb, __func__,
808 -                                       "discard not supported, disabling");
809 -                               clear_opt(EXT4_SB(sb)->s_mount_opt, DISCARD);
810 -                       }
811 -               }
812 +               if (test_opt(sb, DISCARD))
813 +                       ext4_issue_discard(sb, entry->group,
814 +                                          entry->start_blk, entry->count);
815  
816                 err = ext4_mb_load_buddy(sb, entry->group, &e4b);
817                 /* we expect to find existing buddy because it's pinned */
818 @@ -2611,6 +2613,15 @@ static void release_blocks_on_commit(jou
819                 rb_erase(&entry->node, &(db->bb_free_root));
820                 mb_free_blocks(NULL, &e4b, entry->start_blk, entry->count);
821  
822 +               /*
823 +                * Clear the trimmed flag for the group so that the next
824 +                * ext4_trim_fs can trim it.
825 +                * If the volume is mounted with -o discard, online discard
826 +                * is supported and the free blocks will be trimmed online.
827 +                */
828 +               if (!test_opt(sb, DISCARD))
829 +                       EXT4_MB_GRP_CLEAR_TRIMMED(db);
830 +
831                 if (!db->bb_free_root.rb_node) {
832                         /* No more items in the per group rb tree
833                          * balance refcounts from ext4_mb_free_metadata()
834 @@ -2620,7 +2631,7 @@ static void release_blocks_on_commit(jou
835                 }
836                 ext4_unlock_group(sb, entry->group);
837                 kmem_cache_free(ext4_free_ext_cachep, entry);
838 -               ext4_mb_unload_buddy(&e4b);
839 +               ext4_mb_release_desc(&e4b);
840         }
841  
842         mb_debug(1, "freed %u blocks in %u structures\n", count, count2);
843 @@ -2757,7 +2768,7 @@ ext4_mb_mark_diskspace_used(struct ext4_
844  
845         len = ac->ac_b_ex.fe_len;
846         if (!ext4_data_block_valid(sbi, block, len)) {
847 -               ext4_error(sb, __func__,
848 +               ext4_error(sb,
849                            "Allocating blocks %llu-%llu which overlap "
850                            "fs metadata\n", block, block+len);
851                 /* File system mounted not to panic on error
852 @@ -3671,14 +3682,14 @@ ext4_mb_discard_group_preallocations(str
853  
854         bitmap_bh = ext4_read_block_bitmap(sb, group);
855         if (bitmap_bh == NULL) {
856 -               ext4_error(sb, __func__, "Error in reading block "
857 +               ext4_error(sb, "Error in reading block "
858                                 "bitmap for %u", group);
859                 return 0;
860         }
861  
862         err = ext4_mb_load_buddy(sb, group, &e4b);
863         if (err) {
864 -               ext4_error(sb, __func__, "Error in loading buddy "
865 +               ext4_error(sb, "Error in loading buddy "
866                                 "information for %u", group);
867                 put_bh(bitmap_bh);
868                 return 0;
869 @@ -3852,14 +3863,14 @@ repeat:
870  
871                 err = ext4_mb_load_buddy(sb, group, &e4b);
872                 if (err) {
873 -                       ext4_error(sb, __func__, "Error in loading buddy "
874 -                                       "information for %u", group);
875 +                       ext4_error(sb, "Error in loading buddy information for %u",
876 +                                       group);
877                         continue;
878                 }
879  
880                 bitmap_bh = ext4_read_block_bitmap(sb, group);
881                 if (bitmap_bh == NULL) {
882 -                       ext4_error(sb, __func__, "Error in reading block "
883 +                       ext4_error(sb, "Error in reading block "
884                                         "bitmap for %u", group);
885                         ext4_mb_unload_buddy(&e4b);
886                         continue;
887 @@ -4125,7 +4136,7 @@ ext4_mb_discard_lg_preallocations(struct
888  
889                 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL);
890                 if (ext4_mb_load_buddy(sb, group, &e4b)) {
891 -                       ext4_error(sb, __func__, "Error in loading buddy "
892 +                       ext4_error(sb, "Error in loading buddy "
893                                         "information for %u", group);
894                         continue;
895                 }
896 @@ -4516,7 +4527,7 @@ void ext4_mb_free_blocks(handle_t *handl
897         if (block < le32_to_cpu(es->s_first_data_block) ||
898             block + count < block ||
899             block + count > ext4_blocks_count(es)) {
900 -               ext4_error(sb, __func__,
901 +               ext4_error(sb,
902                             "Freeing blocks not in datazone - "
903                             "block = %llu, count = %lu", block, count);
904                 goto error_return;
905 @@ -4561,7 +4572,7 @@ do_more:
906             in_range(block + count - 1, ext4_inode_table(sb, gdp),
907                       EXT4_SB(sb)->s_itb_per_group)) {
908  
909 -               ext4_error(sb, __func__,
910 +               ext4_error(sb,
911                            "Freeing blocks in system zone - "
912                            "Block = %llu, count = %lu", block, count);
913                 /* err = 0. ext4_std_error should be a no op */
914 diff -urpN linux-stage.orig/fs/ext4/move_extent.c linux-stage/fs/ext4/move_extent.c
915 --- linux-stage.orig/fs/ext4/move_extent.c      2012-07-02 12:07:23.000000000 -0400
916 +++ linux-stage/fs/ext4/move_extent.c   2012-07-02 12:07:57.000000000 -0400
917 @@ -152,12 +152,12 @@ mext_check_null_inode(struct inode *inod
918         int ret = 0;
919  
920         if (inode1 == NULL) {
921 -               ext4_error(inode2->i_sb, function,
922 +               ext4_error(inode2->i_sb,
923                         "Both inodes should not be NULL: "
924                         "inode1 NULL inode2 %lu", inode2->i_ino);
925                 ret = -EIO;
926         } else if (inode2 == NULL) {
927 -               ext4_error(inode1->i_sb, function,
928 +               ext4_error(inode1->i_sb,
929                         "Both inodes should not be NULL: "
930                         "inode1 %lu inode2 NULL", inode1->i_ino);
931                 ret = -EIO;
932 @@ -483,7 +483,7 @@ mext_leaf_block(handle_t *handle, struct
933  
934         o_start = o_end = oext = orig_path[depth].p_ext;
935         oext_alen = ext4_ext_get_actual_len(oext);
936 -       start_ext.ee_len = end_ext.ee_len = 0;
937 +       start_ext.ee_block = start_ext.ee_len = end_ext.ee_len = 0;
938  
939         new_ext.ee_block = cpu_to_le32(*from);
940         ext4_ext_store_pblock(&new_ext, ext_pblock(dext));
941 @@ -528,7 +528,7 @@ mext_leaf_block(handle_t *handle, struct
942          * new_ext       |-------|
943          */
944         if (le32_to_cpu(oext->ee_block) + oext_alen - 1 < new_ext_end) {
945 -               ext4_error(orig_inode->i_sb, __func__,
946 +               ext4_error(orig_inode->i_sb,
947                         "new_ext_end(%u) should be less than or equal to "
948                         "oext->ee_block(%u) + oext_alen(%d) - 1",
949                         new_ext_end, le32_to_cpu(oext->ee_block),
950 @@ -691,12 +691,12 @@ mext_replace_branches(handle_t *handle, 
951         while (1) {
952                 /* The extent for donor must be found. */
953                 if (!dext) {
954 -                       ext4_error(donor_inode->i_sb, __func__,
955 +                       ext4_error(donor_inode->i_sb,
956                                    "The extent for donor must be found");
957                         *err = -EIO;
958                         goto out;
959                 } else if (donor_off != le32_to_cpu(tmp_dext.ee_block)) {
960 -                       ext4_error(donor_inode->i_sb, __func__,
961 +                       ext4_error(donor_inode->i_sb,
962                                 "Donor offset(%u) and the first block of donor "
963                                 "extent(%u) should be equal",
964                                 donor_off,
965 @@ -1001,12 +1001,12 @@ mext_check_arguments(struct inode *orig_
966                 return -EINVAL;
967         }
968  
969 -       if ((orig_start > EXT_MAX_BLOCK) ||
970 -           (donor_start > EXT_MAX_BLOCK) ||
971 -           (*len > EXT_MAX_BLOCK) ||
972 -           (orig_start + *len > EXT_MAX_BLOCK))  {
973 +       if ((orig_start > EXT_MAX_BLOCKS) ||
974 +           (donor_start > EXT_MAX_BLOCKS) ||
975 +           (*len > EXT_MAX_BLOCKS) ||
976 +           (orig_start + *len > EXT_MAX_BLOCKS))  {
977                 ext4_debug("ext4 move extent: Can't handle over [%u] blocks "
978 -                       "[ino:orig %lu, donor %lu]\n", EXT_MAX_BLOCK,
979 +                       "[ino:orig %lu, donor %lu]\n", EXT_MAX_BLOCKS,
980                         orig_inode->i_ino, donor_inode->i_ino);
981                 return -EINVAL;
982         }
983 @@ -1356,7 +1356,7 @@ ext4_move_extents(struct file *o_filp, s
984                         if (ret1 < 0)
985                                 break;
986                         if (*moved_len > len) {
987 -                               ext4_error(orig_inode->i_sb, __func__,
988 +                               ext4_error(orig_inode->i_sb,
989                                         "We replaced blocks too much! "
990                                         "sum of replaced: %llu requested: %llu",
991                                         *moved_len, len);
992 diff -urpN linux-stage.orig/fs/ext4/namei.c linux-stage/fs/ext4/namei.c
993 --- linux-stage.orig/fs/ext4/namei.c    2012-07-02 12:07:23.000000000 -0400
994 +++ linux-stage/fs/ext4/namei.c 2012-07-02 12:07:57.000000000 -0400
995 @@ -394,8 +394,7 @@ dx_probe(const struct qstr *d_name, stru
996         if (root->info.hash_version != DX_HASH_TEA &&
997             root->info.hash_version != DX_HASH_HALF_MD4 &&
998             root->info.hash_version != DX_HASH_LEGACY) {
999 -               ext4_warning(dir->i_sb, __func__,
1000 -                            "Unrecognised inode hash code %d",
1001 +               ext4_warning(dir->i_sb, "Unrecognised inode hash code %d",
1002                              root->info.hash_version);
1003                 brelse(bh);
1004                 *err = ERR_BAD_DX_DIR;
1005 @@ -410,8 +409,7 @@ dx_probe(const struct qstr *d_name, stru
1006         hash = hinfo->hash;
1007  
1008         if (root->info.unused_flags & 1) {
1009 -               ext4_warning(dir->i_sb, __func__,
1010 -                            "Unimplemented inode hash flags: %#06x",
1011 +               ext4_warning(dir->i_sb, "Unimplemented inode hash flags: %#06x",
1012                              root->info.unused_flags);
1013                 brelse(bh);
1014                 *err = ERR_BAD_DX_DIR;
1015 @@ -419,8 +417,7 @@ dx_probe(const struct qstr *d_name, stru
1016         }
1017  
1018         if ((indirect = root->info.indirect_levels) > 1) {
1019 -               ext4_warning(dir->i_sb, __func__,
1020 -                            "Unimplemented inode hash depth: %#06x",
1021 +               ext4_warning(dir->i_sb, "Unimplemented inode hash depth: %#06x",
1022                              root->info.indirect_levels);
1023                 brelse(bh);
1024                 *err = ERR_BAD_DX_DIR;
1025 @@ -432,8 +429,7 @@ dx_probe(const struct qstr *d_name, stru
1026  
1027         if (dx_get_limit(entries) != dx_root_limit(dir,
1028                                                    root->info.info_length)) {
1029 -               ext4_warning(dir->i_sb, __func__,
1030 -                            "dx entry: limit != root limit");
1031 +               ext4_warning(dir->i_sb, "dx entry: limit != root limit");
1032                 brelse(bh);
1033                 *err = ERR_BAD_DX_DIR;
1034                 goto fail;
1035 @@ -444,7 +440,7 @@ dx_probe(const struct qstr *d_name, stru
1036         {
1037                 count = dx_get_count(entries);
1038                 if (!count || count > dx_get_limit(entries)) {
1039 -                       ext4_warning(dir->i_sb, __func__,
1040 +                       ext4_warning(dir->i_sb,
1041                                      "dx entry: no count or count > limit");
1042                         brelse(bh);
1043                         *err = ERR_BAD_DX_DIR;
1044 @@ -489,7 +485,7 @@ dx_probe(const struct qstr *d_name, stru
1045                         goto fail2;
1046                 at = entries = ((struct dx_node *) bh->b_data)->entries;
1047                 if (dx_get_limit(entries) != dx_node_limit (dir)) {
1048 -                       ext4_warning(dir->i_sb, __func__,
1049 +                       ext4_warning(dir->i_sb,
1050                                      "dx entry: limit != node limit");
1051                         brelse(bh);
1052                         *err = ERR_BAD_DX_DIR;
1053 @@ -505,7 +501,7 @@ fail2:
1054         }
1055  fail:
1056         if (*err == ERR_BAD_DX_DIR)
1057 -               ext4_warning(dir->i_sb, __func__,
1058 +               ext4_warning(dir->i_sb,
1059                              "Corrupt dir inode %ld, running e2fsck is "
1060                              "recommended.", dir->i_ino);
1061         return NULL;
1062 @@ -969,7 +965,7 @@ restart:
1063                 wait_on_buffer(bh);
1064                 if (!buffer_uptodate(bh)) {
1065                         /* read error, skip block & hope for the best */
1066 -                       ext4_error(sb, __func__, "reading directory #%lu "
1067 +                       ext4_error(sb, "reading directory #%lu "
1068                                    "offset %lu", dir->i_ino,
1069                                    (unsigned long)block);
1070                         brelse(bh);
1071 @@ -1012,8 +1008,9 @@ cleanup_and_exit:
1072  static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct qstr *d_name,
1073                        struct ext4_dir_entry_2 **res_dir, int *err)
1074  {
1075 -       struct super_block * sb = dir->i_sb;
1076 +       struct super_block * sb;
1077         struct dx_hash_info     hinfo;
1078 +       u32 hash;
1079         struct dx_frame frames[2], *frame;
1080         struct ext4_dir_entry_2 *de, *top;
1081         struct buffer_head *bh;
1082 @@ -1022,8 +1019,18 @@ static struct buffer_head * ext4_dx_find
1083         int namelen = d_name->len;
1084         const u8 *name = d_name->name;
1085  
1086 -       if (!(frame = dx_probe(d_name, dir, &hinfo, frames, err)))
1087 -               return NULL;
1088 +       sb = dir->i_sb;
1089 +       /* NFS may look up ".." - look at dx_root directory block */
1090 +       if (namelen > 2 || name[0] != '.'||(name[1] != '.' && name[1] != '\0')){
1091 +               if (!(frame = dx_probe(d_name, dir, &hinfo, frames, err)))
1092 +                       return NULL;
1093 +       } else {
1094 +               frame = frames;
1095 +               frame->bh = NULL;                       /* for dx_release() */
1096 +               frame->at = (struct dx_entry *)frames;  /* hack for zero entry*/
1097 +               dx_set_block(frame->at, 0);             /* dx_root block is 0 */
1098 +       }
1099 +       hash = hinfo.hash;
1100         do {
1101                 block = dx_get_block(frame->at);
1102                 if (!(bh = ext4_bread (NULL,dir, block, 0, err)))
1103 @@ -1049,10 +1056,10 @@ static struct buffer_head * ext4_dx_find
1104                 }
1105                 brelse(bh);
1106                 /* Check to see if we should continue to search */
1107 -               retval = ext4_htree_next_block(dir, hinfo.hash, frame,
1108 +               retval = ext4_htree_next_block(dir, hash, frame,
1109                                                frames, NULL);
1110                 if (retval < 0) {
1111 -                       ext4_warning(sb, __func__,
1112 +                       ext4_warning(sb,
1113                              "error reading index page in directory #%lu",
1114                              dir->i_ino);
1115                         *err = retval;
1116 @@ -1082,14 +1089,13 @@ static struct dentry *ext4_lookup(struct
1117                 __u32 ino = le32_to_cpu(de->inode);
1118                 brelse(bh);
1119                 if (!ext4_valid_inum(dir->i_sb, ino)) {
1120 -                       ext4_error(dir->i_sb, "ext4_lookup",
1121 -                                  "bad inode number: %u", ino);
1122 +                       ext4_error(dir->i_sb, "bad inode number: %u", ino);
1123                         return ERR_PTR(-EIO);
1124                 }
1125                 inode = ext4_iget(dir->i_sb, ino);
1126                 if (unlikely(IS_ERR(inode))) {
1127                         if (PTR_ERR(inode) == -ESTALE) {
1128 -                               ext4_error(dir->i_sb, __func__,
1129 +                               ext4_error(dir->i_sb,
1130                                                 "deleted inode referenced: %u",
1131                                                 ino);
1132                                 return ERR_PTR(-EIO);
1133 @@ -1121,7 +1127,7 @@ struct dentry *ext4_get_parent(struct de
1134         brelse(bh);
1135  
1136         if (!ext4_valid_inum(child->d_inode->i_sb, ino)) {
1137 -               ext4_error(child->d_inode->i_sb, "ext4_get_parent",
1138 +               ext4_error(child->d_inode->i_sb,
1139                            "bad inode number: %u", ino);
1140                 return ERR_PTR(-EIO);
1141         }
1142 @@ -1421,7 +1427,7 @@ static int make_indexed_dir(handle_t *ha
1143         de = (struct ext4_dir_entry_2 *)((char *)fde +
1144                 ext4_rec_len_from_disk(fde->rec_len, blocksize));
1145         if ((char *) de >= (((char *) root) + blocksize)) {
1146 -               ext4_error(dir->i_sb, __func__,
1147 +               ext4_error(dir->i_sb,
1148                            "invalid rec_len for '..' in inode %lu",
1149                            dir->i_ino);
1150                 brelse(bh);
1151 @@ -1468,10 +1474,22 @@ static int make_indexed_dir(handle_t *ha
1152         frame->at = entries;
1153         frame->bh = bh;
1154         bh = bh2;
1155 +
1156 +       ext4_handle_dirty_metadata(handle, dir, frame->bh);
1157 +       ext4_handle_dirty_metadata(handle, dir, bh);
1158 +
1159         de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1160 -       dx_release (frames);
1161 -       if (!(de))
1162 +       if (!de) {
1163 +               /*
1164 +                * Even if the block split failed, we have to properly write
1165 +                * out all the changes we did so far. Otherwise we can end up
1166 +                * with corrupted filesystem.
1167 +                */
1168 +               ext4_mark_inode_dirty(handle, dir);
1169 +               dx_release(frames);
1170                 return retval;
1171 +       }
1172 +       dx_release(frames);
1173  
1174         retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
1175         brelse(bh);
1176 @@ -1588,8 +1606,7 @@ static int ext4_dx_add_entry(handle_t *h
1177  
1178                 if (levels && (dx_get_count(frames->entries) ==
1179                                dx_get_limit(frames->entries))) {
1180 -                       ext4_warning(sb, __func__,
1181 -                                    "Directory index full!");
1182 +                       ext4_warning(sb, "Directory index full!");
1183                         err = -ENOSPC;
1184                         goto cleanup;
1185                 }
1186 @@ -1943,11 +1960,11 @@ static int empty_dir(struct inode *inode
1187         if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
1188             !(bh = ext4_bread(NULL, inode, 0, 0, &err))) {
1189                 if (err)
1190 -                       ext4_error(inode->i_sb, __func__,
1191 +                       ext4_error(inode->i_sb,
1192                                    "error %d reading directory #%lu offset 0",
1193                                    err, inode->i_ino);
1194                 else
1195 -                       ext4_warning(inode->i_sb, __func__,
1196 +                       ext4_warning(inode->i_sb,
1197                                      "bad directory (dir #%lu) - no data block",
1198                                      inode->i_ino);
1199                 return 1;
1200 @@ -1958,7 +1975,7 @@ static int empty_dir(struct inode *inode
1201                         !le32_to_cpu(de1->inode) ||
1202                         strcmp(".", de->name) ||
1203                         strcmp("..", de1->name)) {
1204 -               ext4_warning(inode->i_sb, "empty_dir",
1205 +               ext4_warning(inode->i_sb,
1206                              "bad directory (dir #%lu) - no `.' or `..'",
1207                              inode->i_ino);
1208                 brelse(bh);
1209 @@ -1976,7 +1993,7 @@ static int empty_dir(struct inode *inode
1210                                 offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err);
1211                         if (!bh) {
1212                                 if (err)
1213 -                                       ext4_error(sb, __func__,
1214 +                                       ext4_error(sb,
1215                                                    "error %d reading directory"
1216                                                    " #%lu offset %u",
1217                                                    err, inode->i_ino, offset);
1218 @@ -2198,7 +2215,7 @@ static int ext4_rmdir(struct inode *dir,
1219         if (retval)
1220                 goto end_rmdir;
1221         if (!EXT4_DIR_LINK_EMPTY(inode))
1222 -               ext4_warning(inode->i_sb, "ext4_rmdir",
1223 +               ext4_warning(inode->i_sb,
1224                              "empty directory has too many links (%d)",
1225                              inode->i_nlink);
1226         inode->i_version++;
1227 @@ -2250,7 +2267,7 @@ static int ext4_unlink(struct inode *dir
1228                 goto end_unlink;
1229  
1230         if (!inode->i_nlink) {
1231 -               ext4_warning(inode->i_sb, "ext4_unlink",
1232 +               ext4_warning(inode->i_sb,
1233                              "Deleting nonexistent file (%lu), %d",
1234                              inode->i_ino, inode->i_nlink);
1235                 inode->i_nlink = 1;
1236 @@ -2497,7 +2514,7 @@ static int ext4_rename(struct inode *old
1237                 }
1238         }
1239         if (retval) {
1240 -               ext4_warning(old_dir->i_sb, "ext4_rename",
1241 +               ext4_warning(old_dir->i_sb,
1242                                 "Deleting old file (%lu), %d, error=%d",
1243                                 old_dir->i_ino, old_dir->i_nlink, retval);
1244         }
1245 diff -urpN linux-stage.orig/fs/ext4/resize.c linux-stage/fs/ext4/resize.c
1246 --- linux-stage.orig/fs/ext4/resize.c   2012-07-02 12:07:23.000000000 -0400
1247 +++ linux-stage/fs/ext4/resize.c        2012-07-02 12:07:57.000000000 -0400
1248 @@ -48,63 +48,63 @@ static int verify_group_input(struct sup
1249  
1250         ext4_get_group_no_and_offset(sb, start, NULL, &offset);
1251         if (group != sbi->s_groups_count)
1252 -               ext4_warning(sb, __func__,
1253 +               ext4_warning(sb,
1254                              "Cannot add at group %u (only %u groups)",
1255                              input->group, sbi->s_groups_count);
1256         else if (offset != 0)
1257 -                       ext4_warning(sb, __func__, "Last group not full");
1258 +                       ext4_warning(sb, "Last group not full");
1259         else if (input->reserved_blocks > input->blocks_count / 5)
1260 -               ext4_warning(sb, __func__, "Reserved blocks too high (%u)",
1261 +               ext4_warning(sb, "Reserved blocks too high (%u)",
1262                              input->reserved_blocks);
1263         else if (free_blocks_count < 0)
1264 -               ext4_warning(sb, __func__, "Bad blocks count %u",
1265 +               ext4_warning(sb, "Bad blocks count %u",
1266                              input->blocks_count);
1267         else if (!(bh = sb_bread(sb, end - 1)))
1268 -               ext4_warning(sb, __func__,
1269 +               ext4_warning(sb,
1270                              "Cannot read last block (%llu)",
1271                              end - 1);
1272         else if (outside(input->block_bitmap, start, end))
1273 -               ext4_warning(sb, __func__,
1274 +               ext4_warning(sb,
1275                              "Block bitmap not in group (block %llu)",
1276                              (unsigned long long)input->block_bitmap);
1277         else if (outside(input->inode_bitmap, start, end))
1278 -               ext4_warning(sb, __func__,
1279 +               ext4_warning(sb,
1280                              "Inode bitmap not in group (block %llu)",
1281                              (unsigned long long)input->inode_bitmap);
1282         else if (outside(input->inode_table, start, end) ||
1283                  outside(itend - 1, start, end))
1284 -               ext4_warning(sb, __func__,
1285 +               ext4_warning(sb,
1286                              "Inode table not in group (blocks %llu-%llu)",
1287                              (unsigned long long)input->inode_table, itend - 1);
1288         else if (input->inode_bitmap == input->block_bitmap)
1289 -               ext4_warning(sb, __func__,
1290 +               ext4_warning(sb,
1291                              "Block bitmap same as inode bitmap (%llu)",
1292                              (unsigned long long)input->block_bitmap);
1293         else if (inside(input->block_bitmap, input->inode_table, itend))
1294 -               ext4_warning(sb, __func__,
1295 +               ext4_warning(sb,
1296                              "Block bitmap (%llu) in inode table (%llu-%llu)",
1297                              (unsigned long long)input->block_bitmap,
1298                              (unsigned long long)input->inode_table, itend - 1);
1299         else if (inside(input->inode_bitmap, input->inode_table, itend))
1300 -               ext4_warning(sb, __func__,
1301 +               ext4_warning(sb,
1302                              "Inode bitmap (%llu) in inode table (%llu-%llu)",
1303                              (unsigned long long)input->inode_bitmap,
1304                              (unsigned long long)input->inode_table, itend - 1);
1305         else if (inside(input->block_bitmap, start, metaend))
1306 -               ext4_warning(sb, __func__,
1307 +               ext4_warning(sb,
1308                              "Block bitmap (%llu) in GDT table"
1309                              " (%llu-%llu)",
1310                              (unsigned long long)input->block_bitmap,
1311                              start, metaend - 1);
1312         else if (inside(input->inode_bitmap, start, metaend))
1313 -               ext4_warning(sb, __func__,
1314 +               ext4_warning(sb,
1315                              "Inode bitmap (%llu) in GDT table"
1316                              " (%llu-%llu)",
1317                              (unsigned long long)input->inode_bitmap,
1318                              start, metaend - 1);
1319         else if (inside(input->inode_table, start, metaend) ||
1320                  inside(itend - 1, start, metaend))
1321 -               ext4_warning(sb, __func__,
1322 +               ext4_warning(sb,
1323                              "Inode table (%llu-%llu) overlaps"
1324                              "GDT table (%llu-%llu)",
1325                              (unsigned long long)input->inode_table,
1326 @@ -364,7 +364,7 @@ static int verify_reserved_gdb(struct su
1327         while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) {
1328                 if (le32_to_cpu(*p++) !=
1329                     grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){
1330 -                       ext4_warning(sb, __func__,
1331 +                       ext4_warning(sb,
1332                                      "reserved GDT %llu"
1333                                      " missing grp %d (%llu)",
1334                                      blk, grp,
1335 @@ -420,7 +420,7 @@ static int add_new_gdb(handle_t *handle,
1336           */
1337         if (EXT4_SB(sb)->s_sbh->b_blocknr !=
1338             le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) {
1339 -               ext4_warning(sb, __func__,
1340 +               ext4_warning(sb,
1341                         "won't resize using backup superblock at %llu",
1342                         (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr);
1343                 return -EPERM;
1344 @@ -444,7 +444,7 @@ static int add_new_gdb(handle_t *handle,
1345  
1346         data = (__le32 *)dind->b_data;
1347         if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) {
1348 -               ext4_warning(sb, __func__,
1349 +               ext4_warning(sb,
1350                              "new group %u GDT block %llu not reserved",
1351                              input->group, gdblock);
1352                 err = -EINVAL;
1353 @@ -468,7 +468,7 @@ static int add_new_gdb(handle_t *handle,
1354                         GFP_NOFS);
1355         if (!n_group_desc) {
1356                 err = -ENOMEM;
1357 -               ext4_warning(sb, __func__,
1358 +               ext4_warning(sb,
1359                               "not enough memory for %lu groups", gdb_num + 1);
1360                 goto exit_inode;
1361         }
1362 @@ -567,7 +567,7 @@ static int reserve_backup_gdb(handle_t *
1363         /* Get each reserved primary GDT block and verify it holds backups */
1364         for (res = 0; res < reserved_gdb; res++, blk++) {
1365                 if (le32_to_cpu(*data) != blk) {
1366 -                       ext4_warning(sb, __func__,
1367 +                       ext4_warning(sb,
1368                                      "reserved block %llu"
1369                                      " not at offset %ld",
1370                                      blk,
1371 @@ -713,7 +713,7 @@ static void update_backups(struct super_
1372          */
1373  exit_err:
1374         if (err) {
1375 -               ext4_warning(sb, __func__,
1376 +               ext4_warning(sb,
1377                              "can't update backup for group %u (err %d), "
1378                              "forcing fsck on next reboot", group, err);
1379                 sbi->s_mount_state &= ~EXT4_VALID_FS;
1380 @@ -753,20 +753,20 @@ int ext4_group_add(struct super_block *s
1381  
1382         if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb,
1383                                         EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
1384 -               ext4_warning(sb, __func__,
1385 +               ext4_warning(sb,
1386                              "Can't resize non-sparse filesystem further");
1387                 return -EPERM;
1388         }
1389  
1390         if (ext4_blocks_count(es) + input->blocks_count <
1391             ext4_blocks_count(es)) {
1392 -               ext4_warning(sb, __func__, "blocks_count overflow");
1393 +               ext4_warning(sb, "blocks_count overflow");
1394                 return -EINVAL;
1395         }
1396  
1397         if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) <
1398             le32_to_cpu(es->s_inodes_count)) {
1399 -               ext4_warning(sb, __func__, "inodes_count overflow");
1400 +               ext4_warning(sb, "inodes_count overflow");
1401                 return -EINVAL;
1402         }
1403  
1404 @@ -774,13 +774,13 @@ int ext4_group_add(struct super_block *s
1405                 if (!EXT4_HAS_COMPAT_FEATURE(sb,
1406                                              EXT4_FEATURE_COMPAT_RESIZE_INODE)
1407                     || !le16_to_cpu(es->s_reserved_gdt_blocks)) {
1408 -                       ext4_warning(sb, __func__,
1409 +                       ext4_warning(sb,
1410                                      "No reserved GDT blocks, can't resize");
1411                         return -EPERM;
1412                 }
1413                 inode = ext4_iget(sb, EXT4_RESIZE_INO);
1414                 if (IS_ERR(inode)) {
1415 -                       ext4_warning(sb, __func__,
1416 +                       ext4_warning(sb,
1417                                      "Error opening resize inode");
1418                         return PTR_ERR(inode);
1419                 }
1420 @@ -810,7 +810,7 @@ int ext4_group_add(struct super_block *s
1421  
1422         mutex_lock(&sbi->s_resize_lock);
1423         if (input->group != sbi->s_groups_count) {
1424 -               ext4_warning(sb, __func__,
1425 +               ext4_warning(sb,
1426                              "multiple resizers run on filesystem!");
1427                 err = -EBUSY;
1428                 goto exit_journal;
1429 @@ -998,12 +998,12 @@ int ext4_group_extend(struct super_block
1430                         " too large to resize to %llu blocks safely\n",
1431                         sb->s_id, n_blocks_count);
1432                 if (sizeof(sector_t) < 8)
1433 -                       ext4_warning(sb, __func__, "CONFIG_LBDAF not enabled");
1434 +                       ext4_warning(sb, "CONFIG_LBDAF not enabled");
1435                 return -EINVAL;
1436         }
1437  
1438         if (n_blocks_count < o_blocks_count) {
1439 -               ext4_warning(sb, __func__,
1440 +               ext4_warning(sb,
1441                              "can't shrink FS - resize aborted");
1442                 return -EBUSY;
1443         }
1444 @@ -1012,7 +1012,7 @@ int ext4_group_extend(struct super_block
1445         ext4_get_group_no_and_offset(sb, o_blocks_count, &group, &last);
1446  
1447         if (last == 0) {
1448 -               ext4_warning(sb, __func__,
1449 +               ext4_warning(sb,
1450                              "need to use ext2online to resize further");
1451                 return -EPERM;
1452         }
1453 @@ -1020,7 +1020,7 @@ int ext4_group_extend(struct super_block
1454         add = EXT4_BLOCKS_PER_GROUP(sb) - last;
1455  
1456         if (o_blocks_count + add < o_blocks_count) {
1457 -               ext4_warning(sb, __func__, "blocks_count overflow");
1458 +               ext4_warning(sb, "blocks_count overflow");
1459                 return -EINVAL;
1460         }
1461  
1462 @@ -1028,7 +1028,7 @@ int ext4_group_extend(struct super_block
1463                 add = n_blocks_count - o_blocks_count;
1464  
1465         if (o_blocks_count + add < n_blocks_count)
1466 -               ext4_warning(sb, __func__,
1467 +               ext4_warning(sb,
1468                              "will only finish group (%llu"
1469                              " blocks, %u new)",
1470                              o_blocks_count + add, add);
1471 @@ -1036,7 +1036,7 @@ int ext4_group_extend(struct super_block
1472         /* See if the device is actually as big as what was requested */
1473         bh = sb_bread(sb, o_blocks_count + add - 1);
1474         if (!bh) {
1475 -               ext4_warning(sb, __func__,
1476 +               ext4_warning(sb,
1477                              "can't read last block, resize aborted");
1478                 return -ENOSPC;
1479         }
1480 @@ -1048,13 +1048,13 @@ int ext4_group_extend(struct super_block
1481         handle = ext4_journal_start_sb(sb, 3);
1482         if (IS_ERR(handle)) {
1483                 err = PTR_ERR(handle);
1484 -               ext4_warning(sb, __func__, "error %d on journal start", err);
1485 +               ext4_warning(sb, "error %d on journal start", err);
1486                 goto exit_put;
1487         }
1488  
1489         mutex_lock(&EXT4_SB(sb)->s_resize_lock);
1490         if (o_blocks_count != ext4_blocks_count(es)) {
1491 -               ext4_warning(sb, __func__,
1492 +               ext4_warning(sb,
1493                              "multiple resizers run on filesystem!");
1494                 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
1495                 ext4_journal_stop(handle);
1496 @@ -1064,7 +1064,7 @@ int ext4_group_extend(struct super_block
1497  
1498         if ((err = ext4_journal_get_write_access(handle,
1499                                                  EXT4_SB(sb)->s_sbh))) {
1500 -               ext4_warning(sb, __func__,
1501 +               ext4_warning(sb,
1502                              "error %d on journal write access", err);
1503                 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
1504                 ext4_journal_stop(handle);
1505 diff -urpN linux-stage.orig/fs/ext4/super.c linux-stage/fs/ext4/super.c
1506 --- linux-stage.orig/fs/ext4/super.c    2012-07-02 12:07:23.000000000 -0400
1507 +++ linux-stage/fs/ext4/super.c 2012-07-02 12:07:57.000000000 -0400
1508 @@ -48,11 +48,16 @@
1509  #include "acl.h"
1510  #include "mballoc.h"
1511  
1512 +#define QFMT_OCFS2 3
1513 +#define QFMT_VFS_V1 4
1514 +
1515  #define CREATE_TRACE_POINTS
1516  #include <trace/events/ext4.h>
1517  
1518  struct proc_dir_entry *ext4_proc_root;
1519  static struct kset *ext4_kset;
1520 +static struct ext4_lazy_init *ext4_li_info;
1521 +static struct mutex ext4_li_mtx;
1522  
1523  static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
1524                              unsigned long journal_devnum);
1525 @@ -337,7 +342,7 @@ static void ext4_handle_error(struct sup
1526                         sb->s_id);
1527  }
1528  
1529 -void ext4_error(struct super_block *sb, const char *function,
1530 +void __ext4_error(struct super_block *sb, const char *function,
1531                 const char *fmt, ...)
1532  {
1533         va_list args;
1534 @@ -351,6 +356,42 @@ void ext4_error(struct super_block *sb, 
1535         ext4_handle_error(sb);
1536  }
1537  
1538 +void ext4_error_inode(const char *function, struct inode *inode,
1539 +                      const char *fmt, ...)
1540 +{
1541 +       va_list args;
1542 +
1543 +       va_start(args, fmt);
1544 +       printk(KERN_CRIT "EXT4-fs error (device %s): %s: inode #%lu: (comm %s) ",
1545 +              inode->i_sb->s_id, function, inode->i_ino, current->comm);
1546 +       vprintk(fmt, args);
1547 +       printk("\n");
1548 +       va_end(args);
1549 +
1550 +       ext4_handle_error(inode->i_sb);
1551 +}
1552 +
1553 +void ext4_error_file(const char *function, struct file *file,
1554 +                     const char *fmt, ...)
1555 +{
1556 +       va_list args;
1557 +       struct inode *inode = file->f_dentry->d_inode;
1558 +       char pathname[80], *path;
1559 +
1560 +       va_start(args, fmt);
1561 +       path = d_path(&(file->f_path), pathname, sizeof(pathname));
1562 +       if (!path)
1563 +               path = "(unknown)";
1564 +       printk(KERN_CRIT
1565 +              "EXT4-fs error (device %s): %s: inode #%lu (comm %s path %s): ",
1566 +              inode->i_sb->s_id, function, inode->i_ino, current->comm, path);
1567 +       vprintk(fmt, args);
1568 +       printk("\n");
1569 +       va_end(args);
1570 +
1571 +       ext4_handle_error(inode->i_sb);
1572 +}
1573 +
1574  static const char *ext4_decode_error(struct super_block *sb, int errno,
1575                                      char nbuf[16])
1576  {
1577 @@ -454,7 +495,7 @@ void ext4_msg (struct super_block * sb, 
1578         va_end(args);
1579  }
1580  
1581 -void ext4_warning(struct super_block *sb, const char *function,
1582 +void __ext4_warning(struct super_block *sb, const char *function,
1583                   const char *fmt, ...)
1584  {
1585         va_list args;
1586 @@ -511,7 +552,7 @@ void ext4_update_dynamic_rev(struct supe
1587         if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
1588                 return;
1589  
1590 -       ext4_warning(sb, __func__,
1591 +       ext4_warning(sb,
1592                      "updating to rev %d because of new feature flag, "
1593                      "running e2fsck is recommended",
1594                      EXT4_DYNAMIC_REV);
1595 @@ -777,9 +818,22 @@ static inline void ext4_show_quota_optio
1596  #if defined(CONFIG_QUOTA)
1597         struct ext4_sb_info *sbi = EXT4_SB(sb);
1598  
1599 -       if (sbi->s_jquota_fmt)
1600 -               seq_printf(seq, ",jqfmt=%s",
1601 -               (sbi->s_jquota_fmt == QFMT_VFS_OLD) ? "vfsold" : "vfsv0");
1602 +       if (sbi->s_jquota_fmt) {
1603 +               char *fmtname = "";
1604 +
1605 +               switch (sbi->s_jquota_fmt) {
1606 +               case QFMT_VFS_OLD:
1607 +                       fmtname = "vfsold";
1608 +                       break;
1609 +               case QFMT_VFS_V0:
1610 +                       fmtname = "vfsv0";
1611 +                       break;
1612 +               case QFMT_VFS_V1:
1613 +                       fmtname = "vfsv1";
1614 +                       break;
1615 +               }
1616 +               seq_printf(seq, ",jqfmt=%s", fmtname);
1617 +       }
1618  
1619         if (sbi->s_qf_names[USRQUOTA])
1620                 seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]);
1621 @@ -1096,13 +1150,14 @@ enum {
1622         Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
1623         Opt_data_err_abort, Opt_data_err_ignore,
1624         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
1625 -       Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
1626 -       Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize,
1627 -       Opt_usrquota, Opt_grpquota, Opt_i_version,
1628 +       Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
1629 +       Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
1630 +       Opt_resize, Opt_usrquota, Opt_grpquota, Opt_i_version,
1631         Opt_stripe, Opt_delalloc, Opt_nodelalloc,
1632         Opt_block_validity, Opt_noblock_validity,
1633         Opt_inode_readahead_blks, Opt_journal_ioprio,
1634         Opt_discard, Opt_nodiscard,
1635 +       Opt_init_inode_table, Opt_noinit_inode_table,
1636  };
1637  
1638  static const match_table_t tokens = {
1639 @@ -2709,6 +2764,21 @@ static int ext4_fill_super(struct super_
1640         get_random_bytes(&sbi->s_next_generation, sizeof(u32));
1641         spin_lock_init(&sbi->s_next_gen_lock);
1642  
1643 +       err = percpu_counter_init(&sbi->s_freeblocks_counter,
1644 +                                 ext4_count_free_blocks(sb));
1645 +       if (!err)
1646 +               err = percpu_counter_init(&sbi->s_freeinodes_counter,
1647 +                                         ext4_count_free_inodes(sb));
1648 +       if (!err)
1649 +               err = percpu_counter_init(&sbi->s_dirs_counter,
1650 +                                         ext4_count_dirs(sb));
1651 +       if (!err)
1652 +               err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
1653 +       if (err) {
1654 +               ext4_msg(sb, KERN_ERR, "insufficient memory");
1655 +               goto failed_mount3;
1656 +       }
1657 +
1658         sbi->s_stripe = ext4_get_stripe_size(sbi);
1659         sbi->s_max_writeback_mb_bump = 128;
1660  
1661 @@ -2828,20 +2898,6 @@ static int ext4_fill_super(struct super_
1662         set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
1663  
1664  no_journal:
1665 -       err = percpu_counter_init(&sbi->s_freeblocks_counter,
1666 -                                 ext4_count_free_blocks(sb));
1667 -       if (!err)
1668 -               err = percpu_counter_init(&sbi->s_freeinodes_counter,
1669 -                                         ext4_count_free_inodes(sb));
1670 -       if (!err)
1671 -               err = percpu_counter_init(&sbi->s_dirs_counter,
1672 -                                         ext4_count_dirs(sb));
1673 -       if (!err)
1674 -               err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
1675 -       if (err) {
1676 -               ext4_msg(sb, KERN_ERR, "insufficient memory");
1677 -               goto failed_mount_wq;
1678 -       }
1679         if (test_opt(sb, NOBH)) {
1680                 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
1681                         ext4_msg(sb, KERN_WARNING, "Ignoring nobh option - "
1682 @@ -2955,7 +3011,9 @@ no_journal:
1683         } else
1684                 descr = "out journal";
1685  
1686 -       ext4_msg(sb, KERN_INFO, "mounted filesystem with%s", descr);
1687 +       ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. "
1688 +                "Opts: %s%s", descr, sbi->s_es->s_mount_opts,
1689 +                *sbi->s_es->s_mount_opts ? "; " : "");
1690  
1691         lock_kernel();
1692         return 0;
1693 @@ -2974,10 +3032,6 @@ failed_mount_wq:
1694                 jbd2_journal_destroy(sbi->s_journal);
1695                 sbi->s_journal = NULL;
1696         }
1697 -       percpu_counter_destroy(&sbi->s_freeblocks_counter);
1698 -       percpu_counter_destroy(&sbi->s_freeinodes_counter);
1699 -       percpu_counter_destroy(&sbi->s_dirs_counter);
1700 -       percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
1701  failed_mount3:
1702         if (sbi->s_flex_groups) {
1703                 if (is_vmalloc_addr(sbi->s_flex_groups))
1704 @@ -2985,6 +3039,10 @@ failed_mount3:
1705                 else
1706                         kfree(sbi->s_flex_groups);
1707         }
1708 +       percpu_counter_destroy(&sbi->s_freeblocks_counter);
1709 +       percpu_counter_destroy(&sbi->s_freeinodes_counter);
1710 +       percpu_counter_destroy(&sbi->s_dirs_counter);
1711 +       percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
1712  failed_mount2:
1713         for (i = 0; i < db_count; i++)
1714                 brelse(sbi->s_group_desc[i]);
1715 @@ -3377,9 +3435,9 @@ static void ext4_clear_journal_err(struc
1716                 char nbuf[16];
1717  
1718                 errstr = ext4_decode_error(sb, j_errno, nbuf);
1719 -               ext4_warning(sb, __func__, "Filesystem error recorded "
1720 +               ext4_warning(sb, "Filesystem error recorded "
1721                              "from previous mount: %s", errstr);
1722 -               ext4_warning(sb, __func__, "Marking fs in need of "
1723 +               ext4_warning(sb, "Marking fs in need of "
1724                              "filesystem check.");
1725  
1726                 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
1727 @@ -4007,11 +4065,21 @@ static struct file_system_type ext4_fs_t
1728         .fs_flags       = FS_REQUIRES_DEV,
1729  };
1730  
1731 +static int __init ext4_init_feat_adverts(void)
1732 +{
1733 +       return 0;
1734 +}
1735 +
1736 +static void ext4_exit_feat_adverts(void)
1737 +{
1738 +}
1739 +
1740  static int __init init_ext4_fs(void)
1741  {
1742         int err;
1743  
1744         ext4_check_flag_values();
1745 +
1746         err = init_ext4_system_zone();
1747         if (err)
1748                 return err;
1749 @@ -4019,6 +4087,9 @@ static int __init init_ext4_fs(void)
1750         if (!ext4_kset)
1751                 goto out4;
1752         ext4_proc_root = proc_mkdir("fs/ext4", NULL);
1753 +
1754 +       err = ext4_init_feat_adverts();
1755 +
1756         err = init_ext4_mballoc();
1757         if (err)
1758                 goto out3;
1759 @@ -4032,6 +4103,9 @@ static int __init init_ext4_fs(void)
1760         err = register_filesystem(&ext4_fs_type);
1761         if (err)
1762                 goto out;
1763 +
1764 +       ext4_li_info = NULL;
1765 +       mutex_init(&ext4_li_mtx);
1766         return 0;
1767  out:
1768         destroy_inodecache();
1769 @@ -4040,6 +4114,7 @@ out1:
1770  out2:
1771         exit_ext4_mballoc();
1772  out3:
1773 +       ext4_exit_feat_adverts();
1774         remove_proc_entry("fs/ext4", NULL);
1775         kset_unregister(ext4_kset);
1776  out4:
1777 @@ -4053,6 +4128,7 @@ static void __exit exit_ext4_fs(void)
1778         destroy_inodecache();
1779         exit_ext4_xattr();
1780         exit_ext4_mballoc();
1781 +       ext4_exit_feat_adverts();
1782         remove_proc_entry("fs/ext4", NULL);
1783         kset_unregister(ext4_kset);
1784         exit_ext4_system_zone();
1785 diff -urpN linux-stage.orig/fs/ext4/xattr.c linux-stage/fs/ext4/xattr.c
1786 --- linux-stage.orig/fs/ext4/xattr.c    2012-07-02 12:07:23.000000000 -0400
1787 +++ linux-stage/fs/ext4/xattr.c 2012-07-02 12:07:57.000000000 -0400
1788 @@ -227,7 +227,7 @@ ext4_xattr_block_get(struct inode *inode
1789         ea_bdebug(bh, "b_count=%d, refcount=%d",
1790                 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
1791         if (ext4_xattr_check_block(bh)) {
1792 -bad_block:     ext4_error(inode->i_sb, __func__,
1793 +bad_block:     ext4_error(inode->i_sb,
1794                            "inode %lu: bad block %llu", inode->i_ino,
1795                            EXT4_I(inode)->i_file_acl);
1796                 error = -EIO;
1797 @@ -369,7 +369,7 @@ ext4_xattr_block_list(struct inode *inod
1798         ea_bdebug(bh, "b_count=%d, refcount=%d",
1799                 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
1800         if (ext4_xattr_check_block(bh)) {
1801 -               ext4_error(inode->i_sb, __func__,
1802 +               ext4_error(inode->i_sb,
1803                            "inode %lu: bad block %llu", inode->i_ino,
1804                            EXT4_I(inode)->i_file_acl);
1805                 error = -EIO;
1806 @@ -661,7 +661,7 @@ ext4_xattr_block_find(struct inode *inod
1807                         atomic_read(&(bs->bh->b_count)),
1808                         le32_to_cpu(BHDR(bs->bh)->h_refcount));
1809                 if (ext4_xattr_check_block(bs->bh)) {
1810 -                       ext4_error(sb, __func__,
1811 +                       ext4_error(sb,
1812                                 "inode %lu: bad block %llu", inode->i_ino,
1813                                 EXT4_I(inode)->i_file_acl);
1814                         error = -EIO;
1815 @@ -875,7 +875,7 @@ cleanup_dquot:
1816         goto cleanup;
1817  
1818  bad_block:
1819 -       ext4_error(inode->i_sb, __func__,
1820 +       ext4_error(inode->i_sb,
1821                    "inode %lu: bad block %llu", inode->i_ino,
1822                    EXT4_I(inode)->i_file_acl);
1823         goto cleanup;
1824 @@ -1190,7 +1190,7 @@ retry:
1825                 if (!bh)
1826                         goto cleanup;
1827                 if (ext4_xattr_check_block(bh)) {
1828 -                       ext4_error(inode->i_sb, __func__,
1829 +                       ext4_error(inode->i_sb,
1830                                 "inode %lu: bad block %llu", inode->i_ino,
1831                                 EXT4_I(inode)->i_file_acl);
1832                         error = -EIO;
1833 @@ -1367,14 +1367,14 @@ ext4_xattr_delete_inode(handle_t *handle
1834                 goto cleanup;
1835         bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
1836         if (!bh) {
1837 -               ext4_error(inode->i_sb, __func__,
1838 +               ext4_error(inode->i_sb,
1839                         "inode %lu: block %llu read error", inode->i_ino,
1840                         EXT4_I(inode)->i_file_acl);
1841                 goto cleanup;
1842         }
1843         if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
1844             BHDR(bh)->h_blocks != cpu_to_le32(1)) {
1845 -               ext4_error(inode->i_sb, __func__,
1846 +               ext4_error(inode->i_sb,
1847                         "inode %lu: bad block %llu", inode->i_ino,
1848                         EXT4_I(inode)->i_file_acl);
1849                 goto cleanup;
1850 @@ -1501,7 +1501,7 @@ again:
1851                 }
1852                 bh = sb_bread(inode->i_sb, ce->e_block);
1853                 if (!bh) {
1854 -                       ext4_error(inode->i_sb, __func__,
1855 +                       ext4_error(inode->i_sb,
1856                                 "inode %lu: block %lu read error",
1857                                 inode->i_ino, (unsigned long) ce->e_block);
1858                 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >=