Commit f32d7ac2 authored by David Gstir's avatar David Gstir Committed by Theodore Ts'o

fscrypt: Delay bounce page pool allocation until needed

Since fscrypt users can now indicated if fscrypt_encrypt_page() should
use a bounce page, we can delay the bounce page pool initialization util
it is really needed. That is until fscrypt_operations has no
FS_CFLG_OWN_PAGES flag set.
Signed-off-by: default avatarDavid Gstir <david@sigma-star.at>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent bd7b8290
...@@ -525,17 +525,22 @@ static void fscrypt_destroy(void) ...@@ -525,17 +525,22 @@ static void fscrypt_destroy(void)
/** /**
* fscrypt_initialize() - allocate major buffers for fs encryption. * fscrypt_initialize() - allocate major buffers for fs encryption.
* @cop_flags: fscrypt operations flags
* *
* We only call this when we start accessing encrypted files, since it * We only call this when we start accessing encrypted files, since it
* results in memory getting allocated that wouldn't otherwise be used. * results in memory getting allocated that wouldn't otherwise be used.
* *
* Return: Zero on success, non-zero otherwise. * Return: Zero on success, non-zero otherwise.
*/ */
int fscrypt_initialize(void) int fscrypt_initialize(unsigned int cop_flags)
{ {
int i, res = -ENOMEM; int i, res = -ENOMEM;
if (fscrypt_bounce_page_pool) /*
* No need to allocate a bounce page pool if there already is one or
* this FS won't use it.
*/
if (cop_flags & FS_CFLG_OWN_PAGES || fscrypt_bounce_page_pool)
return 0; return 0;
mutex_lock(&fscrypt_init_mutex); mutex_lock(&fscrypt_init_mutex);
......
...@@ -85,7 +85,7 @@ struct fscrypt_completion_result { ...@@ -85,7 +85,7 @@ struct fscrypt_completion_result {
/* crypto.c */ /* crypto.c */
int fscrypt_initialize(void); int fscrypt_initialize(unsigned int cop_flags);
/* keyinfo.c */ /* keyinfo.c */
extern int fscrypt_get_crypt_info(struct inode *); extern int fscrypt_get_crypt_info(struct inode *);
......
...@@ -188,7 +188,7 @@ int fscrypt_get_crypt_info(struct inode *inode) ...@@ -188,7 +188,7 @@ int fscrypt_get_crypt_info(struct inode *inode)
u8 *raw_key = NULL; u8 *raw_key = NULL;
int res; int res;
res = fscrypt_initialize(); res = fscrypt_initialize(inode->i_sb->s_cop->flags);
if (res) if (res)
return res; return res;
......
...@@ -168,7 +168,6 @@ static inline void fscrypt_set_d_op(struct dentry *dentry) ...@@ -168,7 +168,6 @@ static inline void fscrypt_set_d_op(struct dentry *dentry)
#if IS_ENABLED(CONFIG_FS_ENCRYPTION) #if IS_ENABLED(CONFIG_FS_ENCRYPTION)
/* crypto.c */ /* crypto.c */
extern struct kmem_cache *fscrypt_info_cachep; extern struct kmem_cache *fscrypt_info_cachep;
extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t); extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t);
extern void fscrypt_release_ctx(struct fscrypt_ctx *); extern void fscrypt_release_ctx(struct fscrypt_ctx *);
extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *, extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
......
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