From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH v2 2/4] btrfs: assign checksum shash slots on init
Date: Fri, 29 Jul 2022 19:42:46 +0200 [thread overview]
Message-ID: <ec5ccf0b18c481951f72947fbb63c72c7513c60a.1659116355.git.dsterba@suse.com> (raw)
In-Reply-To: <cover.1659116355.git.dsterba@suse.com>
When initializing checksum implementation on first mount, assign it to
the proper slot based on the driver name. If it contains "generic" it's
considered the non-accelerated one. Based on that properly set the
BTRFS_FS_CSUM_IMPL_FAST bit, previously it could be mistakenly set as
fast despite a different checksum (eg. sha256) with generic
implementation.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/disk-io.c | 13 ++++++++++++-
fs/btrfs/super.c | 2 --
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3c2251199f0c..247187427760 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2430,7 +2430,18 @@ static int btrfs_init_csum_hash(struct btrfs_fs_info *fs_info, u16 csum_type)
return PTR_ERR(csum_shash);
}
- fs_info->csum_shash[CSUM_DEFAULT] = csum_shash;
+ /*
+ * Find the fastest implementation available, but keep the slots
+ * matching the type.
+ */
+ if (strstr(crypto_shash_driver_name(fs_info->csum_shash[CSUM_DEFAULT]),
+ "generic") != NULL) {
+ fs_info->csum_shash[CSUM_GENERIC] = csum_shash;
+ clear_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags);
+ } else {
+ fs_info->csum_shash[CSUM_ACCEL] = csum_shash;
+ set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags);
+ }
btrfs_info(fs_info, "using %s (%s) checksum algorithm",
btrfs_super_csum_name(csum_type),
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 1032aaa2c2f4..595b8d92ef86 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1819,8 +1819,6 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
} else {
snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev);
btrfs_sb(s)->bdev_holder = fs_type;
- if (!strstr(crc32c_impl(), "generic"))
- set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags);
error = btrfs_fill_super(s, fs_devices, data);
}
if (!error)
--
2.36.1
next prev parent reply other threads:[~2022-07-29 17:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 17:42 [PATCH v2 0/4] Selectable checksum implementation David Sterba
2022-07-29 17:42 ` [PATCH v2 1/4] btrfs: prepare more slots for checksum shash David Sterba
2022-07-29 17:42 ` David Sterba [this message]
2022-07-29 17:42 ` [PATCH v2 3/4] btrfs: add checksum implementation selection after mount David Sterba
2022-08-01 8:31 ` Johannes Thumshirn
2022-07-29 17:42 ` [PATCH v2 4/4] btrfs: sysfs: print all loaded csums implementations David Sterba
2022-07-29 21:01 ` [PATCH v2 0/4] Selectable checksum implementation Boris Burkov
2022-08-01 18:55 ` David Sterba
-- strict thread matches above, loose matches on Subject: below --
2022-08-02 12:28 David Sterba
2022-08-02 12:28 ` [PATCH v2 2/4] btrfs: assign checksum shash slots on init David Sterba
2022-08-02 20:30 ` kernel test robot
2022-08-02 21:10 ` kernel test robot
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=ec5ccf0b18c481951f72947fbb63c72c7513c60a.1659116355.git.dsterba@suse.com \
--to=dsterba@suse.com \
--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;
as well as URLs for NNTP newsgroup(s).