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=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS 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 22E44C10F00 for ; Sat, 7 Mar 2020 05:41:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F09662073B for ; Sat, 7 Mar 2020 05:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583559682; bh=Z5bTJVp50KuWeymYhYAdxIiTXYzyTVmZsP2BigxcerM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=QBnxoZoL7U38cPnv6xmjLOHseLvj2IskWNQ3Bh7XXYPOptN6meIS3/7j8FbyySnD8 EpfcYYFurD8CzWh8yLjxNPNStosI5IOppDY5VZq2pMIjBlsWpkOnxxWXpshkwhp42R D0Ge3TXLQkxeuAO+CZ24PBbM9QdYkpZ50IQSNHx4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726296AbgCGFlS (ORCPT ); Sat, 7 Mar 2020 00:41:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:59294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbgCGFlS (ORCPT ); Sat, 7 Mar 2020 00:41:18 -0500 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A95492070A; Sat, 7 Mar 2020 05:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583559677; bh=Z5bTJVp50KuWeymYhYAdxIiTXYzyTVmZsP2BigxcerM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=wI3oLIQFFHIL5ICoqkDZhrwLR+OMO+a4KW9PZo0HtYoZzUNdytbzjj1R7kofMI0br YhDNzK3xcG6s3VWGMLkjJzhFlcnB4XxIl9N4MXpPOM/wD3zWgocEAg5wVV81E/VRTI 7AlRaoulsSD655PjM30iHYYdYN0zupK+ODogkYjw= Date: Fri, 6 Mar 2020 21:41:15 -0800 From: Eric Biggers To: Daniel Rosenberg Cc: Theodore Ts'o , linux-ext4@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, linux-fscrypt@vger.kernel.org, Alexander Viro , Richard Weinberger , linux-mtd@lists.infradead.org, Andreas Dilger , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi , kernel-team@android.com Subject: Re: [PATCH v8 6/8] libfs: Add generic function for setting dentry_ops Message-ID: <20200307054115.GC1069@sol.localdomain> References: <20200307023611.204708-1-drosen@google.com> <20200307023611.204708-7-drosen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200307023611.204708-7-drosen@google.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, Mar 06, 2020 at 06:36:09PM -0800, Daniel Rosenberg wrote: > 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); What's wrong with using dentry->d_sb? Then the 'dir' parameter wouldn't be needed. Also, can you please document why the dentry_operations for casefolding are set per-filesystem while the dentry_operations for encryption are set per-dentry, despite both features actually being per-directory things? - Eric 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=-6.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 A0709C10F00 for ; Sat, 7 Mar 2020 05:41:30 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (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 7256B2070A for ; Sat, 7 Mar 2020 05:41:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="DFUQXlOO"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="Ww5CkUXt"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="wI3oLIQF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7256B2070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jASDI-00040I-WA; Sat, 07 Mar 2020 05:41:29 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jASDH-000407-Bb for linux-f2fs-devel@lists.sourceforge.net; Sat, 07 Mar 2020 05:41:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zulusoVqhUgvWvph0i5LBbviSoTMjBE9o4i5FkW0e6c=; b=DFUQXlOOxpUviHMOZvTcMgcrcm HmGQloQ2p1ivYwfQNr3Rs+MShKgNr37U6jnbe0s20roXNbHbIp7vIGa8rW5fpyl7jl7xSc3oAj9Ev Idhbnare1Ah6i43oT0QEi4rRYU+2x2oFSLo7gxNLY+lo2/x+8NKGd6xoBSr5UaHJHCH8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zulusoVqhUgvWvph0i5LBbviSoTMjBE9o4i5FkW0e6c=; b=Ww5CkUXtgMffILIcND9NrBpgNA hyz2SjVIaebU0Fzs26AS97VV0xfQ2aG0BJEy/VZIeiQPV3faH6Br9rslekMMCW5+UXpfbW9/ONEmJ TgrR2CHiGrRTtFr+wYO7HBhbQgTA1oDauHPOHf3MukjMDByDPx1W7ySMgdLRoCNp/wU8=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jASDG-000xQS-5o for linux-f2fs-devel@lists.sourceforge.net; Sat, 07 Mar 2020 05:41:27 +0000 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A95492070A; Sat, 7 Mar 2020 05:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583559677; bh=Z5bTJVp50KuWeymYhYAdxIiTXYzyTVmZsP2BigxcerM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=wI3oLIQFFHIL5ICoqkDZhrwLR+OMO+a4KW9PZo0HtYoZzUNdytbzjj1R7kofMI0br YhDNzK3xcG6s3VWGMLkjJzhFlcnB4XxIl9N4MXpPOM/wD3zWgocEAg5wVV81E/VRTI 7AlRaoulsSD655PjM30iHYYdYN0zupK+ODogkYjw= Date: Fri, 6 Mar 2020 21:41:15 -0800 From: Eric Biggers To: Daniel Rosenberg Message-ID: <20200307054115.GC1069@sol.localdomain> References: <20200307023611.204708-1-drosen@google.com> <20200307023611.204708-7-drosen@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200307023611.204708-7-drosen@google.com> X-Headers-End: 1jASDG-000xQS-5o Subject: Re: [f2fs-dev] [PATCH v8 6/8] libfs: Add generic function for setting dentry_ops X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-team@android.com, Theodore Ts'o , Jonathan Corbet , Richard Weinberger , Andreas Dilger , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fscrypt@vger.kernel.org, linux-mtd@lists.infradead.org, Alexander Viro , linux-fsdevel@vger.kernel.org, Jaegeuk Kim , linux-ext4@vger.kernel.org, Gabriel Krisman Bertazi Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On Fri, Mar 06, 2020 at 06:36:09PM -0800, Daniel Rosenberg wrote: > 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); What's wrong with using dentry->d_sb? Then the 'dir' parameter wouldn't be needed. Also, can you please document why the dentry_operations for casefolding are set per-filesystem while the dentry_operations for encryption are set per-dentry, despite both features actually being per-directory things? - Eric _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel 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=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS 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 622A4C10F00 for ; Sat, 7 Mar 2020 05:41:44 +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 354F22070A for ; Sat, 7 Mar 2020 05:41:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WSmxiHrD"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="wI3oLIQF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 354F22070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mb2Hxow7fzPJ5Pn5HzmxS/kRQy/Sa6C1XjL3dZQRFGo=; b=WSmxiHrDKJ+2fX Ie9IjrqzNqORBxjx7InZoVT2tZsaqR1CArR12OwWqYd7F09kqbSO8gs8cUxHl43A8ZNOOd0XpXb8l lQG6A681EzTAhqxxfXHJ7hDb4PGmw96Le/XsCuGEpehSOz8A/A8a4ims5tm6b/BXICTI91A99LUhF hyKAJHRlJcO1ymP9HRN7LYYgCwtee3w3riRccmkYqigHgrdCDBSBW4TRz5/9QRaMCT6BSM3wrqjBe T/TVV5A4Xxw0iNm4WsLLrvMcH65N6dYk1oeLEvUcM23dQKmKAob7s8jO+vZ1QOAH+0w2r0R7oEdMe BWE4sb2gV9dJVvtM7jpw==; 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 1jASDA-0000Wx-GQ; Sat, 07 Mar 2020 05:41:20 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jASD7-0000W8-Ra for linux-mtd@lists.infradead.org; Sat, 07 Mar 2020 05:41:19 +0000 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A95492070A; Sat, 7 Mar 2020 05:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583559677; bh=Z5bTJVp50KuWeymYhYAdxIiTXYzyTVmZsP2BigxcerM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=wI3oLIQFFHIL5ICoqkDZhrwLR+OMO+a4KW9PZo0HtYoZzUNdytbzjj1R7kofMI0br YhDNzK3xcG6s3VWGMLkjJzhFlcnB4XxIl9N4MXpPOM/wD3zWgocEAg5wVV81E/VRTI 7AlRaoulsSD655PjM30iHYYdYN0zupK+ODogkYjw= Date: Fri, 6 Mar 2020 21:41:15 -0800 From: Eric Biggers To: Daniel Rosenberg Subject: Re: [PATCH v8 6/8] libfs: Add generic function for setting dentry_ops Message-ID: <20200307054115.GC1069@sol.localdomain> References: <20200307023611.204708-1-drosen@google.com> <20200307023611.204708-7-drosen@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200307023611.204708-7-drosen@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200306_214117_936463_B2475BE0 X-CRM114-Status: GOOD ( 17.34 ) 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: kernel-team@android.com, Theodore Ts'o , Jonathan Corbet , Richard Weinberger , Andreas Dilger , Chao Yu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fscrypt@vger.kernel.org, linux-mtd@lists.infradead.org, Alexander Viro , linux-fsdevel@vger.kernel.org, Jaegeuk Kim , linux-ext4@vger.kernel.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 On Fri, Mar 06, 2020 at 06:36:09PM -0800, Daniel Rosenberg wrote: > 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); What's wrong with using dentry->d_sb? Then the 'dir' parameter wouldn't be needed. Also, can you please document why the dentry_operations for casefolding are set per-filesystem while the dentry_operations for encryption are set per-dentry, despite both features actually being per-directory things? - Eric ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/