From: Qu Wenruo <wqu@suse.com>
To: dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 5/6] btrfs-progs: fix-data-checksum: update csum items to fix csum mismatch
Date: Sat, 31 May 2025 07:53:48 +0930 [thread overview]
Message-ID: <8064a4e8-fd7e-4a14-b7c3-ddfd75359664@suse.com> (raw)
In-Reply-To: <20250530111945.GU4037@twin.jikos.cz>
在 2025/5/30 20:49, David Sterba 写道:
> On Thu, May 15, 2025 at 05:30:20PM +0930, Qu Wenruo wrote:
>> +static int update_csum_item(struct btrfs_fs_info *fs_info, u64 logical,
>> + unsigned int mirror)
>> +{
>> + struct btrfs_trans_handle *trans;
>> + struct btrfs_root *csum_root = btrfs_csum_root(fs_info, logical);
>> + struct btrfs_path path = { 0 };
>> + struct btrfs_csum_item *citem;
>> + u64 read_len = fs_info->sectorsize;
>> + u8 csum[BTRFS_CSUM_SIZE] = { 0 };
>> + u8 *buf;
>> + int ret;
>> +
>> + buf = malloc(fs_info->sectorsize);
>> + if (!buf)
>> + return -ENOMEM;
>
> Not fixed, but the block buffers can be on stack as well if they're just
> for the single function, the size is bounded.
Unfortunately the sectorsize is still runtime determined, thus it can
not be on-stack.
Thanks,
Qu>
>> + ret = read_data_from_disk(fs_info, buf, logical, &read_len, mirror);
>> + if (ret < 0) {
>> + errno = -ret;
>> + error("failed to read block at logical %llu mirror %u: %m",
>> + logical, mirror);
>> + goto out;
>> + }
>> + trans = btrfs_start_transaction(csum_root, 1);
>> + if (IS_ERR(trans)) {
>> + ret = PTR_ERR(trans);
>> + errno = -ret;
>> + error_msg(ERROR_MSG_START_TRANS, "%m");
>> + goto out;
>> + }
>> + citem = btrfs_lookup_csum(trans, csum_root, &path, logical,
>> + BTRFS_EXTENT_CSUM_OBJECTID, fs_info->csum_type, 1);
>> + if (IS_ERR(citem)) {
>> + ret = PTR_ERR(citem);
>> + errno = -ret;
>> + error("failed to find csum item for logical %llu: $m", logical);
>> + btrfs_abort_transaction(trans, ret);
>> + goto out;
>> + }
>> + btrfs_csum_data(fs_info, fs_info->csum_type, buf, csum, fs_info->sectorsize);
>> + write_extent_buffer(path.nodes[0], csum, (unsigned long)citem, fs_info->csum_size);
>> + btrfs_release_path(&path);
>> + ret = btrfs_commit_transaction(trans, csum_root);
>> + if (ret < 0) {
>> + errno = -ret;
>> + error_msg(ERROR_MSG_COMMIT_TRANS, "%m");
>> + }
>> + printf("Csum item for logical %llu updated using data from mirror %u\n",
>> + logical, mirror);
>> +out:
>> + free(buf);
>> + btrfs_release_path(&path);
>> + return ret;
>> }
>>
>> static void report_corrupted_blocks(struct btrfs_fs_info *fs_info,
next prev parent reply other threads:[~2025-05-30 22:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 8:00 [PATCH v2 0/6] btrfs-progs: introduce "btrfs rescue fix-data-checksum" Qu Wenruo
2025-05-15 8:00 ` [PATCH v2 1/6] " Qu Wenruo
2025-05-30 11:10 ` David Sterba
2025-05-15 8:00 ` [PATCH v2 2/6] btrfs-progs: fix a bug in btrfs_find_item() Qu Wenruo
2025-05-30 11:11 ` David Sterba
2025-05-15 8:00 ` [PATCH v2 3/6] btrfs-progs: fix-data-checksum: show affected files Qu Wenruo
2025-05-30 11:14 ` David Sterba
2025-05-15 8:00 ` [PATCH v2 4/6] btrfs-progs: fix-data-checksum: introduce interactive mode Qu Wenruo
2025-05-30 11:18 ` David Sterba
2025-05-15 8:00 ` [PATCH v2 5/6] btrfs-progs: fix-data-checksum: update csum items to fix csum mismatch Qu Wenruo
2025-05-30 11:19 ` David Sterba
2025-05-30 22:23 ` Qu Wenruo [this message]
2025-05-15 8:00 ` [PATCH v2 6/6] btrfs-progs: fix-data-checksum: introduce -m|--mirror option Qu Wenruo
2025-05-30 11:07 ` [PATCH v2 0/6] btrfs-progs: introduce "btrfs rescue fix-data-checksum" David Sterba
2025-05-31 16:58 ` Goffredo Baroncelli
2025-05-31 22:07 ` Qu Wenruo
2025-06-02 17:28 ` Goffredo Baroncelli
2025-06-02 22:55 ` Qu Wenruo
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=8064a4e8-fd7e-4a14-b7c3-ddfd75359664@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
/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