Whamcloud - gitweb
kernel-patches: add dynlocks to -fc{3,5} series.
[fs/lustre-release.git] / lustre / llite / namei.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002, 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/mm.h>
25 #include <linux/smp_lock.h>
26 #include <linux/quotaops.h>
27 #include <linux/highmem.h>
28 #include <linux/pagemap.h>
29
30 #define DEBUG_SUBSYSTEM S_LLITE
31
32 #include <obd_support.h>
33 #include <lustre_fid.h>
34 #include <lustre_lite.h>
35 #include <lustre_dlm.h>
36 #include <lustre_ver.h>
37 #include <lustre_mdc.h>
38 #include "llite_internal.h"
39
40 /* methods */
41
42 extern struct dentry_operations ll_d_ops;
43
44 int ll_unlock(__u32 mode, struct lustre_handle *lockh)
45 {
46         ENTRY;
47
48         ldlm_lock_decref(lockh, mode);
49
50         RETURN(0);
51 }
52
53 /* Get an inode by inode number (already instantiated by the intent lookup).
54  * Returns inode or NULL
55  */
56 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
57 #if 0
58 /* that variant provides correct mapping fid to inode,
59  * it is put here as alternative way to the current one ll_iget() below */
60 int ll_test_inode(struct inode *inode, void *opaque)
61 {
62         return lu_fid_eq(&ll_i2info(inode)->lli_fid, (struct lu_fid *)opaque);
63 }
64
65 int ll_set_inode(struct inode *inode, void *opaque)
66 {
67         struct lu_fid *fid = opaque;
68         ll_i2info(inode)->lli_fid = *fid;
69         inode->i_ino = ll_fid_build_ino(ll_s2sbi(inode->i_sb), fid);
70         return 0;
71 }
72
73 struct inode *ll_iget(struct super_block *sb, ino_t hash,
74                       struct lustre_md *md)
75 {
76         struct ll_inode_info *lli;
77         struct inode *inode;
78         LASSERT(hash != 0);
79
80         inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode,
81                              &md->body->fid1);
82         if (inode) {
83                 if (inode->i_state & I_NEW) {
84                         lli = ll_i2info(inode);
85                         ll_read_inode2(inode, md);
86                         unlock_new_inode(inode);
87                 } else {
88                         ll_update_inode(inode, md);
89                 }
90                 CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n",
91                        inode->i_ino, inode->i_generation, inode);
92         }
93
94         return inode;
95 }
96 #else
97 struct inode *ll_iget(struct super_block *sb, ino_t hash,
98                       struct lustre_md *md)
99 {
100         struct ll_inode_info *lli;
101         struct inode *inode;
102         LASSERT(hash != 0);
103
104         inode = iget_locked(sb, hash);
105         if (inode) {
106                 if (inode->i_state & I_NEW) {
107                         lli = ll_i2info(inode);
108                         ll_read_inode2(inode, md);
109                         unlock_new_inode(inode);
110                 } else {
111                         ll_update_inode(inode, md);
112                 }
113                 CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n",
114                        inode->i_ino, inode->i_generation, inode);
115         }
116
117         return inode;
118 }
119 #endif
120 #else
121 struct inode *ll_iget(struct super_block *sb, ino_t hash,
122                       struct lustre_md *md)
123 {
124         struct inode *inode;
125         LASSERT(hash != 0);
126
127         inode = iget4(sb, hash, NULL, md);
128         if (inode) {
129                 if (!(inode->i_state & (I_FREEING | I_CLEAR)))
130                         ll_update_inode(inode, md);
131
132                 CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n",
133                        inode->i_ino, inode->i_generation, inode);
134         }
135         return inode;
136 }
137 #endif
138
139 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
140                        void *data, int flag)
141 {
142         int rc;
143         struct lustre_handle lockh;
144         ENTRY;
145
146         switch (flag) {
147         case LDLM_CB_BLOCKING:
148                 ldlm_lock2handle(lock, &lockh);
149                 rc = ldlm_cli_cancel(&lockh);
150                 if (rc < 0) {
151                         CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
152                         RETURN(rc);
153                 }
154                 break;
155         case LDLM_CB_CANCELING: {
156                 struct inode *inode = ll_inode_from_lock(lock);
157                 __u64 bits = lock->l_policy_data.l_inodebits.bits;
158                 struct lu_fid *fid;
159
160                 /* Invalidate all dentries associated with this inode */
161                 if (inode == NULL)
162                         break;
163
164                 fid = ll_inode2fid(inode);
165                 if (lock->l_resource->lr_name.name[0] != fid_seq(fid) ||
166                     lock->l_resource->lr_name.name[1] != fid_oid(fid) ||
167                     lock->l_resource->lr_name.name[2] != fid_ver(fid)) {
168                         LDLM_ERROR(lock, "data mismatch with object "
169                                    DFID" (%p)", PFID(fid), inode);
170                 }
171
172                 if (bits & MDS_INODELOCK_OPEN) {
173                         int flags = 0;
174                         switch (lock->l_req_mode) {
175                         case LCK_CW:
176                                 flags = FMODE_WRITE;
177                                 break;
178                         case LCK_PR:
179                                 flags = FMODE_EXEC;
180                                 if (!FMODE_EXEC)
181                                         CERROR("open PR lock without FMODE_EXEC\n");
182                                 break;
183                         case LCK_CR:
184                                 flags = FMODE_READ;
185                                 break;
186                         default:
187                                 CERROR("Unexpected lock mode for OPEN lock "
188                                        "%d, inode %ld\n", lock->l_req_mode,
189                                        inode->i_ino);
190                         }
191                         ll_md_real_close(inode, flags);
192                 }
193
194                 if (bits & MDS_INODELOCK_UPDATE)
195                         ll_i2info(inode)->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
196
197                 if (S_ISDIR(inode->i_mode) &&
198                      (bits & MDS_INODELOCK_UPDATE)) {
199                         struct dentry *dentry, *tmp, *dir;
200                         struct list_head *list;
201                         
202                         CDEBUG(D_INODE, "invalidating inode %lu\n",
203                                inode->i_ino);
204                         truncate_inode_pages(inode->i_mapping, 0);
205
206                         
207                         /* Drop possible cached negative dentries */
208                         list = &inode->i_dentry;
209                         dir = NULL;
210                         spin_lock(&dcache_lock);
211                         
212                         /* It is possible to have several dentries (with 
213                            racer?) */
214                         while ((list = list->next) != &inode->i_dentry) {
215                                 dir = list_entry(list, struct dentry, d_alias);
216 #ifdef LUSTRE_KERNEL_VERSION
217                                 if (!(dir->d_flags & DCACHE_LUSTRE_INVALID))
218 #else
219                                 if (!d_unhashed(dir))
220 #endif
221                                         break;
222
223                                 dir = NULL;
224                         }
225                         
226                         if (dir) {
227 restart:
228                                 list_for_each_entry_safe(dentry, tmp, 
229                                                          &dir->d_subdirs, 
230                                                          d_child)
231                                 {
232                                         /* XXX Print some debug here? */
233                                         if (!dentry->d_inode) 
234                                                 /* Negative dentry. If we were 
235                                                    dropping dcache lock, go 
236                                                    throught the list again */
237                                                 if (ll_drop_dentry(dentry))
238                                                         goto restart;
239                                 }
240                         }
241                         spin_unlock(&dcache_lock);
242                 }
243
244                 if (inode->i_sb->s_root &&
245                     inode != inode->i_sb->s_root->d_inode &&
246                     (bits & MDS_INODELOCK_LOOKUP))
247                         ll_unhash_aliases(inode);
248                 iput(inode);
249                 break;
250         }
251         default:
252                 LBUG();
253         }
254
255         RETURN(0);
256 }
257
258 /* Pack the required supplementary groups into the supplied groups array.
259  * If we don't need to use the groups from the target inode(s) then we
260  * instead pack one or more groups from the user's supplementary group
261  * array in case it might be useful.  Not needed if doing an MDS-side upcall. */
262 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
263 {
264         int i;
265
266         LASSERT(i1 != NULL);
267         LASSERT(suppgids != NULL);
268
269         if (in_group_p(i1->i_gid))
270                 suppgids[0] = i1->i_gid;
271         else
272                 suppgids[0] = -1;
273
274         if (i2) {
275                 if (in_group_p(i2->i_gid))
276                         suppgids[1] = i2->i_gid;
277                 else
278                         suppgids[1] = -1;
279         } else {
280                 suppgids[1] = -1;
281         }
282
283         for (i = 0; i < current_ngroups; i++) {
284                 if (suppgids[0] == -1) {
285                         if (current_groups[i] != suppgids[1])
286                                 suppgids[0] = current_groups[i];
287                         continue;
288                 }
289                 if (suppgids[1] == -1) {
290                         if (current_groups[i] != suppgids[0])
291                                 suppgids[1] = current_groups[i];
292                         continue;
293                 }
294                 break;
295         }
296 }
297
298 static void ll_d_add(struct dentry *de, struct inode *inode)
299 {
300         CDEBUG(D_DENTRY, "adding inode %p to dentry %p\n", inode, de);
301         /* d_instantiate */
302         if (!list_empty(&de->d_alias)) {
303                 spin_unlock(&dcache_lock);
304                 CERROR("dentry %.*s %p alias next %p, prev %p\n",
305                        de->d_name.len, de->d_name.name, de,
306                        de->d_alias.next, de->d_alias.prev);
307                 LBUG();
308         }
309         if (inode)
310                 list_add(&de->d_alias, &inode->i_dentry);
311         de->d_inode = inode;
312
313         /* d_rehash */
314         if (!d_unhashed(de)) {
315                 spin_unlock(&dcache_lock);
316                 CERROR("dentry %.*s %p hash next %p\n",
317                        de->d_name.len, de->d_name.name, de, de->d_hash.next);
318                 LBUG();
319         }
320         __d_rehash(de, 0);
321 }
322
323 /* 2.6.15 and prior versions have buggy d_instantiate_unique that leaks an inode
324  * if suitable alias is found. But we are not going to fix it by just freeing
325  * such inode, because if some vendor's kernel contains this bugfix already,
326  * we will break everything then. We will use our own reimplementation
327  * instead. */
328 #if !defined(HAVE_D_ADD_UNIQUE) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
329 /* Search "inode"'s alias list for a dentry that has the same name and parent as
330  * de.  If found, return it.  If not found, return de. */
331 struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
332 {
333         struct list_head *tmp;
334
335         spin_lock(&dcache_lock);
336         list_for_each(tmp, &inode->i_dentry) {
337                 struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
338
339                 /* We are called here with 'de' already on the aliases list. */
340                 if (dentry == de) {
341                         CERROR("whoops\n");
342                         continue;
343                 }
344
345                 if (dentry->d_parent != de->d_parent)
346                         continue;
347
348                 if (dentry->d_name.len != de->d_name.len)
349                         continue;
350
351                 if (memcmp(dentry->d_name.name, de->d_name.name,
352                            de->d_name.len) != 0)
353                         continue;
354
355                 dget_locked(dentry);
356                 lock_dentry(dentry);
357                 __d_drop(dentry);
358 #ifdef LUSTRE_KERNEL_VERSION
359                 dentry->d_flags &= ~DCACHE_LUSTRE_INVALID;
360 #endif
361                 unlock_dentry(dentry);
362                 __d_rehash(dentry, 0); /* avoid taking dcache_lock inside */
363                 spin_unlock(&dcache_lock);
364                 iput(inode);
365                 CDEBUG(D_DENTRY, "alias dentry %.*s (%p) parent %p inode %p "
366                        "refc %d\n", de->d_name.len, de->d_name.name, de,
367                        de->d_parent, de->d_inode, atomic_read(&de->d_count));
368                 return dentry;
369         }
370
371         ll_d_add(de, inode);
372
373         spin_unlock(&dcache_lock);
374
375         return de;
376 }
377 #else
378 struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
379 {
380         struct dentry *dentry;
381
382         dentry = d_add_unique(de, inode);
383 #ifdef LUSTRE_KERNEL_VERSION
384         if (dentry) {
385                 lock_dentry(dentry);
386                 dentry->d_flags &= ~DCACHE_LUSTRE_INVALID;
387                 unlock_dentry(dentry);
388         }
389 #endif
390
391         return dentry?dentry:de;
392 }
393 #endif
394
395 static int lookup_it_finish(struct ptlrpc_request *request, int offset,
396                             struct lookup_intent *it, void *data)
397 {
398         struct it_cb_data *icbd = data;
399         struct dentry **de = icbd->icbd_childp;
400         struct inode *parent = icbd->icbd_parent;
401         struct ll_sb_info *sbi = ll_i2sbi(parent);
402         struct inode *inode = NULL;
403         int rc;
404
405         /* NB 1 request reference will be taken away by ll_intent_lock()
406          * when I return */
407         if (!it_disposition(it, DISP_LOOKUP_NEG)) {
408                 ENTRY;
409
410                 rc = ll_prep_inode(&inode, request, offset,
411                                    (*de)->d_sb);
412                 if (rc)
413                         RETURN(rc);
414
415                 CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%u)\n",
416                        inode, inode->i_ino, inode->i_generation);
417                 md_set_lock_data(sbi->ll_md_exp,
418                                  &it->d.lustre.it_lock_handle, inode);
419
420                 /* We used to query real size from OSTs here, but actually
421                    this is not needed. For stat() calls size would be updated
422                    from subsequent do_revalidate()->ll_inode_revalidate_it() in
423                    2.4 and
424                    vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
425                    Everybody else who needs correct file size would call
426                    ll_glimpse_size or some equivalent themselves anyway.
427                    Also see bug 7198. */
428
429                 *de = ll_find_alias(inode, *de);
430         } else {
431                 ENTRY;
432                 /* Check that parent has UPDATE lock. If there is none, we
433                    cannot afford to hash this dentry (done by ll_d_add) as it
434                    might get picked up later when UPDATE lock will appear */
435                 if (ll_have_md_lock(parent, MDS_INODELOCK_UPDATE)) {
436                         spin_lock(&dcache_lock);
437                         ll_d_add(*de, inode);
438                         spin_unlock(&dcache_lock);
439                 } else {
440                         (*de)->d_inode = NULL; 
441                 }
442         }
443
444         ll_set_dd(*de);
445         (*de)->d_op = &ll_d_ops;
446
447         RETURN(0);
448 }
449
450 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
451                                    struct lookup_intent *it, int lookup_flags)
452 {
453         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
454         struct dentry *save = dentry, *retval;
455         struct ptlrpc_request *req = NULL;
456         struct md_op_data *op_data;
457         struct it_cb_data icbd;
458         int rc;
459         ENTRY;
460
461         if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
462                 RETURN(ERR_PTR(-ENAMETOOLONG));
463
464         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
465                dentry->d_name.len, dentry->d_name.name, parent->i_ino,
466                parent->i_generation, parent, LL_IT2STR(it));
467
468         if (d_mountpoint(dentry))
469                 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
470
471         ll_frob_intent(&it, &lookup_it);
472
473         icbd.icbd_childp = &dentry;
474         icbd.icbd_parent = parent;
475
476         /* prepare operatoin hint first */
477
478         op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
479                                      dentry->d_name.len, lookup_flags);
480         if (op_data == NULL)
481                 RETURN(ERR_PTR(-ENOMEM));
482
483         /* allocate new fid for child */
484         if (it->it_op & IT_CREAT ||
485             (it->it_op & IT_OPEN && it->it_create_mode & O_CREAT)) {
486                 struct lu_placement_hint hint = { .ph_pname = NULL,
487                                                   .ph_pfid = ll_inode2fid(parent),
488                                                   .ph_cname = &dentry->d_name,
489                                                   .ph_opc = LUSTRE_OPC_CREATE };
490
491                 rc = ll_fid_md_alloc(ll_i2sbi(parent), &op_data->fid2, &hint);
492                 if (rc) {
493                         ll_finish_md_op_data(op_data);
494                         LASSERT(rc < 0);
495                         RETURN(ERR_PTR(rc));
496                 }
497         }
498
499         it->it_create_mode &= ~current->fs->umask;
500
501         rc = md_intent_lock(ll_i2mdexp(parent), op_data, NULL, 0, it,
502                             lookup_flags, &req, ll_md_blocking_ast, 0);
503         ll_finish_md_op_data(op_data);
504         if (rc < 0)
505                 GOTO(out, retval = ERR_PTR(rc));
506
507         rc = lookup_it_finish(req, DLM_REPLY_REC_OFF, it, &icbd);
508         if (rc != 0) {
509                 ll_intent_release(it);
510                 GOTO(out, retval = ERR_PTR(rc));
511         }
512
513         if ((it->it_op & IT_OPEN) && dentry->d_inode &&
514             !S_ISREG(dentry->d_inode->i_mode) &&
515             !S_ISDIR(dentry->d_inode->i_mode)) {
516                 ll_release_openhandle(dentry, it);
517         }
518         ll_lookup_finish_locks(it, dentry);
519
520         if (dentry == save)
521                 GOTO(out, retval = NULL);
522         else
523                 GOTO(out, retval = dentry);
524  out:
525         if (req)
526                 ptlrpc_req_finished(req);
527         return retval;
528 }
529
530 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
531 #ifdef LUSTRE_KERNEL_VERSION
532 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
533                                    struct nameidata *nd)
534 {
535         struct dentry *de;
536         ENTRY;
537
538         if (nd && nd->flags & LOOKUP_LAST && !(nd->flags & LOOKUP_LINK_NOTLAST))
539                 de = ll_lookup_it(parent, dentry, &nd->intent, nd->flags);
540         else
541                 de = ll_lookup_it(parent, dentry, NULL, 0);
542
543         RETURN(de);
544 }
545 #else
546 struct lookup_intent *ll_convert_intent(struct open_intent *oit,
547                                         int lookup_flags)
548 {
549         struct lookup_intent *it;
550
551         OBD_ALLOC(it, sizeof(*it));
552         if (!it)
553                 return ERR_PTR(-ENOMEM);
554
555         if (lookup_flags & LOOKUP_OPEN) {
556                 it->it_op = IT_OPEN;
557                 if (lookup_flags & LOOKUP_CREATE)
558                         it->it_op |= IT_CREAT;
559                 it->it_create_mode = oit->create_mode;
560                 it->it_flags = oit->flags;
561         } else {
562                 it->it_op = IT_GETATTR;
563         }
564
565 #ifndef HAVE_FILE_IN_STRUCT_INTENT
566                 /* Since there is no way to pass our intent to ll_file_open,
567                  * just check the file is there. Actual open will be done
568                  * in ll_file_open */
569                 if (it->it_op & IT_OPEN)
570                         it->it_op = IT_LOOKUP;
571 #endif
572
573         return it;
574 }
575
576 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
577                                    struct nameidata *nd)
578 {
579         struct dentry *de;
580         ENTRY;
581
582         if (nd && !(nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))) {
583                 struct lookup_intent *it;
584
585 #if defined(HAVE_FILE_IN_STRUCT_INTENT) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
586                 /* Did we came here from failed revalidate just to propagate
587                  * its error? */
588                 if (nd->flags & LOOKUP_OPEN)
589                         if (IS_ERR(nd->intent.open.file))
590                                 RETURN((struct dentry *)nd->intent.open.file);
591 #endif
592
593                 if (ll_d2d(dentry) && ll_d2d(dentry)->lld_it) {
594                         it = ll_d2d(dentry)->lld_it;
595                         ll_d2d(dentry)->lld_it = NULL;
596                 } else {
597                         it = ll_convert_intent(&nd->intent.open, nd->flags);
598                         if (IS_ERR(it))
599                                 RETURN((struct dentry *)it);
600                 }
601
602                 de = ll_lookup_it(parent, dentry, it, nd->flags);
603                 if (de)
604                         dentry = de;
605                 if ((nd->flags & LOOKUP_OPEN) && !IS_ERR(dentry)) { /* Open */
606                         if (dentry->d_inode && 
607                             it_disposition(it, DISP_OPEN_OPEN)) { /* nocreate */
608 #ifdef HAVE_FILE_IN_STRUCT_INTENT
609                                 if (S_ISFIFO(dentry->d_inode->i_mode)) {
610                                         // We cannot call open here as it would
611                                         // deadlock.
612                                         ptlrpc_req_finished(
613                                                        (struct ptlrpc_request *)
614                                                           it->d.lustre.it_data);
615                                 } else {
616                                         struct file *filp;
617                                         nd->intent.open.file->private_data = it;
618                                         filp =lookup_instantiate_filp(nd,dentry,
619                                                                       NULL);
620 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
621 /* 2.6.1[456] have a bug in open_namei() that forgets to check
622  * nd->intent.open.file for error, so we need to return it as lookup's result
623  * instead */
624                                         if (IS_ERR(filp)) {
625                                                 if (de)
626                                                         dput(de);
627                                                 de = (struct dentry *) filp;
628                                         }
629 #endif
630                                                 
631                                 }
632 #else /* HAVE_FILE_IN_STRUCT_INTENT */
633                                 /* Release open handle as we have no way to
634                                  * pass it to ll_file_open */
635                                 ll_release_openhandle(dentry, it);
636 #endif /* HAVE_FILE_IN_STRUCT_INTENT */
637                         } else if (it_disposition(it, DISP_OPEN_CREATE)) {
638                                 // XXX This can only reliably work on assumption
639                                 // that there are NO hashed negative dentries.
640                                 ll_d2d(dentry)->lld_it = it;
641                                 it = NULL; /* Will be freed in ll_create_nd */
642                                 /* We absolutely depend on ll_create_nd to be
643                                  * called to not leak this intent and possible
644                                  * data attached to it */
645                         }
646                 }
647
648                 if (it) {
649                         ll_intent_release(it);
650                         OBD_FREE(it, sizeof(*it));
651                 }
652         } else {
653                 de = ll_lookup_it(parent, dentry, NULL, 0);
654         }
655
656         RETURN(de);
657 }
658 #endif
659 #endif
660
661 /* We depend on "mode" being set with the proper file type/umask by now */
662 static struct inode *ll_create_node(struct inode *dir, const char *name,
663                                     int namelen, const void *data, int datalen,
664                                     int mode, __u64 extra,
665                                     struct lookup_intent *it)
666 {
667         struct inode *inode = NULL;
668         struct ptlrpc_request *request = NULL;
669         struct ll_sb_info *sbi = ll_i2sbi(dir);
670         int rc;
671         ENTRY;
672
673         LASSERT(it && it->d.lustre.it_disposition);
674
675         LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
676         request = it->d.lustre.it_data;
677         it_clear_disposition(it, DISP_ENQ_CREATE_REF);
678         rc = ll_prep_inode(&inode, request, DLM_REPLY_REC_OFF, dir->i_sb);
679         if (rc)
680                 GOTO(out, inode = ERR_PTR(rc));
681
682         LASSERT(list_empty(&inode->i_dentry));
683
684         /* We asked for a lock on the directory, but were granted a
685          * lock on the inode.  Since we finally have an inode pointer,
686          * stuff it in the lock. */
687         CDEBUG(D_DLMTRACE, "setting l_ast_data to inode %p (%lu/%u)\n",
688                inode, inode->i_ino, inode->i_generation);
689         md_set_lock_data(sbi->ll_md_exp,
690                          &it->d.lustre.it_lock_handle, inode);
691         EXIT;
692  out:
693         ptlrpc_req_finished(request);
694         return inode;
695 }
696
697 /*
698  * By the time this is called, we already have created the directory cache
699  * entry for the new file, but it is so far negative - it has no inode.
700  *
701  * We defer creating the OBD object(s) until open, to keep the intent and
702  * non-intent code paths similar, and also because we do not have the MDS
703  * inode number before calling ll_create_node() (which is needed for LOV),
704  * so we would need to do yet another RPC to the MDS to store the LOV EA
705  * data on the MDS.  If needed, we would pass the PACKED lmm as data and
706  * lmm_size in datalen (the MDS still has code which will handle that).
707  *
708  * If the create succeeds, we fill in the inode information
709  * with d_instantiate().
710  */
711 static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
712                         struct lookup_intent *it)
713 {
714         struct inode *inode;
715         int rc = 0;
716         ENTRY;
717
718         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
719                dentry->d_name.len, dentry->d_name.name, dir->i_ino,
720                dir->i_generation, dir, LL_IT2STR(it));
721
722         rc = it_open_error(DISP_OPEN_CREATE, it);
723         if (rc)
724                 RETURN(rc);
725
726         inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
727                                NULL, 0, mode, 0, it);
728         if (IS_ERR(inode)) {
729                 RETURN(PTR_ERR(inode));
730         }
731
732         d_instantiate(dentry, inode);
733         RETURN(0);
734 }
735
736 static void ll_update_times(struct ptlrpc_request *request, int offset,
737                             struct inode *inode)
738 {
739         struct mdt_body *body = lustre_msg_buf(request->rq_repmsg, offset,
740                                                sizeof(*body));
741         LASSERT(body);
742
743         /* mtime is always updated with ctime, but can be set in past.
744            As write and utime(2) may happen within 1 second, and utime's
745            mtime has a priority over write's one, so take mtime from mds 
746            for the same ctimes. */
747         if (body->valid & OBD_MD_FLCTIME &&
748             body->ctime >= LTIME_S(inode->i_ctime)) {
749                 LTIME_S(inode->i_ctime) = body->ctime;
750
751                 if (body->valid & OBD_MD_FLMTIME) {
752                         CDEBUG(D_INODE, "setting ino %lu mtime from %lu "
753                                "to "LPU64"\n", inode->i_ino, 
754                                LTIME_S(inode->i_mtime), body->mtime);
755                         LTIME_S(inode->i_mtime) = body->mtime;
756                 }
757         }
758 }
759
760 static int ll_mknod_generic(struct inode *dir, struct qstr *name, int mode,
761                             unsigned rdev, struct dentry *dchild)
762 {
763         struct ptlrpc_request *request = NULL;
764         struct inode *inode = NULL;
765         struct ll_sb_info *sbi = ll_i2sbi(dir);
766         struct md_op_data *op_data;
767         struct lu_placement_hint hint = {
768                 .ph_pname = NULL,
769                 .ph_pfid = ll_inode2fid(dir),
770                 .ph_cname = name,
771                 .ph_opc = LUSTRE_OPC_MKNOD
772         };
773         int err;
774         ENTRY;
775
776         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p) mode %o dev %x\n",
777                name->len, name->name, dir->i_ino, dir->i_generation, dir,
778                mode, rdev);
779
780         mode &= ~current->fs->umask;
781
782         switch (mode & S_IFMT) {
783         case 0:
784         case S_IFREG:
785                 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
786         case S_IFCHR:
787         case S_IFBLK:
788         case S_IFIFO:
789         case S_IFSOCK:
790                 op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name,
791                                              name->len, 0);
792                 if (op_data == NULL)
793                         RETURN(-ENOMEM);
794                 err = ll_fid_md_alloc(sbi, &op_data->fid2, &hint);
795                 if (err) {
796                         ll_finish_md_op_data(op_data);
797                         break;
798                 }
799                 err = md_create(sbi->ll_md_exp, op_data, NULL, 0, mode,
800                                 current->fsuid, current->fsgid,
801                                 current->cap_effective, rdev, &request);
802                 ll_finish_md_op_data(op_data);
803                 if (err)
804                         break;
805                 ll_update_times(request, REPLY_REC_OFF, dir);
806
807                 if (dchild) {
808                         err = ll_prep_inode(&inode, request, REPLY_REC_OFF,
809                                             dchild->d_sb);
810                         if (err)
811                                 break;
812
813                         d_instantiate(dchild, inode);
814                 }
815                 break;
816         case S_IFDIR:
817                 err = -EPERM;
818                 break;
819         default:
820                 err = -EINVAL;
821         }
822         ptlrpc_req_finished(request);
823         RETURN(err);
824 }
825
826 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
827 #ifndef LUSTRE_KERNEL_VERSION
828 static int ll_create_nd(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
829 {
830         struct lookup_intent *it = ll_d2d(dentry)->lld_it;
831         int rc;
832         
833         if (!it)
834                 return ll_mknod_generic(dir, &dentry->d_name, mode, 0, dentry);
835                 
836         ll_d2d(dentry)->lld_it = NULL;
837         
838         /* Was there an error? Propagate it! */
839         if (it->d.lustre.it_status) {
840                 rc = it->d.lustre.it_status;
841                 goto out;
842         }       
843         
844         rc = ll_create_it(dir, dentry, mode, it);
845 #ifdef HAVE_FILE_IN_STRUCT_INTENT
846         if (nd && (nd->flags & LOOKUP_OPEN) && dentry->d_inode) { /* Open */
847                 nd->intent.open.file->private_data = it;
848                 lookup_instantiate_filp(nd, dentry, NULL);
849         }
850 #else
851         ll_release_openhandle(dentry,it);
852 #endif
853
854 out:
855         ll_intent_release(it);
856         OBD_FREE(it, sizeof(*it));
857
858         return rc;
859 }
860 #else
861 static int ll_create_nd(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
862 {
863         if (!nd || !nd->intent.d.lustre.it_disposition)
864                 /* No saved request? Just mknod the file */
865                 return ll_mknod_generic(dir, &dentry->d_name, mode, 0, dentry);
866
867         return ll_create_it(dir, dentry, mode, &nd->intent);
868 }
869 #endif
870 #endif
871
872 static int ll_symlink_generic(struct inode *dir, struct dentry *dchild,
873                               const char *tgt)
874 {
875         struct qstr *name = &dchild->d_name;
876         struct lu_placement_hint hint = { .ph_pname = NULL,
877                                           .ph_pfid = ll_inode2fid(dir),
878                                           .ph_cname = name,
879                                           .ph_opc = LUSTRE_OPC_SYMLINK };
880
881         struct ptlrpc_request *request = NULL;
882         struct ll_sb_info *sbi = ll_i2sbi(dir);
883         struct inode *inode = NULL;
884         struct md_op_data *op_data;
885         int err;
886         ENTRY;
887
888         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),target=%s\n",
889                name->len, name->name, dir->i_ino, dir->i_generation,
890                dir, tgt);
891
892         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len, 0);
893         if (op_data == NULL)
894                 RETURN(-ENOMEM);
895
896         /* allocate new fid */
897         err = ll_fid_md_alloc(ll_i2sbi(dir), &op_data->fid2, &hint);
898         if (err) {
899                 ll_finish_md_op_data(op_data);
900                 RETURN(err);
901         }
902
903         err = md_create(sbi->ll_md_exp, op_data,
904                         tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
905                         current->fsuid, current->fsgid, current->cap_effective,
906                         0, &request);
907         ll_finish_md_op_data(op_data);
908         if (err == 0) {
909                 ll_update_times(request, REPLY_REC_OFF, dir);
910
911                 if (dchild) {
912                         err = ll_prep_inode(&inode, request, REPLY_REC_OFF,
913                                             dchild->d_sb);
914                         if (err == 0)
915                                 d_instantiate(dchild, inode);
916                 }
917         }
918
919         ptlrpc_req_finished(request);
920         RETURN(err);
921 }
922
923 static int ll_link_generic(struct inode *src,  struct inode *dir,
924                            struct qstr *name)
925 {
926         struct ll_sb_info *sbi = ll_i2sbi(dir);
927         struct ptlrpc_request *request = NULL;
928         struct md_op_data *op_data;
929         int err;
930
931         ENTRY;
932         CDEBUG(D_VFSTRACE,
933                "VFS Op: inode=%lu/%u(%p), dir=%lu/%u(%p), target=%.*s\n",
934                src->i_ino, src->i_generation, src, dir->i_ino,
935                dir->i_generation, dir, name->len, name->name);
936
937         op_data = ll_prep_md_op_data(NULL, src, dir, name->name, name->len, 0);
938         if (op_data == NULL)
939                 RETURN(-ENOMEM);
940         err = md_link(sbi->ll_md_exp, op_data, &request);
941         ll_finish_md_op_data(op_data);
942         if (err == 0)
943                 ll_update_times(request, REPLY_REC_OFF, dir);
944
945         ptlrpc_req_finished(request);
946         RETURN(err);
947 }
948
949 static int ll_mkdir_generic(struct inode *dir, struct qstr *name,
950                             int mode, struct dentry *dchild)
951
952 {
953         struct lu_placement_hint hint = { .ph_pname = NULL,
954                                           .ph_pfid = ll_inode2fid(dir),
955                                           .ph_cname = name,
956                                           .ph_opc = LUSTRE_OPC_MKDIR };
957         struct ptlrpc_request *request = NULL;
958         struct ll_sb_info *sbi = ll_i2sbi(dir);
959         struct inode *inode = NULL;
960         struct md_op_data *op_data;
961         int err;
962         ENTRY;
963         
964         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
965                name->len, name->name, dir->i_ino, dir->i_generation, dir);
966
967         mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
968
969         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len, 0);
970         if (op_data == NULL)
971                 RETURN(-ENOMEM);
972
973         /* Allocate new fid. */
974         err = ll_fid_md_alloc(ll_i2sbi(dir), &op_data->fid2, &hint);
975         if (err) {
976                 ll_finish_md_op_data(op_data);
977                 RETURN(err);
978         }
979
980         err = md_create(sbi->ll_md_exp, op_data, NULL, 0, mode,
981                         current->fsuid, current->fsgid,
982                         current->cap_effective, 0, &request);
983         
984         ll_finish_md_op_data(op_data);
985         if (err == 0) {
986                 ll_update_times(request, REPLY_REC_OFF, dir);
987                 if (dchild) {
988                         err = ll_prep_inode(&inode, request, REPLY_REC_OFF,
989                                             dchild->d_sb);
990                         if (err == 0)
991                                 d_instantiate(dchild, inode);
992                 }
993         }
994         if (request != NULL)
995                 ptlrpc_req_finished(request);
996         RETURN(err);
997 }
998
999 static int ll_rmdir_generic(struct inode *dir, struct dentry *dparent,
1000                             struct qstr *name)
1001 {
1002         struct ptlrpc_request *request = NULL;
1003         struct md_op_data *op_data;
1004         struct dentry *dentry;
1005         int rc;
1006         ENTRY;
1007         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
1008                name->len, name->name, dir->i_ino, dir->i_generation, dir);
1009
1010         /* Check if we have something mounted at the dir we are going to delete
1011          * In such a case there would always be dentry present. */
1012         if (dparent) {
1013                 dentry = d_lookup(dparent, name);
1014                 if (dentry) {
1015                         int mounted = d_mountpoint(dentry);
1016                         dput(dentry);
1017                         if (mounted)
1018                                 RETURN(-EBUSY);
1019                 }
1020         }
1021
1022         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len,
1023                                      S_IFDIR);
1024         if (op_data == NULL)
1025                 RETURN(-ENOMEM);
1026         rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1027         ll_finish_md_op_data(op_data);
1028         if (rc == 0)
1029                 ll_update_times(request, REPLY_REC_OFF, dir);
1030         ptlrpc_req_finished(request);
1031         RETURN(rc);
1032 }
1033
1034 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
1035 {
1036         struct mdt_body *body;
1037         struct lov_mds_md *eadata;
1038         struct lov_stripe_md *lsm = NULL;
1039         struct obd_trans_info oti = { 0 };
1040         struct obdo *oa;
1041         int rc;
1042         ENTRY;
1043
1044         /* req is swabbed so this is safe */
1045         body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, sizeof(*body));
1046
1047         if (!(body->valid & OBD_MD_FLEASIZE))
1048                 RETURN(0);
1049
1050         if (body->eadatasize == 0) {
1051                 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
1052                 GOTO(out, rc = -EPROTO);
1053         }
1054
1055         /* The MDS sent back the EA because we unlinked the last reference
1056          * to this file. Use this EA to unlink the objects on the OST.
1057          * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
1058          * check it is complete and sensible. */
1059         eadata = lustre_swab_repbuf(request, REPLY_REC_OFF + 1,
1060                                     body->eadatasize, NULL);
1061         LASSERT(eadata != NULL);
1062         if (eadata == NULL) {
1063                 CERROR("Can't unpack MDS EA data\n");
1064                 GOTO(out, rc = -EPROTO);
1065         }
1066
1067         rc = obd_unpackmd(ll_i2dtexp(dir), &lsm, eadata, body->eadatasize);
1068         if (rc < 0) {
1069                 CERROR("obd_unpackmd: %d\n", rc);
1070                 GOTO(out, rc);
1071         }
1072         LASSERT(rc >= sizeof(*lsm));
1073
1074         rc = obd_checkmd(ll_i2dtexp(dir), ll_i2mdexp(dir), lsm);
1075         if (rc)
1076                 GOTO(out_free_memmd, rc);
1077
1078         oa = obdo_alloc();
1079         if (oa == NULL)
1080                 GOTO(out_free_memmd, rc = -ENOMEM);
1081
1082         oa->o_id = lsm->lsm_object_id;
1083         oa->o_gr = lsm->lsm_object_gr;
1084         oa->o_mode = body->mode & S_IFMT;
1085         oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
1086
1087         if (body->valid & OBD_MD_FLCOOKIE) {
1088                 oa->o_valid |= OBD_MD_FLCOOKIE;
1089                 oti.oti_logcookies =
1090                         lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF + 2,
1091                                        sizeof(struct llog_cookie) *
1092                                        lsm->lsm_stripe_count);
1093                 if (oti.oti_logcookies == NULL) {
1094                         oa->o_valid &= ~OBD_MD_FLCOOKIE;
1095                         body->valid &= ~OBD_MD_FLCOOKIE;
1096                 }
1097         }
1098
1099         rc = obd_destroy(ll_i2dtexp(dir), oa, lsm, &oti, ll_i2mdexp(dir));
1100         obdo_free(oa);
1101         if (rc)
1102                 CERROR("obd destroy objid "LPX64" error %d\n",
1103                        lsm->lsm_object_id, rc);
1104  out_free_memmd:
1105         obd_free_memmd(ll_i2dtexp(dir), &lsm);
1106  out:
1107         return rc;
1108 }
1109
1110 static int ll_unlink_generic(struct inode *dir, struct qstr *name)
1111 {
1112         struct ptlrpc_request *request = NULL;
1113         struct md_op_data *op_data;
1114         int rc;
1115         ENTRY;
1116         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
1117                name->len, name->name, dir->i_ino, dir->i_generation, dir);
1118
1119         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len, 0);
1120         if (op_data == NULL)
1121                 RETURN(-ENOMEM);
1122         rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1123         ll_finish_md_op_data(op_data);
1124         
1125         if (rc)
1126                 GOTO(out, rc);
1127
1128         ll_update_times(request, REPLY_REC_OFF, dir);
1129
1130         rc = ll_objects_destroy(request, dir);
1131  out:
1132         ptlrpc_req_finished(request);
1133         RETURN(rc);
1134 }
1135
1136 static int ll_rename_generic(struct inode *src, struct qstr *src_name,
1137                              struct inode *tgt, struct qstr *tgt_name)
1138 {
1139         struct ptlrpc_request *request = NULL;
1140         struct ll_sb_info *sbi = ll_i2sbi(src);
1141         struct md_op_data *op_data;
1142         int err;
1143         ENTRY;
1144         CDEBUG(D_VFSTRACE,"VFS Op:oldname=%.*s,src_dir=%lu/%u(%p),newname=%.*s,"
1145                "tgt_dir=%lu/%u(%p)\n", src_name->len, src_name->name,
1146                src->i_ino, src->i_generation, src, tgt_name->len,
1147                tgt_name->name, tgt->i_ino, tgt->i_generation, tgt);
1148
1149         op_data = ll_prep_md_op_data(NULL, src, tgt, NULL, 0, 0);
1150         if (op_data == NULL)
1151                 RETURN(-ENOMEM);
1152         err = md_rename(sbi->ll_md_exp, op_data,
1153                         src_name->name, src_name->len,
1154                         tgt_name->name, tgt_name->len, &request);
1155         ll_finish_md_op_data(op_data);
1156         if (!err) {
1157                 ll_update_times(request, REPLY_REC_OFF, src);
1158                 ll_update_times(request, REPLY_REC_OFF, tgt);
1159                 err = ll_objects_destroy(request, src);
1160         }
1161
1162         ptlrpc_req_finished(request);
1163
1164         RETURN(err);
1165 }
1166
1167 #ifdef LUSTRE_KERNEL_VERSION
1168 static int ll_mknod_raw(struct nameidata *nd, int mode, dev_t rdev)
1169 {
1170         return ll_mknod_generic(nd->dentry->d_inode, &nd->last, mode,rdev,NULL);
1171 }
1172 static int ll_rename_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
1173 {
1174         return ll_rename_generic(srcnd->dentry->d_inode, &srcnd->last,
1175                                  tgtnd->dentry->d_inode, &tgtnd->last);
1176 }
1177 static int ll_link_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
1178 {
1179         return ll_link_generic(srcnd->dentry->d_inode, tgtnd->dentry->d_inode,
1180                                &tgtnd->last);
1181 }
1182 static int ll_symlink_raw(struct nameidata *nd, const char *tgt)
1183 {
1184         return -EOPNOTSUPP;
1185 }
1186 static int ll_rmdir_raw(struct nameidata *nd)
1187 {
1188         return ll_rmdir_generic(nd->dentry->d_inode, nd->dentry, &nd->last);
1189 }
1190 static int ll_mkdir_raw(struct nameidata *nd, int mode)
1191 {
1192         return ll_mkdir_generic(nd->dentry->d_inode, &nd->last, mode, NULL);
1193 }
1194 static int ll_unlink_raw(struct nameidata *nd)
1195 {
1196         return ll_unlink_generic(nd->dentry->d_inode, &nd->last);
1197 }
1198 #endif
1199
1200 static int ll_mknod(struct inode *dir, struct dentry *dchild, int mode,
1201                     ll_dev_t rdev)
1202 {
1203         return ll_mknod_generic(dir, &dchild->d_name, mode,
1204                                 old_encode_dev(rdev), dchild);
1205 }
1206
1207 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1208 static int ll_unlink(struct inode * dir, struct dentry *dentry)
1209 {
1210         return ll_unlink_generic(dir, &dentry->d_name);
1211 }
1212 static int ll_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1213 {
1214         return ll_mkdir_generic(dir, &dentry->d_name, mode, dentry);
1215 }
1216 static int ll_rmdir(struct inode *dir, struct dentry *dentry)
1217 {
1218         return ll_rmdir_generic(dir, NULL, &dentry->d_name);
1219 }
1220 static int ll_symlink(struct inode *dir, struct dentry *dentry,
1221                       const char *oldname)
1222 {
1223         return ll_symlink_generic(dir, dentry, oldname);
1224 }
1225 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1226                    struct dentry *new_dentry)
1227 {
1228         return ll_link_generic(old_dentry->d_inode, dir, &new_dentry->d_name);
1229 }
1230 static int ll_rename(struct inode *old_dir, struct dentry *old_dentry,
1231                      struct inode *new_dir, struct dentry *new_dentry)
1232 {
1233         return ll_rename_generic(old_dir, &old_dentry->d_name, new_dir,
1234                                &new_dentry->d_name);
1235 }
1236 #endif
1237
1238 struct inode_operations ll_dir_inode_operations = {
1239 #ifdef LUSTRE_KERNEL_VERSION
1240         .link_raw           = ll_link_raw,
1241         .unlink_raw         = ll_unlink_raw,
1242         .symlink_raw        = ll_symlink_raw,
1243         .mkdir_raw          = ll_mkdir_raw,
1244         .rmdir_raw          = ll_rmdir_raw,
1245         .mknod_raw          = ll_mknod_raw,
1246         .rename_raw         = ll_rename_raw,
1247         .setattr            = ll_setattr,
1248         .setattr_raw        = ll_setattr_raw,
1249 #endif
1250         .mknod              = ll_mknod,
1251 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1252         .create_it          = ll_create_it,
1253         .lookup_it          = ll_lookup_it,
1254         .revalidate_it      = ll_inode_revalidate_it,
1255 #else
1256         .lookup             = ll_lookup_nd,
1257         .create             = ll_create_nd,
1258         /* We need all these non-raw things for NFSD, to not patch it. */
1259         .unlink             = ll_unlink,
1260         .mkdir              = ll_mkdir,
1261         .rmdir              = ll_rmdir,
1262         .symlink            = ll_symlink,
1263         .link               = ll_link,
1264         .rename             = ll_rename,
1265         .setattr            = ll_setattr,
1266         .getattr            = ll_getattr,
1267 #endif
1268         .permission         = ll_inode_permission,
1269         .setxattr           = ll_setxattr,
1270         .getxattr           = ll_getxattr,
1271         .listxattr          = ll_listxattr,
1272         .removexattr        = ll_removexattr,
1273 };
1274
1275 struct inode_operations ll_special_inode_operations = {
1276 #ifdef LUSTRE_KERNEL_VERSION
1277         .setattr_raw    = ll_setattr_raw,
1278 #endif
1279         .setattr        = ll_setattr,
1280 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1281         .getattr        = ll_getattr,
1282 #else   
1283         .revalidate_it  = ll_inode_revalidate_it,
1284 #endif
1285         .permission     = ll_inode_permission,
1286         .setxattr       = ll_setxattr,
1287         .getxattr       = ll_getxattr,
1288         .listxattr      = ll_listxattr,
1289         .removexattr    = ll_removexattr,
1290 };