Commit 11bd143f authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse

Btrfs: Switch to libcrc32c to avoid problems with cryptomgr on highmem machines

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent e011599b
...@@ -286,10 +286,7 @@ struct btrfs_block_group_cache { ...@@ -286,10 +286,7 @@ struct btrfs_block_group_cache {
int cached; int cached;
}; };
struct crypto_hash;
struct btrfs_fs_info { struct btrfs_fs_info {
spinlock_t hash_lock;
struct btrfs_root *extent_root; struct btrfs_root *extent_root;
struct btrfs_root *tree_root; struct btrfs_root *tree_root;
struct radix_tree_root fs_roots_radix; struct radix_tree_root fs_roots_radix;
...@@ -314,7 +311,6 @@ struct btrfs_fs_info { ...@@ -314,7 +311,6 @@ struct btrfs_fs_info {
struct mutex fs_mutex; struct mutex fs_mutex;
struct list_head trans_list; struct list_head trans_list;
struct list_head dead_roots; struct list_head dead_roots;
struct crypto_hash *hash_tfm;
struct delayed_work trans_work; struct delayed_work trans_work;
int do_barriers; int do_barriers;
int closing; int closing;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/crypto.h> #include <linux/crc32c.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/radix-tree.h> #include <linux/radix-tree.h>
...@@ -147,22 +147,12 @@ static int btree_get_block(struct inode *inode, sector_t iblock, ...@@ -147,22 +147,12 @@ static int btree_get_block(struct inode *inode, sector_t iblock,
int btrfs_csum_data(struct btrfs_root * root, char *data, size_t len, int btrfs_csum_data(struct btrfs_root * root, char *data, size_t len,
char *result) char *result)
{ {
struct scatterlist sg; u32 crc;
struct crypto_hash *tfm = root->fs_info->hash_tfm; crc = crc32c(0, data, len);
struct hash_desc desc; memcpy(result, &crc, BTRFS_CRC32_SIZE);
int ret; return 0;
desc.tfm = tfm;
desc.flags = 0;
sg_init_one(&sg, data, len);
spin_lock_irq(&root->fs_info->hash_lock);
ret = crypto_hash_digest(&desc, &sg, 1, result);
spin_unlock_irq(&root->fs_info->hash_lock);
if (ret) {
printk("digest failed\n");
}
return ret;
} }
static int csum_tree_block(struct btrfs_root *root, struct buffer_head *bh, static int csum_tree_block(struct btrfs_root *root, struct buffer_head *bh,
int verify) int verify)
{ {
...@@ -454,14 +444,7 @@ struct btrfs_root *open_ctree(struct super_block *sb) ...@@ -454,14 +444,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
sizeof(struct btrfs_key)); sizeof(struct btrfs_key));
insert_inode_hash(fs_info->btree_inode); insert_inode_hash(fs_info->btree_inode);
mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
fs_info->hash_tfm = crypto_alloc_hash("crc32c", 0, CRYPTO_ALG_ASYNC);
spin_lock_init(&fs_info->hash_lock);
if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) {
printk("btrfs: failed hash setup, modprobe cryptomgr?\n");
err = -ENOMEM;
goto fail_iput;
}
mutex_init(&fs_info->trans_mutex); mutex_init(&fs_info->trans_mutex);
mutex_init(&fs_info->fs_mutex); mutex_init(&fs_info->fs_mutex);
...@@ -613,7 +596,6 @@ int close_ctree(struct btrfs_root *root) ...@@ -613,7 +596,6 @@ int close_ctree(struct btrfs_root *root)
btrfs_block_release(fs_info->tree_root, btrfs_block_release(fs_info->tree_root,
fs_info->tree_root->node); fs_info->tree_root->node);
btrfs_block_release(root, fs_info->sb_buffer); btrfs_block_release(root, fs_info->sb_buffer);
crypto_free_hash(fs_info->hash_tfm);
truncate_inode_pages(fs_info->btree_inode->i_mapping, 0); truncate_inode_pages(fs_info->btree_inode->i_mapping, 0);
iput(fs_info->btree_inode); iput(fs_info->btree_inode);
......
...@@ -607,7 +607,8 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, ...@@ -607,7 +607,8 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
while(count > 0) { while(count > 0) {
size_t offset = pos & (PAGE_CACHE_SIZE - 1); size_t offset = pos & (PAGE_CACHE_SIZE - 1);
size_t write_bytes = min(count, nrptrs * PAGE_CACHE_SIZE - size_t write_bytes = min(count, nrptrs *
(size_t)PAGE_CACHE_SIZE -
offset); offset);
size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >> size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
PAGE_CACHE_SHIFT; PAGE_CACHE_SHIFT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment