]> git.hungrycats.org Git - linux/commit
btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT
authorCheng Yongkang <teel4res@gmail.com>
Sun, 1 Nov 2026 06:25:39 +0000 (23:25 -0700)
committerQu Wenruo <wqu@suse.com>
Sun, 1 Nov 2026 08:30:23 +0000 (19:00 +1030)
commitda7cc40ba243b566a7d6281ef356da58196fa669
tree03594f5abed196c12786f17839eef9a5949e8f81
parent07d844bbfb87d9052c73a43134542afbaf98664d
btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT

btrfs_ioctl_subvol_sync() assumes that a cached root with zero
references has BTRFS_ROOT_SUBVOL_DEAD set, and asserts that before
waiting for the cleaner. Two states break the assumption:

- A corrupt ROOT_ITEM with zero references and a matching orphan item,
  on a writable filesystem.
- A failed subvolume deletion. btrfs_delete_subvolume() zeroes the
  root references, aborts the transaction, which forces the filesystem
  read-only, and then clears DEAD again. No on-disk metadata is
  corrupted in this case.

With CONFIG_BTRFS_ASSERT=y, both reach a BUG().

Change the ASSERT() into a proper rejection to avoid triggering a BUG().

Fixes: 6c83d153ed86 ("btrfs: add new ioctl to wait for cleaned subvolumes")
Cc: stable@vger.kernel.org
Suggested-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Link: https://lore.kernel.org/linux-btrfs/dd97efe9-91ec-495b-b698-acff1447421c@gmx.com/
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
[ Rework the commit message, drop the ad-hoc RW check. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
fs/btrfs/ioctl.c