public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Ritesh Harjani <ritesh.list@gmail.com>
Cc: Jan Kara <jack@suse.cz>, Ted Tso <tytso@mit.edu>,
	linux-ext4@vger.kernel.org
Subject: Re: [PATCH 06/10] ext2: Factor our freeing of xattr block reference
Date: Thu, 14 Jul 2022 16:55:38 +0200	[thread overview]
Message-ID: <20220714145538.jbrbobhi5ppvuxka@quack3> (raw)
In-Reply-To: <20220714123714.xxqo7nnde6xacriu@riteshh-domain>

On Thu 14-07-22 18:07:14, Ritesh Harjani wrote:
> On 22/07/12 12:54PM, Jan Kara wrote:
> > Free of xattr block reference is opencode in two places. Factor it out
> > into a separate function and use it.
> 
> Looked into the refactoring logic. The patch looks good to me.
> Small queries below -
> 
> >
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> >  fs/ext2/xattr.c | 90 +++++++++++++++++++++----------------------------
> >  1 file changed, 38 insertions(+), 52 deletions(-)
> >
> > diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
> > index 841fa6d9d744..9885294993ef 100644
> > --- a/fs/ext2/xattr.c
> > +++ b/fs/ext2/xattr.c
> > @@ -651,6 +651,42 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
> >  	return error;
> >  }
> >
> > +static void ext2_xattr_release_block(struct inode *inode,
> > +				     struct buffer_head *bh)
> > +{
> > +	struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
> > +
> > +	lock_buffer(bh);
> > +	if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
> > +		__u32 hash = le32_to_cpu(HDR(bh)->h_hash);
> > +
> > +		/*
> > +		 * This must happen under buffer lock for
> > +		 * ext2_xattr_set2() to reliably detect freed block
> > +		 */
> > +		mb_cache_entry_delete(ea_block_cache, hash,
> > +				      bh->b_blocknr);
> > +		/* Free the old block. */
> > +		ea_bdebug(bh, "freeing");
> > +		ext2_free_blocks(inode, bh->b_blocknr, 1);
> > +		/* We let our caller release bh, so we
> > +		 * need to duplicate the buffer before. */
> > +		get_bh(bh);
> > +		bforget(bh);
> > +		unlock_buffer(bh);
> > +	} else {
> > +		/* Decrement the refcount only. */
> > +		le32_add_cpu(&HDR(bh)->h_refcount, -1);
> > +		dquot_free_block(inode, 1);
> > +		mark_buffer_dirty(bh);
> > +		unlock_buffer(bh);
> > +		ea_bdebug(bh, "refcount now=%d",
> > +			le32_to_cpu(HDR(bh)->h_refcount));
> > +		if (IS_SYNC(inode))
> > +			sync_dirty_buffer(bh);
> > +	}
> > +}
> > +
> >  /*
> >   * Second half of ext2_xattr_set(): Update the file system.
> >   */
> > @@ -747,34 +783,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
> >  		 * If there was an old block and we are no longer using it,
> >  		 * release the old block.
> >  		 */
> > -		lock_buffer(old_bh);
> > -		if (HDR(old_bh)->h_refcount == cpu_to_le32(1)) {
> > -			__u32 hash = le32_to_cpu(HDR(old_bh)->h_hash);
> > -
> > -			/*
> > -			 * This must happen under buffer lock for
> > -			 * ext2_xattr_set2() to reliably detect freed block
> > -			 */
> > -			mb_cache_entry_delete(ea_block_cache, hash,
> > -					      old_bh->b_blocknr);
> > -			/* Free the old block. */
> > -			ea_bdebug(old_bh, "freeing");
> > -			ext2_free_blocks(inode, old_bh->b_blocknr, 1);
> > -			mark_inode_dirty(inode);
> 
> ^^^ this is not needed because ext2_free_blocks() will take care of it.
> Hence you have dropped this in ext2_xattr_release_block()

Correct. ext2_free_blocks() always dirties the inode (unless there is
metadata inconsistency found in which case we don't really care).

> > -			/* We let our caller release old_bh, so we
> > -			 * need to duplicate the buffer before. */
> > -			get_bh(old_bh);
> > -			bforget(old_bh);
> > -		} else {
> > -			/* Decrement the refcount only. */
> > -			le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
> > -			dquot_free_block_nodirty(inode, 1);
> > -			mark_inode_dirty(inode);
> 
> Quick qn -> Don't we need mark_inode_dirty() here?

Notice that I've changed dquot_free_block_nodirty() to dquot_free_block()
because quota info update is the only reason why we need to dirty the inode
so why not let quota code handle it...

> 
> > -			mark_buffer_dirty(old_bh);
> > -			ea_bdebug(old_bh, "refcount now=%d",
> > -				le32_to_cpu(HDR(old_bh)->h_refcount));
> > -		}
> > -		unlock_buffer(old_bh);
> > +		ext2_xattr_release_block(inode, old_bh);
> >  	}

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2022-07-14 14:55 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 10:54 [PATCH 0/10 v3] ext4: Fix possible fs corruption due to xattr races Jan Kara
2022-07-12 10:54 ` [PATCH 01/10] mbcache: Don't reclaim used entries Jan Kara
2022-07-14 11:47   ` Ritesh Harjani
2022-07-14 14:36     ` Jan Kara
2022-07-14 14:49       ` Ritesh Harjani
2022-07-22 13:58   ` Theodore Ts'o
2022-07-12 10:54 ` [PATCH 02/10] mbcache: Add functions to delete entry if unused Jan Kara
2022-07-14 12:15   ` Ritesh Harjani
2022-07-14 14:49     ` Jan Kara
2022-07-14 15:00       ` Ritesh Harjani
2022-07-12 10:54 ` [PATCH 03/10] ext4: Remove EA inode entry from mbcache on inode eviction Jan Kara
2022-07-12 10:54 ` [PATCH 04/10] ext4: Unindent codeblock in ext4_xattr_block_set() Jan Kara
2022-07-14 12:19   ` Ritesh Harjani
2022-07-12 10:54 ` [PATCH 05/10] ext4: Fix race when reusing xattr blocks Jan Kara
2022-07-14 12:26   ` Ritesh Harjani
2022-07-16  3:00   ` Zhihao Cheng
2022-07-25 15:23     ` Jan Kara
2022-07-26  1:14       ` Zhihao Cheng
2022-07-12 10:54 ` [PATCH 06/10] ext2: Factor our freeing of xattr block reference Jan Kara
2022-07-14 12:37   ` Ritesh Harjani
2022-07-14 14:55     ` Jan Kara [this message]
2022-07-14 16:17       ` Ritesh Harjani
2022-07-12 10:54 ` [PATCH 07/10] ext2: Unindent codeblock in ext2_xattr_set() Jan Kara
2022-07-14 12:38   ` Ritesh Harjani
2022-07-12 10:54 ` [PATCH 08/10] ext2: Avoid deleting xattr block that is being reused Jan Kara
2022-07-12 10:54 ` [PATCH 09/10] mbcache: Remove mb_cache_entry_delete() Jan Kara
2022-07-12 10:54 ` [PATCH 10/10] mbcache: Automatically delete entries from cache on freeing Jan Kara
2022-07-14 13:09   ` Ritesh Harjani
2022-07-14 15:05     ` Jan Kara
2022-07-12 12:47 ` [PATCH 0/10 v3] ext4: Fix possible fs corruption due to xattr races Ritesh Harjani
  -- strict thread matches above, loose matches on Subject: below --
2022-06-14 16:05 [PATCH 0/10 v2] " Jan Kara
2022-06-14 16:05 ` [PATCH 06/10] ext2: Factor our freeing of xattr block reference Jan Kara

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=20220714145538.jbrbobhi5ppvuxka@quack3 \
    --to=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    /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