summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-10-17 10:33:44 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-10-19 12:03:11 +0200
commit89e7c6321de7a9aaa72c42aec7b4764541ee1b75 (patch)
tree70d8dff7c647779e288095ace39ebc5b7934d444
parentdc6f695e4d2734e8e5e7478741b1268093b41498 (diff)
downloadbarebox-89e7c6321de7a9aaa72c42aec7b4764541ee1b75.tar.gz
fs: implement d_revalidate
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>
-rw-r--r--fs/fs.c37
-rw-r--r--include/linux/dcache.h3
2 files changed, 39 insertions, 1 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 2a4d78c9d7..a86279d888 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1101,6 +1101,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;
}
/**
@@ -1245,6 +1251,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);
@@ -1456,7 +1491,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) */