Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: Defer setting new inode mode until after do_set_acl succeeds
Date: Thu, 21 Mar 2019 14:42:29 +0200	[thread overview]
Message-ID: <11112d98-e20d-6e15-c72f-8cbae4e6e550@suse.com> (raw)
In-Reply-To: <20190321092703.8136-1-nborisov@suse.com>



On 21.03.19 г. 11:27 ч., Nikolay Borisov wrote:
> Currently a reference to inode->i_mode is passed directly to
> posix_acl_update_mode when setting an ACL which results in the inode's
> mode always being changed. In case of errors (e.g. in do_set_acl or
> even starting a transaction) the old mode needs to be re-assigned to
> ->i_mode. This mode recovery is done only in case do_set_acl fails,
> which leads to buggy behavior in case btrfs_start_transaction fails.
> 
> Fix it by simply setting the new mode to a temporary variable which is
> assigned to inode->i_mode's only when do_set_acl succeeds. This covers
> both failure cases explained above.
> 
> Fixes: db0f220e98eb ("btrfs: start transaction in btrfs_set_acl")
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>  fs/btrfs/acl.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)


This patch is broken and causes inconsistencies on the fs that btrfs
check detects. Test that triggers it - generic/077. I'm trying to
understand why, meanwhile this works:

diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index b722866e1442..f56ed759e0a4 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -123,8 +123,10 @@ int btrfs_set_acl(struct inode *inode, struct
posix_acl *acl, int type)
        }

        trans = btrfs_start_transaction(root, 2);
-       if (IS_ERR(trans))
+       if (IS_ERR(trans)) {
+               inode->i_mode = old_mode;
                return PTR_ERR(trans);
+       }

        ret = do_set_acl(trans, inode, acl, type);
        if (ret) {



However it feels more like proliferating the bad style btrfs_set_acl is
structured in.

> 
> diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
> index b722866e1442..a0cfd2049ea5 100644
> --- a/fs/btrfs/acl.c
> +++ b/fs/btrfs/acl.c
> @@ -99,7 +99,6 @@ static int do_set_acl(struct btrfs_trans_handle *trans, struct inode *inode,
>  	}
>  
>  	ret = btrfs_setxattr(trans, inode, name, value, size, 0);
> -
>  out:
>  	kfree(value);
>  
> @@ -112,12 +111,12 @@ static int do_set_acl(struct btrfs_trans_handle *trans, struct inode *inode,
>  int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
>  {
>  	int ret;
> -	umode_t old_mode = inode->i_mode;
> +	umode_t mode;
>  	struct btrfs_trans_handle *trans;
>  	struct btrfs_root *root = BTRFS_I(inode)->root;
>  
>  	if (type == ACL_TYPE_ACCESS && acl) {
> -		ret = posix_acl_update_mode(inode, &inode->i_mode, &acl);
> +		ret = posix_acl_update_mode(inode, &mode, &acl);
>  		if (ret)
>  			return ret;
>  	}
> @@ -127,9 +126,8 @@ int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
>  		return PTR_ERR(trans);
>  
>  	ret = do_set_acl(trans, inode, acl, type);
> -	if (ret) {
> -		inode->i_mode = old_mode;
> -	} else {
> +	if (!ret) {
> +		inode->i_mode = mode;
>  		inode_inc_iversion(inode);
>  		inode->i_ctime = current_time(inode);
>  		set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags);
> 

  reply	other threads:[~2019-03-21 12:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-21  9:27 [PATCH] btrfs: Defer setting new inode mode until after do_set_acl succeeds Nikolay Borisov
2019-03-21 12:42 ` Nikolay Borisov [this message]
2019-03-21 13:13   ` Johannes Thumshirn
2019-03-21 13:08 ` Johannes Thumshirn
2019-03-21 15:41 ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11112d98-e20d-6e15-c72f-8cbae4e6e550@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox