#define EXT4_MMP_MAX_CHECK_INTERVAL 300UL
/*
-+ * Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb
++ * Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1MB
+ * This limit is arbitrary, but is reasonable for the xattr API.
+ */
+#define EXT4_XATTR_MAX_LARGE_EA_SIZE (1024 * 1024)
if (IS_ERR(handle)) {
ext4_std_error(inode->i_sb, PTR_ERR(handle));
/*
-@@ -248,9 +248,36 @@ void ext4_evict_inode(struct inode *inod
- sb_end_intwrite(inode->i_sb);
- goto no_delete;
- }
--
+@@ -251,6 +251,32 @@ void ext4_evict_inode(struct inode *inod
+
if (IS_SYNC(inode))
ext4_handle_sync(handle);
+
-+ /*
-+ * Delete xattr inode before deleting the main inode.
-+ */
++ /* Delete xattr inode before deleting the main inode. */
+ err = ext4_xattr_delete_inode(handle, inode, &lea_ino_array);
+ if (err) {
+ ext4_warning(inode->i_sb,
inode->i_size = 0;
err = ext4_mark_inode_dirty(handle, inode);
if (err) {
-@@ -305,8 +332,12 @@ void ext4_evict_inode(struct inode *inod
- ext4_clear_inode(inode);
- else
+@@ -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);
+@@ -307,6 +334,9 @@ void ext4_evict_inode(struct inode *inod
ext4_free_inode(handle, inode);
-+
ext4_journal_stop(handle);
sb_end_intwrite(inode->i_sb);
+
return;
no_delete:
ext4_clear_inode(inode); /* We must guarantee clearing of inode... */
-@@ -4777,7 +4808,7 @@ static int ext4_index_trans_blocks(struc
+@@ -4777,7 +4807,7 @@ static int ext4_index_trans_blocks(struc
*
* Also account for superblock, inode, quota and xattr blocks
*/
===================================================================
--- 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 +233,26 @@ ext4_xattr_check_block(struct inode *ino
}
{
struct ext4_xattr_entry *entry;
size_t name_len;
-@@ -265,11 +272,104 @@ ext4_xattr_find_entry(struct ext4_xattr_
+@@ -265,11 +272,109 @@ ext4_xattr_find_entry(struct ext4_xattr_
break;
}
*pentry = entry;
+/*
+ * Read the EA value from an inode.
+ */
-+static int
-+ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t *size)
++static int ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t *size)
+{
+ unsigned long block = 0;
+ struct buffer_head *bh = NULL;
+ return err;
+}
+
-+struct inode *ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino, int *err)
++/*
++ * Fetch the xattr inode from disk.
++ *
++ * The xattr inode stores the parent inode number and generation so that
++ * the kernel and e2fsck can verify the xattr inode is valid upon access.
++ */
++struct inode *ext4_xattr_inode_iget(struct inode *parent,
++ unsigned long ea_ino, int *err)
+{
+ struct inode *ea_inode = NULL;
+
+/*
+ * Read the value from the EA inode.
+ */
-+static int
-+ext4_xattr_inode_get(struct inode *inode, unsigned long ea_ino, void *buffer,
-+ size_t *size)
++static int ext4_xattr_inode_get(struct inode *inode, unsigned long ea_ino,
++ void *buffer, size_t *size)
+{
+ struct inode *ea_inode = NULL;
+ int err;
size_t offs = le16_to_cpu(last->e_value_offs);
if (offs < *min_offs)
*min_offs = offs;
-@@ -606,16 +722,172 @@ static size_t ext4_xattr_free_space(stru
+@@ -606,16 +722,196 @@ static size_t ext4_xattr_free_space(stru
return (*min_offs - ((void *)last - base) - sizeof(__u32));
}
+ 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;
+
+ */
+ 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;
+ 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.
+ */
+ 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;
+
size_t offs = le16_to_cpu(last->e_value_offs);
if (offs < min_offs)
min_offs = offs;
-@@ -623,16 +895,21 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -623,16 +919,21 @@ ext4_xattr_set_entry(struct ext4_xattr_i
}
free = min_offs - ((void *)last - s->base) - sizeof(__u32);
if (!s->not_found) {
return -ENOSPC;
}
-@@ -646,7 +923,8 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -646,7 +947,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 {
void *first_val = s->base + min_offs;
size_t offs = le16_to_cpu(s->here->e_value_offs);
void *val = s->base + offs;
-@@ -680,13 +958,18 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -680,13 +982,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 (!i->value) {
/* Remove the old name. */
size_t size = EXT4_XATTR_LEN(name_len);
-@@ -700,10 +982,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -700,10 +1006,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 == EXT4_ZERO_XATTR_VALUE) {
memset(val, 0, size);
} else {
-@@ -753,7 +1042,7 @@ ext4_xattr_block_find(struct inode *inod
+@@ -753,7 +1066,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,
- i->name, bs->bh->b_size, 1);
-+ i->name, bs->bh->b_size, 1, inode);
++ i->name, bs->bh->b_size, 1, inode);
if (error && error != -ENODATA)
goto cleanup;
bs->s.not_found = error;
-@@ -777,8 +1066,6 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -777,8 +1090,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);
-@@ -794,7 +1081,7 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -794,7 +1105,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),
-@@ -845,7 +1132,7 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -845,7 +1156,7 @@ ext4_xattr_block_set(handle_t *handle, s
s->end = s->base + sb->s_blocksize;
}
if (error == -EIO)
goto bad_block;
if (error)
-@@ -994,7 +1281,7 @@ int ext4_xattr_ibody_find(struct inode *
+@@ -994,7 +1305,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;
-@@ -1012,7 +1299,7 @@ int ext4_xattr_ibody_inline_set(handle_t
+@@ -1012,7 +1323,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)) {
-@@ -1024,7 +1311,7 @@ int ext4_xattr_ibody_inline_set(handle_t
+@@ -1024,7 +1335,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;
-@@ -1050,7 +1337,7 @@ static int ext4_xattr_ibody_set(handle_t
+@@ -1050,7 +1361,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));
-@@ -1086,7 +1373,7 @@ ext4_xattr_set_handle(handle_t *handle,
+@@ -1086,7 +1397,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, },
-@@ -1151,6 +1438,15 @@ ext4_xattr_set_handle(handle_t *handle,
+@@ -1151,6 +1462,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) {
-@@ -1197,9 +1493,22 @@ ext4_xattr_set(struct inode *inode, int
+@@ -1197,9 +1517,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)) {
-@@ -1211,7 +1520,7 @@ retry:
+@@ -1211,7 +1544,7 @@ retry:
value, value_len, flags);
error2 = ext4_journal_stop(handle);
if (error == -ENOSPC &&
goto retry;
if (error == 0)
error = error2;
-@@ -1233,7 +1542,7 @@ static void ext4_xattr_shift_entries(str
+@@ -1233,7 +1566,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)
-@@ -1472,21 +1781,135 @@ cleanup:
+@@ -1472,21 +1805,135 @@ cleanup:
}
bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
if (!bh) {
EXT4_ERROR_INODE(inode, "block %llu read error",
-@@ -1499,11 +1922,69 @@ ext4_xattr_delete_inode(handle_t *handle
+@@ -1499,11 +1946,69 @@ ext4_xattr_delete_inode(handle_t *handle
EXT4_I(inode)->i_file_acl);
goto cleanup;
}
}
/*
-@@ -1573,10 +2054,9 @@ ext4_xattr_cmp(struct ext4_xattr_header
+@@ -1573,10 +2078,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)))
-@@ -1660,7 +2140,7 @@ static inline void ext4_xattr_hash_entry
+@@ -1660,7 +2164,7 @@ static inline void ext4_xattr_hash_entry
*name++;
}
+ * 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; \
++#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)
++#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