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#include <linux/fs.h>
34#include <linux/sched.h>
35#include <linux/quotaops.h>
36
37#define DEBUG_SUBSYSTEM S_LLITE
38
39#include "../include/obd_support.h"
40#include "../include/lustre/lustre_idl.h"
41#include "../include/lustre_dlm.h"
42
43#include "llite_internal.h"
44
45static void free_dentry_data(struct rcu_head *head)
46{
47 struct ll_dentry_data *lld;
48
49 lld = container_of(head, struct ll_dentry_data, lld_rcu_head);
50 kfree(lld);
51}
52
53
54static void ll_release(struct dentry *de)
55{
56 struct ll_dentry_data *lld;
57
58 LASSERT(de);
59 lld = ll_d2d(de);
60 if (!lld)
61 return;
62
63 if (lld->lld_it) {
64 ll_intent_release(lld->lld_it);
65 kfree(lld->lld_it);
66 }
67
68 de->d_fsdata = NULL;
69 call_rcu(&lld->lld_rcu_head, free_dentry_data);
70}
71
72
73
74
75
76
77
78
79
80static int ll_dcompare(const struct dentry *dentry,
81 unsigned int len, const char *str,
82 const struct qstr *name)
83{
84 if (len != name->len)
85 return 1;
86
87 if (memcmp(str, name->name, len))
88 return 1;
89
90 CDEBUG(D_DENTRY, "found name %.*s(%p) flags %#x refc %d\n",
91 name->len, name->name, dentry, dentry->d_flags,
92 d_count(dentry));
93
94
95 if (d_mountpoint((struct dentry *)dentry))
96 return 0;
97
98 if (d_lustre_invalid(dentry))
99 return 1;
100
101 return 0;
102}
103
104
105
106
107
108
109
110
111static int ll_ddelete(const struct dentry *de)
112{
113 LASSERT(de);
114
115 CDEBUG(D_DENTRY, "%s dentry %pd (%p, parent %p, inode %p) %s%s\n",
116 d_lustre_invalid((struct dentry *)de) ? "deleting" : "keeping",
117 de, de, de->d_parent, d_inode(de),
118 d_unhashed(de) ? "" : "hashed,",
119 list_empty(&de->d_subdirs) ? "" : "subdirs");
120
121
122 LASSERT(d_count(de) == 1);
123
124 if (d_lustre_invalid((struct dentry *)de))
125 return 1;
126 return 0;
127}
128
129int ll_d_init(struct dentry *de)
130{
131 CDEBUG(D_DENTRY, "ldd on dentry %pd (%p) parent %p inode %p refc %d\n",
132 de, de, de->d_parent, d_inode(de), d_count(de));
133
134 if (!de->d_fsdata) {
135 struct ll_dentry_data *lld;
136
137 lld = kzalloc(sizeof(*lld), GFP_NOFS);
138 if (likely(lld)) {
139 spin_lock(&de->d_lock);
140 if (likely(!de->d_fsdata)) {
141 de->d_fsdata = lld;
142 __d_lustre_invalidate(de);
143 } else {
144 kfree(lld);
145 }
146 spin_unlock(&de->d_lock);
147 } else {
148 return -ENOMEM;
149 }
150 }
151 LASSERT(de->d_op == &ll_d_ops);
152
153 return 0;
154}
155
156void ll_intent_drop_lock(struct lookup_intent *it)
157{
158 if (it->it_op && it->it_lock_mode) {
159 struct lustre_handle handle;
160
161 handle.cookie = it->it_lock_handle;
162
163 CDEBUG(D_DLMTRACE, "releasing lock with cookie %#llx from it %p\n",
164 handle.cookie, it);
165 ldlm_lock_decref(&handle, it->it_lock_mode);
166
167
168
169
170 it->it_lock_mode = 0;
171 if (it->it_remote_lock_mode != 0) {
172 handle.cookie = it->it_remote_lock_handle;
173
174 CDEBUG(D_DLMTRACE, "releasing remote lock with cookie%#llx from it %p\n",
175 handle.cookie, it);
176 ldlm_lock_decref(&handle,
177 it->it_remote_lock_mode);
178 it->it_remote_lock_mode = 0;
179 }
180 }
181}
182
183void ll_intent_release(struct lookup_intent *it)
184{
185 CDEBUG(D_INFO, "intent %p released\n", it);
186 ll_intent_drop_lock(it);
187
188 if (it_disposition(it, DISP_ENQ_OPEN_REF))
189 ptlrpc_req_finished(it->it_request);
190
191 if (it_disposition(it, DISP_ENQ_CREATE_REF))
192 ptlrpc_req_finished(it->it_request);
193
194 it->it_disposition = 0;
195 it->it_request = NULL;
196}
197
198void ll_invalidate_aliases(struct inode *inode)
199{
200 struct dentry *dentry;
201
202 CDEBUG(D_INODE, "marking dentries for ino "DFID"(%p) invalid\n",
203 PFID(ll_inode2fid(inode)), inode);
204
205 spin_lock(&inode->i_lock);
206 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
207 CDEBUG(D_DENTRY, "dentry in drop %pd (%p) parent %p inode %p flags %d\n",
208 dentry, dentry, dentry->d_parent,
209 d_inode(dentry), dentry->d_flags);
210
211 d_lustre_invalidate(dentry, 0);
212 }
213 spin_unlock(&inode->i_lock);
214}
215
216int ll_revalidate_it_finish(struct ptlrpc_request *request,
217 struct lookup_intent *it,
218 struct inode *inode)
219{
220 int rc = 0;
221
222 if (!request)
223 return 0;
224
225 if (it_disposition(it, DISP_LOOKUP_NEG))
226 return -ENOENT;
227
228 rc = ll_prep_inode(&inode, request, NULL, it);
229
230 return rc;
231}
232
233void ll_lookup_finish_locks(struct lookup_intent *it, struct inode *inode)
234{
235 if (it->it_lock_mode && inode) {
236 struct ll_sb_info *sbi = ll_i2sbi(inode);
237
238 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"(%p)\n",
239 PFID(ll_inode2fid(inode)), inode);
240 ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
241 }
242
243
244 if (it->it_op == IT_LOOKUP || it->it_op == IT_GETATTR) {
245
246
247
248
249 ll_intent_drop_lock(it);
250 }
251}
252
253static int ll_revalidate_dentry(struct dentry *dentry,
254 unsigned int lookup_flags)
255{
256 struct inode *dir = d_inode(dentry->d_parent);
257
258
259
260
261
262 if (lookup_flags & LOOKUP_PARENT)
263 return 1;
264
265
266 if (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode))
267 return 1;
268
269
270
271
272
273
274 if ((lookup_flags & (LOOKUP_OPEN | LOOKUP_CREATE)) ==
275 (LOOKUP_OPEN | LOOKUP_CREATE))
276 return 0;
277
278 if (lookup_flags & (LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE))
279 return 1;
280
281 if (!dentry_may_statahead(dir, dentry))
282 return 1;
283
284 if (lookup_flags & LOOKUP_RCU)
285 return -ECHILD;
286
287 ll_statahead(dir, &dentry, !d_inode(dentry));
288 return 1;
289}
290
291
292
293
294static int ll_revalidate_nd(struct dentry *dentry, unsigned int flags)
295{
296 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, flags=%u\n",
297 dentry, flags);
298
299 return ll_revalidate_dentry(dentry, flags);
300}
301
302const struct dentry_operations ll_d_ops = {
303 .d_revalidate = ll_revalidate_nd,
304 .d_release = ll_release,
305 .d_delete = ll_ddelete,
306 .d_compare = ll_dcompare,
307};
308