Whamcloud - gitweb
LU-12353 ldiskfs: speedup quota journalling
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel7.6 / ext4-large-eas.patch
1 This patch implements the large EA support in ext4. If the size of
2 an EA value is larger than the blocksize, then the EA value would
3 not be saved in the external EA block, instead it would be saved
4 in an external EA inode. So, the patch also helps support a larger
5 number of EAs.
6
7 Index: linux-stage/fs/ext4/ext4.h
8 ===================================================================
9 --- linux-stage.orig/fs/ext4/ext4.h
10 +++ linux-stage/fs/ext4/ext4.h
11 @@ -1617,6 +1617,7 @@ static inline void ext4_clear_state_flag
12                                          EXT4_FEATURE_INCOMPAT_EXTENTS| \
13                                          EXT4_FEATURE_INCOMPAT_64BIT| \
14                                          EXT4_FEATURE_INCOMPAT_FLEX_BG| \
15 +                                        EXT4_FEATURE_INCOMPAT_EA_INODE| \
16                                          EXT4_FEATURE_INCOMPAT_MMP |    \
17                                          EXT4_FEATURE_INCOMPAT_DIRDATA| \
18                                          EXT4_FEATURE_INCOMPAT_INLINE_DATA)
19 @@ -2028,6 +2029,10 @@ struct mmpd_data {
20  # define ATTRIB_NORET  __attribute__((noreturn))
21  # define NORET_AND     noreturn,
22  
23 +struct ext4_xattr_ino_array {
24 +       unsigned int xia_count;         /* # of used item in the array */
25 +       unsigned int xia_inodes[0];
26 +};
27  /* bitmap.c */
28  extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
29  void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
30 @@ -2233,6 +2238,7 @@ extern void ext4_set_inode_flags(struct
31  extern void ext4_get_inode_flags(struct ext4_inode_info *);
32  extern int ext4_alloc_da_blocks(struct inode *inode);
33  extern void ext4_set_aops(struct inode *inode);
34 +extern int ext4_meta_trans_blocks(struct inode *, int nrblocks, int chunk);
35  extern int ext4_writepage_trans_blocks(struct inode *);
36  extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
37  extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
38 Index: linux-stage/fs/ext4/inode.c
39 ===================================================================
40 --- linux-stage.orig/fs/ext4/inode.c
41 +++ linux-stage/fs/ext4/inode.c
42 @@ -136,8 +136,6 @@ static void ext4_invalidatepage(struct p
43                                 unsigned int length);
44  static int __ext4_journalled_writepage(struct page *page, unsigned int len);
45  static int ext4_bh_delay_or_unwritten(handle_t *handle, struct buffer_head *bh);
46 -static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
47 -                                 int pextents);
48  
49  /*
50   * Test whether an inode is a fast symlink.
51 @@ -186,6 +184,8 @@ void ext4_evict_inode(struct inode *inod
52  {
53         handle_t *handle;
54         int err;
55 +       int extra_credits = 3;
56 +       struct ext4_xattr_ino_array *lea_ino_array = NULL;
57  
58         trace_ext4_evict_inode(inode);
59  
60 @@ -235,8 +235,8 @@ void ext4_evict_inode(struct inode *inod
61          * protection against it
62          */
63         sb_start_intwrite(inode->i_sb);
64 -       handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE,
65 -                                   ext4_blocks_for_truncate(inode)+3);
66 +
67 +       handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, extra_credits);
68         if (IS_ERR(handle)) {
69                 ext4_std_error(inode->i_sb, PTR_ERR(handle));
70                 /*
71 @@ -251,6 +251,32 @@ void ext4_evict_inode(struct inode *inod
72  
73         if (IS_SYNC(inode))
74                 ext4_handle_sync(handle);
75 +
76 +       /* Delete xattr inode before deleting the main inode. */
77 +       err = ext4_xattr_delete_inode(handle, inode, &lea_ino_array);
78 +       if (err) {
79 +               ext4_warning(inode->i_sb,
80 +                            "couldn't delete inode's xattr (err %d)", err);
81 +               goto stop_handle;
82 +       }
83 +
84 +       if (!IS_NOQUOTA(inode))
85 +               extra_credits += 2 * EXT4_QUOTA_DEL_BLOCKS(inode->i_sb);
86 +
87 +       if (!ext4_handle_has_enough_credits(handle,
88 +                       ext4_blocks_for_truncate(inode) + extra_credits)) {
89 +               err = ext4_journal_extend(handle,
90 +                       ext4_blocks_for_truncate(inode) + extra_credits);
91 +               if (err > 0)
92 +                       err = ext4_journal_restart(handle,
93 +                       ext4_blocks_for_truncate(inode) + extra_credits);
94 +               if (err != 0) {
95 +                       ext4_warning(inode->i_sb,
96 +                                    "couldn't extend journal (err %d)", err);
97 +                       goto stop_handle;
98 +               }
99 +       }
100 +
101         inode->i_size = 0;
102         err = ext4_mark_inode_dirty(handle, inode);
103         if (err) {
104 @@ -267,10 +293,10 @@ void ext4_evict_inode(struct inode *inod
105          * enough credits left in the handle to remove the inode from
106          * the orphan list and set the dtime field.
107          */
108 -       if (!ext4_handle_has_enough_credits(handle, 3)) {
109 -               err = ext4_journal_extend(handle, 3);
110 +       if (!ext4_handle_has_enough_credits(handle, extra_credits)) {
111 +               err = ext4_journal_extend(handle, extra_credits);
112                 if (err > 0)
113 -                       err = ext4_journal_restart(handle, 3);
114 +                       err = ext4_journal_restart(handle, extra_credits);
115                 if (err != 0) {
116                         ext4_warning(inode->i_sb,
117                                      "couldn't extend journal (err %d)", err);
118 @@ -307,6 +333,9 @@ void ext4_evict_inode(struct inode *inod
119                 ext4_free_inode(handle, inode);
120         ext4_journal_stop(handle);
121         sb_end_intwrite(inode->i_sb);
122 +
123 +       if (lea_ino_array != NULL)
124 +               ext4_xattr_inode_array_free(inode, lea_ino_array);
125         return;
126  no_delete:
127         ext4_clear_inode(inode);        /* We must guarantee clearing of inode... */
128 @@ -5132,7 +5161,7 @@ static int ext4_index_trans_blocks(struc
129   *
130   * Also account for superblock, inode, quota and xattr blocks
131   */
132 -static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
133 +int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
134                                   int pextents)
135  {
136         ext4_group_t groups, ngroups = ext4_get_groups_count(inode->i_sb);
137 Index: linux-stage/fs/ext4/xattr.c
138 ===================================================================
139 --- linux-stage.orig/fs/ext4/xattr.c
140 +++ linux-stage/fs/ext4/xattr.c
141 @@ -201,6 +201,7 @@ ext4_xattr_check_names(struct ext4_xattr
142  
143         while (!IS_LAST_ENTRY(entry)) {
144                 if (entry->e_value_size != 0 &&
145 +                   entry->e_value_inum == 0 &&
146                     (value_start + le16_to_cpu(entry->e_value_offs) <
147                      (void *)e + sizeof(__u32) ||
148                      value_start + le16_to_cpu(entry->e_value_offs) +
149 @@ -233,19 +234,26 @@ ext4_xattr_check_block(struct inode *ino
150  }
151  
152  static inline int
153 -ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size)
154 +ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size,
155 +                      struct inode *inode)
156  {
157         size_t value_size = le32_to_cpu(entry->e_value_size);
158  
159 -       if (entry->e_value_block != 0 || value_size > size ||
160 +       if (!entry->e_value_inum &&
161             le16_to_cpu(entry->e_value_offs) + value_size > size)
162                 return -EIO;
163 +       if (entry->e_value_inum &&
164 +           (le32_to_cpu(entry->e_value_inum) < EXT4_FIRST_INO(inode->i_sb) ||
165 +            le32_to_cpu(entry->e_value_inum) >
166 +            le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_inodes_count)))
167 +               return -EIO;
168         return 0;
169  }
170  
171  static int
172  ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
173 -                     const char *name, size_t size, int sorted)
174 +                     const char *name, size_t size, int sorted,
175 +                     struct inode *inode)
176  {
177         struct ext4_xattr_entry *entry;
178         size_t name_len;
179 @@ -265,11 +273,109 @@ ext4_xattr_find_entry(struct ext4_xattr_
180                         break;
181         }
182         *pentry = entry;
183 -       if (!cmp && ext4_xattr_check_entry(entry, size))
184 +       if (!cmp && ext4_xattr_check_entry(entry, size, inode))
185                         return -EIO;
186         return cmp ? -ENODATA : 0;
187  }
188  
189 +/*
190 + * Read the EA value from an inode.
191 + */
192 +static int ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t *size)
193 +{
194 +       unsigned long block = 0;
195 +       struct buffer_head *bh = NULL;
196 +       int err, blocksize;
197 +       size_t csize, ret_size = 0;
198 +
199 +       if (*size == 0)
200 +               return 0;
201 +
202 +       blocksize = ea_inode->i_sb->s_blocksize;
203 +
204 +       while (ret_size < *size) {
205 +               csize = (*size - ret_size) > blocksize ? blocksize :
206 +                                                       *size - ret_size;
207 +               bh = ext4_bread(NULL, ea_inode, block, 0, &err);
208 +               if (!bh) {
209 +                       *size = ret_size;
210 +                       return err;
211 +               }
212 +               memcpy(buf, bh->b_data, csize);
213 +               brelse(bh);
214 +
215 +               buf += csize;
216 +               block += 1;
217 +               ret_size += csize;
218 +       }
219 +
220 +       *size = ret_size;
221 +
222 +       return err;
223 +}
224 +
225 +/*
226 + * Fetch the xattr inode from disk.
227 + *
228 + * The xattr inode stores the parent inode number and generation so that
229 + * the kernel and e2fsck can verify the xattr inode is valid upon access.
230 + */
231 +struct inode *ext4_xattr_inode_iget(struct inode *parent,
232 +                                   unsigned long ea_ino, int *err)
233 +{
234 +       struct inode *ea_inode = NULL;
235 +
236 +       ea_inode = ext4_iget(parent->i_sb, ea_ino);
237 +       if (IS_ERR(ea_inode) || is_bad_inode(ea_inode)) {
238 +               int rc = IS_ERR(ea_inode) ? PTR_ERR(ea_inode) : 0;
239 +               ext4_error(parent->i_sb, "error while reading EA inode %lu "
240 +                          "/ %d %d", ea_ino, rc, is_bad_inode(ea_inode));
241 +               *err = rc != 0 ? rc : -EIO;
242 +               return NULL;
243 +       }
244 +
245 +       if (EXT4_XATTR_INODE_GET_PARENT(ea_inode) != parent->i_ino ||
246 +           ea_inode->i_generation != parent->i_generation) {
247 +               ext4_error(parent->i_sb, "Backpointer from EA inode %lu "
248 +                          "to parent invalid.", ea_ino);
249 +               *err = -EINVAL;
250 +               goto error;
251 +       }
252 +
253 +       if (!(EXT4_I(ea_inode)->i_flags & EXT4_EA_INODE_FL)) {
254 +               ext4_error(parent->i_sb, "EA inode %lu does not have "
255 +                          "EXT4_EA_INODE_FL flag set.\n", ea_ino);
256 +               *err = -EINVAL;
257 +               goto error;
258 +       }
259 +
260 +       *err = 0;
261 +       return ea_inode;
262 +
263 +error:
264 +       iput(ea_inode);
265 +       return NULL;
266 +}
267 +
268 +/*
269 + * Read the value from the EA inode.
270 + */
271 +static int ext4_xattr_inode_get(struct inode *inode, unsigned long ea_ino,
272 +                               void *buffer, size_t *size)
273 +{
274 +       struct inode *ea_inode = NULL;
275 +       int err;
276 +
277 +       ea_inode = ext4_xattr_inode_iget(inode, ea_ino, &err);
278 +       if (err)
279 +               return err;
280 +
281 +       err = ext4_xattr_inode_read(ea_inode, buffer, size);
282 +       iput(ea_inode);
283 +
284 +       return err;
285 +}
286 +
287  static int
288  ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
289                      void *buffer, size_t buffer_size)
290 @@ -301,7 +407,8 @@ bad_block:
291         }
292         ext4_xattr_cache_insert(bh);
293         entry = BFIRST(bh);
294 -       error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1);
295 +       error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1,
296 +                                     inode);
297         if (error == -EIO)
298                 goto bad_block;
299         if (error)
300 @@ -311,8 +418,16 @@ bad_block:
301                 error = -ERANGE;
302                 if (size > buffer_size)
303                         goto cleanup;
304 -               memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
305 -                      size);
306 +               if (entry->e_value_inum) {
307 +                       error = ext4_xattr_inode_get(inode,
308 +                                            le32_to_cpu(entry->e_value_inum),
309 +                                            buffer, &size);
310 +                       if (error)
311 +                               goto cleanup;
312 +               } else {
313 +                       memcpy(buffer, bh->b_data +
314 +                              le16_to_cpu(entry->e_value_offs), size);
315 +               }
316         }
317         error = size;
318  
319 @@ -346,7 +461,7 @@ ext4_xattr_ibody_get(struct inode *inode
320         if (error)
321                 goto cleanup;
322         error = ext4_xattr_find_entry(&entry, name_index, name,
323 -                                     end - (void *)entry, 0);
324 +                                     end - (void *)entry, 0, inode);
325         if (error)
326                 goto cleanup;
327         size = le32_to_cpu(entry->e_value_size);
328 @@ -354,8 +469,16 @@ ext4_xattr_ibody_get(struct inode *inode
329                 error = -ERANGE;
330                 if (size > buffer_size)
331                         goto cleanup;
332 -               memcpy(buffer, (void *)IFIRST(header) +
333 -                      le16_to_cpu(entry->e_value_offs), size);
334 +               if (entry->e_value_inum) {
335 +                       error = ext4_xattr_inode_get(inode,
336 +                                            le32_to_cpu(entry->e_value_inum),
337 +                                            buffer, &size);
338 +                       if (error)
339 +                               goto cleanup;
340 +               } else {
341 +                       memcpy(buffer, (void *)IFIRST(header) +
342 +                              le16_to_cpu(entry->e_value_offs), size);
343 +               }
344         }
345         error = size;
346  
347 @@ -600,7 +723,7 @@ static size_t ext4_xattr_free_space(stru
348                                     size_t *min_offs, void *base, int *total)
349  {
350         for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
351 -               if (!last->e_value_block && last->e_value_size) {
352 +               if (!last->e_value_inum && last->e_value_size) {
353                         size_t offs = le16_to_cpu(last->e_value_offs);
354                         if (offs < *min_offs)
355                                 *min_offs = offs;
356 @@ -611,11 +734,193 @@ static size_t ext4_xattr_free_space(stru
357         return (*min_offs - ((void *)last - base) - sizeof(__u32));
358  }
359  
360 +/*
361 + * Write the value of the EA in an inode.
362 + */
363  static int
364 -ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
365 +ext4_xattr_inode_write(handle_t *handle, struct inode *ea_inode,
366 +                      const void *buf, int bufsize)
367 +{
368 +       struct buffer_head *bh = NULL;
369 +       unsigned long block = 0;
370 +       unsigned blocksize = ea_inode->i_sb->s_blocksize;
371 +       unsigned max_blocks = (bufsize + blocksize - 1) >> ea_inode->i_blkbits;
372 +       int csize, wsize = 0;
373 +       int ret = 0;
374 +       int retries = 0;
375 +
376 +retry:
377 +       while (ret >= 0 && ret < max_blocks) {
378 +               struct ext4_map_blocks map;
379 +               map.m_lblk = block += ret;
380 +               map.m_len = max_blocks -= ret;
381 +
382 +               ret = ext4_map_blocks(handle, ea_inode, &map,
383 +                                     EXT4_GET_BLOCKS_CREATE);
384 +               if (ret <= 0) {
385 +                       ext4_mark_inode_dirty(handle, ea_inode);
386 +                       if (ret == -ENOSPC &&
387 +                           ext4_should_retry_alloc(ea_inode->i_sb, &retries)) {
388 +                               ret = 0;
389 +                               goto retry;
390 +                       }
391 +                       break;
392 +               }
393 +       }
394 +
395 +       if (ret < 0)
396 +               return ret;
397 +
398 +       block = 0;
399 +       while (wsize < bufsize) {
400 +               if (bh != NULL)
401 +                       brelse(bh);
402 +               csize = (bufsize - wsize) > blocksize ? blocksize :
403 +                                                               bufsize - wsize;
404 +               bh = ext4_getblk(handle, ea_inode, block, 0, &ret);
405 +               if (!bh)
406 +                       goto out;
407 +               ret = ext4_journal_get_write_access(handle, bh);
408 +               if (ret)
409 +                       goto out;
410 +
411 +               memcpy(bh->b_data, buf, csize);
412 +               set_buffer_uptodate(bh);
413 +               ext4_handle_dirty_metadata(handle, ea_inode, bh);
414 +
415 +               buf += csize;
416 +               wsize += csize;
417 +               block += 1;
418 +       }
419 +
420 +       mutex_lock(&ea_inode->i_mutex);
421 +       i_size_write(ea_inode, wsize);
422 +       ext4_update_i_disksize(ea_inode, wsize);
423 +       mutex_unlock(&ea_inode->i_mutex);
424 +
425 +       ext4_mark_inode_dirty(handle, ea_inode);
426 +
427 +out:
428 +       brelse(bh);
429 +
430 +       return ret;
431 +}
432 +
433 +static void ext4_xattr_inode_set_ref(struct inode *ea_inode, __u64 ref_count)
434 +{
435 +       ea_inode->i_ctime.tv_sec = (__u32)(ref_count >> 32);
436 +       ea_inode->i_version = (__u32)ref_count;
437 +}
438 +
439 +static void ext4_xattr_inode_set_hash(struct inode *ea_inode, __u32 hash)
440 +{
441 +       ea_inode->i_atime.tv_sec = hash;
442 +}
443 +
444 +/*
445 + * Create an inode to store the value of a large EA.
446 + */
447 +static struct inode *
448 +ext4_xattr_inode_create(handle_t *handle, struct inode *inode, __u32 hash)
449 +{
450 +       struct inode *ea_inode = NULL;
451 +
452 +       /*
453 +        * Let the next inode be the goal, so we try and allocate the EA inode
454 +        * in the same group, or nearby one.
455 +        */
456 +       ea_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
457 +                                 S_IFREG|0600, NULL, inode->i_ino + 1, NULL);
458 +
459 +       if (!IS_ERR(ea_inode)) {
460 +               ea_inode->i_op = &ext4_file_inode_operations;
461 +               ea_inode->i_fop = &ext4_file_operations.kabi_fops;
462 +               ext4_set_aops(ea_inode);
463 +               ea_inode->i_generation = inode->i_generation;
464 +               EXT4_I(ea_inode)->i_flags |= EXT4_EA_INODE_FL;
465 +
466 +               /*
467 +                * A back-pointer from EA inode to parent inode will be useful
468 +                * for e2fsck.
469 +                */
470 +               EXT4_XATTR_INODE_SET_PARENT(ea_inode, inode->i_ino);
471 +               unlock_new_inode(ea_inode);
472 +
473 +               ext4_xattr_inode_set_ref(ea_inode, 1);
474 +               ext4_xattr_inode_set_hash(ea_inode, hash);
475 +       }
476 +
477 +       return ea_inode;
478 +}
479 +
480 +/*
481 + * Unlink the inode storing the value of the EA.
482 + */
483 +int
484 +ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino)
485 +{
486 +       struct inode *ea_inode = NULL;
487 +       int err;
488 +
489 +       ea_inode = ext4_xattr_inode_iget(inode, ea_ino, &err);
490 +       if (err)
491 +               return err;
492 +
493 +       clear_nlink(ea_inode);
494 +       iput(ea_inode);
495 +
496 +       return 0;
497 +}
498 +
499 +static __u32
500 +ext4_xattr_inode_hash(struct ext4_sb_info *sbi, const void *buffer, size_t size)
501 +{
502 +       if (ext4_has_metadata_csum(sbi->s_sb))
503 +               return ext4_chksum(sbi, sbi->s_csum_seed, buffer, size);
504 +       return 0;
505 +}
506 +
507 +/*
508 + * Add value of the EA in an inode.
509 + */
510 +static int
511 +ext4_xattr_inode_set(handle_t *handle, struct inode *inode, unsigned long *ea_ino,
512 +                    const void *value, size_t value_len)
513 +{
514 +       struct inode *ea_inode = NULL;
515 +       __u32 hash;
516 +       int err;
517 +
518 +       /* Create an inode for the EA value */
519 +       hash = ext4_xattr_inode_hash(EXT4_SB(inode->i_sb), value, value_len);
520 +       ea_inode = ext4_xattr_inode_create(handle, inode, hash);
521 +       if (IS_ERR(ea_inode))
522 +               return -1;
523 +
524 +       err = ext4_xattr_inode_write(handle, ea_inode, value, value_len);
525 +       if (err)
526 +               clear_nlink(ea_inode);
527 +       else
528 +               *ea_ino = ea_inode->i_ino;
529 +
530 +       iput(ea_inode);
531 +
532 +       return err;
533 +}
534 +
535 +static int
536 +ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s,
537 +                    handle_t *handle, struct inode *inode)
538  {
539         struct ext4_xattr_entry *last, *next;
540         size_t free, min_offs = s->end - s->base, name_len = strlen(i->name);
541 +       int in_inode = i->in_inode;
542 +
543 +       if (EXT4_HAS_INCOMPAT_FEATURE(inode->i_sb,
544 +                EXT4_FEATURE_INCOMPAT_EA_INODE) &&
545 +           (EXT4_XATTR_SIZE(i->value_len) >
546 +            EXT4_XATTR_MIN_LARGE_EA_SIZE(inode->i_sb->s_blocksize)))
547 +               in_inode = 1;
548  
549         /* Compute min_offs and last. */
550         last = s->first;
551 @@ -624,7 +929,7 @@ ext4_xattr_set_entry(struct ext4_xattr_i
552                 if ((void *)next >= s->end) {
553                         return -EIO;
554                 }
555 -               if (!last->e_value_block && last->e_value_size) {
556 +               if (!last->e_value_inum && last->e_value_size) {
557                         size_t offs = le16_to_cpu(last->e_value_offs);
558                         if (offs < min_offs)
559                                 min_offs = offs;
560 @@ -632,15 +937,21 @@ ext4_xattr_set_entry(struct ext4_xattr_i
561         }
562         free = min_offs - ((void *)last - s->base) - sizeof(__u32);
563         if (!s->not_found) {
564 -               if (!s->here->e_value_block && s->here->e_value_size) {
565 +               if (!in_inode &&
566 +                   !s->here->e_value_inum && s->here->e_value_size) {
567                         size_t size = le32_to_cpu(s->here->e_value_size);
568                         free += EXT4_XATTR_SIZE(size);
569                 }
570                 free += EXT4_XATTR_LEN(name_len);
571         }
572         if (i->value) {
573 -               if (free < EXT4_XATTR_LEN(name_len) +
574 -                          EXT4_XATTR_SIZE(i->value_len))
575 +               size_t value_len = EXT4_XATTR_SIZE(i->value_len);
576 +
577 +               if (in_inode)
578 +                       value_len = 0;
579 +
580 +               if (free < value_len ||
581 +                   free < EXT4_XATTR_LEN(name_len) + value_len)
582                         return -ENOSPC;
583         }
584  
585 @@ -654,7 +965,8 @@ ext4_xattr_set_entry(struct ext4_xattr_i
586                 s->here->e_name_len = name_len;
587                 memcpy(s->here->e_name, i->name, name_len);
588         } else {
589 -               if (!s->here->e_value_block && s->here->e_value_size) {
590 +               if (!s->here->e_value_inum && s->here->e_value_size &&
591 +                   s->here->e_value_offs > 0) {
592                         void *first_val = s->base + min_offs;
593                         size_t offs = le16_to_cpu(s->here->e_value_offs);
594                         void *val = s->base + offs;
595 @@ -688,13 +1000,18 @@ ext4_xattr_set_entry(struct ext4_xattr_i
596                         last = s->first;
597                         while (!IS_LAST_ENTRY(last)) {
598                                 size_t o = le16_to_cpu(last->e_value_offs);
599 -                               if (!last->e_value_block &&
600 +                               if (!last->e_value_inum &&
601                                     last->e_value_size && o < offs)
602                                         last->e_value_offs =
603                                                 cpu_to_le16(o + size);
604                                 last = EXT4_XATTR_NEXT(last);
605                         }
606                 }
607 +               if (s->here->e_value_inum) {
608 +                       ext4_xattr_inode_unlink(inode,
609 +                                       le32_to_cpu(s->here->e_value_inum));
610 +                       s->here->e_value_inum = 0;
611 +               }
612                 if (!i->value) {
613                         /* Remove the old name. */
614                         size_t size = EXT4_XATTR_LEN(name_len);
615 @@ -708,10 +1025,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
616         if (i->value) {
617                 /* Insert the new value. */
618                 s->here->e_value_size = cpu_to_le32(i->value_len);
619 -               if (i->value_len) {
620 +               if (in_inode) {
621 +                       unsigned long ea_ino = le32_to_cpu(s->here->e_value_inum);
622 +                       ext4_xattr_inode_set(handle, inode, &ea_ino, i->value,
623 +                                            i->value_len);
624 +                       s->here->e_value_inum = cpu_to_le32(ea_ino);
625 +                       s->here->e_value_offs = 0;
626 +               } else if (i->value_len) {
627                         size_t size = EXT4_XATTR_SIZE(i->value_len);
628                         void *val = s->base + min_offs - size;
629                         s->here->e_value_offs = cpu_to_le16(min_offs - size);
630 +                       s->here->e_value_inum = 0;
631                         if (i->value == EXT4_ZERO_XATTR_VALUE) {
632                                 memset(val, 0, size);
633                         } else {
634 @@ -761,7 +1085,7 @@ ext4_xattr_block_find(struct inode *inod
635                 bs->s.end = bs->bh->b_data + bs->bh->b_size;
636                 bs->s.here = bs->s.first;
637                 error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
638 -                                             i->name, bs->bh->b_size, 1);
639 +                                             i->name, bs->bh->b_size, 1, inode);
640                 if (error && error != -ENODATA)
641                         goto cleanup;
642                 bs->s.not_found = error;
643 @@ -785,8 +1109,6 @@ ext4_xattr_block_set(handle_t *handle, s
644  
645  #define header(x) ((struct ext4_xattr_header *)(x))
646  
647 -       if (i->value && i->value_len > sb->s_blocksize)
648 -               return -ENOSPC;
649         if (s->base) {
650                 ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
651                                         bs->bh->b_blocknr);
652 @@ -802,7 +1124,7 @@ ext4_xattr_block_set(handle_t *handle, s
653                                 ce = NULL;
654                         }
655                         ea_bdebug(bs->bh, "modifying in-place");
656 -                       error = ext4_xattr_set_entry(i, s);
657 +                       error = ext4_xattr_set_entry(i, s, handle, inode);
658                         if (!error) {
659                                 if (!IS_LAST_ENTRY(s->first))
660                                         ext4_xattr_rehash(header(s->base),
661 @@ -853,7 +1175,7 @@ ext4_xattr_block_set(handle_t *handle, s
662                 s->end = s->base + sb->s_blocksize;
663         }
664  
665 -       error = ext4_xattr_set_entry(i, s);
666 +       error = ext4_xattr_set_entry(i, s, handle, inode);
667         if (error == -EIO)
668                 goto bad_block;
669         if (error)
670 @@ -997,7 +1319,7 @@ int ext4_xattr_ibody_find(struct inode *
671                 /* Find the named attribute. */
672                 error = ext4_xattr_find_entry(&is->s.here, i->name_index,
673                                               i->name, is->s.end -
674 -                                             (void *)is->s.base, 0);
675 +                                             (void *)is->s.base, 0, inode);
676                 if (error && error != -ENODATA)
677                         return error;
678                 is->s.not_found = error;
679 @@ -1015,7 +1337,7 @@ int ext4_xattr_ibody_inline_set(handle_t
680  
681         if (EXT4_I(inode)->i_extra_isize == 0)
682                 return -ENOSPC;
683 -       error = ext4_xattr_set_entry(i, s);
684 +       error = ext4_xattr_set_entry(i, s, handle, inode);
685         if (error)
686                 return error;
687         header = IHDR(inode, ext4_raw_inode(&is->iloc));
688 @@ -1039,7 +1361,7 @@ static int ext4_xattr_ibody_set(handle_t
689  
690         if (EXT4_I(inode)->i_extra_isize == 0)
691                 return -ENOSPC;
692 -       error = ext4_xattr_set_entry(i, s);
693 +       error = ext4_xattr_set_entry(i, s, handle, inode);
694         if (error)
695                 return error;
696         header = IHDR(inode, ext4_raw_inode(&is->iloc));
697 @@ -1075,7 +1397,7 @@ ext4_xattr_set_handle(handle_t *handle,
698                 .name = name,
699                 .value = value,
700                 .value_len = value_len,
701 -
702 +               .in_inode = 0,
703         };
704         struct ext4_xattr_ibody_find is = {
705                 .s = { .not_found = -ENODATA, },
706 @@ -1140,6 +1462,15 @@ ext4_xattr_set_handle(handle_t *handle,
707                                         goto cleanup;
708                         }
709                         error = ext4_xattr_block_set(handle, inode, &i, &bs);
710 +                       if (EXT4_HAS_INCOMPAT_FEATURE(inode->i_sb,
711 +                                       EXT4_FEATURE_INCOMPAT_EA_INODE) &&
712 +                           error == -ENOSPC) {
713 +                               /* xattr not fit to block, store at external
714 +                                * inode */
715 +                               i.in_inode = 1;
716 +                               error = ext4_xattr_ibody_set(handle, inode,
717 +                                                            &i, &is);
718 +                       }
719                         if (error)
720                                 goto cleanup;
721                         if (!is.s.not_found) {
722 @@ -1186,9 +1517,22 @@ ext4_xattr_set(struct inode *inode, int
723                const void *value, size_t value_len, int flags)
724  {
725         handle_t *handle;
726 +       struct super_block *sb = inode->i_sb;
727         int error, retries = 0;
728         int credits = ext4_jbd2_credits_xattr(inode);
729  
730 +       if ((value_len >= EXT4_XATTR_MIN_LARGE_EA_SIZE(sb->s_blocksize)) &&
731 +           EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EA_INODE)) {
732 +               int nrblocks = (value_len + sb->s_blocksize - 1) >>
733 +                                       sb->s_blocksize_bits;
734 +
735 +               /* For new inode */
736 +               credits += EXT4_SINGLEDATA_TRANS_BLOCKS(sb) + 3;
737 +
738 +               /* For data blocks of EA inode */
739 +               credits += ext4_meta_trans_blocks(inode, nrblocks, 0);
740 +       }
741 +
742  retry:
743         handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
744         if (IS_ERR(handle)) {
745 @@ -1200,7 +1544,7 @@ retry:
746                                               value, value_len, flags);
747                 error2 = ext4_journal_stop(handle);
748                 if (error == -ENOSPC &&
749 -                   ext4_should_retry_alloc(inode->i_sb, &retries))
750 +                   ext4_should_retry_alloc(sb, &retries))
751                         goto retry;
752                 if (error == 0)
753                         error = error2;
754 @@ -1222,7 +1566,7 @@ static void ext4_xattr_shift_entries(str
755  
756         /* Adjust the value offsets of the entries */
757         for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
758 -               if (!last->e_value_block && last->e_value_size) {
759 +               if (!last->e_value_inum && last->e_value_size) {
760                         new_offs = le16_to_cpu(last->e_value_offs) +
761                                                         value_offs_shift;
762                         BUG_ON(new_offs + le32_to_cpu(last->e_value_size)
763 @@ -1469,21 +1813,135 @@ cleanup:
764  }
765  
766  
767 +#define EIA_INCR 16 /* must be 2^n */
768 +#define EIA_MASK (EIA_INCR - 1)
769 +/* Add the large xattr @ino into @lea_ino_array for later deletion.
770 + * If @lea_ino_array is new or full it will be grown and the old
771 + * contents copied over.
772 + */
773 +static int
774 +ext4_expand_ino_array(struct ext4_xattr_ino_array **lea_ino_array, __u32 ino)
775 +{
776 +       if (*lea_ino_array == NULL) {
777 +               /*
778 +                * Start with 15 inodes, so it fits into a power-of-two size.
779 +                * If *lea_ino_array is NULL, this is essentially offsetof()
780 +                */
781 +               (*lea_ino_array) =
782 +                       kmalloc(offsetof(struct ext4_xattr_ino_array,
783 +                                        xia_inodes[EIA_MASK]),
784 +                               GFP_NOFS);
785 +               if (*lea_ino_array == NULL)
786 +                       return -ENOMEM;
787 +               (*lea_ino_array)->xia_count = 0;
788 +       } else if (((*lea_ino_array)->xia_count & EIA_MASK) == EIA_MASK) {
789 +               /* expand the array once all 15 + n * 16 slots are full */
790 +               struct ext4_xattr_ino_array *new_array = NULL;
791 +               int count = (*lea_ino_array)->xia_count;
792 +
793 +               /* if new_array is NULL, this is essentially offsetof() */
794 +               new_array = kmalloc(
795 +                               offsetof(struct ext4_xattr_ino_array,
796 +                                        xia_inodes[count + EIA_INCR]),
797 +                               GFP_NOFS);
798 +               if (new_array == NULL)
799 +                       return -ENOMEM;
800 +               memcpy(new_array, *lea_ino_array,
801 +                      offsetof(struct ext4_xattr_ino_array,
802 +                               xia_inodes[count]));
803 +               kfree(*lea_ino_array);
804 +               *lea_ino_array = new_array;
805 +       }
806 +       (*lea_ino_array)->xia_inodes[(*lea_ino_array)->xia_count++] = ino;
807 +       return 0;
808 +}
809 +
810 +/**
811 + * Add xattr inode to orphan list
812 + */
813 +static int
814 +ext4_xattr_inode_orphan_add(handle_t *handle, struct inode *inode,
815 +                       int credits, struct ext4_xattr_ino_array *lea_ino_array)
816 +{
817 +       struct inode *ea_inode = NULL;
818 +       int idx = 0, error = 0;
819 +
820 +       if (lea_ino_array == NULL)
821 +               return 0;
822 +
823 +       for (; idx < lea_ino_array->xia_count; ++idx) {
824 +               if (!ext4_handle_has_enough_credits(handle, credits)) {
825 +                       error = ext4_journal_extend(handle, credits);
826 +                       if (error > 0)
827 +                               error = ext4_journal_restart(handle, credits);
828 +
829 +                       if (error != 0) {
830 +                               ext4_warning(inode->i_sb,
831 +                                       "couldn't extend journal "
832 +                                       "(err %d)", error);
833 +                               return error;
834 +                       }
835 +               }
836 +               ea_inode = ext4_xattr_inode_iget(inode,
837 +                               lea_ino_array->xia_inodes[idx], &error);
838 +               if (error)
839 +                       continue;
840 +               ext4_orphan_add(handle, ea_inode);
841 +               /* the inode's i_count will be released by caller */
842 +       }
843 +
844 +       return 0;
845 +}
846  
847  /*
848   * ext4_xattr_delete_inode()
849   *
850 - * Free extended attribute resources associated with this inode. This
851 + * Free extended attribute resources associated with this inode. Traverse
852 + * all entries and unlink any xattr inodes associated with this inode. This
853   * is called immediately before an inode is freed. We have exclusive
854 - * access to the inode.
855 + * access to the inode. If an orphan inode is deleted it will also delete any
856 + * xattr block and all xattr inodes. They are checked by ext4_xattr_inode_iget()
857 + * to ensure they belong to the parent inode and were not deleted already.
858   */
859 -void
860 -ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
861 +int
862 +ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
863 +                       struct ext4_xattr_ino_array **lea_ino_array)
864  {
865         struct buffer_head *bh = NULL;
866 +       struct ext4_xattr_ibody_header *header;
867 +       struct ext4_inode *raw_inode;
868 +       struct ext4_iloc iloc;
869 +       struct ext4_xattr_entry *entry;
870 +       int credits = 3, error = 0;
871  
872 -       if (!EXT4_I(inode)->i_file_acl)
873 +       if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR))
874 +               goto delete_external_ea;
875 +
876 +       error = ext4_get_inode_loc(inode, &iloc);
877 +       if (error)
878 +               goto cleanup;
879 +       raw_inode = ext4_raw_inode(&iloc);
880 +       header = IHDR(inode, raw_inode);
881 +       for (entry = IFIRST(header); !IS_LAST_ENTRY(entry);
882 +            entry = EXT4_XATTR_NEXT(entry)) {
883 +               if (!entry->e_value_inum)
884 +                       continue;
885 +               if (ext4_expand_ino_array(lea_ino_array,
886 +                                         entry->e_value_inum) != 0) {
887 +                       brelse(iloc.bh);
888 +                       goto cleanup;
889 +               }
890 +               entry->e_value_inum = 0;
891 +       }
892 +       brelse(iloc.bh);
893 +
894 +delete_external_ea:
895 +       if (!EXT4_I(inode)->i_file_acl) {
896 +               /* add xattr inode to orphan list */
897 +               ext4_xattr_inode_orphan_add(handle, inode, credits,
898 +                                               *lea_ino_array);
899                 goto cleanup;
900 +       }
901         bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
902         if (!bh) {
903                 EXT4_ERROR_INODE(inode, "block %llu read error",
904 @@ -1496,11 +1954,69 @@ ext4_xattr_delete_inode(handle_t *handle
905                                  EXT4_I(inode)->i_file_acl);
906                 goto cleanup;
907         }
908 +
909 +       for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);
910 +            entry = EXT4_XATTR_NEXT(entry)) {
911 +               if (!entry->e_value_inum)
912 +                       continue;
913 +               if (ext4_expand_ino_array(lea_ino_array,
914 +                                         entry->e_value_inum) != 0)
915 +                       goto cleanup;
916 +               entry->e_value_inum = 0;
917 +       }
918 +
919 +       /* add xattr inode to orphan list */
920 +       error = ext4_xattr_inode_orphan_add(handle, inode, credits,
921 +                                       *lea_ino_array);
922 +       if (error != 0)
923 +               goto cleanup;
924 +
925 +       if (!IS_NOQUOTA(inode))
926 +               credits += 2 * EXT4_QUOTA_DEL_BLOCKS(inode->i_sb);
927 +
928 +       if (!ext4_handle_has_enough_credits(handle, credits)) {
929 +               error = ext4_journal_extend(handle, credits);
930 +               if (error > 0)
931 +                       error = ext4_journal_restart(handle, credits);
932 +               if (error != 0) {
933 +                       ext4_warning(inode->i_sb,
934 +                               "couldn't extend journal (err %d)", error);
935 +                       goto cleanup;
936 +               }
937 +       }
938 +
939         ext4_xattr_release_block(handle, inode, bh);
940         EXT4_I(inode)->i_file_acl = 0;
941  
942  cleanup:
943         brelse(bh);
944 +
945 +       return error;
946 +}
947 +
948 +void
949 +ext4_xattr_inode_array_free(struct inode *inode,
950 +                           struct ext4_xattr_ino_array *lea_ino_array)
951 +{
952 +       struct inode    *ea_inode = NULL;
953 +       int             idx = 0;
954 +       int             err;
955 +
956 +       if (lea_ino_array == NULL)
957 +               return;
958 +
959 +       for (; idx < lea_ino_array->xia_count; ++idx) {
960 +               ea_inode = ext4_xattr_inode_iget(inode,
961 +                               lea_ino_array->xia_inodes[idx], &err);
962 +               if (err)
963 +                       continue;
964 +               /* for inode's i_count get from ext4_xattr_delete_inode */
965 +               if (!list_empty(&EXT4_I(ea_inode)->i_orphan))
966 +                       iput(ea_inode);
967 +               clear_nlink(ea_inode);
968 +               iput(ea_inode);
969 +       }
970 +       kfree(lea_ino_array);
971  }
972  
973  /*
974 @@ -1570,10 +2086,9 @@ ext4_xattr_cmp(struct ext4_xattr_header
975                     entry1->e_name_index != entry2->e_name_index ||
976                     entry1->e_name_len != entry2->e_name_len ||
977                     entry1->e_value_size != entry2->e_value_size ||
978 +                   entry1->e_value_inum != entry2->e_value_inum ||
979                     memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
980                         return 1;
981 -               if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
982 -                       return -EIO;
983                 if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
984                            (char *)header2 + le16_to_cpu(entry2->e_value_offs),
985                            le32_to_cpu(entry1->e_value_size)))
986 @@ -1657,7 +2172,7 @@ static inline void ext4_xattr_hash_entry
987                        *name++;
988         }
989  
990 -       if (entry->e_value_block == 0 && entry->e_value_size != 0) {
991 +       if (!entry->e_value_inum && entry->e_value_size) {
992                 __le32 *value = (__le32 *)((char *)header +
993                         le16_to_cpu(entry->e_value_offs));
994                 for (n = (le32_to_cpu(entry->e_value_size) +
995 Index: linux-stage/fs/ext4/xattr.h
996 ===================================================================
997 --- linux-stage.orig/fs/ext4/xattr.h
998 +++ linux-stage/fs/ext4/xattr.h
999 @@ -42,7 +42,7 @@ struct ext4_xattr_entry {
1000         __u8    e_name_len;     /* length of name */
1001         __u8    e_name_index;   /* attribute name index */
1002         __le16  e_value_offs;   /* offset in disk block of value */
1003 -       __le32  e_value_block;  /* disk block attribute is stored on (n/i) */
1004 +       __le32  e_value_inum;   /* inode in which the value is stored */
1005         __le32  e_value_size;   /* size of attribute value */
1006         __le32  e_hash;         /* hash value of name and value */
1007         char    e_name[0];      /* attribute name */
1008 @@ -67,6 +67,26 @@ struct ext4_xattr_entry {
1009                 EXT4_I(inode)->i_extra_isize))
1010  #define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
1011  
1012 +/*
1013 + * Link EA inode back to parent one using i_mtime field.
1014 + * Extra integer type conversion added to ignore higher
1015 + * bits in i_mtime.tv_sec which might be set by ext4_get()
1016 + */
1017 +#define EXT4_XATTR_INODE_SET_PARENT(inode, inum)       \
1018 +do {                                                   \
1019 +       (inode)->i_mtime.tv_sec = inum;                 \
1020 +} while(0)
1021 +
1022 +#define EXT4_XATTR_INODE_GET_PARENT(inode)             \
1023 +       ((__u32)(inode)->i_mtime.tv_sec)
1024 +
1025 +/*
1026 + * The minimum size of EA value when you start storing it in an external inode
1027 + * size of block - size of header - size of 1 entry - 4 null bytes
1028 +*/
1029 +#define EXT4_XATTR_MIN_LARGE_EA_SIZE(b)                                        \
1030 +       ((b) - EXT4_XATTR_LEN(3) - sizeof(struct ext4_xattr_header) - 4)
1031 +
1032  #define BHDR(bh) ((struct ext4_xattr_header *)((bh)->b_data))
1033  #define ENTRY(ptr) ((struct ext4_xattr_entry *)(ptr))
1034  #define BFIRST(bh) ENTRY(BHDR(bh)+1)
1035 @@ -75,10 +95,11 @@ struct ext4_xattr_entry {
1036  #define EXT4_ZERO_XATTR_VALUE ((void *)-1)
1037  
1038  struct ext4_xattr_info {
1039 -       int name_index;
1040         const char *name;
1041         const void *value;
1042         size_t value_len;
1043 +       int name_index;
1044 +       int in_inode;
1045  };
1046  
1047  struct ext4_xattr_search {
1048 @@ -106,7 +127,13 @@ extern int ext4_xattr_get(struct inode *
1049  extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
1050  extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
1051  
1052 -extern void ext4_xattr_delete_inode(handle_t *, struct inode *);
1053 +extern struct inode *ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,
1054 +                                          int *err);
1055 +extern int ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino);
1056 +extern int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
1057 +                                  struct ext4_xattr_ino_array **array);
1058 +extern void ext4_xattr_inode_array_free(struct inode *inode,
1059 +                                       struct ext4_xattr_ino_array *array);
1060  extern void ext4_xattr_put_super(struct super_block *);
1061  
1062  extern int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
1063 Index: linux-stage/fs/ext4/ialloc.c
1064 ===================================================================
1065 --- linux-stage.orig/fs/ext4/ialloc.c
1066 +++ linux-stage/fs/ext4/ialloc.c
1067 @@ -247,7 +247,6 @@ void ext4_free_inode(handle_t *handle, s
1068          * as writing the quota to disk may need the lock as well.
1069          */
1070         dquot_initialize(inode);
1071 -       ext4_xattr_delete_inode(handle, inode);
1072         dquot_free_inode(inode);
1073         dquot_drop(inode);
1074  
1075 Index: linux-stage/fs/ext4/inline.c
1076 ===================================================================
1077 --- linux-stage.orig/fs/ext4/inline.c
1078 +++ linux-stage/fs/ext4/inline.c
1079 @@ -59,7 +59,7 @@ static int get_max_inline_xattr_value_si
1080  
1081         /* Compute min_offs. */
1082         for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
1083 -               if (!entry->e_value_block && entry->e_value_size) {
1084 +               if (!entry->e_value_inum && entry->e_value_size) {
1085                         size_t offs = le16_to_cpu(entry->e_value_offs);
1086                         if (offs < min_offs)
1087                                 min_offs = offs;
1088 Index: linux-stage/fs/ext4/extents.c
1089 ===================================================================
1090 --- linux-stage.orig/fs/ext4/extents.c
1091 +++ linux-stage/fs/ext4/extents.c
1092 @@ -2461,7 +2461,8 @@ int ext4_ext_index_trans_blocks(struct i
1093  
1094  static inline int get_default_free_blocks_flags(struct inode *inode)
1095  {
1096 -       if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
1097 +       if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode) ||
1098 +               ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE))
1099                 return EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET;
1100         else if (ext4_should_journal_data(inode))
1101                 return EXT4_FREE_BLOCKS_FORGET;
1102 Index: linux-stage/fs/ext4/indirect.c
1103 ===================================================================
1104 --- linux-stage.orig/fs/ext4/indirect.c
1105 +++ linux-stage/fs/ext4/indirect.c
1106 @@ -959,7 +959,8 @@ static int ext4_clear_blocks(handle_t *h
1107         int     flags = EXT4_FREE_BLOCKS_VALIDATED;
1108         int     err;
1109  
1110 -       if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
1111 +       if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode) ||
1112 +               ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE))
1113                 flags |= EXT4_FREE_BLOCKS_FORGET | EXT4_FREE_BLOCKS_METADATA;
1114         else if (ext4_should_journal_data(inode))
1115                 flags |= EXT4_FREE_BLOCKS_FORGET;