-
Notifications
You must be signed in to change notification settings - Fork 0
/
dentry.c
90 lines (79 loc) · 2.56 KB
/
dentry.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright (c) 1998-2020 Erez Zadok
* Copyright (c) 2009 Shrikar Archak
* Copyright (c) 2003-2020 Stony Brook University
* Copyright (c) 2003-2020 The Research Foundation of SUNY
* Copyright (c) 2020-2021 Barnim Dzwillo @ Strato AG
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include "wrapfs.h"
/*
* returns: -ERRNO if error (returned to user)
* 0: tell VFS to invalidate dentry (calls d_invalidate(dentry) there)
* 1: dentry is valid
*/
static int wrapfs_d_revalidate(struct dentry *dentry, unsigned int flags)
{
struct dentry *lower_dentry;
int ret = 1;
/* If in rcu-walk mode, the filesystem must revalidate the dentry without
* blocking or storing to the dentry, d_parent and d_inode should not be
* used without care (because they can change and, in d_inode case, even
* become NULL under us)
*
* This might even be the case for wrapfs_get_lower_dentry() where
* dentry->d_fsdata can be NULL here.
*/
if (flags & LOOKUP_RCU) {
return -ECHILD; // call d_revalidate() again in ref-walk-mode
}
lower_dentry = wrapfs_get_lower_dentry(dentry);
if (!(lower_dentry->d_flags & DCACHE_OP_REVALIDATE))
goto out;
ret = lower_dentry->d_op->d_revalidate(lower_dentry, flags);
pr_debug("wrapfs: revalidate(%pd4, 0x%04x) = %d", dentry, flags, ret);
if (ret < 0) {
goto out; // might also be ECHILD to call revalidate again
}
out:
return ret;
}
/*
* weak_revalidate is called for result of path lookup (namei:complete_walk())
* 0: returns ESTALE there
* 1: dentry is valid
*/
static int wrapfs_d_weak_revalidate(struct dentry *dentry, unsigned int flags)
{
struct dentry *lower_dentry;
int ret = 1;
lower_dentry = wrapfs_get_lower_dentry(dentry);
if (!(lower_dentry->d_flags & DCACHE_OP_WEAK_REVALIDATE))
goto out;
ret = lower_dentry->d_op->d_weak_revalidate(lower_dentry, flags);
pr_debug("wrapfs: weak_revalidate(%pd4, 0x%04x) = %d", dentry, flags, ret);
out:
return ret;
}
static void wrapfs_d_release(struct dentry *dentry)
{
/* release and reset the lower paths */
if (WRAPFS_D(dentry)) {
if (wrapfs_get_lower_dentry(dentry)) {
wrapfs_put_reset_lower_path(dentry);
}
wrapfs_free_dentry_private_data(dentry);
}
return;
}
const struct dentry_operations wrapfs_dops = {
.d_revalidate = wrapfs_d_revalidate,
.d_release = wrapfs_d_release,
.d_weak_revalidate = wrapfs_d_weak_revalidate,
};
const struct dentry_operations wrapfs_norev_dops = {
.d_release = wrapfs_d_release,
};