Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp624946rdb; Mon, 29 Jan 2024 12:44:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpUNdU62B2oUyMqqewfdjSPY9WgBqAzcjmB/ozTxHX42C+aJwRSL+JA/Wo1Bu2lasmdZ1w X-Received: by 2002:a05:6402:27d0:b0:55e:dbb8:4c6b with SMTP id c16-20020a05640227d000b0055edbb84c6bmr3432483ede.42.1706561084442; Mon, 29 Jan 2024 12:44:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706561084; cv=pass; d=google.com; s=arc-20160816; b=XwXrSKWiiBdCElzrRLDvg/dN1aN0LE8aAy4L2r8W6LplxotPZBA5OUQXvhBLF3tMrx 3dzwA+z3EmiBJIPq6lkyHS8oODn1RS+FV/ckWBr1XEZrREzppus/qtf7TiZUSvPXVh5q CP1evgqfVgsQLd6DfkfoOLz87zi6zRRScM30xMOJY3plQnaOMtWnfQhnhwrpuj6eaviy iuVfEXu+zE02gwa4qLwzEd0nU42dR79iCzUEjQjwwv75A9F2l1oP3xnkSqwtWu/SLqaH 9na+9vCZF1AdxJHLTC52MAqUMMWJisG9uMNgZQxCVjN5LE0ZNl1WF7uYxiycrdgTi+My UGOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=S7ZNiObuWDS9LBRJ78fuLAlJGd+uQndWdyw51G7pKEU=; fh=M648oune0DwZmCHpgeKmdqyNG9Pnhrh1APj5VeeCjyQ=; b=anHxw+GtofJV30pL5s7ENfdcq5f6ZgCdAZIW+4FWgeaV5pfpa6XwTixY25KpMmofk3 iumafkz+8JmaiQIupj0D8++ZHHEGWfB7gZkdWiL5+34Qt3Qot3XhYvm9F7M3QDtw/SXP YjQyM1nrEqQ1FHXMKiGThFDC17AZtZ+jk58XwFgL6oP31mBBFcUMaQFKOdoEQMALvPOL 0Vfk/sIxUNHIYJlmzIgIlqsFc+dZbGuEHDeJLgLbwqMj2hHjcyO0urVADWZtLY7Tg12x 5/wJvuWZghYMF3fpQ7dhzPwicdUV9kEaT2oAFYwjauTTwhuYWKFNHHmMLwD2u6XI6iEb /Onw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-1007-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1007-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g29-20020a056402321d00b0055ed343be5asi2295169eda.52.2024.01.29.12.44.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 12:44:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1007-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-ext4+bounces-1007-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1007-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 35B1C1F21FA1 for ; Mon, 29 Jan 2024 20:44:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99761157E8F; Mon, 29 Jan 2024 20:44:09 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C28A64CB24; Mon, 29 Jan 2024 20:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706561049; cv=none; b=bq1Xwr6vEp1q47n1X0Dr6kqbAw0vSol5GlXfMwm9uARTu+DHddC+RGJrFwzDpraQPZONCpOxJZB6cbGb+EjSTPpi9oX6Nd8Hlss2DcUI7F5BzRsh+oVBwp8TLnn1uJMMMDJHHcuHa6n2sryLM1IMHEi4EQ85ZMxZNysSCLXm4ss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706561049; c=relaxed/simple; bh=8KvF2pTb3E+igBwE1A5eAT6de1YY3lOPRIH1gV1BZRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oPgINGDOdgZZMmUc5VIW59gk5TwHXgI//JRjg+OrSxwk1fK/jPHS4fzXqcKB0+eSgy5gbhluA2CM5Q3RHfG2mdTgmNFsVPzS+XES/Czt0u0ywnJzFTdIozEsWkPyPU4uBJBu24vinuwuG5OJgDiS4ZlDJ6BILvaido3qwA0Rju8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 25A342207E; Mon, 29 Jan 2024 20:44:06 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7BB0612FF7; Mon, 29 Jan 2024 20:44:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id k8BlDBUOuGXwDAAAD6G6ig (envelope-from ); Mon, 29 Jan 2024 20:44:05 +0000 From: Gabriel Krisman Bertazi To: ebiggers@kernel.org, viro@zeniv.linux.org.uk, jaegeuk@kernel.org, tytso@mit.edu Cc: amir73il@gmail.com, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v5 08/12] libfs: Add helper to choose dentry operations at mount-time Date: Mon, 29 Jan 2024 17:43:26 -0300 Message-ID: <20240129204330.32346-9-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129204330.32346-1-krisman@suse.de> References: <20240129204330.32346-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 25A342207E X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO In preparation to drop the similar helper that sets d_op at lookup time, add a version to set the right d_op filesystem-wide, through sb->s_d_op. The operations structures are shared across filesystems supporting fscrypt and/or casefolding, therefore we can keep it in common libfs code. Signed-off-by: Gabriel Krisman Bertazi --- changes since v3: - Fix typo in comment (Eric) --- fs/libfs.c | 28 ++++++++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 29 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index c4be0961faf0..0aa388ee82ff 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1822,6 +1822,34 @@ void generic_set_encrypted_ci_d_ops(struct dentry *dentry) } EXPORT_SYMBOL(generic_set_encrypted_ci_d_ops); +/** + * generic_set_sb_d_ops - helper for choosing the set of + * filesystem-wide dentry operations for the enabled features + * @sb: superblock to be configured + * + * Filesystems supporting casefolding and/or fscrypt can call this + * helper at mount-time to configure sb->s_d_op to best set of dentry + * operations required for the enabled features. The helper must be + * called after these have been configured, but before the root dentry + * is created. + */ +void generic_set_sb_d_ops(struct super_block *sb) +{ +#if IS_ENABLED(CONFIG_UNICODE) + if (sb->s_encoding) { + sb->s_d_op = &generic_ci_dentry_ops; + return; + } +#endif +#ifdef CONFIG_FS_ENCRYPTION + if (sb->s_cop) { + sb->s_d_op = &generic_encrypted_dentry_ops; + return; + } +#endif +} +EXPORT_SYMBOL(generic_set_sb_d_ops); + /** * inode_maybe_inc_iversion - increments i_version * @inode: inode with the i_version that should be updated diff --git a/include/linux/fs.h b/include/linux/fs.h index e6667ece5e64..c985d9392b61 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3202,6 +3202,7 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); +extern void generic_set_sb_d_ops(struct super_block *sb); static inline bool sb_has_encoding(const struct super_block *sb) { -- 2.43.0