Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 4131817

Browse files
maharmstoneCarlotta-Montelli
authored andcommitted
btrfs: update superblock's device bytes_used when dropping chunk
commit ae4477f937569d097ca5dbce92a89ba384b49bc6 upstream. 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 kdave/btrfs-progs#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: [email protected] # 5.10+ Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Mark Harmstone <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 07c37b7 commit 4131817

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/btrfs/volumes.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,6 +2819,12 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
28192819
device->bytes_used - dev_extent_len);
28202820
atomic64_add(dev_extent_len, &fs_info->free_chunk_space);
28212821
btrfs_clear_space_info_full(fs_info);
2822+
2823+
if (list_empty(&device->post_commit_list)) {
2824+
list_add_tail(&device->post_commit_list,
2825+
&trans->transaction->dev_update_list);
2826+
}
2827+
28222828
mutex_unlock(&fs_info->chunk_mutex);
28232829
}
28242830

0 commit comments

Comments
 (0)