summaryrefslogtreecommitdiff
path: root/fs/ext4/inode.c
diff options
context:
space:
mode:
authorMiao Xie <miaoxie@huawei.com>2017-08-06 00:27:38 -0400
committerTheodore Ts'o <tytso@mit.edu>2017-08-06 00:27:38 -0400
commit3b10fdc6d8bd048f4fb14af5eda2051ace7b8b16 (patch)
treecab4fdbe9b87cda858f93fa1b89519d69a9fd4df /fs/ext4/inode.c
parent9699d4f91d9bd2f70dcc37afe3c9f18145ab2dba (diff)
ext4: fix forgetten xattr lock protection in ext4_expand_extra_isize
We should avoid the contention between the i_extra_isize update and the inline data insertion, so move the xattr trylock in front of i_extra_isize update. Signed-off-by: Miao Xie <miaoxie@huawei.com> Reviewed-by: Wang Shilong <wshilong@ddn.com>
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r--fs/ext4/inode.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 56bca45bcdf4..5dabbf276651 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5713,10 +5713,15 @@ static int ext4_expand_extra_isize(struct inode *inode,
{
struct ext4_inode *raw_inode;
struct ext4_xattr_ibody_header *header;
+ int no_expand;
+ int error;
if (EXT4_I(inode)->i_extra_isize >= new_extra_isize)
return 0;
+ if (ext4_write_trylock_xattr(inode, &no_expand) == 0)
+ return 0;
+
raw_inode = ext4_raw_inode(&iloc);
header = IHDR(inode, raw_inode);
@@ -5728,12 +5733,21 @@ static int ext4_expand_extra_isize(struct inode *inode,
EXT4_I(inode)->i_extra_isize, 0,
new_extra_isize - EXT4_I(inode)->i_extra_isize);
EXT4_I(inode)->i_extra_isize = new_extra_isize;
+ ext4_write_unlock_xattr(inode, &no_expand);
return 0;
}
/* try to expand with EAs present */
- return ext4_expand_extra_isize_ea(inode, new_extra_isize,
- raw_inode, handle);
+ error = ext4_expand_extra_isize_ea(inode, new_extra_isize,
+ raw_inode, handle);
+ if (error) {
+ /*
+ * Inode size expansion failed; don't try again
+ */
+ no_expand = 1;
+ }
+ ext4_write_unlock_xattr(inode, &no_expand);
+ return error;
}
/*