提交 ce855a3b 编写于 作者: J Jaegeuk Kim

f2fs crypto: f2fs_page_crypto() doesn't need a encryption context

This patch adopts:
	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: NTheodore Ts'o <tytso@mit.edu>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 0fac2d50
...@@ -156,7 +156,7 @@ static void completion_pages(struct work_struct *work) ...@@ -156,7 +156,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 = f2fs_decrypt(ctx, page); int ret = f2fs_decrypt(page);
if (ret) { if (ret) {
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
...@@ -320,8 +320,7 @@ typedef enum { ...@@ -320,8 +320,7 @@ typedef enum {
F2FS_ENCRYPT, F2FS_ENCRYPT,
} f2fs_direction_t; } f2fs_direction_t;
static int f2fs_page_crypto(struct f2fs_crypto_ctx *ctx, static int f2fs_page_crypto(struct inode *inode,
struct inode *inode,
f2fs_direction_t rw, f2fs_direction_t rw,
pgoff_t index, pgoff_t index,
struct page *src_page, struct page *src_page,
...@@ -418,7 +417,7 @@ struct page *f2fs_encrypt(struct inode *inode, ...@@ -418,7 +417,7 @@ struct page *f2fs_encrypt(struct inode *inode,
goto err_out; goto err_out;
ctx->w.control_page = plaintext_page; ctx->w.control_page = plaintext_page;
err = f2fs_page_crypto(ctx, inode, F2FS_ENCRYPT, plaintext_page->index, err = f2fs_page_crypto(inode, F2FS_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);
...@@ -446,30 +445,14 @@ struct page *f2fs_encrypt(struct inode *inode, ...@@ -446,30 +445,14 @@ struct page *f2fs_encrypt(struct inode *inode,
* *
* Return: Zero on success, non-zero otherwise. * Return: Zero on success, non-zero otherwise.
*/ */
int f2fs_decrypt(struct f2fs_crypto_ctx *ctx, struct page *page) int f2fs_decrypt(struct page *page)
{ {
BUG_ON(!PageLocked(page)); BUG_ON(!PageLocked(page));
return f2fs_page_crypto(ctx, page->mapping->host, return f2fs_page_crypto(page->mapping->host,
F2FS_DECRYPT, page->index, page, page); F2FS_DECRYPT, page->index, page, page);
} }
/*
* Convenience function which takes care of allocating and
* deallocating the encryption context
*/
int f2fs_decrypt_one(struct inode *inode, struct page *page)
{
struct f2fs_crypto_ctx *ctx = f2fs_get_crypto_ctx(inode);
int ret;
if (IS_ERR(ctx))
return PTR_ERR(ctx);
ret = f2fs_decrypt(ctx, page);
f2fs_release_crypto_ctx(ctx);
return ret;
}
bool f2fs_valid_contents_enc_mode(uint32_t mode) bool f2fs_valid_contents_enc_mode(uint32_t mode)
{ {
return (mode == F2FS_ENCRYPTION_MODE_AES_256_XTS); return (mode == F2FS_ENCRYPTION_MODE_AES_256_XTS);
......
...@@ -1592,7 +1592,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, ...@@ -1592,7 +1592,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
/* avoid symlink page */ /* avoid symlink page */
if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) { if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) {
err = f2fs_decrypt_one(inode, page); err = f2fs_decrypt(page);
if (err) if (err)
goto fail; goto fail;
} }
......
...@@ -2213,8 +2213,7 @@ uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); ...@@ -2213,8 +2213,7 @@ uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t);
struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *);
void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *);
struct page *f2fs_encrypt(struct inode *, struct page *); struct page *f2fs_encrypt(struct inode *, struct page *);
int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *); int f2fs_decrypt(struct page *);
int f2fs_decrypt_one(struct inode *, struct page *);
void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *);
/* crypto_key.c */ /* crypto_key.c */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册