From: Bernd Schubert <bschubert@ddn.com>
To: linux-fsdevel@vger.kernel.org
Cc: bernd.schubert@fastmail.fm, miklos@szeredi.hu, dsingh@ddn.com,
Bernd Schubert <bschubert@ddn.com>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH v9 3/7] [RFC] Allow atomic_open() on positive dentry
Date: Wed, 20 Sep 2023 19:34:41 +0200 [thread overview]
Message-ID: <20230920173445.3943581-4-bschubert@ddn.com> (raw)
In-Reply-To: <20230920173445.3943581-1-bschubert@ddn.com>
From: Miklos Szeredi <miklos@szeredi.hu>
atomic_open() will do an open-by-name or create-and-open
depending on the flags.
If file was created, then the old positive dentry is obviously
stale, so it will be invalidated and a new one will be allocated.
If not created, then check whether it's the same inode (same as in
->d_revalidate()) and if not, invalidate & allocate new dentry.
Co-developed-by: Bernd Schubert <bschubert@ddn.com>
Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Bernd Schubert <bschubert@ddn.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Dharmendra Singh <dsingh@ddn.com>
Cc: linux-fsdevel@vger.kernel.org
---
fs/namei.c | 25 ++++++++++++++++++++-----
include/linux/namei.h | 7 +++++++
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index e56ff39a79bc..f01b278ac0ef 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -858,7 +858,7 @@ static inline int d_revalidate(struct dentry *dentry, unsigned int flags)
if (unlikely(dentry->d_flags & DCACHE_OP_REVALIDATE))
return dentry->d_op->d_revalidate(dentry, flags);
else
- return 1;
+ return D_REVALIDATE_VALID;
}
/**
@@ -1611,10 +1611,11 @@ struct dentry *lookup_one_qstr_excl(const struct qstr *name,
}
EXPORT_SYMBOL(lookup_one_qstr_excl);
-static struct dentry *lookup_fast(struct nameidata *nd)
+static struct dentry *lookup_fast(struct nameidata *nd, bool *atomic_revalidate)
{
struct dentry *dentry, *parent = nd->path.dentry;
int status = 1;
+ *atomic_revalidate = false;
/*
* Rename seqlock is not required here because in the off chance
@@ -1656,6 +1657,10 @@ static struct dentry *lookup_fast(struct nameidata *nd)
dput(dentry);
return ERR_PTR(status);
}
+
+ if (status == D_REVALIDATE_ATOMIC)
+ *atomic_revalidate = true;
+
return dentry;
}
@@ -1981,6 +1986,7 @@ static const char *handle_dots(struct nameidata *nd, int type)
static const char *walk_component(struct nameidata *nd, int flags)
{
struct dentry *dentry;
+ bool atomic_revalidate;
/*
* "." and ".." are special - ".." especially so because it has
* to be able to know about the current root directory and
@@ -1991,7 +1997,7 @@ static const char *walk_component(struct nameidata *nd, int flags)
put_link(nd);
return handle_dots(nd, nd->last_type);
}
- dentry = lookup_fast(nd);
+ dentry = lookup_fast(nd, &atomic_revalidate);
if (IS_ERR(dentry))
return ERR_CAST(dentry);
if (unlikely(!dentry)) {
@@ -1999,6 +2005,9 @@ static const char *walk_component(struct nameidata *nd, int flags)
if (IS_ERR(dentry))
return ERR_CAST(dentry);
}
+
+ WARN_ON(atomic_revalidate);
+
if (!(flags & WALK_MORE) && nd->depth)
put_link(nd);
return step_into(nd, flags, dentry);
@@ -3430,7 +3439,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
dput(dentry);
dentry = NULL;
}
- if (dentry->d_inode) {
+ if (dentry->d_inode && error != D_REVALIDATE_ATOMIC) {
/* Cached positive dentry: will open in f_op->open */
return dentry;
}
@@ -3523,12 +3532,18 @@ static const char *open_last_lookups(struct nameidata *nd,
}
if (!(open_flag & O_CREAT)) {
+ bool atomic_revalidate;
+
if (nd->last.name[nd->last.len])
nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
/* we _can_ be in RCU mode here */
- dentry = lookup_fast(nd);
+ dentry = lookup_fast(nd, &atomic_revalidate);
if (IS_ERR(dentry))
return ERR_CAST(dentry);
+ if (dentry && unlikely(atomic_revalidate)) {
+ dput(dentry);
+ dentry = NULL;
+ }
if (likely(dentry))
goto finish_lookup;
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 1463cbda4888..a70e87d2b2a9 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -47,6 +47,13 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT};
/* LOOKUP_* flags which do scope-related checks based on the dirfd. */
#define LOOKUP_IS_SCOPED (LOOKUP_BENEATH | LOOKUP_IN_ROOT)
+/* ->d_revalidate return codes */
+enum {
+ D_REVALIDATE_INVALID = 0, /* invalid dentry */
+ D_REVALIDATE_VALID = 1, /* valid dentry */
+ D_REVALIDATE_ATOMIC = 2, /* atomic_open will revalidate */
+};
+
extern int path_pts(struct path *path);
extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
--
2.39.2
next prev parent reply other threads:[~2023-09-20 17:35 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-20 17:34 [PATCH v9 0/7] fuse: full atomic open and atomic-open-revalidate Bernd Schubert
2023-09-20 17:34 ` [PATCH v9 1/7] fuse: rename fuse_create_open Bernd Schubert
2023-09-20 17:34 ` [PATCH v9 2/7] fuse: introduce atomic open Bernd Schubert
[not found] ` <7616CA3C-312F-4F9F-9BB3-903D3A77289B@chromium.org>
2023-10-02 22:42 ` Bernd Schubert
2023-10-12 20:44 ` Bernd Schubert
2023-10-03 3:38 ` Yuan Yao
2023-09-20 17:34 ` Bernd Schubert [this message]
2023-09-21 6:20 ` [PATCH v9 3/7] [RFC] Allow atomic_open() on positive dentry Amir Goldstein
2023-09-20 17:34 ` [PATCH v9 4/7] vfs: Optimize " Bernd Schubert
2023-09-21 6:16 ` Amir Goldstein
2023-09-21 8:09 ` Bernd Schubert
2023-09-21 8:29 ` Amir Goldstein
2023-09-21 9:16 ` Bernd Schubert
2023-10-11 7:17 ` Dan Carpenter
2023-10-17 14:25 ` Bernd Schubert
2023-09-20 17:34 ` [PATCH v9 5/7] fuse: Revalidate positive entries in fuse_atomic_open Bernd Schubert
2023-09-20 17:34 ` [PATCH v9 6/7] fuse: Return D_REVALIDATE_ATOMIC for cached dentries Bernd Schubert
2023-09-20 17:34 ` [PATCH v9 7/7] fuse: Avoid code duplication in atomic open Bernd Schubert
2023-09-21 9:33 ` [PATCH v9 0/7] fuse: full atomic open and atomic-open-revalidate Amir Goldstein
2023-09-21 11:59 ` Bernd Schubert
2023-09-21 14:24 ` Amir Goldstein
2023-09-21 14:44 ` Bernd Schubert
2023-09-29 11:34 ` Amir Goldstein
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=20230920173445.3943581-4-bschubert@ddn.com \
--to=bschubert@ddn.com \
--cc=bernd.schubert@fastmail.fm \
--cc=brauner@kernel.org \
--cc=dsingh@ddn.com \
--cc=linux-fsdevel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).