From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Mark Harmstone <maharmstone@fb.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: update superblock's device bytes_used when dropping chunk
Date: Thu, 29 May 2025 19:13:55 +0930 [thread overview]
Message-ID: <7e483f82-af39-4fdf-9e28-67cd09f243c7@gmx.com> (raw)
In-Reply-To: <20250529093821.2818081-1-maharmstone@fb.com>
在 2025/5/29 19:07, Mark Harmstone 写道:
> 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.
Oh! This explains why the image in
fsck/020/keyed_data_ref_with_shared_leaf.img has the mismatched result.
It's not an older kernel (almost 4 years after another related kernel
fix), but really some bug in the kernel.
>
> This can be seen by doing the following:
>
> # cd
> # 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
> 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.
>
> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Looks good to me.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu> ---
> fs/btrfs/volumes.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index e59aa0b5c4f3..ee886dc08d15 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -3272,6 +3272,12 @@ int btrfs_remove_dev_extents(struct btrfs_trans_handle *trans,
> device->bytes_used - dev_extent_len);
> atomic64_add(dev_extent_len, &fs_info->free_chunk_space);
> btrfs_clear_space_info_full(fs_info);
> +
> + if (list_empty(&device->post_commit_list)) {
> + list_add_tail(&device->post_commit_list,
> + &trans->transaction->dev_update_list);
> + }
> +
> mutex_unlock(&fs_info->chunk_mutex);
> }
> }
next prev parent reply other threads:[~2025-05-29 9:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-29 9:37 [PATCH] btrfs: update superblock's device bytes_used when dropping chunk Mark Harmstone
2025-05-29 9:43 ` Qu Wenruo [this message]
2025-06-02 20:16 ` David Sterba
2025-06-03 9:40 ` Mark Harmstone
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7e483f82-af39-4fdf-9e28-67cd09f243c7@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=maharmstone@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox