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