From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Ladislav Michl <ladis@linux-mips.org>
Subject: [PATCH 1/2] fs: implement d_revalidate
Date: Wed, 17 Oct 2018 10:43:52 +0200 [thread overview]
Message-ID: <20181017084353.5217-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20181017084353.5217-1-s.hauer@pengutronix.de>
d_revalidate is useful when filesystems change under the hood of the
fs layer. This can happen with network filesystems or with devfs.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fs.c | 37 ++++++++++++++++++++++++++++++++++++-
include/linux/dcache.h | 3 +++
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/fs/fs.c b/fs/fs.c
index d76d829140..eed0155f0d 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1141,6 +1141,12 @@ const struct qstr slash_name = QSTR_INIT("/", 1);
void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
{
dentry->d_op = op;
+
+ if (!op)
+ return;
+
+ if (op->d_revalidate)
+ dentry->d_flags |= DCACHE_OP_REVALIDATE;
}
/**
@@ -1285,6 +1291,35 @@ void d_invalidate(struct dentry *dentry)
{
}
+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;
+}
+
+/*
+ * This looks up the name in dcache and possibly revalidates the found dentry.
+ * NULL is returned if the dentry does not exist in the cache.
+ */
+static struct dentry *lookup_dcache(const struct qstr *name,
+ struct dentry *dir,
+ unsigned int flags)
+{
+ struct dentry *dentry = d_lookup(dir, name);
+ if (dentry) {
+ int error = d_revalidate(dentry, flags);
+ if (unlikely(error <= 0)) {
+ if (!error)
+ d_invalidate(dentry);
+ dput(dentry);
+ return ERR_PTR(error);
+ }
+ }
+ return dentry;
+}
+
static inline void __d_clear_type_and_inode(struct dentry *dentry)
{
dentry->d_flags &= ~(DCACHE_ENTRY_TYPE | DCACHE_FALLTHRU);
@@ -1496,7 +1531,7 @@ static struct dentry *__lookup_hash(const struct qstr *name,
if (!base)
return ERR_PTR(-ENOENT);
- dentry = d_lookup(base, name);
+ dentry = lookup_dcache(name, base, flags);
if (dentry)
return dentry;
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 16244129bf..1581ddc701 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -82,6 +82,7 @@ struct dentry {
};
struct dentry_operations {
+ int (*d_revalidate)(struct dentry *, unsigned int);
};
struct dentry * d_make_root(struct inode *);
@@ -93,6 +94,8 @@ void d_delete(struct dentry *);
struct dentry *dget(struct dentry *);
void dput(struct dentry *);
+#define DCACHE_OP_REVALIDATE 0x00000004
+
#define DCACHE_ENTRY_TYPE 0x00700000
#define DCACHE_MISS_TYPE 0x00000000 /* Negative dentry (maybe fallthru to nowhere) */
#define DCACHE_WHITEOUT_TYPE 0x00100000 /* Whiteout dentry (stop pathwalk) */
--
2.19.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-10-17 8:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-17 8:43 [PATCH 0/2] fs: add revalidating of dentries Sascha Hauer
2018-10-17 8:43 ` Sascha Hauer [this message]
2018-10-17 8:43 ` [PATCH 2/2] fs: devfs: implement d_revalidate hook Sascha Hauer
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=20181017084353.5217-2-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=ladis@linux-mips.org \
/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