@@ -2536,7 +2536,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);
+ }
return 0;
}
@@ -1816,8 +1816,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)
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(-)