From patchwork Wed Feb 22 21:25:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9587479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B95FD600CA for ; Wed, 22 Feb 2017 21:26:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7A1027F94 for ; Wed, 22 Feb 2017 21:26:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A801286A1; Wed, 22 Feb 2017 21:26:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A17327F94 for ; Wed, 22 Feb 2017 21:26:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934611AbdBVV0k (ORCPT ); Wed, 22 Feb 2017 16:26:40 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33242 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933492AbdBVV0c (ORCPT ); Wed, 22 Feb 2017 16:26:32 -0500 Received: by mail-pf0-f195.google.com with SMTP id p185so277967pfb.0; Wed, 22 Feb 2017 13:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=whF3jSJVlZHovh7UMPKDITjhiq9VPETPus+znz5Kl3E=; b=Qgz4afMK23nHxnzjPIKQjb9mZ/+HIO2DveYSRAu4QY6v+uvYFlhzUY9dh0lbB2UzWS rpB04OJ1CsmfZW7gY9qYlA8guqG54YeENIcDHmXgv6VueRViCRcleXDzODXNj3PsUB8p ifPwLJR+KRBDItBjnm5Ff2N1MCAmMC5efIZuGxhZXOvYJ8n3cmxAj3ukE/j7xv+Ug0bw d9Y9YuI3Lg0R7c6gVXpGddkWLhr0yJJPl/+ul05F5A41WynY1Jv0YUWM85betHl3hdpz cefLO6ht3sWLeJEdKnCotOCWUuZfnt1RMQBOz0A2zRWr2Hp6VAgiyS5q52rbbqYdpP95 nG2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=whF3jSJVlZHovh7UMPKDITjhiq9VPETPus+znz5Kl3E=; b=a/BVldFT8tN5DcQVbppf/D0xTI1XgvgfHgnfKjnIU1PqCpsTQVvd7m1BSsDwwo/Uak O9PfjAE5sksBCu1ecu4xIb7pdIvNsKHi755dA7XBOuGzPTnSpAZVNt9NbKBFjK7uZ1sv kbeeBGgmCqDUVooE5GLxQ88i0vm3gydFXsdgK/67UGcc0yYssFsIILhWVC1e8IyLOUOF neZZyUeRdJN+em+NagEcCEjXDD4pQM/vernsyxuQa2TuIyC1jTfFvN+8lErSIH9ujaBv Bo7RjFHIYezywWSHAhotM9xEG/j3c16Fz225NuYhHZ0tmL2IGJTT1xDnEnaGwtThWwUp aisA== X-Gm-Message-State: AMke39k+QTIDMrLbPYandT0K9iir8OBES5mm2ulH10hSjb2/NDc1qfqufd+EXDjzXniDvw== X-Received: by 10.84.238.1 with SMTP id u1mr50835206plk.174.1487798735417; Wed, 22 Feb 2017 13:25:35 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.119.30.131]) by smtp.gmail.com with ESMTPSA id 143sm5346601pgb.66.2017.02.22.13.25.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 13:25:34 -0800 (PST) From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: "Theodore Y . Ts'o" , Jaegeuk Kim , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Eric Biggers Subject: [PATCH] fscrypt: eliminate ->prepare_context() operation Date: Wed, 22 Feb 2017 13:25:14 -0800 Message-Id: <20170222212514.61919-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers The only use of the ->prepare_context() fscrypt operation was to allow ext4 to evict inline data from the inode before ->set_context(). However, there is no reason why this cannot be done as simply the first step in ->set_context(), and in fact it makes more sense to do it that way because then the policy modes and flags get validated before any real work is done. Therefore, merge ext4_prepare_context() into ext4_set_context(), and remove ->prepare_context(). Signed-off-by: Eric Biggers --- fs/crypto/policy.c | 7 ------- fs/ext4/super.c | 10 ++++------ include/linux/fscrypt_common.h | 1 - 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index 14b76da71269..4908906d54d5 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -33,17 +33,10 @@ static int create_encryption_context_from_policy(struct inode *inode, const struct fscrypt_policy *policy) { struct fscrypt_context ctx; - int res; if (!inode->i_sb->s_cop->set_context) return -EOPNOTSUPP; - if (inode->i_sb->s_cop->prepare_context) { - res = inode->i_sb->s_cop->prepare_context(inode); - if (res) - return res; - } - ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1; memcpy(ctx.master_key_descriptor, policy->master_key_descriptor, FS_KEY_DESCRIPTOR_SIZE); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 2e03a0a88d92..a9448db1cf7e 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1120,17 +1120,16 @@ static int ext4_get_context(struct inode *inode, void *ctx, size_t len) EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, ctx, len); } -static int ext4_prepare_context(struct inode *inode) -{ - return ext4_convert_inline_data(inode); -} - static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, void *fs_data) { handle_t *handle = fs_data; int res, res2, retries = 0; + res = ext4_convert_inline_data(inode); + if (res) + return res; + /* * If a journal handle was specified, then the encryption context is * being set on a new inode via inheritance and is part of a larger @@ -1196,7 +1195,6 @@ static unsigned ext4_max_namelen(struct inode *inode) static const struct fscrypt_operations ext4_cryptops = { .key_prefix = "ext4:", .get_context = ext4_get_context, - .prepare_context = ext4_prepare_context, .set_context = ext4_set_context, .dummy_context = ext4_dummy_context, .is_encrypted = ext4_encrypted_inode, diff --git a/include/linux/fscrypt_common.h b/include/linux/fscrypt_common.h index 547f81592ba1..10c1abfbac6c 100644 --- a/include/linux/fscrypt_common.h +++ b/include/linux/fscrypt_common.h @@ -87,7 +87,6 @@ struct fscrypt_operations { unsigned int flags; const char *key_prefix; int (*get_context)(struct inode *, void *, size_t); - int (*prepare_context)(struct inode *); int (*set_context)(struct inode *, const void *, size_t, void *); int (*dummy_context)(struct inode *); bool (*is_encrypted)(struct inode *);