]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: fix clearing of BTRFS_FS_RELOC_RUNNING if relocation already running
authorFilipe Manana <fdmanana@suse.com>
Wed, 24 Sep 2025 15:10:38 +0000 (16:10 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 13 Oct 2025 20:29:03 +0000 (22:29 +0200)
commit7e5a5983edda664e8e4bb20af17b80f5135c655c
tree331214dccbac7bed3b52af4eed4fca29e179f1e8
parent4335c4496b1bcf8e85761af23550a180e937bac6
btrfs: fix clearing of BTRFS_FS_RELOC_RUNNING if relocation already running

When starting relocation, at reloc_chunk_start(), if we happen to find
the flag BTRFS_FS_RELOC_RUNNING is already set we return an error
(-EINPROGRESS) to the callers, however the callers call reloc_chunk_end()
which will clear the flag BTRFS_FS_RELOC_RUNNING, which is wrong since
relocation was started by another task and still running.

Finding the BTRFS_FS_RELOC_RUNNING flag already set is an unexpected
scenario, but still our current behaviour is not correct.

Fix this by never calling reloc_chunk_end() if reloc_chunk_start() has
returned an error, which is what logically makes sense, since the general
widespread pattern is to have end functions called only if the counterpart
start functions succeeded. This requires changing reloc_chunk_start() to
clear BTRFS_FS_RELOC_RUNNING if there's a pending cancel request.

Fixes: 907d2710d727 ("btrfs: add cancellable chunk relocation support")
CC: stable@vger.kernel.org # 5.15+
Reviewed-by: Boris Burkov <boris@bur.io>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/relocation.c