]> git.hungrycats.org Git - linux/commit
btrfs: commit the canceled state when a device replace fails or is canceled
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 16 Oct 2026 05:19:17 +0000 (01:19 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:17:13 +0000 (21:17 -0500)
commitb3281fe3706819e0af40bd44efff8d90e7877c71
treeb82dc3623f88354a5e7fb4ceb1bd0715cec6b7c0
parent21605f7637b658d5373dafb988ec3fcc253b4d55
btrfs: commit the canceled state when a device replace fails or is canceled

When the scrub copying a device replace returns an error, including
-ECANCELED from "btrfs replace cancel" on a running replace,
btrfs_dev_replace_finishing() sets the replace state to CANCELED, marks
the dev_replace item for writeback and destroys the target device, but
returns without committing a transaction.

If no other transaction commits before the filesystem is unmounted (an
idle filesystem), the item on disk still says STARTED.  The next mount
then tries to resume the replace and fails:

  BTRFS warning (device ...): cannot mount because device replace operation is ongoing and
  BTRFS warning (device ...): tgtdev (devid 0) is missing, need to run 'btrfs dev scan'?
  BTRFS error (device ...): failed to init dev_replace: -EIO

Commit a transaction after the cleanup, as btrfs_dev_replace_cancel()
already does when it cancels a suspended replace, so the CANCELED state
reaches the disk.  A failure to commit is only logged: the replace has
already failed, and its return value is the scrub error.

Assisted-by: Claude:claude-opus-5-5
fs/btrfs/dev-replace.c