btrfs: use crypto_shash_digest() instead of open coding
Use crypto_shash_digest() instead of crypto_shash_init() + crypto_shash_update() + crypto_shash_final(). This is more efficient. Signed-off-by: Eric Biggers <ebiggers@google.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
committed by
David Sterba
parent
1ed802c972
commit
fd08001f17
@@ -194,11 +194,9 @@ static int check_compressed_csum(struct btrfs_inode *inode,
|
|||||||
for (i = 0; i < cb->nr_pages; i++) {
|
for (i = 0; i < cb->nr_pages; i++) {
|
||||||
page = cb->compressed_pages[i];
|
page = cb->compressed_pages[i];
|
||||||
|
|
||||||
crypto_shash_init(shash);
|
|
||||||
kaddr = kmap_atomic(page);
|
kaddr = kmap_atomic(page);
|
||||||
crypto_shash_update(shash, kaddr, PAGE_SIZE);
|
crypto_shash_digest(shash, kaddr, PAGE_SIZE, csum);
|
||||||
kunmap_atomic(kaddr);
|
kunmap_atomic(kaddr);
|
||||||
crypto_shash_final(shash, (u8 *)&csum);
|
|
||||||
|
|
||||||
if (memcmp(&csum, cb_sum, csum_size)) {
|
if (memcmp(&csum, cb_sum, csum_size)) {
|
||||||
btrfs_print_data_csum_error(inode, disk_start,
|
btrfs_print_data_csum_error(inode, disk_start,
|
||||||
|
|||||||
@@ -358,16 +358,14 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
|
|||||||
SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
|
SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
|
||||||
|
|
||||||
shash->tfm = fs_info->csum_shash;
|
shash->tfm = fs_info->csum_shash;
|
||||||
crypto_shash_init(shash);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The super_block structure does not span the whole
|
* The super_block structure does not span the whole
|
||||||
* BTRFS_SUPER_INFO_SIZE range, we expect that the unused space is
|
* BTRFS_SUPER_INFO_SIZE range, we expect that the unused space is
|
||||||
* filled with zeros and is included in the checksum.
|
* filled with zeros and is included in the checksum.
|
||||||
*/
|
*/
|
||||||
crypto_shash_update(shash, raw_disk_sb + BTRFS_CSUM_SIZE,
|
crypto_shash_digest(shash, raw_disk_sb + BTRFS_CSUM_SIZE,
|
||||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE, result);
|
||||||
crypto_shash_final(shash, result);
|
|
||||||
|
|
||||||
if (memcmp(disk_sb->csum, result, btrfs_super_csum_size(disk_sb)))
|
if (memcmp(disk_sb->csum, result, btrfs_super_csum_size(disk_sb)))
|
||||||
return 1;
|
return 1;
|
||||||
@@ -3504,10 +3502,9 @@ static int write_dev_supers(struct btrfs_device *device,
|
|||||||
|
|
||||||
btrfs_set_super_bytenr(sb, bytenr);
|
btrfs_set_super_bytenr(sb, bytenr);
|
||||||
|
|
||||||
crypto_shash_init(shash);
|
crypto_shash_digest(shash, (const char *)sb + BTRFS_CSUM_SIZE,
|
||||||
crypto_shash_update(shash, (const char *)sb + BTRFS_CSUM_SIZE,
|
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE,
|
||||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
sb->csum);
|
||||||
crypto_shash_final(shash, sb->csum);
|
|
||||||
|
|
||||||
page = find_or_create_page(mapping, bytenr >> PAGE_SHIFT,
|
page = find_or_create_page(mapping, bytenr >> PAGE_SHIFT,
|
||||||
GFP_NOFS);
|
GFP_NOFS);
|
||||||
|
|||||||
@@ -601,13 +601,12 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio,
|
|||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto_shash_init(shash);
|
|
||||||
data = kmap_atomic(bvec.bv_page);
|
data = kmap_atomic(bvec.bv_page);
|
||||||
crypto_shash_update(shash, data + bvec.bv_offset
|
crypto_shash_digest(shash, data + bvec.bv_offset
|
||||||
+ (i * fs_info->sectorsize),
|
+ (i * fs_info->sectorsize),
|
||||||
fs_info->sectorsize);
|
fs_info->sectorsize,
|
||||||
|
sums->sums + index);
|
||||||
kunmap_atomic(data);
|
kunmap_atomic(data);
|
||||||
crypto_shash_final(shash, (char *)(sums->sums + index));
|
|
||||||
index += csum_size;
|
index += csum_size;
|
||||||
offset += fs_info->sectorsize;
|
offset += fs_info->sectorsize;
|
||||||
this_sum_bytes += fs_info->sectorsize;
|
this_sum_bytes += fs_info->sectorsize;
|
||||||
|
|||||||
@@ -2742,9 +2742,7 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio,
|
|||||||
kaddr = kmap_atomic(page);
|
kaddr = kmap_atomic(page);
|
||||||
shash->tfm = fs_info->csum_shash;
|
shash->tfm = fs_info->csum_shash;
|
||||||
|
|
||||||
crypto_shash_init(shash);
|
crypto_shash_digest(shash, kaddr + pgoff, len, csum);
|
||||||
crypto_shash_update(shash, kaddr + pgoff, len);
|
|
||||||
crypto_shash_final(shash, csum);
|
|
||||||
|
|
||||||
if (memcmp(csum, csum_expected, csum_size))
|
if (memcmp(csum, csum_expected, csum_size))
|
||||||
goto zeroit;
|
goto zeroit;
|
||||||
|
|||||||
Reference in New Issue
Block a user