Commit 3684de8c authored by Theodore Ts'o's avatar Theodore Ts'o

ext4 crypto: ext4_page_crypto() doesn't need a encryption context

Since ext4_page_crypto() doesn't need an encryption context (at least
not any more), this allows us to simplify a number function signature
and also allows us to avoid needing to allocate a context in
ext4_block_write_begin().  It also means we no longer need a separate
ext4_decrypt_one() function.
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent cccd147a
...@@ -253,8 +253,7 @@ typedef enum { ...@@ -253,8 +253,7 @@ typedef enum {
EXT4_ENCRYPT, EXT4_ENCRYPT,
} ext4_direction_t; } ext4_direction_t;
static int ext4_page_crypto(struct ext4_crypto_ctx *ctx, static int ext4_page_crypto(struct inode *inode,
struct inode *inode,
ext4_direction_t rw, ext4_direction_t rw,
pgoff_t index, pgoff_t index,
struct page *src_page, struct page *src_page,
...@@ -353,7 +352,7 @@ struct page *ext4_encrypt(struct inode *inode, ...@@ -353,7 +352,7 @@ struct page *ext4_encrypt(struct inode *inode,
if (IS_ERR(ciphertext_page)) if (IS_ERR(ciphertext_page))
goto errout; goto errout;
ctx->w.control_page = plaintext_page; ctx->w.control_page = plaintext_page;
err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, plaintext_page->index, err = ext4_page_crypto(inode, EXT4_ENCRYPT, plaintext_page->index,
plaintext_page, ciphertext_page); plaintext_page, ciphertext_page);
if (err) { if (err) {
ciphertext_page = ERR_PTR(err); ciphertext_page = ERR_PTR(err);
...@@ -378,31 +377,14 @@ struct page *ext4_encrypt(struct inode *inode, ...@@ -378,31 +377,14 @@ struct page *ext4_encrypt(struct inode *inode,
* *
* Return: Zero on success, non-zero otherwise. * Return: Zero on success, non-zero otherwise.
*/ */
int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page) int ext4_decrypt(struct page *page)
{ {
BUG_ON(!PageLocked(page)); BUG_ON(!PageLocked(page));
return ext4_page_crypto(ctx, page->mapping->host, return ext4_page_crypto(page->mapping->host,
EXT4_DECRYPT, page->index, page, page); EXT4_DECRYPT, page->index, page, page);
} }
/*
* Convenience function which takes care of allocating and
* deallocating the encryption context
*/
int ext4_decrypt_one(struct inode *inode, struct page *page)
{
int ret;
struct ext4_crypto_ctx *ctx = ext4_get_crypto_ctx(inode);
if (IS_ERR(ctx))
return PTR_ERR(ctx);
ret = ext4_decrypt(ctx, page);
ext4_release_crypto_ctx(ctx);
return ret;
}
int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex) int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex)
{ {
struct ext4_crypto_ctx *ctx; struct ext4_crypto_ctx *ctx;
...@@ -426,7 +408,7 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex) ...@@ -426,7 +408,7 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex)
} }
while (len--) { while (len--) {
err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, lblk, err = ext4_page_crypto(inode, EXT4_ENCRYPT, lblk,
ZERO_PAGE(0), ciphertext_page); ZERO_PAGE(0), ciphertext_page);
if (err) if (err)
goto errout; goto errout;
......
...@@ -2063,8 +2063,7 @@ void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx); ...@@ -2063,8 +2063,7 @@ void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx);
void ext4_restore_control_page(struct page *data_page); void ext4_restore_control_page(struct page *data_page);
struct page *ext4_encrypt(struct inode *inode, struct page *ext4_encrypt(struct inode *inode,
struct page *plaintext_page); struct page *plaintext_page);
int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page); int ext4_decrypt(struct page *page);
int ext4_decrypt_one(struct inode *inode, struct page *page);
int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex); int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex);
#ifdef CONFIG_EXT4_FS_ENCRYPTION #ifdef CONFIG_EXT4_FS_ENCRYPTION
......
...@@ -965,7 +965,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, ...@@ -965,7 +965,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
if (unlikely(err)) if (unlikely(err))
page_zero_new_buffers(page, from, to); page_zero_new_buffers(page, from, to);
else if (decrypt) else if (decrypt)
err = ext4_decrypt_one(inode, page); err = ext4_decrypt(page);
return err; return err;
} }
#endif #endif
...@@ -3404,7 +3404,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, ...@@ -3404,7 +3404,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
/* We expect the key to be set. */ /* We expect the key to be set. */
BUG_ON(!ext4_has_encryption_key(inode)); BUG_ON(!ext4_has_encryption_key(inode));
BUG_ON(blocksize != PAGE_CACHE_SIZE); BUG_ON(blocksize != PAGE_CACHE_SIZE);
WARN_ON_ONCE(ext4_decrypt_one(inode, page)); WARN_ON_ONCE(ext4_decrypt(page));
} }
} }
if (ext4_should_journal_data(inode)) { if (ext4_should_journal_data(inode)) {
......
...@@ -62,7 +62,7 @@ static void completion_pages(struct work_struct *work) ...@@ -62,7 +62,7 @@ static void completion_pages(struct work_struct *work)
bio_for_each_segment_all(bv, bio, i) { bio_for_each_segment_all(bv, bio, i) {
struct page *page = bv->bv_page; struct page *page = bv->bv_page;
int ret = ext4_decrypt(ctx, page); int ret = ext4_decrypt(page);
if (ret) { if (ret) {
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
SetPageError(page); SetPageError(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