From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>,
Christian Brauner <brauner@kernel.org>
Cc: Qing Wang <wangqing7171@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org
Subject: [PATCH 3/3] ovl: use name_is_dot* helpers in readdir code
Date: Wed, 28 Jan 2026 14:24:06 +0100 [thread overview]
Message-ID: <20260128132406.23768-4-amir73il@gmail.com> (raw)
In-Reply-To: <20260128132406.23768-1-amir73il@gmail.com>
Use the helpers in place of all the different open coded variants.
This makes the code more readable and robust.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/readdir.c | 36 +++++++++++++-----------------------
1 file changed, 13 insertions(+), 23 deletions(-)
diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
index 9f6b36f3d4cf8..5727948d6566a 100644
--- a/fs/overlayfs/readdir.c
+++ b/fs/overlayfs/readdir.c
@@ -154,7 +154,7 @@ static bool ovl_calc_d_ino(struct ovl_readdir_data *rdd,
return true;
/* Always recalc d_ino for parent */
- if (strcmp(p->name, "..") == 0)
+ if (name_is_dotdot(p->name, p->len))
return true;
/* If this is lower, then native d_ino will do */
@@ -165,7 +165,7 @@ static bool ovl_calc_d_ino(struct ovl_readdir_data *rdd,
* Recalc d_ino for '.' and for all entries if dir is impure (contains
* copied up entries)
*/
- if ((p->name[0] == '.' && p->len == 1) ||
+ if (name_is_dot(p->name, p->len) ||
ovl_test_flag(OVL_IMPURE, d_inode(rdd->dentry)))
return true;
@@ -561,12 +561,12 @@ static int ovl_cache_update(const struct path *path, struct ovl_cache_entry *p,
if (!ovl_same_dev(ofs) && !p->check_xwhiteout)
goto out;
- if (p->name[0] == '.') {
+ if (name_is_dot_dotdot(p->name, p->len)) {
if (p->len == 1) {
this = dget(dir);
goto get;
}
- if (p->len == 2 && p->name[1] == '.') {
+ if (p->len == 2) {
/* we shall not be moved */
this = dget(dir->d_parent);
goto get;
@@ -666,8 +666,7 @@ static int ovl_dir_read_impure(const struct path *path, struct list_head *list,
return err;
list_for_each_entry_safe(p, n, list, l_node) {
- if (strcmp(p->name, ".") != 0 &&
- strcmp(p->name, "..") != 0) {
+ if (!name_is_dot_dotdot(p->name, p->len)) {
err = ovl_cache_update(path, p, true);
if (err)
return err;
@@ -756,7 +755,7 @@ static bool ovl_fill_real(struct dir_context *ctx, const char *name,
struct dir_context *orig_ctx = rdt->orig_ctx;
bool res;
- if (rdt->parent_ino && namelen == 2 && !strncmp(name, "..", 2)) {
+ if (rdt->parent_ino && name_is_dotdot(name, namelen)) {
ino = rdt->parent_ino;
} else if (rdt->cache) {
struct ovl_cache_entry *p;
@@ -1097,11 +1096,8 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
goto del_entry;
}
- if (p->name[0] == '.') {
- if (p->len == 1)
- goto del_entry;
- if (p->len == 2 && p->name[1] == '.')
- goto del_entry;
+ if (name_is_dot_dotdot(p->name, p->len)) {
+ goto del_entry;
}
err = -ENOTEMPTY;
break;
@@ -1146,7 +1142,7 @@ static bool ovl_check_d_type(struct dir_context *ctx, const char *name,
container_of(ctx, struct ovl_readdir_data, ctx);
/* Even if d_type is not supported, DT_DIR is returned for . and .. */
- if (!strncmp(name, ".", namelen) || !strncmp(name, "..", namelen))
+ if (name_is_dot_dotdot(name, namelen))
return true;
if (d_type != DT_UNKNOWN)
@@ -1209,11 +1205,8 @@ static int ovl_workdir_cleanup_recurse(struct ovl_fs *ofs, const struct path *pa
list_for_each_entry(p, &list, l_node) {
struct dentry *dentry;
- if (p->name[0] == '.') {
- if (p->len == 1)
- continue;
- if (p->len == 2 && p->name[1] == '.')
- continue;
+ if (name_is_dot_dotdot(p->name, p->len)) {
+ continue;
} else if (incompat) {
pr_err("overlay with incompat feature '%s' cannot be mounted\n",
p->name);
@@ -1278,11 +1271,8 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs)
goto out;
list_for_each_entry(p, &list, l_node) {
- if (p->name[0] == '.') {
- if (p->len == 1)
- continue;
- if (p->len == 2 && p->name[1] == '.')
- continue;
+ if (name_is_dot_dotdot(p->name, p->len)) {
+ continue;
}
index = ovl_lookup_upper_unlocked(ofs, p->name, indexdir, p->len);
if (IS_ERR(index)) {
--
2.52.0
next prev parent reply other threads:[~2026-01-28 13:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 13:24 [PATCH 0/3] name_is_dot* cleanup Amir Goldstein
2026-01-28 13:24 ` [PATCH 1/3] ovl: Fix uninit-value in ovl_fill_real Amir Goldstein
2026-01-29 8:44 ` Miklos Szeredi
2026-01-28 13:24 ` [PATCH 2/3] fs: add helpers name_is_dot{,dot,_dotdot} Amir Goldstein
2026-01-28 13:24 ` Amir Goldstein [this message]
2026-01-29 0:14 ` [PATCH 3/3] ovl: use name_is_dot* helpers in readdir code Eric Biggers
2026-01-29 8:38 ` Christian Brauner
2026-01-29 0:16 ` [PATCH 0/3] name_is_dot* cleanup Eric Biggers
2026-01-29 9:09 ` Christian Brauner
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=20260128132406.23768-4-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=wangqing7171@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox