in an external EA inode. So, the patch also helps support a larger
number of EAs.
-Index: linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/ext4.h
+Index: linux-stage/fs/ext4/ext4.h
===================================================================
---- linux-3.10.0-123.13.2.el7.x86_64.orig/fs/ext4/ext4.h
-+++ linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/ext4.h
-@@ -1534,6 +1534,7 @@ static inline void ext4_clear_state_flag
+--- linux-stage.orig/fs/ext4/ext4.h
++++ linux-stage/fs/ext4/ext4.h
+@@ -1579,6 +1579,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| \
EXT4_FEATURE_INCOMPAT_INLINE_DATA)
-@@ -1934,6 +1935,12 @@ struct mmpd_data {
+@@ -1979,6 +1980,12 @@ struct mmpd_data {
#define EXT4_MMP_MAX_CHECK_INTERVAL 300UL
/*
* Function prototypes
*/
-@@ -1945,6 +1952,10 @@ struct mmpd_data {
+@@ -1990,6 +1997,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);
void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
-@@ -2157,6 +2168,7 @@ extern void ext4_set_inode_flags(struct
+@@ -2194,6 +2205,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);
+extern int ext4_meta_trans_blocks(struct inode *, int nrblocks, int chunk);
extern int ext4_writepage_trans_blocks(struct inode *);
extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
- extern int ext4_discard_partial_page_buffers(handle_t *handle,
-Index: linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/inode.c
+ extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
+Index: linux-stage/fs/ext4/inode.c
===================================================================
---- linux-3.10.0-123.13.2.el7.x86_64.orig/fs/ext4/inode.c
-+++ linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/inode.c
-@@ -133,8 +183,6 @@ void ext4_evict_inode(struct inode *inod
+--- linux-stage.orig/fs/ext4/inode.c
++++ linux-stage/fs/ext4/inode.c
+@@ -134,8 +134,6 @@ static void ext4_invalidatepage(struct p
unsigned int length);
static int __ext4_journalled_writepage(struct page *page, unsigned int len);
static int ext4_bh_delay_or_unwritten(handle_t *handle, struct buffer_head *bh);
/*
* Test whether an inode is a fast symlink.
-@@ -183,6 +183,8 @@ void ext4_evict_inode(struct inode *inod
+@@ -184,6 +182,8 @@ void ext4_evict_inode(struct inode *inod
{
handle_t *handle;
int err;
trace_ext4_evict_inode(inode);
-@@ -235,8 +237,8 @@ void ext4_evict_inode(struct inode *inod
+@@ -236,8 +236,8 @@ void ext4_evict_inode(struct inode *inod
* protection against it
*/
sb_start_intwrite(inode->i_sb);
if (IS_ERR(handle)) {
ext4_std_error(inode->i_sb, PTR_ERR(handle));
/*
-@@ -248,9 +250,36 @@ void ext4_evict_inode(struct inode *inod
+@@ -249,9 +249,36 @@ void ext4_evict_inode(struct inode *inod
sb_end_intwrite(inode->i_sb);
goto no_delete;
}
inode->i_size = 0;
err = ext4_mark_inode_dirty(handle, inode);
if (err) {
-@@ -305,8 +334,12 @@ void ext4_evict_inode(struct inode *inod
+@@ -269,10 +296,10 @@ void ext4_evict_inode(struct inode *inod
+ * enough credits left in the handle to remove the inode from
+ * the orphan list and set the dtime field.
+ */
+- if (!ext4_handle_has_enough_credits(handle, 3)) {
+- err = ext4_journal_extend(handle, 3);
++ if (!ext4_handle_has_enough_credits(handle, extra_credits)) {
++ err = ext4_journal_extend(handle, extra_credits);
+ if (err > 0)
+- err = ext4_journal_restart(handle, 3);
++ err = ext4_journal_restart(handle, extra_credits);
+ if (err != 0) {
+ ext4_warning(inode->i_sb,
+ "couldn't extend journal (err %d)", err);
+@@ -306,8 +333,12 @@ void ext4_evict_inode(struct inode *inod
ext4_clear_inode(inode);
else
ext4_free_inode(handle, inode);
return;
no_delete:
ext4_clear_inode(inode); /* We must guarantee clearing of inode... */
-@@ -4841,7 +4874,7 @@ static int ext4_index_trans_blocks(struc
+@@ -4681,7 +4712,7 @@ static int ext4_index_trans_blocks(struc
*
* Also account for superblock, inode, quota and xattr blocks
*/
int pextents)
{
ext4_group_t groups, ngroups = ext4_get_groups_count(inode->i_sb);
- int gdpblocks;
-Index: linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/xattr.c
+Index: linux-stage/fs/ext4/xattr.c
===================================================================
---- linux-3.10.0-123.13.2.el7.x86_64.orig/fs/ext4/xattr.c
-+++ linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/xattr.c
-@@ -220,19 +220,26 @@ ext4_xattr_check_block(struct inode *ino
+--- linux-stage.orig/fs/ext4/xattr.c
++++ linux-stage/fs/ext4/xattr.c
+@@ -201,6 +201,7 @@ ext4_xattr_check_names(struct ext4_xattr
+
+ while (!IS_LAST_ENTRY(entry)) {
+ if (entry->e_value_size != 0 &&
++ entry->e_value_inum == 0 &&
+ (value_start + le16_to_cpu(entry->e_value_offs) <
+ (void *)e + sizeof(__u32) ||
+ value_start + le16_to_cpu(entry->e_value_offs) +
+@@ -233,19 +234,26 @@ ext4_xattr_check_block(struct inode *ino
}
static inline int
size_t value_size = le32_to_cpu(entry->e_value_size);
- if (entry->e_value_block != 0 || value_size > size ||
-- le16_to_cpu(entry->e_value_offs) + value_size > size)
-+ if ((entry->e_value_inum == 0) &&
-+ (le16_to_cpu(entry->e_value_offs) + value_size > size))
++ if (!entry->e_value_inum &&
+ le16_to_cpu(entry->e_value_offs) + value_size > size)
+ return -EIO;
-+ if (entry->e_value_inum != 0 &&
++ if (entry->e_value_inum &&
+ (le32_to_cpu(entry->e_value_inum) < EXT4_FIRST_INO(inode->i_sb) ||
+ le32_to_cpu(entry->e_value_inum) >
+ le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_inodes_count)))
{
struct ext4_xattr_entry *entry;
size_t name_len;
-@@ -252,11 +259,103 @@ ext4_xattr_find_entry(struct ext4_xattr_
+@@ -265,11 +273,104 @@ ext4_xattr_find_entry(struct ext4_xattr_
break;
}
*pentry = entry;
+ return err;
+}
+
-+struct inode *ext4_xattr_inode_iget(struct inode *parent, int ea_ino, int *err)
++struct inode *ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino, int *err)
+{
+ struct inode *ea_inode = NULL;
+
+ ea_inode = ext4_iget(parent->i_sb, ea_ino);
+ if (IS_ERR(ea_inode) || is_bad_inode(ea_inode)) {
-+ ext4_error(parent->i_sb, "error while reading EA inode %d",
-+ ea_ino);
-+ *err = -EIO;
++ int rc = IS_ERR(ea_inode) ? PTR_ERR(ea_inode) : 0;
++ ext4_error(parent->i_sb, "error while reading EA inode %lu "
++ "/ %d %d", ea_ino, rc, is_bad_inode(ea_inode));
++ *err = rc != 0 ? rc : -EIO;
+ return NULL;
+ }
+
-+ if (ea_inode->i_xattr_inode_parent != parent->i_ino ||
++ if (EXT4_XATTR_INODE_GET_PARENT(ea_inode) != parent->i_ino ||
+ ea_inode->i_generation != parent->i_generation) {
-+ ext4_error(parent->i_sb, "Backpointer from EA inode %d "
++ ext4_error(parent->i_sb, "Backpointer from EA inode %lu "
+ "to parent invalid.", ea_ino);
+ *err = -EINVAL;
+ goto error;
+ }
+
+ if (!(EXT4_I(ea_inode)->i_flags & EXT4_EA_INODE_FL)) {
-+ ext4_error(parent->i_sb, "EA inode %d does not have "
++ ext4_error(parent->i_sb, "EA inode %lu does not have "
+ "EXT4_EA_INODE_FL flag set.\n", ea_ino);
+ *err = -EINVAL;
+ goto error;
+ * Read the value from the EA inode.
+ */
+static int
-+ext4_xattr_inode_get(struct inode *inode, int ea_ino, void *buffer,
++ext4_xattr_inode_get(struct inode *inode, unsigned long ea_ino, void *buffer,
+ size_t *size)
+{
+ struct inode *ea_inode = NULL;
static int
ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
void *buffer, size_t buffer_size)
-@@ -288,7 +387,8 @@ bad_block:
+@@ -301,7 +401,8 @@ bad_block:
}
ext4_xattr_cache_insert(bh);
entry = BFIRST(bh);
if (error == -EIO)
goto bad_block;
if (error)
-@@ -298,8 +398,16 @@ bad_block:
+@@ -311,8 +412,16 @@ bad_block:
error = -ERANGE;
if (size > buffer_size)
goto cleanup;
- memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
- size);
-+ if (entry->e_value_inum != 0) {
++ if (entry->e_value_inum) {
+ error = ext4_xattr_inode_get(inode,
+ le32_to_cpu(entry->e_value_inum),
+ buffer, &size);
}
error = size;
-@@ -333,7 +441,7 @@ ext4_xattr_ibody_get(struct inode *inode
+@@ -346,7 +455,7 @@ ext4_xattr_ibody_get(struct inode *inode
if (error)
goto cleanup;
error = ext4_xattr_find_entry(&entry, name_index, name,
if (error)
goto cleanup;
size = le32_to_cpu(entry->e_value_size);
-@@ -341,8 +449,16 @@ ext4_xattr_ibody_get(struct inode *inode
+@@ -354,8 +463,16 @@ ext4_xattr_ibody_get(struct inode *inode
error = -ERANGE;
if (size > buffer_size)
goto cleanup;
- memcpy(buffer, (void *)IFIRST(header) +
- le16_to_cpu(entry->e_value_offs), size);
-+ if (entry->e_value_inum != 0) {
++ if (entry->e_value_inum) {
+ error = ext4_xattr_inode_get(inode,
+ le32_to_cpu(entry->e_value_inum),
+ buffer, &size);
}
error = size;
-@@ -568,7 +684,7 @@ static size_t ext4_xattr_free_space(stru
- *total += EXT4_XATTR_LEN(last->e_name_len);
+@@ -600,7 +717,7 @@ static size_t ext4_xattr_free_space(stru
+ size_t *min_offs, void *base, int *total)
{
for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
- if (!last->e_value_block && last->e_value_size) {
-+ if (last->e_value_inum == 0 && last->e_value_size > 0) {
++ if (!last->e_value_inum && last->e_value_size) {
size_t offs = le16_to_cpu(last->e_value_offs);
if (offs < *min_offs)
*min_offs = offs;
-@@ -577,16 +693,172 @@ static size_t ext4_xattr_free_space(stru
+@@ -611,16 +728,198 @@ static size_t ext4_xattr_free_space(stru
return (*min_offs - ((void *)last - base) - sizeof(__u32));
}
+/*
+ * Write the value of the EA in an inode.
+ */
-+static int
+ static int
+-ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
+ext4_xattr_inode_write(handle_t *handle, struct inode *ea_inode,
+ const void *buf, int bufsize)
+{
+ block += 1;
+ }
+
++ mutex_lock(&ea_inode->i_mutex);
+ i_size_write(ea_inode, wsize);
+ ext4_update_i_disksize(ea_inode, wsize);
++ mutex_unlock(&ea_inode->i_mutex);
+
+ ext4_mark_inode_dirty(handle, ea_inode);
+
+ return ret;
+}
+
++static void ext4_xattr_inode_set_ref(struct inode *ea_inode, __u64 ref_count)
++{
++ ea_inode->i_ctime.tv_sec = (__u32)(ref_count >> 32);
++ ea_inode->i_version = (__u32)ref_count;
++}
++
++static void ext4_xattr_inode_set_hash(struct inode *ea_inode, __u32 hash)
++{
++ ea_inode->i_atime.tv_sec = hash;
++}
++
+/*
+ * Create an inode to store the value of a large EA.
+ */
+static struct inode *
-+ext4_xattr_inode_create(handle_t *handle, struct inode *inode)
++ext4_xattr_inode_create(handle_t *handle, struct inode *inode, __u32 hash)
+{
+ struct inode *ea_inode = NULL;
+
+ * A back-pointer from EA inode to parent inode will be useful
+ * for e2fsck.
+ */
-+ ea_inode->i_xattr_inode_parent = inode->i_ino;
++ EXT4_XATTR_INODE_SET_PARENT(ea_inode, inode->i_ino);
+ unlock_new_inode(ea_inode);
++
++ ext4_xattr_inode_set_ref(ea_inode, 1);
++ ext4_xattr_inode_set_hash(ea_inode, hash);
+ }
+
+ return ea_inode;
+ * Unlink the inode storing the value of the EA.
+ */
+int
-+ext4_xattr_inode_unlink(struct inode *inode, int ea_ino)
++ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino)
+{
+ struct inode *ea_inode = NULL;
+ int err;
+ return 0;
+}
+
++static __u32
++ext4_xattr_inode_hash(struct ext4_sb_info *sbi, const void *buffer, size_t size)
++{
++ if (ext4_has_metadata_csum(sbi->s_sb))
++ return ext4_chksum(sbi, sbi->s_csum_seed, buffer, size);
++ return 0;
++}
++
+/*
+ * Add value of the EA in an inode.
+ */
- static int
--ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
-+ext4_xattr_inode_set(handle_t *handle, struct inode *inode, int *ea_ino,
++static int
++ext4_xattr_inode_set(handle_t *handle, struct inode *inode, unsigned long *ea_ino,
+ const void *value, size_t value_len)
+{
+ struct inode *ea_inode = NULL;
++ __u32 hash;
+ int err;
+
+ /* Create an inode for the EA value */
-+ ea_inode = ext4_xattr_inode_create(handle, inode);
++ hash = ext4_xattr_inode_hash(EXT4_SB(inode->i_sb), value, value_len);
++ ea_inode = ext4_xattr_inode_create(handle, inode, hash);
+ if (IS_ERR(ea_inode))
+ return -1;
+
last = s->first;
for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
- if (!last->e_value_block && last->e_value_size) {
-+ if (last->e_value_inum == 0 && last->e_value_size > 0) {
++ if (!last->e_value_inum && last->e_value_size) {
size_t offs = le16_to_cpu(last->e_value_offs);
if (offs < min_offs)
min_offs = offs;
-@@ -594,16 +865,21 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -628,16 +927,21 @@ ext4_xattr_set_entry(struct ext4_xattr_i
}
free = min_offs - ((void *)last - s->base) - sizeof(__u32);
if (!s->not_found) {
- if (!s->here->e_value_block && s->here->e_value_size) {
-+ if (!in_inode && s->here->e_value_inum == 0 &&
-+ s->here->e_value_size > 0) {
++ if (!in_inode &&
++ !s->here->e_value_inum && s->here->e_value_size) {
size_t size = le32_to_cpu(s->here->e_value_size);
free += EXT4_XATTR_SIZE(size);
}
return -ENOSPC;
}
-@@ -617,7 +893,8 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -651,7 +955,8 @@ ext4_xattr_set_entry(struct ext4_xattr_i
s->here->e_name_len = name_len;
memcpy(s->here->e_name, i->name, name_len);
} else {
- if (!s->here->e_value_block && s->here->e_value_size) {
-+ if (s->here->e_value_offs > 0 && s->here->e_value_inum == 0 &&
-+ s->here->e_value_size > 0) {
++ if (!s->here->e_value_inum && s->here->e_value_size &&
++ s->here->e_value_offs > 0) {
void *first_val = s->base + min_offs;
size_t offs = le16_to_cpu(s->here->e_value_offs);
void *val = s->base + offs;
-@@ -651,13 +928,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -685,13 +990,18 @@ ext4_xattr_set_entry(struct ext4_xattr_i
last = s->first;
while (!IS_LAST_ENTRY(last)) {
size_t o = le16_to_cpu(last->e_value_offs);
- if (!last->e_value_block &&
-- last->e_value_size && o < offs)
-+ if (last->e_value_size > 0 && o < offs)
++ if (!last->e_value_inum &&
+ last->e_value_size && o < offs)
last->e_value_offs =
cpu_to_le16(o + size);
last = EXT4_XATTR_NEXT(last);
}
}
-+ if (s->here->e_value_inum != 0) {
++ if (s->here->e_value_inum) {
+ ext4_xattr_inode_unlink(inode,
+ le32_to_cpu(s->here->e_value_inum));
+ s->here->e_value_inum = 0;
if (!i->value) {
/* Remove the old name. */
size_t size = EXT4_XATTR_LEN(name_len);
-@@ -671,10 +952,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -705,10 +1014,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
if (i->value) {
/* Insert the new value. */
s->here->e_value_size = cpu_to_le32(i->value_len);
- if (i->value_len) {
+ if (in_inode) {
-+ int ea_ino = le32_to_cpu(s->here->e_value_inum);
++ unsigned long ea_ino = le32_to_cpu(s->here->e_value_inum);
+ ext4_xattr_inode_set(handle, inode, &ea_ino, i->value,
+ i->value_len);
+ s->here->e_value_inum = cpu_to_le32(ea_ino);
if (i->value == EXT4_ZERO_XATTR_VALUE) {
memset(val, 0, size);
} else {
-@@ -724,7 +1012,7 @@ ext4_xattr_block_find(struct inode *inod
+@@ -758,7 +1074,7 @@ ext4_xattr_block_find(struct inode *inod
bs->s.end = bs->bh->b_data + bs->bh->b_size;
bs->s.here = bs->s.first;
error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
if (error && error != -ENODATA)
goto cleanup;
bs->s.not_found = error;
-@@ -748,8 +1036,6 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -782,8 +1098,6 @@ ext4_xattr_block_set(handle_t *handle, s
#define header(x) ((struct ext4_xattr_header *)(x))
if (s->base) {
ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
bs->bh->b_blocknr);
-@@ -764,7 +1050,7 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -799,7 +1113,7 @@ ext4_xattr_block_set(handle_t *handle, s
ce = NULL;
}
ea_bdebug(bs->bh, "modifying in-place");
if (!error) {
if (!IS_LAST_ENTRY(s->first))
ext4_xattr_rehash(header(s->base),
-@@ -815,7 +1101,7 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -850,7 +1164,7 @@ ext4_xattr_block_set(handle_t *handle, s
s->end = s->base + sb->s_blocksize;
}
if (error == -EIO)
goto bad_block;
if (error)
-@@ -963,7 +1249,7 @@ int ext4_xattr_ibody_find(struct inode *
+@@ -1000,7 +1314,7 @@ int ext4_xattr_ibody_find(struct inode *
/* Find the named attribute. */
error = ext4_xattr_find_entry(&is->s.here, i->name_index,
i->name, is->s.end -
if (error && error != -ENODATA)
return error;
is->s.not_found = error;
-@@ -981,7 +1267,7 @@ int ext4_xattr_ibody_inline_set(handle_t
+@@ -1018,7 +1332,7 @@ int ext4_xattr_ibody_inline_set(handle_t
if (EXT4_I(inode)->i_extra_isize == 0)
return -ENOSPC;
if (error) {
if (error == -ENOSPC &&
ext4_has_inline_data(inode)) {
-@@ -993,7 +1279,7 @@ int ext4_xattr_ibody_inline_set(handle_t
+@@ -1030,7 +1344,7 @@ int ext4_xattr_ibody_inline_set(handle_t
error = ext4_xattr_ibody_find(inode, i, is);
if (error)
return error;
}
if (error)
return error;
-@@ -1019,7 +1305,7 @@ static int ext4_xattr_ibody_set(handle_t
+@@ -1056,7 +1370,7 @@ static int ext4_xattr_ibody_set(handle_t
if (EXT4_I(inode)->i_extra_isize == 0)
return -ENOSPC;
if (error)
return error;
header = IHDR(inode, ext4_raw_inode(&is->iloc));
-@@ -1055,7 +1341,7 @@ ext4_xattr_set_handle(handle_t *handle,
+@@ -1092,7 +1406,7 @@ ext4_xattr_set_handle(handle_t *handle,
.name = name,
.value = value,
.value_len = value_len,
};
struct ext4_xattr_ibody_find is = {
.s = { .not_found = -ENODATA, },
-@@ -1120,6 +1406,15 @@ ext4_xattr_set_handle(handle_t *handle,
+@@ -1157,6 +1471,15 @@ ext4_xattr_set_handle(handle_t *handle,
goto cleanup;
}
error = ext4_xattr_block_set(handle, inode, &i, &bs);
if (error)
goto cleanup;
if (!is.s.not_found) {
-@@ -1166,9 +1461,22 @@ ext4_xattr_set(struct inode *inode, int
+@@ -1203,9 +1526,22 @@ ext4_xattr_set(struct inode *inode, int
const void *value, size_t value_len, int flags)
{
handle_t *handle;
retry:
handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
if (IS_ERR(handle)) {
-@@ -1180,7 +1488,7 @@ retry:
+@@ -1217,7 +1553,7 @@ retry:
value, value_len, flags);
error2 = ext4_journal_stop(handle);
if (error == -ENOSPC &&
goto retry;
if (error == 0)
error = error2;
-@@ -1202,7 +1510,7 @@ static void ext4_xattr_shift_entries(str
+@@ -1239,7 +1575,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)) {
- if (!last->e_value_block && last->e_value_size) {
-+ if (last->e_value_inum == 0 && last->e_value_size > 0) {
++ if (!last->e_value_inum && last->e_value_size) {
new_offs = le16_to_cpu(last->e_value_offs) +
value_offs_shift;
BUG_ON(new_offs + le32_to_cpu(last->e_value_size)
-@@ -1441,19 +1749,91 @@ cleanup:
+@@ -1477,21 +1813,135 @@ cleanup:
}
--
+#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);
-+ for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
-+ if (entry->e_value_inum == 0)
++ for (entry = IFIRST(header); !IS_LAST_ENTRY(entry);
++ entry = EXT4_XATTR_NEXT(entry)) {
++ if (!entry->e_value_inum)
+ continue;
+ if (ext4_expand_ino_array(lea_ino_array,
+ entry->e_value_inum) != 0) {
+ 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);
-@@ -1468,11 +1848,88 @@ ext4_xattr_delete_inode(handle_t *handle
+ if (!bh) {
+ EXT4_ERROR_INODE(inode, "block %llu read error",
+@@ -1504,11 +1954,69 @@ ext4_xattr_delete_inode(handle_t *handle
EXT4_I(inode)->i_file_acl);
goto cleanup;
}
+
-+ entry = BFIRST(bh);
-+ for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
-+ if (entry->e_value_inum == 0)
++ for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);
++ entry = EXT4_XATTR_NEXT(entry)) {
++ if (!entry->e_value_inum)
+ continue;
+ if (ext4_expand_ino_array(lea_ino_array,
+ entry->e_value_inum) != 0)
+ }
+
+ /* add xattr inode to orphan list */
-+ if (*lea_ino_array != NULL) {
-+ struct inode *ea_inode = NULL;
-+ int idx = 0;
-+
-+ for (; idx < (*lea_ino_array)->xia_count; ++idx) {
-+ if (!ext4_handle_has_enough_credits(handle, 3)) {
-+ error = ext4_journal_extend(handle, 3);
-+ if (error > 0)
-+ error = ext4_journal_restart(handle, 3);
-+ 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;
-+ clear_nlink(ea_inode);
-+ 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);
++ clear_nlink(ea_inode);
+ iput(ea_inode);
+ }
+ kfree(lea_ino_array);
}
/*
-@@ -1542,10 +1999,9 @@ ext4_xattr_cmp(struct ext4_xattr_header
+@@ -1578,10 +2086,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)))
-@@ -1629,7 +2085,7 @@ static inline void ext4_xattr_hash_entry
+@@ -1665,7 +2172,7 @@ static inline void ext4_xattr_hash_entry
*name++;
}
- if (entry->e_value_block == 0 && entry->e_value_size != 0) {
-+ if (entry->e_value_inum == 0 && entry->e_value_size != 0) {
++ if (!entry->e_value_inum && entry->e_value_size) {
__le32 *value = (__le32 *)((char *)header +
le16_to_cpu(entry->e_value_offs));
for (n = (le32_to_cpu(entry->e_value_size) +
-Index: linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/xattr.h
+Index: linux-stage/fs/ext4/xattr.h
===================================================================
---- linux-3.10.0-123.13.2.el7.x86_64.orig/fs/ext4/xattr.h
-+++ linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/xattr.h
+--- linux-stage.orig/fs/ext4/xattr.h
++++ linux-stage/fs/ext4/xattr.h
@@ -42,7 +42,7 @@ struct ext4_xattr_entry {
__u8 e_name_len; /* length of name */
__u8 e_name_index; /* attribute name index */
__le32 e_value_size; /* size of attribute value */
__le32 e_hash; /* hash value of name and value */
char e_name[0]; /* attribute name */
-@@ -67,6 +67,15 @@ struct ext4_xattr_entry {
+@@ -67,6 +67,26 @@ struct ext4_xattr_entry {
EXT4_I(inode)->i_extra_isize))
#define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
-+#define i_xattr_inode_parent i_mtime.tv_sec
++/*
++ * Link EA inode back to parent one using i_mtime field.
++ * Extra integer type conversion added to ignore higher
++ * bits in i_mtime.tv_sec which might be set by ext4_get()
++ */
++#define EXT4_XATTR_INODE_SET_PARENT(inode, inum) \
++do { \
++ (inode)->i_mtime.tv_sec = inum; \
++} while(0)
++
++#define EXT4_XATTR_INODE_GET_PARENT(inode) \
++((__u32)(inode)->i_mtime.tv_sec)
+
+/*
+ * The minimum size of EA value when you start storing it in an external inode
extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
-extern void ext4_xattr_delete_inode(handle_t *, struct inode *);
-+extern struct inode *ext4_xattr_inode_iget(struct inode *parent, int ea_ino,
++extern struct inode *ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,
+ int *err);
-+extern int ext4_xattr_inode_unlink(struct inode *inode, int ea_ino);
++extern int ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino);
+extern int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
+ struct ext4_xattr_ino_array **array);
+extern void ext4_xattr_inode_array_free(struct inode *inode,
extern void ext4_xattr_put_super(struct super_block *);
extern int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
-Index: linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/ialloc.c
+Index: linux-stage/fs/ext4/ialloc.c
===================================================================
---- linux-3.10.0-123.13.2.el7.x86_64.orig/fs/ext4/ialloc.c
-+++ linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/ialloc.c
-@@ -250,7 +250,6 @@ void ext4_free_inode(handle_t *handle, s
+--- linux-stage.orig/fs/ext4/ialloc.c
++++ linux-stage/fs/ext4/ialloc.c
+@@ -269,7 +269,6 @@ void ext4_free_inode(handle_t *handle, s
* as writing the quota to disk may need the lock as well.
*/
dquot_initialize(inode);
dquot_free_inode(inode);
dquot_drop(inode);
-Index: linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/inline.c
+Index: linux-stage/fs/ext4/inline.c
===================================================================
---- linux-3.10.0-123.13.2.el7.x86_64.orig/fs/ext4/inline.c
-+++ linux-3.10.0-123.13.2.el7.x86_64/fs/ext4/inline.c
+--- linux-stage.orig/fs/ext4/inline.c
++++ linux-stage/fs/ext4/inline.c
@@ -59,7 +59,7 @@ static int get_max_inline_xattr_value_si
/* Compute min_offs. */