public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: "Luis Henriques (SUSE)" <luis.henriques@linux.dev>
Cc: Theodore Ts'o <tytso@mit.edu>, Andreas Dilger <adilger@dilger.ca>,
	Jan Kara <jack@suse.cz>,
	Harshad Shirwadkar <harshadshirwadkar@gmail.com>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] ext4: fix incorrect tid assumption in ext4_fc_mark_ineligible()
Date: Wed, 24 Jul 2024 12:15:04 +0200	[thread overview]
Message-ID: <20240724101504.e2t4pvgw6td7rrmm@quack3> (raw)
In-Reply-To: <20240723154402.21125-5-luis.henriques@linux.dev>

On Tue 23-07-24 16:44:02, Luis Henriques (SUSE) wrote:
> Function jbd2_journal_shrink_checkpoint_list() assumes that '0' is not a
> valid value for transaction IDs, which is incorrect.
> 
> Furthermore, the sbi->s_fc_ineligible_tid handling also makes the same
> assumption by being initialised to '0'.  Fortunately, the sb flag
> EXT4_MF_FC_INELIGIBLE can be used to check whether sbi->s_fc_ineligible_tid
> has been previously set instead of comparing it with '0'.
> 
> Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>

Just one style nit below, otherwise looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

BTW, the ineligibility handling looks flaky to me, in particular the cases
where we call ext4_fc_mark_ineligible() with NULL handle seem racy to me as
fastcommit can happen *before* we mark the filesystem as ineligible.  But
that's not really related to your changes, they just made me look at that
code in detail and I couldn't resist complaining :)

> ---
>  fs/ext4/fast_commit.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> index 3926a05eceee..3e0793cfea38 100644
> --- a/fs/ext4/fast_commit.c
> +++ b/fs/ext4/fast_commit.c
> @@ -339,22 +339,29 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
>  {
>  	struct ext4_sb_info *sbi = EXT4_SB(sb);
>  	tid_t tid;
> +	bool has_transaction = true;
> +	bool is_ineligible;
>  
>  	if (ext4_fc_disabled(sb))
>  		return;
>  
> -	ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
>  	if (handle && !IS_ERR(handle))
>  		tid = handle->h_transaction->t_tid;
>  	else {
>  		read_lock(&sbi->s_journal->j_state_lock);
> -		tid = sbi->s_journal->j_running_transaction ?
> -				sbi->s_journal->j_running_transaction->t_tid : 0;
> +		if (sbi->s_journal->j_running_transaction)
> +			tid = sbi->s_journal->j_running_transaction->t_tid;
> +		else
> +			has_transaction = false;
>  		read_unlock(&sbi->s_journal->j_state_lock);
>  	}
>  	spin_lock(&sbi->s_fc_lock);
> -	if (tid_gt(tid, sbi->s_fc_ineligible_tid))
> +	is_ineligible = ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
> +	if (has_transaction &&
> +	    ((!is_ineligible) ||
	     ^^ these extra braces look strange

> +	     (is_ineligible && tid_gt(tid, sbi->s_fc_ineligible_tid))))
>  		sbi->s_fc_ineligible_tid = tid;
> +	ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);

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

  reply	other threads:[~2024-07-24 10:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23 15:43 [PATCH 0/4] ext4: fix incorrect tid assumptions Luis Henriques (SUSE)
2024-07-23 15:43 ` [PATCH 1/4] ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit() Luis Henriques (SUSE)
2024-07-24  9:17   ` Jan Kara
2024-07-24 13:35     ` Luis Henriques
2024-07-23 15:44 ` [PATCH 2/4] ext4: fix incorrect tid assumption in __jbd2_log_wait_for_space() Luis Henriques (SUSE)
2024-07-24  9:20   ` Jan Kara
2024-07-23 15:44 ` [PATCH 3/4] ext4: fix incorrect tid assumption in jbd2_journal_shrink_checkpoint_list() Luis Henriques (SUSE)
2024-07-24  9:29   ` Jan Kara
2024-07-24 13:38     ` Luis Henriques
2024-07-23 15:44 ` [PATCH 4/4] ext4: fix incorrect tid assumption in ext4_fc_mark_ineligible() Luis Henriques (SUSE)
2024-07-24 10:15   ` Jan Kara [this message]
2024-07-24 14:02     ` Luis Henriques
2024-07-24 15:13       ` 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=20240724101504.e2t4pvgw6td7rrmm@quack3 \
    --to=jack@suse.cz \
    --cc=adilger@dilger.ca \
    --cc=harshadshirwadkar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luis.henriques@linux.dev \
    --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