From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1B42C10DCE for ; Sat, 7 Mar 2020 02:38:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8F5F206CC for ; Sat, 7 Mar 2020 02:38:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CQ+nWBxY"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="G0s2YXUs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8F5F206CC Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aqTutcki7tCsb3aGocH8U2Co9AnnqaR9rGDIsP43Zuw=; b=CQ+nWBxYBt353U 881XaX6zJ5sZVx15NVGSAG3Ty+Yi+BdgC165cen2DWui1/DQ6yMMciuAG8O++5avL4EnbCnGP4V08 i6BPbWIn8O+vyhw7kbeFYRAgJlX0d2KrSJSwZPxwlRWT4ESSuzFdTBELcwRfAuhQjHpVYiEY3N7JN uqNcm/lgKdY7dy8mFvQio13EXZNF15m7Rai7cmuD6BvaR1Ye95VYevaOvNyM9EObZ83lthGygbupK DTsmThPHy0EA2DTOg5wzPWGGxNeXUEGVMEWqpNrlV2LaYvrZpTrfOJLZQ1k9ZuwCGjkaw03GTnriW zTAoGhWSiyrIwMFkIi/g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jAPLq-00032F-MI; Sat, 07 Mar 2020 02:38:06 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jAPKc-0001Yc-UV for linux-mtd@lists.infradead.org; Sat, 07 Mar 2020 02:36:52 +0000 Received: by mail-pg1-x549.google.com with SMTP id 12so2530340pgv.1 for ; Fri, 06 Mar 2020 18:36:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=W0NRqN4tKUIiubnsRHwnrkHz9xP0jc5bUIehefjfrK0=; b=G0s2YXUs60QGYd1azRm9N+DEtQUa9U2sfAd7n5dRhxO4cGELADBu0RCaWtuzEoewXq 1VwOG8xo3CB9fbum61PZal2AG/c+LDNuGpC5Dn34tE/7BTiNV7muT/IgD/5qvclPBYsk NSksw1pSB68xMWgFtawTFTriTdVmMrqzLqA1fu4hLkqzoe2cf9WuUIC4XADWtB98O0ZP Is0GE72LBQG5PVK60mFNlIYkSAAEJG9mDWg9xSGIh35AOUDLTbDtW0UrjNt3C1uYMYei R+Ls5Xyc6wNjOVdx/6KOdhkjZoQQphnTOmOyurHwqzeKiBMk6KoHk01PPlq5KUHg417s P61A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=W0NRqN4tKUIiubnsRHwnrkHz9xP0jc5bUIehefjfrK0=; b=k7ZppxhCf11siQm1Zq/b4QKHLilHsbSGLS95IqcsMS2lkZ3Sp3BJgVs5AgA/bD4DJd Xh0xISc9xgr7rH4X5xDejOfYzvDneRk5B2EW/CkUvDq4DpsF9TowX+UoDkvExTK9hBVk 5KRW2ah3d4XNuM1SbIcvcywkQpbxpinm/xeF0wvdKpWJeUwZFSwEkQL7kgg+zpQrW3vN Bb0wQIMNzcklBpTXO2H0bah3xXDkCBBqYE+jypleCwH5z+RsvJ4w2VcHw5RlKjp9dtyH XGOZ9/uuwaYPM+PnB3k/y/dS3FSJ7yz900KYW5TJ6uP73qNZN97UL+rHuvdlt2MRIcCs XCEw== X-Gm-Message-State: ANhLgQ2XA1B4GmEGdK5XeTARAagcCP+SYYRAs8JwpxuHWI2wp0nm0/KR NI1geQTn04N/WXteTIdT8Ny0GK0Chro= X-Google-Smtp-Source: ADFU+vu+t300mRWdVo2OXw72+/s87iy5D1YclwxP2iiwivGLHC6RCrgND3FdQ3hsIGdTsdhsQ7keJGHqVng= X-Received: by 2002:a65:6715:: with SMTP id u21mr5823467pgf.17.1583548608053; Fri, 06 Mar 2020 18:36:48 -0800 (PST) Date: Fri, 6 Mar 2020 18:36:09 -0800 In-Reply-To: <20200307023611.204708-1-drosen@google.com> Message-Id: <20200307023611.204708-7-drosen@google.com> Mime-Version: 1.0 References: <20200307023611.204708-1-drosen@google.com> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog Subject: [PATCH v8 6/8] libfs: Add generic function for setting dentry_ops From: Daniel Rosenberg To: "Theodore Ts'o" , linux-ext4@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, Eric Biggers , linux-fscrypt@vger.kernel.org, Alexander Viro , Richard Weinberger X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200306_183651_084389_03F920EC X-CRM114-Status: GOOD ( 10.84 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Rosenberg , linux-doc@vger.kernel.org, kernel-team@android.com, Jonathan Corbet , linux-kernel@vger.kernel.org, Andreas Dilger , linux-fsdevel@vger.kernel.org, linux-mtd@lists.infradead.org, Gabriel Krisman Bertazi Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org This adds a function to set dentry operations at lookup time that will work for both encrypted files and casefolded filenames. A filesystem that supports both features simultaneously can use this function during lookup preperations to set up its dentry operations once fscrypt no longer does that itself. Signed-off-by: Daniel Rosenberg --- fs/libfs.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 2 files changed, 52 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 0eaa63a9ae037..bdda03c8ece9e 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1474,4 +1474,54 @@ int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) return ret; } EXPORT_SYMBOL(generic_ci_d_hash); + +static const struct dentry_operations generic_ci_dentry_ops = { + .d_hash = generic_ci_d_hash, + .d_compare = generic_ci_d_compare, +}; +#endif + +#ifdef CONFIG_FS_ENCRYPTION +static const struct dentry_operations generic_encrypted_dentry_ops = { + .d_revalidate = fscrypt_d_revalidate, +}; +#endif + +#if IS_ENABLED(CONFIG_UNICODE) && IS_ENABLED(CONFIG_FS_ENCRYPTION) +static const struct dentry_operations generic_encrypted_ci_dentry_ops = { + .d_hash = generic_ci_d_hash, + .d_compare = generic_ci_d_compare, + .d_revalidate = fscrypt_d_revalidate, +}; +#endif + +/** + * generic_set_encrypted_ci_d_ops - helper for setting d_ops for given dentry + * @dir: parent of dentry whose ops to set + * @dentry: dentry to set ops on + * + * This function sets the dentry ops for the given dentry to handle both + * casefolding and encryption of the dentry name. + */ +void generic_set_encrypted_ci_d_ops(struct inode *dir, struct dentry *dentry) +{ +#ifdef CONFIG_FS_ENCRYPTION + if (dentry->d_flags & DCACHE_ENCRYPTED_NAME) { +#ifdef CONFIG_UNICODE + if (dir->i_sb->s_encoding) { + d_set_d_op(dentry, &generic_encrypted_ci_dentry_ops); + return; + } #endif + d_set_d_op(dentry, &generic_encrypted_dentry_ops); + return; + } +#endif +#ifdef CONFIG_UNICODE + if (dir->i_sb->s_encoding) { + d_set_d_op(dentry, &generic_ci_dentry_ops); + return; + } +#endif +} +EXPORT_SYMBOL(generic_set_encrypted_ci_d_ops); diff --git a/include/linux/fs.h b/include/linux/fs.h index 8d20a3daa49a0..dc433bc4f0602 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3389,6 +3389,8 @@ static inline bool needs_casefold(const struct inode *dir) return false; } #endif +extern void generic_set_encrypted_ci_d_ops(struct inode *dir, + struct dentry *dentry); #ifdef CONFIG_MIGRATION extern int buffer_migrate_page(struct address_space *, -- 2.25.1.481.gfbce0eb801-goog ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/