+This patch implements the large EA support in ext4. If the size of
+an EA value is larger than the blocksize, then the EA value would
+not be saved in the external EA block, instead it would be saved
+in an external EA inode. So, the patch also helps support a larger
+number of EAs.
+
Index: linux-stage/fs/ext4/ext4.h
===================================================================
--- linux-stage.orig/fs/ext4/ext4.h
+++ linux-stage/fs/ext4/ext4.h
-@@ -1412,6 +1412,7 @@ static inline void ext4_clear_state_flag
+@@ -1408,6 +1408,7 @@ static inline void ext4_clear_state_flag
EXT4_FEATURE_INCOMPAT_EXTENTS| \
EXT4_FEATURE_INCOMPAT_64BIT| \
EXT4_FEATURE_INCOMPAT_FLEX_BG| \
EXT4_FEATURE_INCOMPAT_MMP| \
EXT4_FEATURE_INCOMPAT_DIRDATA)
-@@ -1775,6 +1776,12 @@ struct mmpd_data {
- #endif
+@@ -1764,6 +1765,12 @@ struct mmpd_data {
+ #define EXT4_MMP_MAX_CHECK_INTERVAL 300UL
/*
+ * Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb
* Function prototypes
*/
-@@ -1786,6 +1793,10 @@ struct mmpd_data {
+@@ -1775,6 +1782,10 @@ struct mmpd_data {
# define ATTRIB_NORET __attribute__((noreturn))
# define NORET_AND noreturn,
/* bitmap.c */
extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
-@@ -1905,6 +1916,7 @@ extern void ext4_set_inode_flags(struct
+@@ -1893,6 +1904,7 @@ extern void ext4_set_inode_flags(struct
extern void ext4_get_inode_flags(struct ext4_inode_info *);
extern int ext4_alloc_da_blocks(struct inode *inode);
extern void ext4_set_aops(struct inode *inode);
return;
no_delete:
ext4_clear_inode(inode); /* We must guarantee clearing of inode... */
-@@ -5551,7 +5584,7 @@ static int ext4_index_trans_blocks(struc
+@@ -5552,7 +5585,7 @@ static int ext4_index_trans_blocks(struc
*
* Also account for superblock, inode, quota and xattr blocks
*/
if (error)
goto cleanup;
if (!is.s.not_found) {
-@@ -1089,10 +1388,25 @@ ext4_xattr_set(struct inode *inode, int
+@@ -1088,10 +1387,25 @@ ext4_xattr_set(struct inode *inode, int
const void *value, size_t value_len, int flags)
{
handle_t *handle;
if (IS_ERR(handle)) {
error = PTR_ERR(handle);
} else {
-@@ -1102,7 +1416,7 @@ retry:
+@@ -1101,7 +1415,7 @@ retry:
value, value_len, flags);
error2 = ext4_journal_stop(handle);
if (error == -ENOSPC &&
goto retry;
if (error == 0)
error = error2;
-@@ -1124,7 +1438,7 @@ static void ext4_xattr_shift_entries(str
+@@ -1123,7 +1437,7 @@ static void ext4_xattr_shift_entries(str
/* Adjust the value offsets of the entries */
for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
new_offs = le16_to_cpu(last->e_value_offs) +
value_offs_shift;
BUG_ON(new_offs + le32_to_cpu(last->e_value_size)
-@@ -1359,20 +1673,92 @@ cleanup:
+@@ -1358,22 +1672,135 @@ cleanup:
return error;
}
--
+#define EIA_INCR 16 /* must be 2^n */
+#define EIA_MASK (EIA_INCR - 1)
+/* Add the large xattr @ino into @lea_ino_array for later deletion.
+ (*lea_ino_array)->xia_inodes[(*lea_ino_array)->xia_count++] = ino;
+ return 0;
+}
++
++/**
++ * Add xattr inode to orphan list
++ */
++static int
++ext4_xattr_inode_orphan_add(handle_t *handle, struct inode *inode,
++ int credits, struct ext4_xattr_ino_array *lea_ino_array)
++{
++ struct inode *ea_inode = NULL;
++ int idx = 0, error = 0;
++
++ if (lea_ino_array == NULL)
++ return 0;
+
++ for (; idx < lea_ino_array->xia_count; ++idx) {
++ if (!ext4_handle_has_enough_credits(handle, credits)) {
++ error = ext4_journal_extend(handle, credits);
++ if (error > 0)
++ error = ext4_journal_restart(handle, credits);
++
++ if (error != 0) {
++ ext4_warning(inode->i_sb,
++ "couldn't extend journal "
++ "(err %d)", error);
++ return error;
++ }
++ }
++ ea_inode = ext4_xattr_inode_iget(inode,
++ lea_ino_array->xia_inodes[idx], &error);
++ if (error)
++ continue;
++ ext4_orphan_add(handle, ea_inode);
++ /* the inode's i_count will be released by caller */
++ }
++
++ return 0;
++}
/*
* ext4_xattr_delete_inode()
+ struct ext4_iloc iloc;
+ struct ext4_xattr_entry *entry;
+ int credits = 3, error = 0;
-+
+
+- if (!EXT4_I(inode)->i_file_acl)
+ if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR))
+ goto delete_external_ea;
+
+ error = ext4_get_inode_loc(inode, &iloc);
+ if (error)
-+ goto cleanup;
+ goto cleanup;
+ raw_inode = ext4_raw_inode(&iloc);
+ header = IHDR(inode, raw_inode);
+ entry = IFIRST(header);
+ entry->e_value_inum = 0;
+ }
+ brelse(iloc.bh);
-
++
+delete_external_ea:
- if (!EXT4_I(inode)->i_file_acl)
- goto cleanup;
++ if (!EXT4_I(inode)->i_file_acl) {
++ /* add xattr inode to orphan list */
++ ext4_xattr_inode_orphan_add(handle, inode, credits,
++ *lea_ino_array);
++ goto cleanup;
++ }
bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
-@@ -1387,11 +1770,88 @@ ext4_xattr_delete_inode(handle_t *handle
+ if (!bh) {
+ EXT4_ERROR_INODE(inode, "block %llu read error",
+@@ -1386,11 +1813,69 @@ ext4_xattr_delete_inode(handle_t *handle
EXT4_I(inode)->i_file_acl);
goto cleanup;
}
+ }
+
+ /* adding xattr inode to orphan list */
-+ if (*lea_ino_array != NULL) {
-+ struct inode *ea_inode = NULL;
-+ int idx = (*lea_ino_array)->xia_count;
-+
-+ for (idx = 0; idx < (*lea_ino_array)->xia_count; ++idx) {
-+ if (!ext4_handle_has_enough_credits(handle, credits)) {
-+ error = ext4_journal_extend(handle, credits);
-+ if (error > 0)
-+ error = ext4_journal_restart(handle, credits);
-+ if (error != 0) {
-+ ext4_warning(inode->i_sb,
-+ "couldn't extend journal "
-+ "(err %d)", error);
-+ goto cleanup;
-+ }
-+ }
-+ ea_inode = ext4_xattr_inode_iget(inode,
-+ (*lea_ino_array)->xia_inodes[idx], &error);
-+ if (error)
-+ continue;
-+ ext4_orphan_add(handle, ea_inode);
-+ /* the inode's i_count will be released by caller */
-+ }
-+ }
++ error = ext4_xattr_inode_orphan_add(handle, inode, credits,
++ *lea_ino_array);
++ if (error != 0)
++ goto cleanup;
+
+ if (!IS_NOQUOTA(inode))
+ credits += 2 * EXT4_QUOTA_DEL_BLOCKS(inode->i_sb);
+ lea_ino_array->xia_inodes[idx], &err);
+ if (err)
+ continue;
-+ ea_inode->i_nlink = 0;
-+ iput(ea_inode);
+ /* for inode's i_count get from ext4_xattr_delete_inode */
++ if (!list_empty(&EXT4_I(ea_inode)->i_orphan))
++ iput(ea_inode);
++ ea_inode->i_nlink = 0;
+ iput(ea_inode);
+ }
+ kfree(lea_ino_array);
}
/*
-@@ -1461,10 +1921,9 @@ ext4_xattr_cmp(struct ext4_xattr_header
+@@ -1460,10 +1945,9 @@ ext4_xattr_cmp(struct ext4_xattr_header
entry1->e_name_index != entry2->e_name_index ||
entry1->e_name_len != entry2->e_name_len ||
entry1->e_value_size != entry2->e_value_size ||
if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
(char *)header2 + le16_to_cpu(entry2->e_value_offs),
le32_to_cpu(entry1->e_value_size)))
-@@ -1548,7 +2007,7 @@ static inline void ext4_xattr_hash_entry
+@@ -1547,7 +2031,7 @@ static inline void ext4_xattr_hash_entry
*name++;
}
===================================================================
--- linux-stage.orig/fs/ext4/ialloc.c
+++ linux-stage/fs/ext4/ialloc.c
-@@ -222,7 +222,6 @@ void ext4_free_inode(handle_t *handle, s
+@@ -221,7 +221,6 @@ void ext4_free_inode(handle_t *handle, s
* as writing the quota to disk may need the lock as well.
*/
dquot_initialize(inode);