jbd2: Grab a reference to the crc32c driver if necessary

Obtain a reference to the crc32c driver if needed for the v2 checksum.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Darrick J. Wong 2012-05-27 07:50:56 -04:00 committed by Theodore Ts'o
parent 25ed6e8a54
commit 01b5adcebb
3 changed files with 50 additions and 0 deletions

View file

@ -31,6 +31,7 @@
#include <linux/mutex.h>
#include <linux/timer.h>
#include <linux/slab.h>
#include <crypto/hash.h>
#endif
#define journal_oom_retry 1
@ -965,6 +966,9 @@ struct journal_s
* superblock pointer here
*/
void *j_private;
/* Reference to checksum algorithm driver via cryptoapi */
struct crypto_shash *j_chksum_driver;
};
/*
@ -1294,6 +1298,25 @@ static inline int jbd_space_needed(journal_t *journal)
extern int jbd_blocks_per_page(struct inode *inode);
static inline u32 jbd2_chksum(journal_t *journal, u32 crc,
const void *address, unsigned int length)
{
struct {
struct shash_desc shash;
char ctx[crypto_shash_descsize(journal->j_chksum_driver)];
} desc;
int err;
desc.shash.tfm = journal->j_chksum_driver;
desc.shash.flags = 0;
*(u32 *)desc.ctx = crc;
err = crypto_shash_update(&desc.shash, address, length);
BUG_ON(err);
return *(u32 *)desc.ctx;
}
#ifdef __KERNEL__
#define buffer_trace_init(bh) do {} while (0)