1 Index: linux-stage/fs/ext4/ext4.h
2 ===================================================================
3 --- linux-stage.orig/fs/ext4/ext4.h
4 +++ linux-stage/fs/ext4/ext4.h
5 @@ -1333,6 +1333,7 @@ EXT4_INODE_BIT_FNS(state, state_flags)
6 #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
7 #define EXT4_FEATURE_INCOMPAT_MMP 0x0100
8 #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
9 +#define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400
10 #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000
12 #define EXT4_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
13 @@ -1342,6 +1343,7 @@ EXT4_INODE_BIT_FNS(state, state_flags)
14 EXT4_FEATURE_INCOMPAT_EXTENTS| \
15 EXT4_FEATURE_INCOMPAT_64BIT| \
16 EXT4_FEATURE_INCOMPAT_FLEX_BG| \
17 + EXT4_FEATURE_INCOMPAT_EA_INODE| \
18 EXT4_FEATURE_INCOMPAT_MMP| \
19 EXT4_FEATURE_INCOMPAT_DIRDATA)
21 @@ -1706,6 +1708,12 @@ struct mmpd_data {
25 + * Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb
26 + * This limit is arbitrary, but is reasonable for the xattr API.
28 +#define EXT4_XATTR_MAX_LARGE_EA_SIZE (1024 * 1024)
34 @@ -1717,6 +1725,10 @@ struct mmpd_data {
35 # define ATTRIB_NORET __attribute__((noreturn))
36 # define NORET_AND noreturn,
38 +struct ext4_xattr_ino_array {
39 + unsigned int xia_count; /* # of used item in the array */
40 + unsigned int xia_inodes[0];
43 extern unsigned int ext4_count_free(struct buffer_head *, unsigned);
45 Index: linux-stage/fs/ext4/xattr.c
46 ===================================================================
47 --- linux-stage.orig/fs/ext4/xattr.c
48 +++ linux-stage/fs/ext4/xattr.c
49 @@ -168,19 +168,26 @@ ext4_xattr_check_block(struct buffer_hea
53 -ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size)
54 +ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size,
55 + struct inode *inode)
57 size_t value_size = le32_to_cpu(entry->e_value_size);
59 - if (entry->e_value_block != 0 || value_size > size ||
60 - le16_to_cpu(entry->e_value_offs) + value_size > size)
61 + if ((entry->e_value_inum == 0) &&
62 + (le16_to_cpu(entry->e_value_offs) + value_size > size))
64 + if (entry->e_value_inum != 0 &&
65 + (le32_to_cpu(entry->e_value_inum) < EXT4_FIRST_INO(inode->i_sb) ||
66 + le32_to_cpu(entry->e_value_inum) >
67 + le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_inodes_count)))
73 ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
74 - const char *name, size_t size, int sorted)
75 + const char *name, size_t size, int sorted,
76 + struct inode *inode)
78 struct ext4_xattr_entry *entry;
80 @@ -200,11 +207,103 @@ ext4_xattr_find_entry(struct ext4_xattr_
84 - if (!cmp && ext4_xattr_check_entry(entry, size))
85 + if (!cmp && ext4_xattr_check_entry(entry, size, inode))
87 return cmp ? -ENODATA : 0;
91 + * Read the EA value from an inode.
94 +ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t *size)
96 + unsigned long block = 0;
97 + struct buffer_head *bh = NULL;
99 + size_t csize, ret_size = 0;
104 + blocksize = ea_inode->i_sb->s_blocksize;
106 + while (ret_size < *size) {
107 + csize = (*size - ret_size) > blocksize ? blocksize :
109 + bh = ext4_bread(NULL, ea_inode, block, 0, &err);
114 + memcpy(buf, bh->b_data, csize);
127 +struct inode *ext4_xattr_inode_iget(struct inode *parent, int ea_ino, int *err)
129 + struct inode *ea_inode = NULL;
131 + ea_inode = ext4_iget(parent->i_sb, ea_ino);
132 + if (IS_ERR(ea_inode) || is_bad_inode(ea_inode)) {
133 + ext4_error(parent->i_sb, "error while reading EA inode %d",
139 + if (ea_inode->i_xattr_inode_parent != parent->i_ino ||
140 + ea_inode->i_generation != parent->i_generation) {
141 + ext4_error(parent->i_sb, "Backpointer from EA inode %d "
142 + "to parent invalid.", ea_ino);
147 + if (!(EXT4_I(ea_inode)->i_flags & EXT4_EA_INODE_FL)) {
148 + ext4_error(parent->i_sb, "EA inode %d does not have "
149 + "EXT4_EA_INODE_FL flag set.\n", ea_ino);
163 + * Read the value from the EA inode.
166 +ext4_xattr_inode_get(struct inode *inode, int ea_ino, void *buffer,
169 + struct inode *ea_inode = NULL;
172 + ea_inode = ext4_xattr_inode_iget(inode, ea_ino, &err);
176 + err = ext4_xattr_inode_read(ea_inode, buffer, size);
183 ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
184 void *buffer, size_t buffer_size)
185 @@ -236,7 +335,8 @@ bad_block:
187 ext4_xattr_cache_insert(bh);
189 - error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1);
190 + error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1,
195 @@ -246,8 +346,16 @@ bad_block:
197 if (size > buffer_size)
199 - memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
201 + if (entry->e_value_inum != 0) {
202 + error = ext4_xattr_inode_get(inode,
203 + le32_to_cpu(entry->e_value_inum),
208 + memcpy(buffer, bh->b_data +
209 + le16_to_cpu(entry->e_value_offs), size);
214 @@ -281,7 +389,7 @@ ext4_xattr_ibody_get(struct inode *inode
217 error = ext4_xattr_find_entry(&entry, name_index, name,
218 - end - (void *)entry, 0);
219 + end - (void *)entry, 0, inode);
222 size = le32_to_cpu(entry->e_value_size);
223 @@ -289,8 +397,16 @@ ext4_xattr_ibody_get(struct inode *inode
225 if (size > buffer_size)
227 - memcpy(buffer, (void *)IFIRST(header) +
228 - le16_to_cpu(entry->e_value_offs), size);
229 + if (entry->e_value_inum != 0) {
230 + error = ext4_xattr_inode_get(inode,
231 + le32_to_cpu(entry->e_value_inum),
236 + memcpy(buffer, (void *)IFIRST(header) +
237 + le16_to_cpu(entry->e_value_offs), size);
242 @@ -513,7 +629,7 @@ static size_t ext4_xattr_free_space(stru
244 for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
245 *total += EXT4_XATTR_LEN(last->e_name_len);
246 - if (!last->e_value_block && last->e_value_size) {
247 + if (last->e_value_inum == 0 && last->e_value_size > 0) {
248 size_t offs = le16_to_cpu(last->e_value_offs);
249 if (offs < *min_offs)
251 @@ -522,11 +638,159 @@ static size_t ext4_xattr_free_space(stru
252 return (*min_offs - ((void *)last - base) - sizeof(__u32));
256 + * Write the value of the EA in an inode.
259 +ext4_xattr_inode_write(handle_t *handle, struct inode *ea_inode,
260 + const void *buf, int bufsize)
262 + struct buffer_head *bh = NULL, dummy;
263 + unsigned long block = 0;
264 + unsigned blocksize = ea_inode->i_sb->s_blocksize;
265 + unsigned max_blocks = (bufsize + blocksize - 1) >> ea_inode->i_blkbits;
266 + int csize, wsize = 0;
271 + while (ret >= 0 && ret < max_blocks) {
275 + ret = ext4_get_blocks(handle, ea_inode, block, max_blocks,
276 + &dummy, EXT4_GET_BLOCKS_CREATE);
278 + ext4_mark_inode_dirty(handle, ea_inode);
279 + if (ret == -ENOSPC &&
280 + ext4_should_retry_alloc(ea_inode->i_sb, &retries)) {
292 + while (wsize < bufsize) {
295 + csize = (bufsize - wsize) > blocksize ? blocksize :
297 + bh = ext4_getblk(handle, ea_inode, block, 0, &ret);
300 + ret = ext4_journal_get_write_access(handle, bh);
304 + memcpy(bh->b_data, buf, csize);
305 + set_buffer_uptodate(bh);
306 + ext4_handle_dirty_metadata(handle, ea_inode, bh);
313 + i_size_write(ea_inode, wsize);
314 + ext4_update_i_disksize(ea_inode, wsize);
316 + ext4_mark_inode_dirty(handle, ea_inode);
325 + * Create an inode to store the value of a large EA.
327 +static struct inode *
328 +ext4_xattr_inode_create(handle_t *handle, struct inode *inode)
330 + struct inode *ea_inode = NULL;
333 + * Let the next inode be the goal, so we try and allocate the EA inode
334 + * in the same group, or nearby one.
336 + ea_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
337 + S_IFREG|0600, NULL, inode->i_ino + 1);
339 + if (!IS_ERR(ea_inode)) {
340 + ea_inode->i_op = &ext4_file_inode_operations;
341 + ea_inode->i_fop = &ext4_file_operations;
342 + ext4_set_aops(ea_inode);
343 + ea_inode->i_generation = inode->i_generation;
344 + EXT4_I(ea_inode)->i_flags |= EXT4_EA_INODE_FL;
347 + * A back-pointer from EA inode to parent inode will be useful
350 + ea_inode->i_xattr_inode_parent = inode->i_ino;
351 + unlock_new_inode(ea_inode);
358 + * Unlink the inode storing the value of the EA.
361 +ext4_xattr_inode_unlink(struct inode *inode, int ea_ino)
363 + struct inode *ea_inode = NULL;
366 + ea_inode = ext4_xattr_inode_iget(inode, ea_ino, &err);
370 + ea_inode->i_nlink = 0;
377 + * Add value of the EA in an inode.
380 +ext4_xattr_inode_set(handle_t *handle, struct inode *inode, int *ea_ino,
381 + const void *value, size_t value_len)
383 + struct inode *ea_inode = NULL;
386 + /* Create an inode for the EA value */
387 + ea_inode = ext4_xattr_inode_create(handle, inode);
388 + if (IS_ERR(ea_inode))
391 + err = ext4_xattr_inode_write(handle, ea_inode, value, value_len);
393 + ea_inode->i_nlink = 0;
395 + *ea_ino = ea_inode->i_ino;
402 struct ext4_xattr_info {
411 struct ext4_xattr_search {
412 @@ -538,15 +802,23 @@ struct ext4_xattr_search {
416 -ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
417 +ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s,
418 + handle_t *handle, struct inode *inode)
420 struct ext4_xattr_entry *last;
421 size_t free, min_offs = s->end - s->base, name_len = strlen(i->name);
422 + int in_inode = i->in_inode;
424 + if (EXT4_HAS_INCOMPAT_FEATURE(inode->i_sb,
425 + EXT4_FEATURE_INCOMPAT_EA_INODE) &&
426 + (EXT4_XATTR_SIZE(i->value_len) >
427 + EXT4_XATTR_MIN_LARGE_EA_SIZE(inode->i_sb->s_blocksize)))
430 /* Compute min_offs and last. */
432 for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
433 - if (!last->e_value_block && last->e_value_size) {
434 + if (last->e_value_inum == 0 && last->e_value_size > 0) {
435 size_t offs = le16_to_cpu(last->e_value_offs);
438 @@ -554,16 +826,21 @@ ext4_xattr_set_entry(struct ext4_xattr_i
440 free = min_offs - ((void *)last - s->base) - sizeof(__u32);
442 - if (!s->here->e_value_block && s->here->e_value_size) {
443 + if (!in_inode && s->here->e_value_inum == 0 &&
444 + s->here->e_value_size > 0) {
445 size_t size = le32_to_cpu(s->here->e_value_size);
446 free += EXT4_XATTR_SIZE(size);
448 free += EXT4_XATTR_LEN(name_len);
451 - if (free < EXT4_XATTR_SIZE(i->value_len) ||
452 - free < EXT4_XATTR_LEN(name_len) +
453 - EXT4_XATTR_SIZE(i->value_len))
454 + size_t value_len = EXT4_XATTR_SIZE(i->value_len);
459 + if (free < value_len ||
460 + free < EXT4_XATTR_LEN(name_len) + value_len)
464 @@ -577,7 +854,8 @@ ext4_xattr_set_entry(struct ext4_xattr_i
465 s->here->e_name_len = name_len;
466 memcpy(s->here->e_name, i->name, name_len);
468 - if (!s->here->e_value_block && s->here->e_value_size) {
469 + if (s->here->e_value_offs > 0 && s->here->e_value_inum == 0 &&
470 + s->here->e_value_size > 0) {
471 void *first_val = s->base + min_offs;
472 size_t offs = le16_to_cpu(s->here->e_value_offs);
473 void *val = s->base + offs;
474 @@ -606,13 +884,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
476 while (!IS_LAST_ENTRY(last)) {
477 size_t o = le16_to_cpu(last->e_value_offs);
478 - if (!last->e_value_block &&
479 - last->e_value_size && o < offs)
480 + if (last->e_value_size > 0 && o < offs)
482 cpu_to_le16(o + size);
483 last = EXT4_XATTR_NEXT(last);
486 + if (s->here->e_value_inum != 0) {
487 + ext4_xattr_inode_unlink(inode,
488 + le32_to_cpu(s->here->e_value_inum));
489 + s->here->e_value_inum = 0;
492 /* Remove the old name. */
493 size_t size = EXT4_XATTR_LEN(name_len);
494 @@ -626,10 +908,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
496 /* Insert the new value. */
497 s->here->e_value_size = cpu_to_le32(i->value_len);
498 - if (i->value_len) {
500 + int ea_ino = le32_to_cpu(s->here->e_value_inum);
501 + ext4_xattr_inode_set(handle, inode, &ea_ino, i->value,
503 + s->here->e_value_inum = cpu_to_le32(ea_ino);
504 + s->here->e_value_offs = 0;
505 + } else if (i->value_len) {
506 size_t size = EXT4_XATTR_SIZE(i->value_len);
507 void *val = s->base + min_offs - size;
508 s->here->e_value_offs = cpu_to_le16(min_offs - size);
509 + s->here->e_value_inum = 0;
510 memset(val + size - EXT4_XATTR_PAD, 0,
511 EXT4_XATTR_PAD); /* Clear the pad bytes. */
512 memcpy(val, i->value, i->value_len);
513 @@ -674,7 +963,7 @@ ext4_xattr_block_find(struct inode *inod
514 bs->s.end = bs->bh->b_data + bs->bh->b_size;
515 bs->s.here = bs->s.first;
516 error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
517 - i->name, bs->bh->b_size, 1);
518 + i->name, bs->bh->b_size, 1, inode);
519 if (error && error != -ENODATA)
521 bs->s.not_found = error;
522 @@ -698,8 +987,6 @@ ext4_xattr_block_set(handle_t *handle, s
524 #define header(x) ((struct ext4_xattr_header *)(x))
526 - if (i->value && i->value_len > sb->s_blocksize)
529 ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
531 @@ -714,7 +1001,7 @@ ext4_xattr_block_set(handle_t *handle, s
534 ea_bdebug(bs->bh, "modifying in-place");
535 - error = ext4_xattr_set_entry(i, s);
536 + error = ext4_xattr_set_entry(i, s, handle, inode);
538 if (!IS_LAST_ENTRY(s->first))
539 ext4_xattr_rehash(header(s->base),
540 @@ -766,7 +1053,7 @@ ext4_xattr_block_set(handle_t *handle, s
541 s->end = s->base + sb->s_blocksize;
544 - error = ext4_xattr_set_entry(i, s);
545 + error = ext4_xattr_set_entry(i, s, handle, inode);
549 @@ -917,7 +1204,7 @@ ext4_xattr_ibody_find(struct inode *inod
550 /* Find the named attribute. */
551 error = ext4_xattr_find_entry(&is->s.here, i->name_index,
553 - (void *)is->s.base, 0);
554 + (void *)is->s.base, 0, inode);
555 if (error && error != -ENODATA)
557 is->s.not_found = error;
558 @@ -936,7 +1223,7 @@ ext4_xattr_ibody_set(handle_t *handle, s
560 if (EXT4_I(inode)->i_extra_isize == 0)
562 - error = ext4_xattr_set_entry(i, s);
563 + error = ext4_xattr_set_entry(i, s, handle, inode);
566 header = IHDR(inode, ext4_raw_inode(&is->iloc));
567 @@ -972,7 +1259,7 @@ ext4_xattr_set_handle(handle_t *handle,
570 .value_len = value_len,
574 struct ext4_xattr_ibody_find is = {
575 .s = { .not_found = -ENODATA, },
576 @@ -1041,6 +1328,15 @@ ext4_xattr_set_handle(handle_t *handle,
579 error = ext4_xattr_block_set(handle, inode, &i, &bs);
580 + if (EXT4_HAS_INCOMPAT_FEATURE(inode->i_sb,
581 + EXT4_FEATURE_INCOMPAT_EA_INODE) &&
582 + error == -ENOSPC) {
583 + /* xattr not fit to block, store at external
586 + error = ext4_xattr_ibody_set(handle, inode,
591 if (!is.s.not_found) {
592 @@ -1088,10 +1384,25 @@ ext4_xattr_set(struct inode *inode, int
593 const void *value, size_t value_len, int flags)
596 + struct super_block *sb = inode->i_sb;
597 + int buffer_credits;
598 int error, retries = 0;
600 + buffer_credits = EXT4_DATA_TRANS_BLOCKS(sb);
601 + if ((value_len >= EXT4_XATTR_MIN_LARGE_EA_SIZE(sb->s_blocksize)) &&
602 + EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EA_INODE)) {
603 + int nrblocks = (value_len + sb->s_blocksize - 1) >>
604 + sb->s_blocksize_bits;
606 + /* For new inode */
607 + buffer_credits += EXT4_SINGLEDATA_TRANS_BLOCKS(sb) + 3;
609 + /* For data blocks of EA inode */
610 + buffer_credits += ext4_meta_trans_blocks(inode, nrblocks, 0);
614 - handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
615 + handle = ext4_journal_start(inode, buffer_credits);
616 if (IS_ERR(handle)) {
617 error = PTR_ERR(handle);
619 @@ -1101,7 +1412,7 @@ retry:
620 value, value_len, flags);
621 error2 = ext4_journal_stop(handle);
622 if (error == -ENOSPC &&
623 - ext4_should_retry_alloc(inode->i_sb, &retries))
624 + ext4_should_retry_alloc(sb, &retries))
628 @@ -1123,7 +1434,7 @@ static void ext4_xattr_shift_entries(str
630 /* Adjust the value offsets of the entries */
631 for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
632 - if (!last->e_value_block && last->e_value_size) {
633 + if (last->e_value_inum == 0 && last->e_value_size > 0) {
634 new_offs = le16_to_cpu(last->e_value_offs) +
636 BUG_ON(new_offs + le32_to_cpu(last->e_value_size)
637 @@ -1356,20 +1667,89 @@ cleanup:
642 +#define EIA_INCR 16 /* must be 2^n */
643 +#define EIA_MASK (EIA_INCR - 1)
644 +/* Add the large xattr @ino into @lea_ino_array for later deletion.
645 + * If @lea_ino_array is new or full it will be grown and the old
646 + * contents copied over.
649 +ext4_expand_ino_array(struct ext4_xattr_ino_array **lea_ino_array, __u32 ino)
651 + if (*lea_ino_array == NULL) {
653 + * Start with 15 inodes, so it fits into a power-of-two size.
654 + * If *lea_ino_array is NULL, this is essentially offsetof()
657 + kmalloc(offsetof(struct ext4_xattr_ino_array,
658 + xia_inodes[EIA_MASK]),
660 + if (*lea_ino_array == NULL)
662 + (*lea_ino_array)->xia_count = 0;
663 + } else if (((*lea_ino_array)->xia_count & EIA_MASK) == EIA_MASK) {
664 + /* expand the array once all 15 + n * 16 slots are full */
665 + struct ext4_xattr_ino_array *new_array = NULL;
666 + int count = (*lea_ino_array)->xia_count;
668 + /* if new_array is NULL, this is essentially offsetof() */
669 + new_array = kmalloc(
670 + offsetof(struct ext4_xattr_ino_array,
671 + xia_inodes[count + EIA_INCR]),
673 + if (new_array == NULL)
675 + memcpy(new_array, *lea_ino_array,
676 + offsetof(struct ext4_xattr_ino_array,
677 + xia_inodes[count]));
678 + kfree(*lea_ino_array);
679 + *lea_ino_array = new_array;
681 + (*lea_ino_array)->xia_inodes[(*lea_ino_array)->xia_count++] = ino;
686 * ext4_xattr_delete_inode()
688 - * Free extended attribute resources associated with this inode. This
689 + * Free extended attribute resources associated with this inode. Traverse
690 + * all entries and unlink any xattr inodes associated with this inode. This
691 * is called immediately before an inode is freed. We have exclusive
692 - * access to the inode.
693 + * access to the inode. If an orphan inode is deleted it will also delete any
694 + * xattr block and all xattr inodes. They are checked by ext4_xattr_inode_iget()
695 + * to ensure they belong to the parent inode and were not deleted already.
698 -ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
700 +ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
701 + struct ext4_xattr_ino_array **lea_ino_array)
703 struct buffer_head *bh = NULL;
704 + struct ext4_xattr_ibody_header *header;
705 + struct ext4_inode *raw_inode;
706 + struct ext4_iloc iloc;
707 + struct ext4_xattr_entry *entry;
710 + if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR))
711 + goto delete_external_ea;
713 + error = ext4_get_inode_loc(inode, &iloc);
716 + raw_inode = ext4_raw_inode(&iloc);
717 + header = IHDR(inode, raw_inode);
718 + entry = IFIRST(header);
719 + for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
720 + if (entry->e_value_inum == 0)
722 + if (ext4_expand_ino_array(lea_ino_array,
723 + entry->e_value_inum) != 0)
725 + entry->e_value_inum = 0;
729 if (!EXT4_I(inode)->i_file_acl)
731 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
732 @@ -1384,11 +1764,74 @@ ext4_xattr_delete_inode(handle_t *handle
733 inode->i_ino, EXT4_I(inode)->i_file_acl);
737 + entry = BFIRST(bh);
738 + for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
739 + if (entry->e_value_inum == 0)
741 + if (ext4_expand_ino_array(lea_ino_array,
742 + entry->e_value_inum) != 0)
744 + entry->e_value_inum = 0;
747 + /* add xattr inode to orphan list */
748 + if (*lea_ino_array != NULL) {
749 + struct inode *ea_inode = NULL;
752 + for (; idx < (*lea_ino_array)->xia_count; ++idx) {
753 + if (!ext4_handle_has_enough_credits(handle, 3)) {
754 + error = ext4_journal_extend(handle, 3);
756 + error = ext4_journal_restart(handle, 3);
758 + ext4_warning(inode->i_sb,
759 + "couldn't extend journal "
760 + "(err %d)", error);
764 + ea_inode = ext4_xattr_inode_iget(inode,
765 + (*lea_ino_array)->xia_inodes[idx], &error);
768 + ext4_orphan_add(handle, ea_inode);
769 + /* the inode's i_count will be released by caller */
773 ext4_xattr_release_block(handle, inode, bh);
774 EXT4_I(inode)->i_file_acl = 0;
783 +ext4_xattr_inode_array_free(struct inode *inode,
784 + struct ext4_xattr_ino_array *lea_ino_array)
786 + struct inode *ea_inode = NULL;
790 + if (lea_ino_array == NULL)
793 + for (; idx < lea_ino_array->xia_count; ++idx) {
794 + ea_inode = ext4_xattr_inode_iget(inode,
795 + lea_ino_array->xia_inodes[idx], &err);
798 + ea_inode->i_nlink = 0;
800 + /* for inode's i_count get from ext4_xattr_delete_inode */
803 + kfree(lea_ino_array);
807 @@ -1458,10 +1901,9 @@ ext4_xattr_cmp(struct ext4_xattr_header
808 entry1->e_name_index != entry2->e_name_index ||
809 entry1->e_name_len != entry2->e_name_len ||
810 entry1->e_value_size != entry2->e_value_size ||
811 + entry1->e_value_inum != entry2->e_value_inum ||
812 memcmp(entry1->e_name, entry2->e_name, entry1->e_name_len))
814 - if (entry1->e_value_block != 0 || entry2->e_value_block != 0)
816 if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
817 (char *)header2 + le16_to_cpu(entry2->e_value_offs),
818 le32_to_cpu(entry1->e_value_size)))
819 @@ -1546,7 +1988,7 @@ static inline void ext4_xattr_hash_entry
823 - if (entry->e_value_block == 0 && entry->e_value_size != 0) {
824 + if (entry->e_value_inum == 0 && entry->e_value_size != 0) {
825 __le32 *value = (__le32 *)((char *)header +
826 le16_to_cpu(entry->e_value_offs));
827 for (n = (le32_to_cpu(entry->e_value_size) +
828 Index: linux-stage/fs/ext4/xattr.h
829 ===================================================================
830 --- linux-stage.orig/fs/ext4/xattr.h
831 +++ linux-stage/fs/ext4/xattr.h
832 @@ -38,7 +38,7 @@ struct ext4_xattr_entry {
833 __u8 e_name_len; /* length of name */
834 __u8 e_name_index; /* attribute name index */
835 __le16 e_value_offs; /* offset in disk block of value */
836 - __le32 e_value_block; /* disk block attribute is stored on (n/i) */
837 + __le32 e_value_inum; /* inode in which the value is stored */
838 __le32 e_value_size; /* size of attribute value */
839 __le32 e_hash; /* hash value of name and value */
840 char e_name[0]; /* attribute name */
841 @@ -63,6 +63,15 @@ struct ext4_xattr_entry {
842 EXT4_I(inode)->i_extra_isize))
843 #define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
845 +#define i_xattr_inode_parent i_mtime.tv_sec
848 + * The minimum size of EA value when you start storing it in an external inode
849 + * size of block - size of header - size of 1 entry - 4 null bytes
851 +#define EXT4_XATTR_MIN_LARGE_EA_SIZE(b) \
852 + ((b) - EXT4_XATTR_LEN(3) - sizeof(struct ext4_xattr_header) - 4)
854 # ifdef CONFIG_EXT4_FS_XATTR
856 extern struct xattr_handler ext4_xattr_user_handler;
857 @@ -77,7 +86,13 @@ extern int ext4_xattr_get(struct inode *
858 extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
859 extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
861 -extern void ext4_xattr_delete_inode(handle_t *, struct inode *);
862 +extern struct inode *ext4_xattr_inode_iget(struct inode *parent, int ea_ino,
864 +extern int ext4_xattr_inode_unlink(struct inode *inode, int ea_ino);
865 +extern int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
866 + struct ext4_xattr_ino_array **array);
867 +extern void ext4_xattr_inode_array_free(struct inode *inode,
868 + struct ext4_xattr_ino_array *array);
869 extern void ext4_xattr_put_super(struct super_block *);
871 extern int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
872 @@ -111,9 +126,11 @@ ext4_xattr_set_handle(handle_t *handle,
877 -ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
879 +ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
880 + struct ext4_xattr_ino_array **array)
882 + return -EOPNOTSUPP;
886 Index: linux-stage/fs/ext4/inode.c
887 ===================================================================
888 --- linux-stage.orig/fs/ext4/inode.c
889 +++ linux-stage/fs/ext4/inode.c
890 @@ -223,6 +223,7 @@ void ext4_delete_inode(struct inode *ino
893 int extra_credits = 3;
894 + struct ext4_xattr_ino_array *lea_ino_array = NULL;
896 if (ext4_should_order_data(inode))
897 ext4_begin_ordered_truncate(inode, 0);
898 @@ -238,8 +239,8 @@ void ext4_delete_inode(struct inode *ino
899 * protection against it
901 sb_start_intwrite(inode->i_sb);
902 - handle = ext4_journal_start(inode,
903 - blocks_for_truncate(inode) + extra_credits);
905 + handle = ext4_journal_start(inode, extra_credits);
906 if (IS_ERR(handle)) {
907 ext4_std_error(inode->i_sb, PTR_ERR(handle));
909 @@ -251,9 +252,33 @@ void ext4_delete_inode(struct inode *ino
910 sb_end_intwrite(inode->i_sb);
915 ext4_handle_sync(handle);
918 + * Delete xattr inode before deleting the main inode.
920 + err = ext4_xattr_delete_inode(handle, inode, &lea_ino_array);
922 + ext4_warning(inode->i_sb,
923 + "couldn't delete inode's xattr (err %d)", err);
927 + if (!ext4_handle_has_enough_credits(handle,
928 + blocks_for_truncate(inode) + extra_credits)) {
929 + err = ext4_journal_extend(handle,
930 + blocks_for_truncate(inode) + extra_credits);
932 + err = ext4_journal_restart(handle,
933 + blocks_for_truncate(inode) + extra_credits);
935 + ext4_warning(inode->i_sb,
936 + "couldn't extend journal (err %d)", err);
942 err = ext4_mark_inode_dirty(handle, inode);
944 @@ -307,8 +332,12 @@ void ext4_delete_inode(struct inode *ino
947 ext4_free_inode(handle, inode);
949 ext4_journal_stop(handle);
950 sb_end_intwrite(inode->i_sb);
952 + if (lea_ino_array != NULL)
953 + ext4_xattr_inode_array_free(inode, lea_ino_array);
956 clear_inode(inode); /* We must guarantee clearing of inode... */
957 Index: linux-stage/fs/ext4/ialloc.c
958 ===================================================================
959 --- linux-stage.orig/fs/ext4/ialloc.c
960 +++ linux-stage/fs/ext4/ialloc.c
961 @@ -219,7 +219,6 @@ void ext4_free_inode(handle_t *handle, s
962 * as writing the quota to disk may need the lock as well.
965 - ext4_xattr_delete_inode(handle, inode);
966 vfs_dq_free_inode(inode);