summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/compression.c
diff options
context:
space:
mode:
authorJohannes Thumshirn <jthumshirn@suse.de>2019-06-03 16:58:57 +0200
committerDavid Sterba <dsterba@suse.com>2019-07-01 13:35:02 +0200
commitd5178578bcd461cc79118c7a139882350fe505aa (patch)
treeb6ee534e6aca76d6aee0c18ecf01fd7b7f576449 /fs/btrfs/compression.c
parent6d97c6e31b553bc9f58b83ac3c4c79c17affbda8 (diff)
downloadlinux-d5178578bcd461cc79118c7a139882350fe505aa.tar.gz
linux-d5178578bcd461cc79118c7a139882350fe505aa.tar.bz2
linux-d5178578bcd461cc79118c7a139882350fe505aa.zip
btrfs: directly call into crypto framework for checksumming
Currently btrfs_csum_data() relied on the crc32c() wrapper around the crypto framework for calculating the CRCs. As we have our own crypto_shash structure in the fs_info now, we can directly call into the crypto framework without going trough the wrapper. This way we can even remove the btrfs_csum_data() and btrfs_csum_final() wrappers. The module dependency on crc32c is preserved via MODULE_SOFTDEP("pre: crc32c"), which was previously provided by LIBCRC32C config option doing the same. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/compression.c')
-rw-r--r--fs/btrfs/compression.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 92291f266324..935c0c564c02 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -17,6 +17,7 @@
#include <linux/slab.h>
#include <linux/sched/mm.h>
#include <linux/log2.h>
+#include <crypto/hash.h>
#include "ctree.h"
#include "disk-io.h"
#include "transaction.h"
@@ -58,29 +59,33 @@ static int check_compressed_csum(struct btrfs_inode *inode,
u64 disk_start)
{
struct btrfs_fs_info *fs_info = inode->root->fs_info;
+ SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
const u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
int ret;
struct page *page;
unsigned long i;
char *kaddr;
- u32 csum;
+ u8 csum[BTRFS_CSUM_SIZE];
u8 *cb_sum = cb->sums;
if (inode->flags & BTRFS_INODE_NODATASUM)
return 0;
+ shash->tfm = fs_info->csum_shash;
+
for (i = 0; i < cb->nr_pages; i++) {
page = cb->compressed_pages[i];
- csum = ~(u32)0;
+ crypto_shash_init(shash);
kaddr = kmap_atomic(page);
- csum = btrfs_csum_data(kaddr, csum, PAGE_SIZE);
- btrfs_csum_final(csum, (u8 *)&csum);
+ crypto_shash_update(shash, kaddr, PAGE_SIZE);
kunmap_atomic(kaddr);
+ crypto_shash_final(shash, (u8 *)&csum);
if (memcmp(&csum, cb_sum, csum_size)) {
- btrfs_print_data_csum_error(inode, disk_start, csum,
- *(u32 *)cb_sum, cb->mirror_num);
+ btrfs_print_data_csum_error(inode, disk_start,
+ *(u32 *)csum, *(u32 *)cb_sum,
+ cb->mirror_num);
ret = -EIO;
goto fail;
}