From: Johannes Thumshirn <jthumshirn@suse.de>
To: Nikolay Borisov <nborisov@suse.com>, David Sterba <dsterba@suse.com>
Cc: Linux BTRFS Mailinglist <linux-btrfs@vger.kernel.org>
Subject: Re: [RFC PATCH 10/17] btrfs-progs: add checksum type to checksumming functions
Date: Mon, 26 Aug 2019 11:34:12 +0200 [thread overview]
Message-ID: <c159de9e-0c69-eae7-62dd-7f9efe315f21@suse.de> (raw)
In-Reply-To: <f7db0360-adcc-05c7-f99a-8302ac99a06d@suse.com>
On 12/08/2019 12:21, Nikolay Borisov wrote:
>
>
> On 25.07.19 г. 12:33 ч., Johannes Thumshirn wrote:
>> Add the checksum type to csum_tree_block_size(), __csum_tree_block_size()
>> and verify_tree_block_csum_silent().
>>
>> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
>> ---
>> btrfs-corrupt-block.c | 3 ++-
>> cmds/rescue-chunk-recover.c | 3 ++-
>> convert/common.c | 3 ++-
>> convert/main.c | 3 ++-
>> disk-io.c | 21 ++++++++++++---------
>> disk-io.h | 5 +++--
>> mkfs/common.c | 21 ++++++++++++++-------
>> 7 files changed, 37 insertions(+), 22 deletions(-)
>>
>> diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
>> index bbef0c02e5d1..1dde9594bdcc 100644
>> --- a/btrfs-corrupt-block.c
>> +++ b/btrfs-corrupt-block.c
>> @@ -158,7 +158,8 @@ static void corrupt_keys(struct btrfs_trans_handle *trans,
>> if (!trans) {
>> u16 csum_size =
>> btrfs_super_csum_size(fs_info->super_copy);
>> - csum_tree_block_size(eb, csum_size, 0);
>> + u16 csum_type = btrfs_super_csum_type(fs_info->super_copy);
>> + csum_tree_block_size(eb, csum_size, 0, csum_type);
>
> I'm not a big fan of open-coding this csum manipulation. Generally if we
> ensure that we always pass a well-formed eb to csum_tree_block_size and
> by well-formed I mean one which has its ->fs_info, which in turn is
> well-formed then we can encapsulate this interrogation of csum type into
> csum_tree_block.
>
>> write_extent_to_disk(eb);
>> }
>> }
>> diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c
>> index 308731ea5ea6..1a368310d895 100644
>> --- a/cmds/rescue-chunk-recover.c
>> +++ b/cmds/rescue-chunk-recover.c
>> @@ -768,7 +768,8 @@ static int scan_one_device(void *dev_scan_struct)
>> continue;
>> }
>>
>> - if (verify_tree_block_csum_silent(buf, rc->csum_size)) {
>> + if (verify_tree_block_csum_silent(buf, rc->csum_size,
>> + rc->csum_type)) {
>
> But this is not a well-formed eb :(
>
>> bytenr += rc->sectorsize;
>> continue;
>> }
>> diff --git a/convert/common.c b/convert/common.c
>> index dea5f5b20d50..f8bbb23cba89 100644
>> --- a/convert/common.c
>> +++ b/convert/common.c
>> @@ -223,7 +223,8 @@ static inline int write_temp_extent_buffer(int fd, struct extent_buffer *buf,
>> {
>> int ret;
>>
>> - csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0);
>> + csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
>> + cfg->csum_type);
>
> Neither is this ...
>>
>> /* Temporary extent buffer is always mapped 1:1 on disk */
>> ret = pwrite(fd, buf->data, buf->len, bytenr);
>> diff --git a/convert/main.c b/convert/main.c
>> index 9711874bd137..5e6b12431f59 100644
>> --- a/convert/main.c
>> +++ b/convert/main.c
>> @@ -1058,7 +1058,8 @@ static int migrate_super_block(int fd, u64 old_bytenr)
>> BUG_ON(btrfs_super_bytenr(super) != old_bytenr);
>> btrfs_set_super_bytenr(super, BTRFS_SUPER_INFO_OFFSET);
>>
>> - csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0);
>> + csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0,
>> + btrfs_super_csum_type(super));
>> ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
>> BTRFS_SUPER_INFO_OFFSET);
>> if (ret != BTRFS_SUPER_INFO_SIZE)
>> diff --git a/disk-io.c b/disk-io.c
>> index 01314504a50a..a4995a628210 100644
>> --- a/disk-io.c
>> +++ b/disk-io.c
>> @@ -149,7 +149,7 @@ void btrfs_csum_final(u32 crc, u8 *result)
>> }
>>
>> static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
>> - int verify, int silent)
>> + int verify, int silent, u16 csum_type)
>> {
>> u8 result[BTRFS_CSUM_SIZE];
>> u32 len;
>> @@ -174,24 +174,27 @@ static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
>> return 0;
>> }
>>
>> -int csum_tree_block_size(struct extent_buffer *buf, u16 csum_size, int verify)
>> +int csum_tree_block_size(struct extent_buffer *buf, u16 csum_size, int verify,
>> + u16 csum_type)
>> {
>> - return __csum_tree_block_size(buf, csum_size, verify, 0);
>> + return __csum_tree_block_size(buf, csum_size, verify, 0, csum_type);
>> }
>>
>> -int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size)
>> +int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size,
>> + u16 csum_type)
>> {
>> - return __csum_tree_block_size(buf, csum_size, 1, 1);
>> + return __csum_tree_block_size(buf, csum_size, 1, 1, csum_type);
>> }
>
> Now that those function take the csum_type it renders passing the
> csum_size redundant. Refactor them so that only csum_type is passed and
> make __csum_tree_block_size (perhahps it should be renamed now?) get the
> size based on the type.
>
> I think the csum interface can be simplified further:
>
> 1. Leave csum_tree_block for callers that pass well-formed eb's (as is
> currently)
>
> 2. Rename __csum_tree_block_size to __csum_tree_block which takes just
> the buffer, boolean flag verify and u16 (or better enum btrfs_csum_type)
> csum_type arguments and the nitty-gritty details
>
> 3. Remove csum_tree_block_size and directly call the new
> __csum_tree_block. The former just wraps the 'silent' parameter...
>
> In the end we will be left with just 2 functions:
>
> (__)csum_tree_blocks .
>
> Additionally verify_tree_block_csum_silent has really one caller because
> in csum_tree_block it's enough to call __csum_tree_block_size just once
> and pass verify and fs_info->suppress_check_block_errors directly to it.
> Then you can also directly call __csum_tree_block in scan_one_device in
> rescue-chunk-recover.c . And this would put some sanity into the current
> csum interfaces in progs.
>
> I guess this could land as a follow-up to your patches...
>
I'd really like to have this rework as a follow up as it introduces a
non-negligible regression potential and can "easily" be done after this
series has landed.
--
Johannes Thumshirn SUSE Labs Filesystems
jthumshirn@suse.de +49 911 74053 689
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5
90409 Nürnberg
Germany
(HRB 247165, AG München)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
next prev parent reply other threads:[~2019-08-26 9:34 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 9:33 [RFC PATCH 0/4] Support xxhash64 checksums Johannes Thumshirn
2019-07-25 9:33 ` [RFC PATCH 1/4] btrfs: turn checksum type define into a union Johannes Thumshirn
2019-07-25 11:08 ` Mike Fleetwood
2019-07-25 11:21 ` Johannes Thumshirn
2019-07-25 9:33 ` [RFC PATCH 2/4] btrfs: create structure to encode checksum type and length Johannes Thumshirn
2019-07-26 3:09 ` Su Yue
2019-07-30 17:25 ` David Sterba
2019-08-12 9:07 ` Nikolay Borisov
2019-08-19 9:15 ` Johannes Thumshirn
2019-07-25 9:33 ` [RFC PATCH 3/4] btrfs: use xxhash64 for checksumming Johannes Thumshirn
2019-07-25 12:02 ` Qu Wenruo
2019-07-25 14:18 ` Johannes Thumshirn
2019-07-26 13:45 ` David Sterba
2019-07-25 9:33 ` [RFC PATCH 4/4] btrfs: sysfs: export supported checksums Johannes Thumshirn
2019-07-30 17:19 ` David Sterba
2019-07-31 8:06 ` Johannes Thumshirn
2019-08-07 14:10 ` Johannes Thumshirn
2019-08-21 16:19 ` David Sterba
2019-08-12 9:19 ` Nikolay Borisov
2019-08-19 9:15 ` Johannes Thumshirn
2019-07-25 9:33 ` [RFC PATCH 05/17] btrfs-progs: add option for checksum type to mkfs Johannes Thumshirn
2019-07-30 17:36 ` David Sterba
2019-08-12 9:30 ` Nikolay Borisov
2019-07-25 9:33 ` [RFC PATCH 06/17] btrfs-progs: don't blindly assume crc32c in csum_tree_block_size() Johannes Thumshirn
2019-08-12 9:49 ` Nikolay Borisov
2019-07-25 9:33 ` [RFC PATCH 07/17] btrfs-progs: use btrfs_csum_data() in __csum_tree_block_size() Johannes Thumshirn
2019-07-30 17:37 ` David Sterba
2019-07-25 9:33 ` [RFC PATCH 08/17] btrfs-progs: cache csum_type in recover_control Johannes Thumshirn
2019-08-12 9:52 ` Nikolay Borisov
2019-07-25 9:33 ` [RFC PATCH 09/17] progs: pass in a btrfs_mkfs_config to write_temp_extent_buffer Johannes Thumshirn
2019-07-30 17:38 ` David Sterba
2019-08-12 9:56 ` Nikolay Borisov
2019-07-25 9:33 ` [RFC PATCH 10/17] btrfs-progs: add checksum type to checksumming functions Johannes Thumshirn
2019-08-12 10:21 ` Nikolay Borisov
2019-08-26 9:34 ` Johannes Thumshirn [this message]
2019-07-25 9:33 ` [RFC PATCH 11/17] btrfs-progs: don't assume checksums are always 4 bytes Johannes Thumshirn
2019-07-25 9:33 ` [RFC PATCH 12/17] btrfs-progs: pass checksum type to btrfs_csum_data() Johannes Thumshirn
2019-08-12 10:51 ` Nikolay Borisov
2019-08-20 9:12 ` Johannes Thumshirn
2019-07-25 9:34 ` [RFC PATCH 13/17] " Johannes Thumshirn
2019-07-25 9:34 ` [RFC PATCH 14/17] btrfs-progs: simplify update_block_csum() in btrfs-sb-mod.c Johannes Thumshirn
2019-08-12 10:53 ` Nikolay Borisov
2019-07-25 9:34 ` [RFC PATCH 15/17] btrfs-progs: update checksumming api Johannes Thumshirn
2019-07-25 9:34 ` [RFC PATCH 16/17] btrfs-progs: add xxhash sources Johannes Thumshirn
2019-07-25 9:34 ` [RFC PATCH 17/17] btrfs-progs: add xxhash64 as checksum algorithm Johannes Thumshirn
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=c159de9e-0c69-eae7-62dd-7f9efe315f21@suse.de \
--to=jthumshirn@suse.de \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.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;
as well as URLs for NNTP newsgroup(s).