All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-unionfs@vger.kernel.org
Cc: Kent Overstreet <kent.overstreet@linux.dev>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Amir Goldstein <amir73il@gmail.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH 6/6] overlayfs: Support casefolded filesystems
Date: Tue, 20 May 2025 01:15:58 -0400	[thread overview]
Message-ID: <20250520051600.1903319-7-kent.overstreet@linux.dev> (raw)
In-Reply-To: <20250520051600.1903319-1-kent.overstreet@linux.dev>

Overlayfs can now work on filesystems that support casefolding, provided
the specific subtree overlayfs is using as layers don't have casefolding
enabled.

d_casefold_disabled_get() and put() are used, which check that
casefolding is enabled nowhere on a given subtree, and get and release a
reference that prevents the filesystem from enabling casefolding on that
tree while overlayfs is in use.

We also now check the new SB_CASEFOLD superblock flag; if it's set we
allow for dcache hash and compare ops to be set, relying instead on the
new dcache methods.

Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Amir Goldstein <amir73il@gmail.com>
Cc: linux-unionfs@vger.kernel.org
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 fs/overlayfs/params.c | 20 +++++++++++++++++---
 fs/overlayfs/util.c   | 19 +++++++++++++++----
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c
index 6759f7d040c8..ae7424e075a7 100644
--- a/fs/overlayfs/params.c
+++ b/fs/overlayfs/params.c
@@ -287,7 +287,8 @@ static int ovl_mount_dir_check(struct fs_context *fc, const struct path *path,
 	 * with overlayfs.  Check explicitly to prevent post-mount
 	 * failures.
 	 */
-	if (sb_has_encoding(path->mnt->mnt_sb))
+	if ((path->mnt->mnt_sb->s_flags & SB_CASEFOLD) &&
+	    !(path->dentry->d_inode->i_flags & S_NO_CASEFOLD))
 		return invalfc(fc, "case-insensitive capable filesystem on %s not supported", name);
 
 	if (ovl_dentry_weird(path->dentry))
@@ -411,20 +412,32 @@ static int ovl_do_parse_layer(struct fs_context *fc, const char *layer_name,
 	if (!name)
 		return -ENOMEM;
 
+	if (layer != Opt_workdir &&
+	    layer != Opt_upperdir) {
+		err = d_casefold_disabled_get(layer_path->dentry);
+		if (err)
+			return err;
+	}
+
 	upper = is_upper_layer(layer);
 	err = ovl_mount_dir_check(fc, layer_path, layer, name, upper);
 	if (err)
-		return err;
+		goto err_put;
 
 	if (!upper) {
 		err = ovl_ctx_realloc_lower(fc);
 		if (err)
-			return err;
+			goto err_put;
 	}
 
 	/* Store the user provided path string in ctx to show in mountinfo */
 	ovl_add_layer(fc, layer, layer_path, &name);
 	return err;
+err_put:
+	if (layer != Opt_workdir &&
+	    layer != Opt_upperdir)
+		d_casefold_disabled_put(layer_path->dentry);
+	return err;
 }
 
 static int ovl_parse_layer(struct fs_context *fc, struct fs_parameter *param,
@@ -475,6 +488,7 @@ static void ovl_reset_lowerdirs(struct ovl_fs_context *ctx)
 	ctx->lowerdir_all = NULL;
 
 	for (size_t nr = 0; nr < ctx->nr; nr++, l++) {
+		d_casefold_disabled_put(l->path.dentry);
 		path_put(&l->path);
 		kfree(l->name);
 		l->name = NULL;
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index 0819c739cc2f..c515f260032c 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -205,10 +205,21 @@ bool ovl_dentry_weird(struct dentry *dentry)
 	if (!d_can_lookup(dentry) && !d_is_file(dentry) && !d_is_symlink(dentry))
 		return true;
 
-	return dentry->d_flags & (DCACHE_NEED_AUTOMOUNT |
-				  DCACHE_MANAGE_TRANSIT |
-				  DCACHE_OP_HASH |
-				  DCACHE_OP_COMPARE);
+	if (dentry->d_flags & (DCACHE_NEED_AUTOMOUNT |
+			       DCACHE_MANAGE_TRANSIT))
+		return true;
+
+	/*
+	 * The filesystem might support casefolding, but we've already checked
+	 * that casefolding isn't present on this tree: we only need to check
+	 * for non-casefolding hash/compare ops
+	 */
+	if (!(dentry->d_sb->s_flags & SB_CASEFOLD) &&
+	    (dentry->d_flags & (DCACHE_OP_HASH |
+				DCACHE_OP_COMPARE)))
+		return true;
+
+	return false;
 }
 
 enum ovl_path_type ovl_path_type(struct dentry *dentry)
-- 
2.49.0


  parent reply	other threads:[~2025-05-20  5:16 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-20  5:15 [PATCH 0/6] overlayfs + casefolding Kent Overstreet
2025-05-20  5:15 ` [PATCH 1/6] bcachefs: BCH_INODE_has_case_insensitive Kent Overstreet
2025-05-20  5:15 ` [PATCH 2/6] darray: lift from bcachefs Kent Overstreet
2025-05-20  5:15 ` [PATCH 3/6] fs: SB_CASEFOLD Kent Overstreet
2025-05-20  5:15 ` [PATCH 4/6] fs: dcache locking for exlusion between overlayfs, casefolding Kent Overstreet
2025-05-20 15:25   ` Al Viro
2025-05-20 15:27     ` Kent Overstreet
2025-05-23 11:54   ` [PATCH v2] fs: dcache " Kent Overstreet
2025-05-20  5:15 ` [PATCH 5/6] bcachefs: Hook up d_casefold_enable() Kent Overstreet
2025-05-20  5:15 ` Kent Overstreet [this message]
2025-05-20  8:05 ` [PATCH 0/6] overlayfs + casefolding Amir Goldstein
2025-05-20 12:25   ` Kent Overstreet
2025-05-20 12:40     ` Amir Goldstein
2025-05-20 12:43       ` Kent Overstreet
2025-05-20 14:03         ` Amir Goldstein
2025-05-20 14:12           ` Kent Overstreet
2025-05-20 14:33             ` Amir Goldstein
2025-05-20 14:44               ` Kent Overstreet
2025-05-20 15:13                 ` Amir Goldstein
2025-05-20 15:21                   ` Kent Overstreet
2025-05-20 16:40                     ` Miklos Szeredi
2025-05-20 16:49                       ` Kent Overstreet
2025-05-23 14:10               ` Kent Overstreet
2025-05-23 17:14                 ` Amir Goldstein
2025-05-23 20:30                   ` Amir Goldstein
2025-05-23 21:09                     ` Kent Overstreet
2025-05-24 13:01                       ` Amir Goldstein
2025-05-25 18:27                         ` Kent Overstreet
2025-05-27  8:57                           ` Amir Goldstein
2025-05-27 18:07                             ` Kent Overstreet
2025-05-20 18:49             ` John Stoffel
2025-05-21  1:49               ` Kent Overstreet
2025-05-22 21:44                 ` John Stoffel
2025-05-21 11:26               ` Malte Schröder
2025-05-22  7:53                 ` Christopher Snowhill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250520051600.1903319-7-kent.overstreet@linux.dev \
    --to=kent.overstreet@linux.dev \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.