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