From patchwork Tue May 12 21:19:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 471569 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2336E14078C for ; Wed, 13 May 2015 07:21:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754276AbbELVUN (ORCPT ); Tue, 12 May 2015 17:20:13 -0400 Received: from mail.kernel.org ([198.145.29.136]:38416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754110AbbELVUK (ORCPT ); Tue, 12 May 2015 17:20:10 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ABE2E203DF; Tue, 12 May 2015 21:20:09 +0000 (UTC) Received: from localhost (mobile-166-171-248-079.mycingular.net [166.171.248.79]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1F16E203DC; Tue, 12 May 2015 21:20:05 +0000 (UTC) From: Jaegeuk Kim To: linux-ext4@vger.kernel.org, Theodore Ts'o Cc: Jaegeuk Kim Subject: [PATCH 1/3] ext4 crypto: move io_completion work into crypto.c Date: Tue, 12 May 2015 14:19:14 -0700 Message-Id: <1431465556-36626-1-git-send-email-jaegeuk@kernel.org> X-Mailer: git-send-email 2.1.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In order to use this completion work across the filesystems, it'd be better to relocate them into crypto.c. Signed-off-by: Jaegeuk Kim --- fs/ext4/crypto.c | 38 ++++++++++++++++++++++++++++++++++++-- fs/ext4/ext4.h | 2 +- fs/ext4/readpage.c | 35 +---------------------------------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index 1484b58..04c620f 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -55,6 +55,9 @@ static mempool_t *ext4_bounce_page_pool; static LIST_HEAD(ext4_free_crypto_ctxs); static DEFINE_SPINLOCK(ext4_crypto_ctx_lock); +static struct workqueue_struct *ext4_read_workqueue; +static DEFINE_MUTEX(crypto_init); + static struct kmem_cache *ext4_crypto_ctx_cachep; struct kmem_cache *ext4_crypt_info_cachep; @@ -175,8 +178,39 @@ out: return ctx; } -struct workqueue_struct *ext4_read_workqueue; -static DEFINE_MUTEX(crypto_init); +/* + * Call ext4_decrypt on every single page, reusing the encryption + * context. + */ +static void completion_pages(struct work_struct *work) +{ + struct ext4_crypto_ctx *ctx = + container_of(work, struct ext4_crypto_ctx, r.work); + struct bio *bio = ctx->r.bio; + struct bio_vec *bv; + int i; + + bio_for_each_segment_all(bv, bio, i) { + struct page *page = bv->bv_page; + + int ret = ext4_decrypt(ctx, page); + if (ret) { + WARN_ON_ONCE(1); + SetPageError(page); + } else + SetPageUptodate(page); + unlock_page(page); + } + ext4_release_crypto_ctx(ctx); + bio_put(bio); +} + +void ext4_end_io_crypto_work(struct ext4_crypto_ctx *ctx, struct bio *bio) +{ + INIT_WORK(&ctx->r.work, completion_pages); + ctx->r.bio = bio; + queue_work(ext4_read_workqueue, &ctx->r.work); +} /** * ext4_exit_crypto() - Shutdown the ext4 encryption system diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 550fe95..505bc66 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2062,7 +2062,7 @@ int ext4_get_policy(struct inode *inode, extern struct kmem_cache *ext4_crypt_info_cachep; bool ext4_valid_contents_enc_mode(uint32_t mode); uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size); -extern struct workqueue_struct *ext4_read_workqueue; +void ext4_end_io_crypto_work(struct ext4_crypto_ctx *ctx, struct bio *bio); struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode); void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx); void ext4_restore_control_page(struct page *data_page); diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c index ec3ef93..a7b074e 100644 --- a/fs/ext4/readpage.c +++ b/fs/ext4/readpage.c @@ -46,37 +46,6 @@ #include "ext4.h" -/* - * Call ext4_decrypt on every single page, reusing the encryption - * context. - */ -static void completion_pages(struct work_struct *work) -{ -#ifdef CONFIG_EXT4_FS_ENCRYPTION - struct ext4_crypto_ctx *ctx = - container_of(work, struct ext4_crypto_ctx, r.work); - struct bio *bio = ctx->r.bio; - struct bio_vec *bv; - int i; - - bio_for_each_segment_all(bv, bio, i) { - struct page *page = bv->bv_page; - - int ret = ext4_decrypt(ctx, page); - if (ret) { - WARN_ON_ONCE(1); - SetPageError(page); - } else - SetPageUptodate(page); - unlock_page(page); - } - ext4_release_crypto_ctx(ctx); - bio_put(bio); -#else - BUG(); -#endif -} - static inline bool ext4_bio_encrypted(struct bio *bio) { #ifdef CONFIG_EXT4_FS_ENCRYPTION @@ -109,9 +78,7 @@ static void mpage_end_io(struct bio *bio, int err) if (err) { ext4_release_crypto_ctx(ctx); } else { - INIT_WORK(&ctx->r.work, completion_pages); - ctx->r.bio = bio; - queue_work(ext4_read_workqueue, &ctx->r.work); + ext4_end_io_crypto_work(ctx, bio); return; } }