blob: dcb55bbb0b691b568f484f84454b11bc1201a3a9 [file] [log] [blame]
Mike Marshall5db11c22015-07-17 10:38:12 -04001/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7/*
8 * Implementation of dentry (directory cache) functions.
9 */
10
11#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -050012#include "orangefs-kernel.h"
Mike Marshall5db11c22015-07-17 10:38:12 -040013
14/* Returns 1 if dentry can still be trusted, else 0. */
Yi Liu8bb8aef2015-11-24 15:12:14 -050015static int orangefs_revalidate_lookup(struct dentry *dentry)
Mike Marshall5db11c22015-07-17 10:38:12 -040016{
17 struct dentry *parent_dentry = dget_parent(dentry);
18 struct inode *parent_inode = parent_dentry->d_inode;
Yi Liu8bb8aef2015-11-24 15:12:14 -050019 struct orangefs_inode_s *parent = ORANGEFS_I(parent_inode);
Mike Marshall5db11c22015-07-17 10:38:12 -040020 struct inode *inode = dentry->d_inode;
Yi Liu8bb8aef2015-11-24 15:12:14 -050021 struct orangefs_kernel_op_s *new_op;
Mike Marshall5db11c22015-07-17 10:38:12 -040022 int ret = 0;
23 int err = 0;
24
25 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: attempting lookup.\n", __func__);
26
Yi Liu8bb8aef2015-11-24 15:12:14 -050027 new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
Mike Marshall5db11c22015-07-17 10:38:12 -040028 if (!new_op)
29 goto out_put_parent;
30
Yi Liu8bb8aef2015-11-24 15:12:14 -050031 new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
Mike Marshall5db11c22015-07-17 10:38:12 -040032 new_op->upcall.req.lookup.parent_refn = parent->refn;
33 strncpy(new_op->upcall.req.lookup.d_name,
34 dentry->d_name.name,
Martin Brandenburg47b49482016-02-20 14:22:40 -050035 ORANGEFS_NAME_MAX);
Mike Marshall5db11c22015-07-17 10:38:12 -040036
37 gossip_debug(GOSSIP_DCACHE_DEBUG,
38 "%s:%s:%d interrupt flag [%d]\n",
39 __FILE__,
40 __func__,
41 __LINE__,
42 get_interruptible_flag(parent_inode));
43
Yi Liu8bb8aef2015-11-24 15:12:14 -050044 err = service_operation(new_op, "orangefs_lookup",
Mike Marshall5db11c22015-07-17 10:38:12 -040045 get_interruptible_flag(parent_inode));
Mike Marshall5db11c22015-07-17 10:38:12 -040046
Martin Brandenburg99109822016-01-28 10:19:40 -050047 /* Positive dentry: reject if error or not the same inode. */
48 if (inode) {
49 if (err) {
50 gossip_debug(GOSSIP_DCACHE_DEBUG,
51 "%s:%s:%d lookup failure.\n",
52 __FILE__, __func__, __LINE__);
53 goto out_drop;
54 }
55 if (!match_handle(new_op->downcall.resp.lookup.refn.khandle,
56 inode)) {
57 gossip_debug(GOSSIP_DCACHE_DEBUG,
58 "%s:%s:%d no match.\n",
59 __FILE__, __func__, __LINE__);
60 goto out_drop;
61 }
62
63 /* Negative dentry: reject if success or error other than ENOENT. */
64 } else {
65 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: negative dentry.\n",
66 __func__);
67 if (!err || err != -ENOENT) {
68 if (new_op->downcall.status != 0)
69 gossip_debug(GOSSIP_DCACHE_DEBUG,
70 "%s:%s:%d lookup failure.\n",
71 __FILE__, __func__, __LINE__);
72 goto out_drop;
73 }
Mike Marshall5db11c22015-07-17 10:38:12 -040074 }
75
Martin Brandenburg31b7c1a2016-02-08 17:01:29 -050076 dentry->d_time = jiffies + HZ;
Mike Marshall5db11c22015-07-17 10:38:12 -040077 ret = 1;
78out_release_op:
79 op_release(new_op);
80out_put_parent:
81 dput(parent_dentry);
82 return ret;
83out_drop:
Martin Brandenburg99109822016-01-28 10:19:40 -050084 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s:%s:%d revalidate failed\n",
85 __FILE__, __func__, __LINE__);
Mike Marshall5db11c22015-07-17 10:38:12 -040086 goto out_release_op;
87}
88
89/*
90 * Verify that dentry is valid.
91 *
Mike Marshallf987f4c2015-12-30 13:04:28 -050092 * Should return 1 if dentry can still be trusted, else 0.
Mike Marshall5db11c22015-07-17 10:38:12 -040093 */
Yi Liu8bb8aef2015-11-24 15:12:14 -050094static int orangefs_d_revalidate(struct dentry *dentry, unsigned int flags)
Mike Marshall5db11c22015-07-17 10:38:12 -040095{
Martin Brandenburg99109822016-01-28 10:19:40 -050096 int ret;
Mike Marshall5db11c22015-07-17 10:38:12 -040097
Martin Brandenburg31b7c1a2016-02-08 17:01:29 -050098 if (dentry->d_time > jiffies)
99 return 1;
100
Mike Marshall5db11c22015-07-17 10:38:12 -0400101 if (flags & LOOKUP_RCU)
102 return -ECHILD;
103
104 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: called on dentry %p.\n",
105 __func__, dentry);
106
Mike Marshallf987f4c2015-12-30 13:04:28 -0500107 /* skip root handle lookups. */
Martin Brandenburg99109822016-01-28 10:19:40 -0500108 if (dentry->d_inode && is_root_handle(dentry->d_inode))
109 return 1;
110
111 /*
112 * If this passes, the positive dentry still exists or the negative
113 * dentry still does not exist.
114 */
Martin Brandenburgee70fca2016-02-20 13:10:47 -0500115 if (!orangefs_revalidate_lookup(dentry))
Martin Brandenburg99109822016-01-28 10:19:40 -0500116 return 0;
Mike Marshall5db11c22015-07-17 10:38:12 -0400117
Martin Brandenburg99109822016-01-28 10:19:40 -0500118 /* We do not need to continue with negative dentries. */
119 if (!dentry->d_inode)
120 goto out;
121
122 /* Now we must perform a getattr to validate the inode contents. */
Martin Brandenburg933287d2016-01-30 13:46:54 -0500123
Martin Brandenburg5859d772016-03-17 15:15:16 -0400124 ret = orangefs_inode_check_changed(dentry->d_inode);
Martin Brandenburg99109822016-01-28 10:19:40 -0500125 if (ret < 0) {
126 gossip_debug(GOSSIP_DCACHE_DEBUG, "%s:%s:%d getattr failure.\n",
127 __FILE__, __func__, __LINE__);
Martin Brandenburg99109822016-01-28 10:19:40 -0500128 return 0;
129 }
Martin Brandenburgee70fca2016-02-20 13:10:47 -0500130 if (ret == 0)
Martin Brandenburg99109822016-01-28 10:19:40 -0500131 return 0;
Mike Marshall5db11c22015-07-17 10:38:12 -0400132
Mike Marshallf987f4c2015-12-30 13:04:28 -0500133out:
Martin Brandenburg99109822016-01-28 10:19:40 -0500134 gossip_debug(GOSSIP_DCACHE_DEBUG,
135 "%s: negative dentry or positive dentry and inode valid.\n",
136 __func__);
137 return 1;
Mike Marshall5db11c22015-07-17 10:38:12 -0400138}
139
Yi Liu8bb8aef2015-11-24 15:12:14 -0500140const struct dentry_operations orangefs_dentry_operations = {
141 .d_revalidate = orangefs_d_revalidate,
Mike Marshall5db11c22015-07-17 10:38:12 -0400142};