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