dm: dm-zoned: use __bio_add_page for adding single metadata page
[linux-block.git] / fs / orangefs / dcache.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
5db11c21
MM
2/*
3 * (C) 2001 Clemson University and The University of Chicago
4 *
5 * See COPYING in top-level directory.
6 */
7
8/*
9 * Implementation of dentry (directory cache) functions.
10 */
11
12#include "protocol.h"
575e9461 13#include "orangefs-kernel.h"
5db11c21
MM
14
15/* Returns 1 if dentry can still be trusted, else 0. */
8bb8aefd 16static int orangefs_revalidate_lookup(struct dentry *dentry)
5db11c21
MM
17{
18 struct dentry *parent_dentry = dget_parent(dentry);
19 struct inode *parent_inode = parent_dentry->d_inode;
8bb8aefd 20 struct orangefs_inode_s *parent = ORANGEFS_I(parent_inode);
5db11c21 21 struct inode *inode = dentry->d_inode;
8bb8aefd 22 struct orangefs_kernel_op_s *new_op;
5db11c21
MM
23 int ret = 0;
24 int err = 0;
25
26 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: attempting lookup.\n", __func__);
27
8bb8aefd 28 new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
4c2b46c8
JJB
29 if (!new_op) {
30 ret = -ENOMEM;
5db11c21 31 goto out_put_parent;
4c2b46c8 32 }
5db11c21 33
8bb8aefd 34 new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
5db11c21
MM
35 new_op->upcall.req.lookup.parent_refn = parent->refn;
36 strncpy(new_op->upcall.req.lookup.d_name,
37 dentry->d_name.name,
6bdfb48d 38 ORANGEFS_NAME_MAX - 1);
5db11c21
MM
39
40 gossip_debug(GOSSIP_DCACHE_DEBUG,
41 "%s:%s:%d interrupt flag [%d]\n",
42 __FILE__,
43 __func__,
44 __LINE__,
45 get_interruptible_flag(parent_inode));
46
8bb8aefd 47 err = service_operation(new_op, "orangefs_lookup",
5db11c21 48 get_interruptible_flag(parent_inode));
99109822
MB
49
50 /* Positive dentry: reject if error or not the same inode. */
51 if (inode) {
52 if (err) {
53 gossip_debug(GOSSIP_DCACHE_DEBUG,
54 "%s:%s:%d lookup failure.\n",
55 __FILE__, __func__, __LINE__);
56 goto out_drop;
57 }
58 if (!match_handle(new_op->downcall.resp.lookup.refn.khandle,
59 inode)) {
60 gossip_debug(GOSSIP_DCACHE_DEBUG,
61 "%s:%s:%d no match.\n",
62 __FILE__, __func__, __LINE__);
63 goto out_drop;
64 }
65
66 /* Negative dentry: reject if success or error other than ENOENT. */
67 } else {
68 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: negative dentry.\n",
69 __func__);
70 if (!err || err != -ENOENT) {
71 if (new_op->downcall.status != 0)
72 gossip_debug(GOSSIP_DCACHE_DEBUG,
73 "%s:%s:%d lookup failure.\n",
74 __FILE__, __func__, __LINE__);
75 goto out_drop;
76 }
5db11c21
MM
77 }
78
804b1737 79 orangefs_set_timeout(dentry);
5db11c21
MM
80 ret = 1;
81out_release_op:
82 op_release(new_op);
83out_put_parent:
84 dput(parent_dentry);
85 return ret;
86out_drop:
99109822
MB
87 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s:%s:%d revalidate failed\n",
88 __FILE__, __func__, __LINE__);
5db11c21
MM
89 goto out_release_op;
90}
91
92/*
93 * Verify that dentry is valid.
94 *
f987f4c2 95 * Should return 1 if dentry can still be trusted, else 0.
5db11c21 96 */
8bb8aefd 97static int orangefs_d_revalidate(struct dentry *dentry, unsigned int flags)
5db11c21 98{
99109822 99 int ret;
804b1737 100 unsigned long time = (unsigned long) dentry->d_fsdata;
5db11c21 101
804b1737 102 if (time_before(jiffies, time))
31b7c1ab
MB
103 return 1;
104
5db11c21
MM
105 if (flags & LOOKUP_RCU)
106 return -ECHILD;
107
108 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: called on dentry %p.\n",
109 __func__, dentry);
110
99109822
MB
111 /* skip root handle lookups. */
112 if (dentry->d_inode && is_root_handle(dentry->d_inode))
113 return 1;
114
115 /*
116 * If this passes, the positive dentry still exists or the negative
117 * dentry still does not exist.
118 */
ee70fca0 119 if (!orangefs_revalidate_lookup(dentry))
99109822 120 return 0;
5db11c21 121
99109822 122 /* We do not need to continue with negative dentries. */
74e938c2
MB
123 if (!dentry->d_inode) {
124 gossip_debug(GOSSIP_DCACHE_DEBUG,
125 "%s: negative dentry or positive dentry and inode valid.\n",
126 __func__);
127 return 1;
128 }
5db11c21 129
99109822 130 /* Now we must perform a getattr to validate the inode contents. */
933287da 131
5859d77e 132 ret = orangefs_inode_check_changed(dentry->d_inode);
99109822
MB
133 if (ret < 0) {
134 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s:%s:%d getattr failure.\n",
135 __FILE__, __func__, __LINE__);
99109822
MB
136 return 0;
137 }
74e938c2 138 return !ret;
5db11c21
MM
139}
140
8bb8aefd
YL
141const struct dentry_operations orangefs_dentry_operations = {
142 .d_revalidate = orangefs_d_revalidate,
5db11c21 143};