diff mbox series

[5/5] fs/ntfs3: Refactoring lock in ntfs_init_acl

Message ID ed6426f4-a579-86ce-a54f-ac356991a797@paragon-software.com (mailing list archive)
State New, archived
Headers show
Series Refactor locking in inode_operations | expand

Commit Message

Konstantin Komarov Sept. 22, 2021, 4:20 p.m. UTC
This is possible because of moving lock into ntfs_create_inode.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
 fs/ntfs3/xattr.c | 55 ++++++++++++------------------------------------
 1 file changed, 14 insertions(+), 41 deletions(-)

Comments

Kari Argillander Sept. 22, 2021, 6:41 p.m. UTC | #1
On Wed, Sep 22, 2021 at 07:20:49PM +0300, Konstantin Komarov wrote:
> This is possible because of moving lock into ntfs_create_inode.
> 
> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>

Looks good.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>

> ---
>  fs/ntfs3/xattr.c | 55 ++++++++++++------------------------------------
>  1 file changed, 14 insertions(+), 41 deletions(-)
> 
> diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c
> index 59ec5e61a239..83bbee277e12 100644
> --- a/fs/ntfs3/xattr.c
> +++ b/fs/ntfs3/xattr.c
> @@ -693,54 +693,27 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,
>  	struct posix_acl *default_acl, *acl;
>  	int err;
>  
> -	/*
> -	 * TODO: Refactoring lock.
> -	 * ni_lock(dir) ... -> posix_acl_create(dir,...) -> ntfs_get_acl -> ni_lock(dir)
> -	 */
> -	inode->i_default_acl = NULL;
> -
> -	default_acl = ntfs_get_acl_ex(mnt_userns, dir, ACL_TYPE_DEFAULT, 1);
> -
> -	if (!default_acl || default_acl == ERR_PTR(-EOPNOTSUPP)) {
> -		inode->i_mode &= ~current_umask();
> -		err = 0;
> -		goto out;
> -	}
> -
> -	if (IS_ERR(default_acl)) {
> -		err = PTR_ERR(default_acl);
> -		goto out;
> -	}
> -
> -	acl = default_acl;
> -	err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
> -	if (err < 0)
> -		goto out1;
> -	if (!err) {
> -		posix_acl_release(acl);
> -		acl = NULL;
> -	}
> -
> -	if (!S_ISDIR(inode->i_mode)) {
> -		posix_acl_release(default_acl);
> -		default_acl = NULL;
> -	}
> +	err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
> +	if (err)
> +		return err;
>  
> -	if (default_acl)
> +	if (default_acl) {
>  		err = ntfs_set_acl_ex(mnt_userns, inode, default_acl,
>  				      ACL_TYPE_DEFAULT, 1);
> +		posix_acl_release(default_acl);
> +	} else {
> +		inode->i_default_acl = NULL;
> +	}
>  
>  	if (!acl)
>  		inode->i_acl = NULL;
> -	else if (!err)
> -		err = ntfs_set_acl_ex(mnt_userns, inode, acl, ACL_TYPE_ACCESS,
> -				      1);
> -
> -	posix_acl_release(acl);
> -out1:
> -	posix_acl_release(default_acl);
> +	else {
> +		if (!err)
> +			err = ntfs_set_acl_ex(mnt_userns, inode, acl,
> +					      ACL_TYPE_ACCESS, 1);
> +		posix_acl_release(acl);
> +	}
>  
> -out:
>  	return err;
>  }
>  #endif
> -- 
> 2.33.0
> 
> 
>
diff mbox series

Patch

diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c
index 59ec5e61a239..83bbee277e12 100644
--- a/fs/ntfs3/xattr.c
+++ b/fs/ntfs3/xattr.c
@@ -693,54 +693,27 @@  int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,
 	struct posix_acl *default_acl, *acl;
 	int err;
 
-	/*
-	 * TODO: Refactoring lock.
-	 * ni_lock(dir) ... -> posix_acl_create(dir,...) -> ntfs_get_acl -> ni_lock(dir)
-	 */
-	inode->i_default_acl = NULL;
-
-	default_acl = ntfs_get_acl_ex(mnt_userns, dir, ACL_TYPE_DEFAULT, 1);
-
-	if (!default_acl || default_acl == ERR_PTR(-EOPNOTSUPP)) {
-		inode->i_mode &= ~current_umask();
-		err = 0;
-		goto out;
-	}
-
-	if (IS_ERR(default_acl)) {
-		err = PTR_ERR(default_acl);
-		goto out;
-	}
-
-	acl = default_acl;
-	err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
-	if (err < 0)
-		goto out1;
-	if (!err) {
-		posix_acl_release(acl);
-		acl = NULL;
-	}
-
-	if (!S_ISDIR(inode->i_mode)) {
-		posix_acl_release(default_acl);
-		default_acl = NULL;
-	}
+	err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
+	if (err)
+		return err;
 
-	if (default_acl)
+	if (default_acl) {
 		err = ntfs_set_acl_ex(mnt_userns, inode, default_acl,
 				      ACL_TYPE_DEFAULT, 1);
+		posix_acl_release(default_acl);
+	} else {
+		inode->i_default_acl = NULL;
+	}
 
 	if (!acl)
 		inode->i_acl = NULL;
-	else if (!err)
-		err = ntfs_set_acl_ex(mnt_userns, inode, acl, ACL_TYPE_ACCESS,
-				      1);
-
-	posix_acl_release(acl);
-out1:
-	posix_acl_release(default_acl);
+	else {
+		if (!err)
+			err = ntfs_set_acl_ex(mnt_userns, inode, acl,
+					      ACL_TYPE_ACCESS, 1);
+		posix_acl_release(acl);
+	}
 
-out:
 	return err;
 }
 #endif