[1/4] ext4: fix forgetten xattr lock protection in ext4_expand_extra_isize

Submitted by Miao Xie on July 6, 2017, 5:09 p.m.

Details

Message ID 1499360993-17130-1-git-send-email-miaoxie@huawei.com
State New
Headers show

Commit Message

Miao Xie July 6, 2017, 5:09 p.m.
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>
---
 fs/ext4/inode.c | 18 ++++++++++++++++--
 fs/ext4/xattr.c | 10 ----------
 2 files changed, 16 insertions(+), 12 deletions(-)

Comments

Miao Xie July 13, 2017, 12:55 p.m.
Ping......

on 2017/7/7 at 1:09, Miao Xie wrote:
> 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>
> ---
>  fs/ext4/inode.c | 18 ++++++++++++++++--
>  fs/ext4/xattr.c | 10 ----------
>  2 files changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 5cf82d0..4af3edc 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5639,10 +5639,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);
> @@ -5654,12 +5659,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;
>  }
>  
>  /*
> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index 5d3c253..12ee5fb 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
> @@ -1472,10 +1472,6 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
>  	int error = 0, tried_min_extra_isize = 0;
>  	int s_min_extra_isize = le16_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_min_extra_isize);
>  	int isize_diff;	/* How much do we need to grow i_extra_isize */
> -	int no_expand;
> -
> -	if (ext4_write_trylock_xattr(inode, &no_expand) == 0)
> -		return 0;
>  
>  retry:
>  	isize_diff = new_extra_isize - EXT4_I(inode)->i_extra_isize;
> @@ -1558,16 +1554,10 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
>  	EXT4_I(inode)->i_extra_isize = new_extra_isize;
>  	brelse(bh);
>  out:
> -	ext4_write_unlock_xattr(inode, &no_expand);
>  	return 0;
>  
>  cleanup:
>  	brelse(bh);
> -	/*
> -	 * Inode size expansion failed; don't try again
> -	 */
> -	no_expand = 1;
> -	ext4_write_unlock_xattr(inode, &no_expand);
>  	return error;
>  }
>  
>
Wang Shilong July 13, 2017, 1:04 p.m.
I guess Maintainer will reply you when development cycle is ready for this.
Please be patient Miao!, let's play Glory of the king.^^^_^^^
Theodore Ts'o July 13, 2017, 4:47 p.m.
On Thu, Jul 13, 2017 at 01:04:08PM +0000, Wang Shilong wrote:
>   I guess Maintainer will reply you when development cycle is ready for this.
> Please be patient Miao!, let's play Glory of the king.^^^_^^^

Sorry, this come in too late for it be included in the merge window,
since at that time I Was trying to do final regression testing before
sending a pull request to Linus.

I'm also currently on travel (attending Usenix ATC and visiting $WORK
in the Bay Area).  I will start accumulating fixes soon, probably
shortly after 4.13-rc1 comes out.  It *would* be helpful if other ext4
developers could review the patches while on travel (hint, hint).
Otherwise, I'll start reviewing patches in a week or two.

Cheers,

					- Ted

Patch hide | download patch | download mbox

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 5cf82d0..4af3edc 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5639,10 +5639,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);
@@ -5654,12 +5659,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;
 }
 
 /*
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 5d3c253..12ee5fb 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1472,10 +1472,6 @@  int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
 	int error = 0, tried_min_extra_isize = 0;
 	int s_min_extra_isize = le16_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_min_extra_isize);
 	int isize_diff;	/* How much do we need to grow i_extra_isize */
-	int no_expand;
-
-	if (ext4_write_trylock_xattr(inode, &no_expand) == 0)
-		return 0;
 
 retry:
 	isize_diff = new_extra_isize - EXT4_I(inode)->i_extra_isize;
@@ -1558,16 +1554,10 @@  int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
 	EXT4_I(inode)->i_extra_isize = new_extra_isize;
 	brelse(bh);
 out:
-	ext4_write_unlock_xattr(inode, &no_expand);
 	return 0;
 
 cleanup:
 	brelse(bh);
-	/*
-	 * Inode size expansion failed; don't try again
-	 */
-	no_expand = 1;
-	ext4_write_unlock_xattr(inode, &no_expand);
 	return error;
 }