Skip to content

Commit 68d99ab

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: fix fast csum implementation detection
The BTRFS_FS_CSUM_IMPL_FAST flag is currently set whenever a non-generic crc32c is detected, which is the incorrect check if the file system uses a different checksumming algorithm. Refactor the code to only check this if crc32c is actually used. Note that in an ideal world the information if an algorithm is hardware accelerated or not should be provided by the crypto API instead, but that's left for another day. CC: [email protected] # 5.4.x: c8a5f8c: btrfs: print checksum type and implementation at mount time CC: [email protected] # 5.4.x Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 40fac64 commit 68d99ab

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

fs/btrfs/disk-io.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,20 @@ static int btrfs_init_csum_hash(struct btrfs_fs_info *fs_info, u16 csum_type)
22502250

22512251
fs_info->csum_shash = csum_shash;
22522252

2253+
/*
2254+
* Check if the checksum implementation is a fast accelerated one.
2255+
* As-is this is a bit of a hack and should be replaced once the csum
2256+
* implementations provide that information themselves.
2257+
*/
2258+
switch (csum_type) {
2259+
case BTRFS_CSUM_TYPE_CRC32:
2260+
if (!strstr(crypto_shash_driver_name(csum_shash), "generic"))
2261+
set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags);
2262+
break;
2263+
default:
2264+
break;
2265+
}
2266+
22532267
btrfs_info(fs_info, "using %s (%s) checksum algorithm",
22542268
btrfs_super_csum_name(csum_type),
22552269
crypto_shash_driver_name(csum_shash));

fs/btrfs/super.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,8 +1516,6 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
15161516
shrinker_debugfs_rename(&s->s_shrink, "sb-%s:%s", fs_type->name,
15171517
s->s_id);
15181518
btrfs_sb(s)->bdev_holder = fs_type;
1519-
if (!strstr(crc32c_impl(), "generic"))
1520-
set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags);
15211519
error = btrfs_fill_super(s, fs_devices, data);
15221520
}
15231521
if (!error)

0 commit comments

Comments
 (0)