Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / llite / dcache.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include <linux/fs.h>
23 #include <linux/sched.h>
24 #include <linux/smp_lock.h>
25 #include <linux/quotaops.h>
26
27 #define DEBUG_SUBSYSTEM S_LLITE
28
29 #include <obd_support.h>
30 #include <lustre_lite.h>
31 #include <lustre/lustre_idl.h>
32 #include <lustre_dlm.h>
33 #include <linux/lustre_version.h>
34
35 #include "llite_internal.h"
36
37 /* should NOT be called with the dcache lock, see fs/dcache.c */
38 static void ll_release(struct dentry *de)
39 {
40         struct ll_dentry_data *lld;
41         ENTRY;
42         LASSERT(de != NULL);
43         lld = ll_d2d(de);
44         if (lld == NULL) { /* NFS copies the de->d_op methods (bug 4655) */
45                 EXIT;
46                 return;
47         }
48 #ifndef LUSTRE_KERNEL_VERSION
49         if (lld->lld_it) {
50                 ll_intent_release(lld->lld_it);
51                 OBD_FREE(lld->lld_it, sizeof(*lld->lld_it));
52         }
53 #endif
54         LASSERT(lld->lld_cwd_count == 0);
55         LASSERT(lld->lld_mnt_count == 0);
56         OBD_FREE(de->d_fsdata, sizeof(*lld));
57
58         EXIT;
59 }
60
61 #ifdef LUSTRE_KERNEL_VERSION
62 /* Compare if two dentries are the same.  Don't match if the existing dentry
63  * is marked DCACHE_LUSTRE_INVALID.  Returns 1 if different, 0 if the same.
64  *
65  * This avoids a race where ll_lookup_it() instantiates a dentry, but we get
66  * an AST before calling d_revalidate_it().  The dentry still exists (marked
67  * INVALID) so d_lookup() matches it, but we have no lock on it (so
68  * lock_match() fails) and we spin around real_lookup(). */
69 int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name)
70 {
71         struct dentry *dchild;
72         ENTRY;
73
74         if (d_name->len != name->len)
75                 RETURN(1);
76
77         if (memcmp(d_name->name, name->name, name->len))
78                 RETURN(1);
79
80         /* XXX: d_name must be in-dentry structure */
81         dchild = container_of(d_name, struct dentry, d_name); /* ugh */
82         if (dchild->d_flags & DCACHE_LUSTRE_INVALID) {
83                 CDEBUG(D_DENTRY,"INVALID dentry %p not matched, was bug 3784\n",
84                        dchild);
85                 RETURN(1);
86         }
87
88         RETURN(0);
89 }
90 #endif
91
92 /* should NOT be called with the dcache lock, see fs/dcache.c */
93 static int ll_ddelete(struct dentry *de)
94 {
95         ENTRY;
96         LASSERT(de);
97 #ifndef DCACHE_LUSTRE_INVALID
98 #define DCACHE_LUSTRE_INVALID 0
99 #endif
100
101         CDEBUG(D_DENTRY, "%s dentry %.*s (%p, parent %p, inode %p) %s%s\n",
102                (de->d_flags & DCACHE_LUSTRE_INVALID ? "deleting" : "keeping"),
103                de->d_name.len, de->d_name.name, de, de->d_parent, de->d_inode,
104                d_unhashed(de) ? "" : "hashed,",
105                list_empty(&de->d_subdirs) ? "" : "subdirs");
106 #if DCACHE_LUSTRE_INVALID == 0
107 #undef DCACHE_LUSTRE_INVALID
108 #endif
109
110         RETURN(0);
111 }
112
113 void ll_set_dd(struct dentry *de)
114 {
115         ENTRY;
116         LASSERT(de != NULL);
117
118         CDEBUG(D_DENTRY, "ldd on dentry %.*s (%p) parent %p inode %p refc %d\n",
119                de->d_name.len, de->d_name.name, de, de->d_parent, de->d_inode,
120                atomic_read(&de->d_count));
121         lock_kernel();
122         if (de->d_fsdata == NULL) {
123                 OBD_ALLOC(de->d_fsdata, sizeof(struct ll_dentry_data));
124         }
125         unlock_kernel();
126
127         EXIT;
128 }
129
130 void ll_intent_drop_lock(struct lookup_intent *it)
131 {
132         struct lustre_handle *handle;
133
134         if (it->it_op && it->d.lustre.it_lock_mode) {
135                 handle = (struct lustre_handle *)&it->d.lustre.it_lock_handle;
136                 CDEBUG(D_DLMTRACE, "releasing lock with cookie "LPX64
137                        " from it %p\n", handle->cookie, it);
138                 ldlm_lock_decref(handle, it->d.lustre.it_lock_mode);
139
140                 /* bug 494: intent_release may be called multiple times, from
141                  * this thread and we don't want to double-decref this lock */
142                 it->d.lustre.it_lock_mode = 0;
143         }
144 }
145
146 void ll_intent_release(struct lookup_intent *it)
147 {
148         ENTRY;
149
150         ll_intent_drop_lock(it);
151 #ifdef LUSTRE_KERNEL_VERSION
152         it->it_magic = 0;
153         it->it_op_release = 0;
154 #endif
155         /* We are still holding extra reference on a request, need to free it */
156         if (it_disposition(it, DISP_ENQ_OPEN_REF)) /* open req for llfile_open*/
157                 ptlrpc_req_finished(it->d.lustre.it_data);
158         if (it_disposition(it, DISP_ENQ_CREATE_REF)) /* create rec */
159                 ptlrpc_req_finished(it->d.lustre.it_data);
160         if (it_disposition(it, DISP_ENQ_COMPLETE)) /* saved req from revalidate
161                                                     * to lookup */
162                 ptlrpc_req_finished(it->d.lustre.it_data);
163
164         it->d.lustre.it_disposition = 0;
165         it->d.lustre.it_data = NULL;
166         EXIT;
167 }
168
169 /* Drop dentry if it is not used already, unhash otherwise.
170    Should be called with dcache lock held!
171    Returns: 1 if dentry was dropped, 0 if unhashed. */
172 int ll_drop_dentry(struct dentry *dentry)
173 {
174         lock_dentry(dentry);
175         if (atomic_read(&dentry->d_count) == 0) {
176                 CDEBUG(D_DENTRY, "deleting dentry %.*s (%p) parent %p "
177                        "inode %p\n", dentry->d_name.len,
178                        dentry->d_name.name, dentry, dentry->d_parent,
179                        dentry->d_inode);
180                 dget_locked(dentry);
181                 __d_drop(dentry);
182                 unlock_dentry(dentry);
183                 spin_unlock(&dcache_lock);
184                 dput(dentry);
185                 spin_lock(&dcache_lock);
186                 return 1;
187         }
188
189 #ifdef LUSTRE_KERNEL_VERSION
190         if (!(dentry->d_flags & DCACHE_LUSTRE_INVALID)) {
191 #else
192         if (!d_unhashed(dentry)) {
193 #endif
194                 CDEBUG(D_DENTRY, "unhashing dentry %.*s (%p) parent %p "
195                        "inode %p refc %d\n", dentry->d_name.len,
196                        dentry->d_name.name, dentry, dentry->d_parent,
197                        dentry->d_inode, atomic_read(&dentry->d_count));
198                 /* actually we don't unhash the dentry, rather just
199                  * mark it inaccessible for to __d_lookup(). otherwise
200                  * sys_getcwd() could return -ENOENT -bzzz */
201 #ifdef LUSTRE_KERNEL_VERSION
202                 dentry->d_flags |= DCACHE_LUSTRE_INVALID;
203 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
204                 __d_drop(dentry);
205                 if (dentry->d_inode) {
206                         /* Put positive dentries to orphan list */
207                         list_add(&dentry->d_hash,
208                                  &ll_i2sbi(dentry->d_inode)->ll_orphan_dentry_list);
209                 }
210 #endif
211 #else
212                 if (!dentry->d_inode || !S_ISDIR(dentry->d_inode->i_mode))
213                         __d_drop(dentry);
214 #endif
215
216         }
217         unlock_dentry(dentry);
218         return 0;
219 }
220
221 void ll_unhash_aliases(struct inode *inode)
222 {
223         struct list_head *tmp, *head;
224         ENTRY;
225
226         if (inode == NULL) {
227                 CERROR("unexpected NULL inode, tell phil\n");
228                 return;
229         }
230
231         CDEBUG(D_INODE, "marking dentries for ino %lu/%u(%p) invalid\n",
232                inode->i_ino, inode->i_generation, inode);
233
234         head = &inode->i_dentry;
235         spin_lock(&dcache_lock);
236 restart:
237         tmp = head;
238         while ((tmp = tmp->next) != head) {
239                 struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
240
241                 if (dentry->d_name.len == 1 && dentry->d_name.name[0] == '/') {
242                         CERROR("called on root (?) dentry=%p, inode=%p "
243                                "ino=%lu\n", dentry, inode, inode->i_ino);
244                         lustre_dump_dentry(dentry, 1);
245                         libcfs_debug_dumpstack(NULL);
246                 } else if (d_mountpoint(dentry)) {
247                         /* For mountpoints we skip removal of the dentry
248                            which happens solely because we have a lock on it
249                            obtained when this dentry was not a mountpoint yet */
250                         CDEBUG(D_DENTRY, "Skippind mountpoint dentry removal "
251                                          "%.*s (%p) parent %p\n",
252                                           dentry->d_name.len,
253                                           dentry->d_name.name,
254                                           dentry, dentry->d_parent);
255
256                         continue;
257                 }
258                 
259                 if (ll_drop_dentry(dentry))
260                           goto restart;
261         }
262         spin_unlock(&dcache_lock);
263         EXIT;
264 }
265
266 int revalidate_it_finish(struct ptlrpc_request *request, int offset,
267                          struct lookup_intent *it, struct dentry *de)
268 {
269         int rc = 0;
270         ENTRY;
271
272         if (!request)
273                 RETURN(0);
274
275         if (it_disposition(it, DISP_LOOKUP_NEG))
276                 RETURN(-ENOENT);
277
278         rc = ll_prep_inode(ll_i2sbi(de->d_inode)->ll_osc_exp, &de->d_inode,
279                            request, offset, NULL);
280
281         RETURN(rc);
282 }
283
284 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry)
285 {
286         LASSERT(it != NULL);
287         LASSERT(dentry != NULL);
288
289         if (it->d.lustre.it_lock_mode && dentry->d_inode != NULL) {
290                 struct inode *inode = dentry->d_inode;
291                 CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%u)\n",
292                        inode, inode->i_ino, inode->i_generation);
293                 mdc_set_lock_data(&it->d.lustre.it_lock_handle, inode);
294         }
295
296         /* drop lookup or getattr locks immediately */
297         if (it->it_op == IT_LOOKUP || it->it_op == IT_GETATTR) {
298 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
299                 /* on 2.6 there are situation when several lookups and
300                  * revalidations may be requested during single operation.
301                  * therefore, we don't release intent here -bzzz */
302                 ll_intent_drop_lock(it);
303 #else
304                 ll_intent_release(it);
305 #endif
306         }
307 }
308
309 void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft)
310 {
311         struct lookup_intent *it = *itp;
312 #if defined(LUSTRE_KERNEL_VERSION)&&(LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
313         if (it) {
314                 LASSERTF(it->it_magic == INTENT_MAGIC, "bad intent magic: %x\n",
315                          it->it_magic);
316         }
317 #endif
318
319         if (!it || it->it_op == IT_GETXATTR)
320                 it = *itp = deft;
321
322 #ifdef LUSTRE_KERNEL_VERSION
323         it->it_op_release = ll_intent_release;
324 #endif
325 }
326
327 int ll_revalidate_it(struct dentry *de, int lookup_flags,
328                      struct lookup_intent *it)
329 {
330         int rc;
331         struct mdc_op_data op_data;
332         struct ptlrpc_request *req = NULL;
333         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
334         struct obd_export *exp;
335
336         ENTRY;
337         CDEBUG(D_VFSTRACE, "VFS Op:name=%s,intent=%s\n", de->d_name.name,
338                LL_IT2STR(it));
339
340         if (de->d_inode == NULL) {
341                 /* We can only use negative dentries if this is stat or lookup,
342                    for opens and stuff we do need to query server. */
343                 /* If there is IT_CREAT in intent op set, then we must throw
344                    away this negative dentry and actually do the request to
345                    kernel to create whatever needs to be created (if possible)*/
346                 if (it && (it->it_op & IT_CREAT))
347                         RETURN(0);
348
349 #ifdef LUSTRE_KERNEL_VERSION
350                 if (de->d_flags & DCACHE_LUSTRE_INVALID)
351                         RETURN(0);
352 #endif
353
354                 rc = ll_have_md_lock(de->d_parent->d_inode, 
355                                      MDS_INODELOCK_UPDATE);
356         
357                 RETURN(rc);
358         }
359
360         exp = ll_i2mdcexp(de->d_inode);
361
362         /* Never execute intents for mount points.
363          * Attributes will be fixed up in ll_inode_revalidate_it */
364         if (d_mountpoint(de))
365                 RETURN(1);
366
367         /* Root of the lustre tree. Always valid.
368          * Attributes will be fixed up in ll_inode_revalidate_it */
369         if (de->d_name.name[0] == '/' && de->d_name.len == 1)
370                 RETURN(1);
371
372         OBD_FAIL_TIMEOUT(OBD_FAIL_MDC_REVALIDATE_PAUSE, 5);
373         ll_frob_intent(&it, &lookup_it);
374         LASSERT(it);
375
376         ll_prepare_mdc_op_data(&op_data, de->d_parent->d_inode, de->d_inode,
377                                de->d_name.name, de->d_name.len, 0);
378
379         if ((it->it_op == IT_OPEN) && de->d_inode) {
380                 struct inode *inode = de->d_inode;
381                 struct ll_inode_info *lli = ll_i2info(inode);
382                 struct obd_client_handle **och_p;
383                 __u64 *och_usecount;
384                 /* We used to check for MDS_INODELOCK_OPEN here, but in fact
385                  * just having LOOKUP lock is enough to justify inode is the
386                  * same. And if inode is the same and we have suitable
387                  * openhandle, then there is no point in doing another OPEN RPC
388                  * just to throw away newly received openhandle.
389                  * There are no security implications too, if file owner or
390                  * access mode is change, LOOKUP lock is revoked */
391
392                 if (it->it_flags & FMODE_WRITE) {
393                         och_p = &lli->lli_mds_write_och;
394                         och_usecount = &lli->lli_open_fd_write_count;
395                 } else if (it->it_flags & FMODE_EXEC) {
396                         och_p = &lli->lli_mds_exec_och;
397                         och_usecount = &lli->lli_open_fd_exec_count;
398                  } else {
399                         och_p = &lli->lli_mds_read_och;
400                         och_usecount = &lli->lli_open_fd_read_count;
401                 }
402                 /* Check for the proper lock. */
403                 if (!ll_have_md_lock(inode, MDS_INODELOCK_LOOKUP))
404                         goto do_lock;
405                 down(&lli->lli_och_sem);
406                 if (*och_p) { /* Everything is open already, do nothing */
407                         /*(*och_usecount)++;  Do not let them steal our open
408                                               handle from under us */
409                         /* XXX The code above was my original idea, but in case
410                            we have the handle, but we cannot use it due to later
411                            checks (e.g. O_CREAT|O_EXCL flags set), nobody
412                            would decrement counter increased here. So we just
413                            hope the lock won't be invalidated in between. But
414                            if it would be, we'll reopen the open request to
415                            MDS later during file open path */
416                         up(&lli->lli_och_sem);
417                         RETURN(1);
418                 } else {
419                         up(&lli->lli_och_sem);
420                 }
421         }
422
423 do_lock:
424         it->it_create_mode &= ~current->fs->umask;
425
426         rc = mdc_intent_lock(exp, &op_data, NULL, 0, it, lookup_flags,
427                              &req, ll_mdc_blocking_ast, 0);
428         /* If req is NULL, then mdc_intent_lock only tried to do a lock match;
429          * if all was well, it will return 1 if it found locks, 0 otherwise. */
430         if (req == NULL && rc >= 0) {
431                 if (!rc)
432                         goto do_lookup;
433                 GOTO(out, rc);
434         }
435
436         if (rc < 0) {
437                 if (rc != -ESTALE) {
438                         CDEBUG(D_INFO, "ll_intent_lock: rc %d : it->it_status "
439                                "%d\n", rc, it->d.lustre.it_status);
440                 }
441                 GOTO(out, rc = 0);
442         }
443
444 revalidate_finish:
445         rc = revalidate_it_finish(req, DLM_REPLY_REC_OFF, it, de);
446         if (rc != 0) {
447                 ll_intent_release(it);
448                 GOTO(out, rc = 0);
449         }
450         if ((it->it_op & IT_OPEN) && de->d_inode && 
451             !S_ISREG(de->d_inode->i_mode) && 
452             !S_ISDIR(de->d_inode->i_mode)) {
453                 ll_release_openhandle(de, it);
454         }
455         rc = 1;
456
457         /* unfortunately ll_intent_lock may cause a callback and revoke our
458          * dentry */
459         spin_lock(&dcache_lock);
460         lock_dentry(de);
461         __d_drop(de);
462         unlock_dentry(de);
463         __d_rehash(de, 0);
464         spin_unlock(&dcache_lock);
465
466  out:
467         /* We do not free request as it may be reused during following lookup
468          * (see comment in mdc/mdc_locks.c::mdc_intent_lock()), request will
469          * be freed in ll_lookup_it or in ll_intent_release. But if
470          * request was not completed, we need to free it. (bug 5154, 9903) */
471         if (req != NULL && !it_disposition(it, DISP_ENQ_COMPLETE))
472                 ptlrpc_req_finished(req);
473         if (rc == 0) {
474 #ifdef LUSTRE_KERNEL_VERSION
475                 ll_unhash_aliases(de->d_inode);
476                 /* done in ll_unhash_aliases()
477                 dentry->d_flags |= DCACHE_LUSTRE_INVALID; */
478 #else
479                 /* We do not want d_invalidate to kill all child dentries too */
480                 d_drop(de);
481 #endif
482         } else {
483                 CDEBUG(D_DENTRY, "revalidated dentry %.*s (%p) parent %p "
484                                "inode %p refc %d\n", de->d_name.len,
485                                de->d_name.name, de, de->d_parent, de->d_inode,
486                                atomic_read(&de->d_count));
487                 ll_lookup_finish_locks(it, de);
488 #ifdef LUSTRE_KERNEL_VERSION
489                 lock_dentry(de);
490                 de->d_flags &= ~DCACHE_LUSTRE_INVALID;
491                 unlock_dentry(de);
492 #endif
493         }
494         RETURN(rc);
495 /* This part is here to combat evil-evil race in real_lookup on 2.6 kernels.
496  * The race details are: We enter do_lookup() looking for some name,
497  * there is nothing in dcache for this name yet and d_lookup() returns NULL.
498  * We proceed to real_lookup(), and while we do this, another process does
499  * open on the same file we looking up (most simple reproducer), open succeeds
500  * and the dentry is added. Now back to us. In real_lookup() we do d_lookup()
501  * again and suddenly find the dentry, so we call d_revalidate on it, but there
502  * is no lock, so without this code we would return 0, but unpatched
503  * real_lookup just returns -ENOENT in such a case instead of retrying the
504  * lookup. Once this is dealt with in real_lookup(), all of this ugly mess
505  * can go and we can just check locks in ->d_revalidate without doing any
506  * RPCs ever. */
507 do_lookup:
508         if (it != &lookup_it) {
509                 ll_lookup_finish_locks(it, de);
510                 it = &lookup_it;
511         }
512         /*do real lookup here */
513         ll_prepare_mdc_op_data(&op_data, de->d_parent->d_inode, NULL,
514                                de->d_name.name, de->d_name.len, 0);
515         rc = mdc_intent_lock(exp, &op_data, NULL, 0,  it, 0, &req,
516                              ll_mdc_blocking_ast, 0);
517         if (rc >= 0) {
518                 struct mds_body *mds_body = lustre_msg_buf(req->rq_repmsg,
519                                                            DLM_REPLY_REC_OFF,
520                                                            sizeof(*mds_body));
521                 /* see if we got same inode, if not - return error */
522                 if(!memcmp(&op_data.fid2, &mds_body->fid1,
523                            sizeof(op_data.fid2)))
524                         goto revalidate_finish;
525                 ll_intent_release(it);
526         }
527         GOTO(out, rc = 0);
528 }
529
530 /*static*/ void ll_pin(struct dentry *de, struct vfsmount *mnt, int flag)
531 {
532         struct inode *inode= de->d_inode;
533         struct ll_sb_info *sbi = ll_i2sbi(inode);
534         struct ll_dentry_data *ldd = ll_d2d(de);
535         struct obd_client_handle *handle;
536         int rc = 0;
537         ENTRY;
538         LASSERT(ldd);
539
540         lock_kernel();
541         /* Strictly speaking this introduces an additional race: the
542          * increments should wait until the rpc has returned.
543          * However, given that at present the function is void, this
544          * issue is moot. */
545         if (flag == 1 && (++ldd->lld_mnt_count) > 1) {
546                 unlock_kernel();
547                 EXIT;
548                 return;
549         }
550
551         if (flag == 0 && (++ldd->lld_cwd_count) > 1) {
552                 unlock_kernel();
553                 EXIT;
554                 return;
555         }
556         unlock_kernel();
557
558         handle = (flag) ? &ldd->lld_mnt_och : &ldd->lld_cwd_och;
559         rc = obd_pin(sbi->ll_mdc_exp, inode->i_ino, inode->i_generation,
560                      inode->i_mode & S_IFMT, handle, flag);
561
562         if (rc) {
563                 lock_kernel();
564                 memset(handle, 0, sizeof(*handle));
565                 if (flag == 0)
566                         ldd->lld_cwd_count--;
567                 else
568                         ldd->lld_mnt_count--;
569                 unlock_kernel();
570         }
571
572         EXIT;
573         return;
574 }
575
576 /*static*/ void ll_unpin(struct dentry *de, struct vfsmount *mnt, int flag)
577 {
578         struct ll_sb_info *sbi = ll_i2sbi(de->d_inode);
579         struct ll_dentry_data *ldd = ll_d2d(de);
580         struct obd_client_handle handle;
581         int count, rc = 0;
582         ENTRY;
583         LASSERT(ldd);
584
585         lock_kernel();
586         /* Strictly speaking this introduces an additional race: the
587          * increments should wait until the rpc has returned.
588          * However, given that at present the function is void, this
589          * issue is moot. */
590         handle = (flag) ? ldd->lld_mnt_och : ldd->lld_cwd_och;
591         if (handle.och_magic != OBD_CLIENT_HANDLE_MAGIC) {
592                 /* the "pin" failed */
593                 unlock_kernel();
594                 EXIT;
595                 return;
596         }
597
598         if (flag)
599                 count = --ldd->lld_mnt_count;
600         else
601                 count = --ldd->lld_cwd_count;
602         unlock_kernel();
603
604         if (count != 0) {
605                 EXIT;
606                 return;
607         }
608
609         rc = obd_unpin(sbi->ll_mdc_exp, &handle, flag);
610         EXIT;
611         return;
612 }
613
614 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
615 #ifdef LUSTRE_KERNEL_VERSION
616 static int ll_revalidate_nd(struct dentry *dentry, struct nameidata *nd)
617 {
618         int rc;
619         ENTRY;
620
621         if (nd && nd->flags & LOOKUP_LAST && !(nd->flags & LOOKUP_LINK_NOTLAST))
622                 rc = ll_revalidate_it(dentry, nd->flags, &nd->intent);
623         else
624                 rc = ll_revalidate_it(dentry, 0, NULL);
625
626         RETURN(rc);
627 }
628 #else
629 int ll_revalidate_nd(struct dentry *dentry, struct nameidata *nd)
630 {
631         int rc;
632         ENTRY;
633
634         if (nd && !(nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))) {
635                 struct lookup_intent *it;
636                 it = ll_convert_intent(&nd->intent.open, nd->flags);
637                 if (IS_ERR(it))
638                         RETURN(0);
639                 if (it->it_op == (IT_OPEN|IT_CREAT))
640                         if (nd->intent.open.flags & O_EXCL) {
641                                 CDEBUG(D_VFSTRACE, "create O_EXCL, returning 0\n");
642                                 rc = 0;
643                                 goto out_it;
644                         }
645
646                 rc = ll_revalidate_it(dentry, nd->flags, it);
647
648                 if (rc && (nd->flags & LOOKUP_OPEN) &&
649                     it_disposition(it, DISP_OPEN_OPEN)) {/*Open*/
650 #ifdef HAVE_FILE_IN_STRUCT_INTENT
651 // XXX Code duplication with ll_lookup_nd
652                         if (S_ISFIFO(dentry->d_inode->i_mode)) {
653                                 // We cannot call open here as it would
654                                 // deadlock.
655                                 ptlrpc_req_finished(
656                                                (struct ptlrpc_request *)
657                                                   it->d.lustre.it_data);
658                         } else {
659                                 struct file *filp;
660
661                                 nd->intent.open.file->private_data = it;
662                                 filp = lookup_instantiate_filp(nd, dentry,NULL);
663 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
664 /* 2.6.1[456] have a bug in open_namei() that forgets to check
665  * nd->intent.open.file for error, so we need to return it as lookup's result
666  * instead */
667                                 if (IS_ERR(filp))
668                                         rc = 0;
669 #endif
670                         }
671 #else
672                         ll_release_openhandle(dentry, it);
673 #endif /* HAVE_FILE_IN_STRUCT_INTENT */
674                 }
675                 if (!rc && (nd->flags & LOOKUP_CREATE) &&
676                     it_disposition(it, DISP_OPEN_CREATE)) {
677                         /* We created something but we may only return
678                          * negative dentry here, so save request in dentry,
679                          * if lookup will be called later on, it will
680                          * pick the request, otherwise it would be freed
681                          * with dentry */
682                         ll_d2d(dentry)->lld_it = it;
683                         it = NULL; /* avoid freeing */
684                 }
685                         
686 out_it:
687                 if (it) {
688                         ll_intent_release(it);
689                         OBD_FREE(it, sizeof(*it));
690                 }
691         } else {
692                 rc = ll_revalidate_it(dentry, 0, NULL);
693         }
694
695         RETURN(rc);
696 }
697 #endif
698 #endif
699
700 struct dentry_operations ll_d_ops = {
701 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
702         .d_revalidate = ll_revalidate_nd,
703 #else
704         .d_revalidate_it = ll_revalidate_it,
705 #endif
706         .d_release = ll_release,
707         .d_delete = ll_ddelete,
708 #ifdef LUSTRE_KERNEL_VERSION
709         .d_compare = ll_dcompare,
710 #endif
711 #if 0
712         .d_pin = ll_pin,
713         .d_unpin = ll_unpin,
714 #endif
715 };