summaryrefslogtreecommitdiffstats
path: root/fs/fs.c
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-29 12:23:34 +0100
commit4e601546388e2e2968eed3b96b1ff19c4e421c31 (patch)
tree133f70d8bbec9ab0e28e69aab970ca6e746f8f86 /fs/fs.c
parentfb40e3c1cb2d5182edcd9dabfcd24e30bdf4ee25 (diff)
downloadbarebox-4e601546388e2e2968eed3b96b1ff19c4e421c31.tar.gz
barebox-4e601546388e2e2968eed3b96b1ff19c4e421c31.tar.xz
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>
Diffstat (limited to 'fs/fs.c')
-rw-r--r--fs/fs.c37
1 files changed, 36 insertions, 1 deletions
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;