]> www.infradead.org Git - users/jedix/linux-maple.git/commit
btrfs: update superblock's device bytes_used when dropping chunk
authorMark Harmstone <maharmstone@fb.com>
Thu, 29 May 2025 09:37:44 +0000 (10:37 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 19 Jun 2025 13:20:22 +0000 (15:20 +0200)
commitae4477f937569d097ca5dbce92a89ba384b49bc6
treec77161e5898f0a45b1935a2a08504f6267716aa5
parent3ca864de852bc91007b32d2a0d48993724f4abad
btrfs: update superblock's device bytes_used when dropping chunk

Each superblock contains a copy of the device item for that device. In a
transaction which drops a chunk but doesn't create any new ones, we were
correctly updating the device item in the chunk tree but not copying
over the new bytes_used value to the superblock.

This can be seen by doing the following:

  # dd if=/dev/zero of=test bs=4096 count=2621440
  # mkfs.btrfs test
  # mount test /root/temp

  # cd /root/temp
  # for i in {00..10}; do dd if=/dev/zero of=$i bs=4096 count=32768; done
  # sync
  # rm *
  # sync
  # btrfs balance start -dusage=0 .
  # sync

  # cd
  # umount /root/temp
  # btrfs check test

For btrfs-check to detect this, you will also need my patch at
https://github.com/kdave/btrfs-progs/pull/991.

Change btrfs_remove_dev_extents() so that it adds the devices to the
fs_info->post_commit_list if they're not there already. This causes
btrfs_commit_device_sizes() to be called, which updates the bytes_used
value in the superblock.

Fixes: bbbf7243d62d ("btrfs: combine device update operations during transaction commit")
CC: stable@vger.kernel.org # 5.10+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c