Skip to contentSkip to conversation

btrfs: fix failed sprout device add rollback

PATCH Superseded Guanghui Yang 2 participants 2 messages Aug 10 Btrfs file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover btrfs: fix failed sprout device add rollback

Hi,

This series fixes the error path for adding the first writable device to a seed filesystem.

I verified the failure path locally in QEMU with null_blk and a seed btrfs filesystem:

- create btrfs on /dev/nullb0
- set the seed flag with btrfstune -S 1
- mount the filesystem read-only
- run "btrfs device add -f /dev/nullb1 /mnt"
- inject -EIO after metadata chunk creation in init_first_rw_device()

Before these fixes, the injected failure triggered:

- WARN_ON(!list_empty(&device->post_commit_list)) in btrfs_free_device()
- a NULL pointer dereference through btrfs_show_devname()
- the sprout fs_devices state left with no open devices

Without the injected failure, the same device-add path succeeds.

Guanghui Yang (3):
btrfs: detach failed sprout device from transaction update list
btrfs: restore active device pointers after failed sprout
btrfs: roll back sprout setup after device add failure

This v2 keeps the code changes unchanged and adds the local reproduction result to the cover letter.

 fs/btrfs/volumes.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

base-commit: 38fec10eb60d687e30c8c6b5420d86e8149f7557

Signature · 1 line
2.53.0
#1 lore raw
Quoted 14 lines · Guanghui Yang

Hi,

This series fixes the error path for adding the first writable device to a seed filesystem.

I verified the failure path locally in QEMU with null_blk and a seed btrfs filesystem:

- create btrfs on /dev/nullb0
- set the seed flag with btrfstune -S 1
- mount the filesystem read-only
- run "btrfs device add -f /dev/nullb1 /mnt"
- inject -EIO after metadata chunk creation in init_first_rw_device()

Quoted 7 lines

Before these fixes, the injected failure triggered:

- WARN_ON(!list_empty(&device->post_commit_list)) in btrfs_free_device()
- a NULL pointer dereference through btrfs_show_devname()
- the sprout fs_devices state left with no open devices

Without the injected failure, the same device-add path succeeds.

Missing AI disclosure?

Quoted 14 lines

Guanghui Yang (3):
btrfs: detach failed sprout device from transaction update list
btrfs: restore active device pointers after failed sprout
btrfs: roll back sprout setup after device add failure

This v2 keeps the code changes unchanged and adds the local reproduction result to the cover letter.

  fs/btrfs/volumes.c | 43 +++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 43 insertions(+)

base-commit: 38fec10eb60d687e30c8c6b5420d86e8149f7557