public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com,
	yukuai3@huawei.com, chengzhihao1@huawei.com
Subject: Re: [PATCH v2 5/6] jbd2: fix a race when checking checkpoint buffer busy
Date: Tue, 6 Jun 2023 09:59:46 +0200	[thread overview]
Message-ID: <20230606075946.dj3ldknkoehr4agp@quack3> (raw)
In-Reply-To: <20230606061447.1125036-6-yi.zhang@huaweicloud.com>

On Tue 06-06-23 14:14:46, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> Before removing checkpoint buffer from the t_checkpoint_list, we have to
> check both BH_Dirty and BH_Lock bits together to distinguish buffers
> have not been or were being written back. But __cp_buffer_busy() checks
> them separately, it first check lock state and then check dirty, the
> window between these two checks could be raced by writing back
> procedure, which locks buffer and clears buffer dirty before I/O
> completes. So it cannot guarantee checkpointing buffers been written
> back to disk if some error happens later. Finally, it may clean
> checkpoint transactions and lead to inconsistent filesystem.
> 
> jbd2_journal_forget() and __journal_try_to_free_buffer() also have the
> same problem (journal_unmap_buffer() escape from this issue since it's
> running under the buffer lock), so fix them through introducing a new
> helper to try holding the buffer lock and remove really clean buffer.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217490
> Cc: stable@vger.kernel.org
> Suggested-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>

Looks good. Feel free to add:

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

Just a type correction below:

> @@ -615,6 +619,34 @@ int __jbd2_journal_remove_checkpoint(struct journal_head *jh)
>  	return 1;
>  }
>  
> +/*
> + * Check the checkpoint buffer and try to remove it from the checkpoint
> + * list if it's clean. Returns -EBUSY if it is not clean, returns 1 if
> + * it frees the transaction, 0 otherwise.
> + *
> + * This function is called with j_list_lock held.
> + */
> +int jbd2_journal_try_remove_checkpoint(struct journal_head *jh)
> +{
> +	struct buffer_head *bh = jh2bh(jh);
> +
> +	if (!trylock_buffer(bh))
> +		return -EBUSY;
> +	if (buffer_dirty(bh)) {
> +		unlock_buffer(bh);
> +		return -EBUSY;
> +	}
> +	unlock_buffer(bh);
> +
> +	/*
> +	 * Buffer is clean and the IO has finished (we hold the buffer
							^^^ held

> +	 * lock) so the checkpoint is done. We can safely remove the
> +	 * buffer from this transaction.
> +	 */
> +	JBUFFER_TRACE(jh, "remove from checkpoint list");
> +	return __jbd2_journal_remove_checkpoint(jh);
> +}

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

  reply	other threads:[~2023-06-06  8:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06  6:14 [PATCH v2 0/6] jbd2: fix several checkpoint inconsistent issues Zhang Yi
2023-06-06  6:14 ` [PATCH v2 1/6] jbd2: recheck chechpointing non-dirty buffer Zhang Yi
2023-06-06  6:14 ` [PATCH v2 2/6] jbd2: remove t_checkpoint_io_list Zhang Yi
2023-06-06  6:14 ` [PATCH v2 3/6] jbd2: remove journal_clean_one_cp_list() Zhang Yi
2023-06-06  7:46   ` Jan Kara
2023-06-06 13:58     ` Zhang Yi
2023-06-06  6:14 ` [PATCH v2 4/6] jbd2: Fix wrongly judgement for buffer head removing while doing checkpoint Zhang Yi
2023-06-06  8:01   ` Jan Kara
2023-06-06  6:14 ` [PATCH v2 5/6] jbd2: fix a race when checking checkpoint buffer busy Zhang Yi
2023-06-06  7:59   ` Jan Kara [this message]
2023-06-06  6:14 ` [PATCH v2 6/6] jbd2: remove __journal_try_to_free_buffer() Zhang Yi
2023-06-06  7:56   ` 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=20230606075946.dj3ldknkoehr4agp@quack3 \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=chengzhihao1@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    --cc=yi.zhang@huaweicloud.com \
    --cc=yukuai3@huawei.com \
    /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