mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>, Chris Mason <mason@kernel.org>,
	Naohiro Aota <naohiro.aota@wdc.com>,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	Boris Burkov <boris@bur.io>, Filipe Manana <fdmanana@suse.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 5/5] btrfs: don't trim the target of a device replace
Date: Sat, 31 Oct 2026 07:32:45 +1030	[thread overview]
Message-ID: <09771899-6a3f-462f-bba6-9243415efefb@suse.com> (raw)
In-Reply-To: <20261030-b4-btrfs-data-integrity-v1-5-f4d4196731e6@toxicpanda.com>



在 2026/10/31 01:08, Josef Bacik 写道:
> FITRIM also discards the space of every device that is not allocated to a
> chunk. btrfs_trim_free_extents() goes over fs_devices->devices and, for
> each device that is writeable, discards the ranges that have neither
> CHUNK_ALLOCATED nor CHUNK_TRIMMED set in device->alloc_state.
> 
> The target device of a running replace operation is on that list and it is
> writeable. But its alloc_state is empty. The allocated ranges of the
> source device are only copied to it by btrfs_set_target_alloc_state(),
> when the replace finishes. Until then the whole device looks unallocated,
> so an fstrim discards everything that was copied to it so far, and what is
> being written to it in parallel to the source device.
> 
> The replace finishes without any error and the source device is dropped.
> With a single device filesystem, 700M of data and fstrim called in a loop
> while the replace runs:
> 
>    BTRFS info: dev_replace from /dev/vdb (devid 1) to /dev/vdc finished
>    BTRFS error: bad tree block start, mirror 1 want 30638080 have 0
>    BTRFS error: bad tree block start, mirror 2 want 30638080 have 0
>    BTRFS info: scrub: not finished on devid 1 with status: -5
> 
> Skip the target device. The flag is cleared with the device list mutex
> held, after the alloc_state was set up, and the trimming code holds that
> mutex while it works on a device.
> 
> Fixes: 499f377f49f0 ("btrfs: iterate over unused chunk space in FITRIM")
> CC: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   fs/btrfs/extent-tree.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 9b0a5c6b96f3..22155507f905 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -6641,6 +6641,14 @@ static int btrfs_trim_free_extents_throttle(struct btrfs_device *device,
>   	if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) || !device->bdev)
>   		return 0;
>   
> +	/*
> +	 * The target of a running device replace has nothing in its alloc_state
> +	 * until the replace finishes, all of it would look unallocated and we
> +	 * would discard what was already copied to it.
> +	 */
> +	if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
> +		return 0;
> +
>   	/* Discard not supported = nothing to do. */
>   	if (!bdev_max_discard_sectors(device->bdev))
>   		return 0;
> 


      reply	other threads:[~2026-10-30 21:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 14:38 [PATCH 0/5] btrfs: data integrity fixes Josef Bacik
2026-10-30 14:38 ` [PATCH 1/5] btrfs: don't drop the error of the last split bio Josef Bacik
2026-10-30 21:03   ` Qu Wenruo
2026-10-30 14:38 ` [PATCH 2/5] btrfs: clear dirty blocks after a delalloc failure Josef Bacik
2026-10-30 20:57   ` Qu Wenruo
2026-10-30 14:38 ` [PATCH 3/5] btrfs: make fsync wait after pre-submission errors Josef Bacik
2026-10-30 21:06   ` Qu Wenruo
2026-10-30 14:38 ` [PATCH 4/5] btrfs: don't report success for a skipped log sync Josef Bacik
2026-10-30 14:38 ` [PATCH 5/5] btrfs: don't trim the target of a device replace Josef Bacik
2026-10-30 21:02   ` Qu Wenruo [this message]

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=09771899-6a3f-462f-bba6-9243415efefb@suse.com \
    --to=wqu@suse.com \
    --cc=boris@bur.io \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=naohiro.aota@wdc.com \
    --cc=stable@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

all inboxes | Powered by JetHome®