mirror of
https://github.com/torvalds/linux.git
synced 2024-11-14 08:02:07 +00:00
5f9e1059d9
Since several architectures support hardware-accelerated crc32c calculation, it would be nice to confirm that btrfs is actually using it. We can see an elevated use count for the module, but it doesn't actually show who the users are. This patch simply prints the name of the driver after successfully initializing the shash. Signed-off-by: Jeff Mahoney <jeffm@suse.com> [ added a helper and used in module load-time message ] Signed-off-by: David Sterba <dsterba@suse.com>
52 lines
1.1 KiB
C
52 lines
1.1 KiB
C
/*
|
|
* Copyright (C) 2014 Filipe David Borba Manana <fdmanana@gmail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License v2 as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*/
|
|
|
|
#include <crypto/hash.h>
|
|
#include <linux/err.h>
|
|
#include "hash.h"
|
|
|
|
static struct crypto_shash *tfm;
|
|
|
|
int __init btrfs_hash_init(void)
|
|
{
|
|
tfm = crypto_alloc_shash("crc32c", 0, 0);
|
|
|
|
return PTR_ERR_OR_ZERO(tfm);
|
|
}
|
|
|
|
const char* btrfs_crc32c_impl(void)
|
|
{
|
|
return crypto_tfm_alg_driver_name(crypto_shash_tfm(tfm));
|
|
}
|
|
|
|
void btrfs_hash_exit(void)
|
|
{
|
|
crypto_free_shash(tfm);
|
|
}
|
|
|
|
u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length)
|
|
{
|
|
SHASH_DESC_ON_STACK(shash, tfm);
|
|
u32 *ctx = (u32 *)shash_desc_ctx(shash);
|
|
int err;
|
|
|
|
shash->tfm = tfm;
|
|
shash->flags = 0;
|
|
*ctx = crc;
|
|
|
|
err = crypto_shash_update(shash, address, length);
|
|
BUG_ON(err);
|
|
|
|
return *ctx;
|
|
}
|