Whamcloud - gitweb
Branch b1_6
[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 static void ll_drop_negative_dentry(struct inode *dir)
154
155         struct dentry *dentry, *tmp_alias, *tmp_subdir;
156
157         spin_lock(&dcache_lock);
158 restart:
159         list_for_each_entry_safe(dentry, tmp_alias,
160                                  &dir->i_dentry,d_alias) {
161                 if (!list_empty(&dentry->d_subdirs)) {
162                         struct dentry *child;
163                         list_for_each_entry_safe(child, tmp_subdir,
164                                                  &dentry->d_subdirs,
165                                                  d_child) {
166                                 /* XXX Print some debug here? */
167                                 if (!child->d_inode)
168                                 /* Negative dentry. If we were
169                                    dropping dcache lock, go
170                                    throught the list again */
171                                         if (ll_drop_dentry(child))
172                                                 goto restart;
173                         }
174                 }
175         }
176         spin_unlock(&dcache_lock);
177 }
178
179 int ll_mdc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
180                         void *data, int flag)
181 {
182         int rc;
183         struct lustre_handle lockh;
184         ENTRY;
185
186         switch (flag) {
187         case LDLM_CB_BLOCKING:
188                 ldlm_lock2handle(lock, &lockh);
189                 rc = ldlm_cli_cancel(&lockh);
190                 if (rc < 0) {
191                         CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
192                         RETURN(rc);
193                 }
194                 break;
195         case LDLM_CB_CANCELING: {
196                 struct inode *inode = ll_inode_from_lock(lock);
197                 __u64 bits = lock->l_policy_data.l_inodebits.bits;
198
199                 /* Invalidate all dentries associated with this inode */
200                 if (inode == NULL)
201                         break;
202
203                 LASSERT(lock->l_flags & LDLM_FL_CANCELING);
204                 if ((bits & MDS_INODELOCK_LOOKUP) &&
205                     ll_have_md_lock(inode, MDS_INODELOCK_LOOKUP))
206                         bits &= ~MDS_INODELOCK_LOOKUP;
207                 if ((bits & MDS_INODELOCK_UPDATE) &&
208                     ll_have_md_lock(inode, MDS_INODELOCK_UPDATE))
209                         bits &= ~MDS_INODELOCK_UPDATE;
210                 if ((bits & MDS_INODELOCK_OPEN) &&
211                     ll_have_md_lock(inode, MDS_INODELOCK_OPEN))
212                         bits &= ~MDS_INODELOCK_OPEN;
213                 
214                 if (lock->l_resource->lr_name.name[0] != inode->i_ino ||
215                     lock->l_resource->lr_name.name[1] != inode->i_generation) {
216                         LDLM_ERROR(lock, "data mismatch with ino %lu/%u (%p)",
217                                    inode->i_ino, inode->i_generation, inode);
218                 }
219
220                 if (bits & MDS_INODELOCK_OPEN) {
221                         int flags = 0;
222                         switch (lock->l_req_mode) {
223                         case LCK_CW:
224                                 flags = FMODE_WRITE;
225                                 break;
226                         case LCK_PR:
227                                 flags = FMODE_EXEC;
228                                 if (!FMODE_EXEC)
229                                         CERROR("open PR lock without FMODE_EXEC\n");
230                                 break;
231                         case LCK_CR:
232                                 flags = FMODE_READ;
233                                 break;
234                         default:
235                                 CERROR("Unexpected lock mode for OPEN lock "
236                                        "%d, inode %ld\n", lock->l_req_mode,
237                                        inode->i_ino);
238                         }
239                         ll_mdc_real_close(inode, flags);
240                 }
241
242                 if (bits & MDS_INODELOCK_UPDATE)
243                         clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
244                                   &(ll_i2info(inode)->lli_flags));
245
246                 if (S_ISDIR(inode->i_mode) &&
247                      (bits & MDS_INODELOCK_UPDATE)) {
248                         CDEBUG(D_INODE, "invalidating inode %lu\n",
249                                inode->i_ino);
250                         truncate_inode_pages(inode->i_mapping, 0);
251                         ll_drop_negative_dentry(inode);
252                 }
253
254                 if (inode->i_sb->s_root &&
255                     inode != inode->i_sb->s_root->d_inode &&
256                     (bits & MDS_INODELOCK_LOOKUP))
257                         ll_unhash_aliases(inode);
258                 iput(inode);
259                 break;
260         }
261         default:
262                 LBUG();
263         }
264
265         RETURN(0);
266 }
267
268 int ll_mdc_cancel_unused(struct lustre_handle *conn, struct inode *inode,
269                          int flags, void *opaque)
270 {
271         struct ldlm_res_id res_id =
272                 { .name = {inode->i_ino, inode->i_generation} };
273         struct obd_device *obddev = class_conn2obd(conn);
274         ENTRY;
275
276         RETURN(ldlm_cli_cancel_unused(obddev->obd_namespace, &res_id, flags,
277                                       opaque));
278 }
279
280 /* Pack the required supplementary groups into the supplied groups array.
281  * If we don't need to use the groups from the target inode(s) then we
282  * instead pack one or more groups from the user's supplementary group
283  * array in case it might be useful.  Not needed if doing an MDS-side upcall. */
284 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
285 {
286         int i;
287
288         LASSERT(i1 != NULL);
289         LASSERT(suppgids != NULL);
290
291         if (in_group_p(i1->i_gid))
292                 suppgids[0] = i1->i_gid;
293         else
294                 suppgids[0] = -1;
295
296         if (i2) {
297                 if (in_group_p(i2->i_gid))
298                         suppgids[1] = i2->i_gid;
299                 else
300                         suppgids[1] = -1;
301         } else {
302                 suppgids[1] = -1;
303         }
304
305         for (i = 0; i < current_ngroups; i++) {
306                 if (suppgids[0] == -1) {
307                         if (current_groups[i] != suppgids[1])
308                                 suppgids[0] = current_groups[i];
309                         continue;
310                 }
311                 if (suppgids[1] == -1) {
312                         if (current_groups[i] != suppgids[0])
313                                 suppgids[1] = current_groups[i];
314                         continue;
315                 }
316                 break;
317         }
318 }
319
320 int ll_prepare_mdc_op_data(struct mdc_op_data *op_data, struct inode *i1,
321                             struct inode *i2, const char *name, int namelen,
322                             int mode, void *data)
323 {
324         LASSERT(i1);
325
326         if (namelen > ll_i2sbi(i1)->ll_namelen)
327                 return -ENAMETOOLONG;
328         ll_i2gids(op_data->suppgids, i1, i2);
329         ll_inode2fid(&op_data->fid1, i1);
330
331         if (i2)
332                 ll_inode2fid(&op_data->fid2, i2);
333         else
334                 memset(&op_data->fid2, 0, sizeof(op_data->fid2));
335
336         op_data->name = name;
337         op_data->namelen = namelen;
338         op_data->create_mode = mode;
339         op_data->mod_time = CURRENT_SECONDS;
340         op_data->data = data;
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
371  * as de.  If found, return it.  If not found, return de.
372  * Lustre can't use d_add_unique because don't unhash aliases for directory
373  * in ll_revalidate_it.  After revaliadate inode will be have hashed aliases
374  * and it triggers BUG_ON in d_instantiate_unique (bug #10954).
375  */
376 static 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 DCACHE_LUSTRE_INVALID
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 disconnected dentry %p inode %p "
428                         "refc %d\n", 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 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
492                          * unhashed. (bug 10796). */
493                         d_rehash(*de);
494                         d_drop(*de);
495                 }
496         }
497
498         ll_set_dd(*de);
499         (*de)->d_op = &ll_d_ops;
500
501         RETURN(0);
502 }
503
504 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
505                                    struct lookup_intent *it, int lookup_flags)
506 {
507         struct dentry *save = dentry, *retval;
508         struct mdc_op_data op_data;
509         struct it_cb_data icbd;
510         struct ptlrpc_request *req = NULL;
511         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
512         int rc;
513         ENTRY;
514
515         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
516                dentry->d_name.len, dentry->d_name.name, parent->i_ino,
517                parent->i_generation, parent, LL_IT2STR(it));
518
519         if (d_mountpoint(dentry))
520                 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
521
522         ll_frob_intent(&it, &lookup_it);
523
524         /* As do_lookup is called before follow_mount, root dentry may be left
525          * not valid, revalidate it here. */
526         if (parent->i_sb->s_root && (parent->i_sb->s_root->d_inode == parent) &&
527             (it->it_op & (IT_OPEN | IT_CREAT))) {
528                 rc = ll_inode_revalidate_it(parent->i_sb->s_root, it);
529                 if (rc)
530                         RETURN(ERR_PTR(rc));
531         }
532
533         if (it->it_op == IT_GETATTR) {
534                 rc = ll_statahead_enter(parent, &dentry, 1);
535                 if (rc >= 0) {
536                         ll_statahead_exit(dentry, rc);
537                         if (rc == 1)
538                                 RETURN(retval = dentry);
539                 }
540         }
541
542         icbd.icbd_parent = parent;
543         icbd.icbd_childp = &dentry;
544
545         rc = ll_prepare_mdc_op_data(&op_data, parent, NULL, dentry->d_name.name,
546                                     dentry->d_name.len, lookup_flags, NULL);
547         if (rc)
548                 RETURN(ERR_PTR(rc));
549
550         it->it_create_mode &= ~current->fs->umask;
551
552         rc = mdc_intent_lock(ll_i2mdcexp(parent), &op_data, NULL, 0, it,
553                              lookup_flags, &req, ll_mdc_blocking_ast, 0);
554
555         if (rc < 0)
556                 GOTO(out, retval = ERR_PTR(rc));
557
558         rc = lookup_it_finish(req, DLM_REPLY_REC_OFF, it, &icbd);
559         if (rc != 0) {
560                 ll_intent_release(it);
561                 GOTO(out, retval = ERR_PTR(rc));
562         }
563
564         if ((it->it_op & IT_OPEN) && dentry->d_inode &&
565             !S_ISREG(dentry->d_inode->i_mode) &&
566             !S_ISDIR(dentry->d_inode->i_mode)) {
567                 ll_release_openhandle(dentry, it);
568         }
569         ll_lookup_finish_locks(it, dentry);
570
571         if (dentry == save)
572                 GOTO(out, retval = NULL);
573         else
574                 GOTO(out, retval = dentry);
575  out:
576         if (req)
577                 ptlrpc_req_finished(req);
578         return retval;
579 }
580
581 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
582 #ifdef HAVE_VFS_INTENT_PATCHES
583 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
584                                    struct nameidata *nd)
585 {
586         struct dentry *de;
587         ENTRY;
588
589         if (nd && nd->flags & LOOKUP_LAST && !(nd->flags & LOOKUP_LINK_NOTLAST))
590                 de = ll_lookup_it(parent, dentry, &nd->intent, nd->flags);
591         else
592                 de = ll_lookup_it(parent, dentry, NULL, 0);
593
594         RETURN(de);
595 }
596 #else
597 struct lookup_intent *ll_convert_intent(struct open_intent *oit,
598                                         int lookup_flags)
599 {
600         struct lookup_intent *it;
601
602         OBD_ALLOC(it, sizeof(*it));
603         if (!it)
604                 return ERR_PTR(-ENOMEM);
605
606         if (lookup_flags & LOOKUP_OPEN) {
607                 it->it_op = IT_OPEN;
608                 if (lookup_flags & LOOKUP_CREATE)
609                         it->it_op |= IT_CREAT;
610                 it->it_create_mode = oit->create_mode;
611                 it->it_flags = oit->flags;
612         } else {
613                 it->it_op = IT_GETATTR;
614         }
615
616 #ifndef HAVE_FILE_IN_STRUCT_INTENT
617                 /* Since there is no way to pass our intent to ll_file_open,
618                  * just check the file is there. Actual open will be done
619                  * in ll_file_open */
620                 if (it->it_op & IT_OPEN)
621                         it->it_op = IT_LOOKUP;
622 #endif
623
624         return it;
625 }
626
627 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
628                                    struct nameidata *nd)
629 {
630         struct dentry *de;
631         ENTRY;
632
633         if (nd && !(nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))) {
634                 struct lookup_intent *it;
635
636 #if defined(HAVE_FILE_IN_STRUCT_INTENT) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
637                 /* Did we came here from failed revalidate just to propagate
638                  * its error? */
639                 if (nd->flags & LOOKUP_OPEN)
640                         if (IS_ERR(nd->intent.open.file))
641                                 RETURN((struct dentry *)nd->intent.open.file);
642 #endif
643
644                 if (ll_d2d(dentry) && ll_d2d(dentry)->lld_it) {
645                         it = ll_d2d(dentry)->lld_it;
646                         ll_d2d(dentry)->lld_it = NULL;
647                 } else {
648                         it = ll_convert_intent(&nd->intent.open, nd->flags);
649                         if (IS_ERR(it))
650                                 RETURN((struct dentry *)it);
651                 }
652
653                 de = ll_lookup_it(parent, dentry, it, nd->flags);
654                 if (de)
655                         dentry = de;
656                 if ((nd->flags & LOOKUP_OPEN) && !IS_ERR(dentry)) { /* Open */
657                         if (dentry->d_inode &&
658                             it_disposition(it, DISP_OPEN_OPEN)) { /* nocreate */
659 #ifdef HAVE_FILE_IN_STRUCT_INTENT
660                                 if (S_ISFIFO(dentry->d_inode->i_mode)) {
661                                         // We cannot call open here as it would
662                                         // deadlock.
663                                         ptlrpc_req_finished(
664                                                        (struct ptlrpc_request *)
665                                                           it->d.lustre.it_data);
666                                 } else {
667                                         struct file *filp;
668                                         nd->intent.open.file->private_data = it;
669                                         filp =lookup_instantiate_filp(nd,dentry,
670                                                                       NULL);
671 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
672 /* 2.6.1[456] have a bug in open_namei() that forgets to check
673  * nd->intent.open.file for error, so we need to return it as lookup's result
674  * instead */
675                                         if (IS_ERR(filp)) {
676                                                 if (de)
677                                                         dput(de);
678                                                 de = (struct dentry *) filp;
679                                         }
680 #endif
681
682                                 }
683 #else /* HAVE_FILE_IN_STRUCT_INTENT */
684                                 /* Release open handle as we have no way to
685                                  * pass it to ll_file_open */
686                                 ll_release_openhandle(dentry, it);
687 #endif /* HAVE_FILE_IN_STRUCT_INTENT */
688                         } else if (it_disposition(it, DISP_OPEN_CREATE)) {
689                                 // XXX This can only reliably work on assumption
690                                 // that there are NO hashed negative dentries.
691                                 ll_d2d(dentry)->lld_it = it;
692                                 it = NULL; /* Will be freed in ll_create_nd */
693                                 /* We absolutely depend on ll_create_nd to be
694                                  * called to not leak this intent and possible
695                                  * data attached to it */
696                         }
697                 }
698
699                 if (it) {
700                         ll_intent_release(it);
701                         OBD_FREE(it, sizeof(*it));
702                 }
703         } else {
704                 de = ll_lookup_it(parent, dentry, NULL, 0);
705         }
706
707         RETURN(de);
708 }
709 #endif
710 #endif
711
712 /* We depend on "mode" being set with the proper file type/umask by now */
713 static struct inode *ll_create_node(struct inode *dir, const char *name,
714                                     int namelen, const void *data, int datalen,
715                                     int mode, __u64 extra,
716                                     struct lookup_intent *it)
717 {
718         struct inode *inode = NULL;
719         struct ptlrpc_request *request = NULL;
720         struct ll_sb_info *sbi = ll_i2sbi(dir);
721         int rc;
722         ENTRY;
723
724         LASSERT(it && it->d.lustre.it_disposition);
725
726         LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
727         request = it->d.lustre.it_data;
728         it_clear_disposition(it, DISP_ENQ_CREATE_REF);
729         rc = ll_prep_inode(sbi->ll_osc_exp, &inode, request, DLM_REPLY_REC_OFF,
730                            dir->i_sb);
731         if (rc)
732                 GOTO(out, inode = ERR_PTR(rc));
733
734         LASSERT(list_empty(&inode->i_dentry));
735
736         /* We asked for a lock on the directory, but were granted a
737          * lock on the inode.  Since we finally have an inode pointer,
738          * stuff it in the lock. */
739         CDEBUG(D_DLMTRACE, "setting l_ast_data to inode %p (%lu/%u)\n",
740                inode, inode->i_ino, inode->i_generation);
741         mdc_set_lock_data(&it->d.lustre.it_lock_handle, inode);
742         EXIT;
743  out:
744         ptlrpc_req_finished(request);
745         return inode;
746 }
747
748 /*
749  * By the time this is called, we already have created the directory cache
750  * entry for the new file, but it is so far negative - it has no inode.
751  *
752  * We defer creating the OBD object(s) until open, to keep the intent and
753  * non-intent code paths similar, and also because we do not have the MDS
754  * inode number before calling ll_create_node() (which is needed for LOV),
755  * so we would need to do yet another RPC to the MDS to store the LOV EA
756  * data on the MDS.  If needed, we would pass the PACKED lmm as data and
757  * lmm_size in datalen (the MDS still has code which will handle that).
758  *
759  * If the create succeeds, we fill in the inode information
760  * with d_instantiate().
761  */
762 static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
763                         struct lookup_intent *it)
764 {
765         struct inode *inode;
766         struct ptlrpc_request *request = it->d.lustre.it_data;
767         int rc = 0;
768         ENTRY;
769
770         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
771                dentry->d_name.len, dentry->d_name.name, dir->i_ino,
772                dir->i_generation, dir, LL_IT2STR(it));
773
774         rc = it_open_error(DISP_OPEN_CREATE, it);
775         if (rc)
776                 RETURN(rc);
777
778         mdc_store_inode_generation(request, DLM_INTENT_REC_OFF,
779                                    DLM_REPLY_REC_OFF);
780         inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
781                                NULL, 0, mode, 0, it);
782         if (IS_ERR(inode)) {
783                 RETURN(PTR_ERR(inode));
784         }
785
786         d_instantiate(dentry, inode);
787         /* Negative dentry may be unhashed if parent does not have UPDATE lock,
788          * but some callers, e.g. do_coredump, expect dentry to be hashed after
789          * successful create. Hash it here. */
790         spin_lock(&dcache_lock);
791         if (d_unhashed(dentry))
792                 __d_rehash(dentry, 0);
793         spin_unlock(&dcache_lock);
794         RETURN(0);
795 }
796
797 static void ll_update_times(struct ptlrpc_request *request, int offset,
798                             struct inode *inode)
799 {
800         struct mds_body *body = lustre_msg_buf(request->rq_repmsg, offset,
801                                                sizeof(*body));
802         LASSERT(body);
803
804         /* mtime is always updated with ctime, but can be set in past.
805            As write and utime(2) may happen within 1 second, and utime's
806            mtime has a priority over write's one, so take mtime from mds
807            for the same ctimes. */
808         if (body->valid & OBD_MD_FLCTIME &&
809             body->ctime >= LTIME_S(inode->i_ctime)) {
810                 LTIME_S(inode->i_ctime) = body->ctime;
811
812                 if (body->valid & OBD_MD_FLMTIME) {
813                         CDEBUG(D_INODE, "setting ino %lu mtime from %lu "
814                                "to "LPU64"\n", inode->i_ino,
815                                LTIME_S(inode->i_mtime), body->mtime);
816                         LTIME_S(inode->i_mtime) = body->mtime;
817                 }
818         }
819 }
820
821 static int ll_new_node(struct inode *dir, struct qstr *name,
822                        const char *tgt, int mode,
823                        int rdev, struct dentry *dchild)
824 {
825         struct ptlrpc_request *request = NULL;
826         struct inode *inode = NULL;
827         struct ll_sb_info *sbi = ll_i2sbi(dir);
828         struct mdc_op_data op_data;
829         int tgt_len = 0;
830         int err;
831
832         ENTRY;
833         if (unlikely(tgt != NULL))
834                 tgt_len = strlen(tgt)+1;
835
836         err = ll_prepare_mdc_op_data(&op_data, dir, NULL, name->name,
837                                      name->len, 0, NULL);
838         if (err)
839                 GOTO(err_exit, err);
840
841         err = mdc_create(sbi->ll_mdc_exp, &op_data, tgt, tgt_len,
842                          mode, current->fsuid, current->fsgid,
843                          current->cap_effective, rdev, &request);
844         if (err)
845                 GOTO(err_exit, err);
846
847         ll_update_times(request, REPLY_REC_OFF, dir);
848
849         if (dchild) {
850                 err = ll_prep_inode(sbi->ll_osc_exp, &inode, request,
851                                     REPLY_REC_OFF, dchild->d_sb);
852                 if (err)
853                      GOTO(err_exit, err);
854
855                 d_drop(dchild);
856                 d_instantiate(dchild, inode);
857                 EXIT;
858         }
859 err_exit:
860         ptlrpc_req_finished(request);
861
862         return err;
863 }
864
865
866 static int ll_mknod_generic(struct inode *dir, struct qstr *name, int mode,
867                             unsigned rdev, struct dentry *dchild)
868 {
869         int err;
870         ENTRY;
871
872         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p) mode %o dev %x\n",
873                name->len, name->name, dir->i_ino, dir->i_generation, dir,
874                mode, rdev);
875
876         mode &= ~current->fs->umask;
877
878         switch (mode & S_IFMT) {
879         case 0:
880                 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
881         case S_IFREG:
882         case S_IFCHR:
883         case S_IFBLK:
884         case S_IFIFO:
885         case S_IFSOCK:
886                 err = ll_new_node(dir, name, NULL, mode, rdev, dchild);
887                 break;
888         case S_IFDIR:
889                 err = -EPERM;
890                 break;
891         default:
892                 err = -EINVAL;
893         }
894         RETURN(err);
895 }
896
897 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
898 #ifndef HAVE_VFS_INTENT_PATCHES
899 static int ll_create_nd(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
900 {
901         struct lookup_intent *it = ll_d2d(dentry)->lld_it;
902         int rc;
903
904         if (!it)
905                 return ll_mknod_generic(dir, &dentry->d_name, mode, 0, dentry);
906
907         ll_d2d(dentry)->lld_it = NULL;
908
909         /* Was there an error? Propagate it! */
910         if (it->d.lustre.it_status) {
911                 rc = it->d.lustre.it_status;
912                 goto out;
913         }
914
915         rc = ll_create_it(dir, dentry, mode, it);
916 #ifdef HAVE_FILE_IN_STRUCT_INTENT
917         if (nd && (nd->flags & LOOKUP_OPEN) && dentry->d_inode) { /* Open */
918                 nd->intent.open.file->private_data = it;
919                 lookup_instantiate_filp(nd, dentry, NULL);
920         }
921 #else
922         ll_release_openhandle(dentry,it);
923 #endif
924
925 out:
926         ll_intent_release(it);
927         OBD_FREE(it, sizeof(*it));
928
929         return rc;
930 }
931 #else
932 static int ll_create_nd(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
933 {
934
935         if (!nd || !nd->intent.d.lustre.it_disposition)
936                 /* No saved request? Just mknod the file */
937                 return ll_mknod_generic(dir, &dentry->d_name, mode, 0, dentry);
938
939         return ll_create_it(dir, dentry, mode, &nd->intent);
940 }
941 #endif
942 #endif
943
944 static int ll_symlink_generic(struct inode *dir, struct qstr *name,
945                               const char *tgt, struct dentry *dchild)
946 {
947         int err;
948         ENTRY;
949
950         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),target=%.*s\n",
951                name->len, name->name, dir->i_ino, dir->i_generation,
952                dir, 3000, tgt);
953
954         err = ll_new_node(dir, name, (char *)tgt, S_IFLNK | S_IRWXUGO,
955                           0, dchild);
956         RETURN(err);
957 }
958
959 static int ll_link_generic(struct inode *src,  struct inode *dir,
960                            struct qstr *name, struct dentry *dchild)
961 {
962         struct ptlrpc_request *request = NULL;
963         struct mdc_op_data op_data;
964         int err;
965         struct ll_sb_info *sbi = ll_i2sbi(dir);
966
967         ENTRY;
968         CDEBUG(D_VFSTRACE,
969                "VFS Op: inode=%lu/%u(%p), dir=%lu/%u(%p), target=%.*s\n",
970                src->i_ino, src->i_generation, src, dir->i_ino,
971                dir->i_generation, dir, name->len, name->name);
972
973         err = ll_prepare_mdc_op_data(&op_data, src, dir, name->name,
974                                      name->len, 0, NULL);
975         if (err)
976                 GOTO(out, err);
977         err = mdc_link(sbi->ll_mdc_exp, &op_data, &request);
978         if (err)
979                GOTO(out, err);
980
981         if (dchild) {
982                 d_drop(dchild);
983         }
984         ll_update_times(request, REPLY_REC_OFF, dir);
985
986         EXIT;
987 out:
988         ptlrpc_req_finished(request);
989         RETURN(err);
990 }
991
992 static int ll_mkdir_generic(struct inode *dir, struct qstr *name, int mode,
993                             struct dentry *dchild)
994
995 {
996         int err;
997
998         ENTRY;
999         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
1000                name->len, name->name, dir->i_ino, dir->i_generation, dir);
1001
1002         mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
1003         err = ll_new_node(dir, name, NULL, mode, 0, dchild);
1004
1005         RETURN(err);
1006 }
1007
1008 /* Try to find the child dentry by its name.
1009    If found, put the result fid into @fid. */
1010 static void ll_get_child_fid(struct inode * dir, struct qstr *name,
1011                              struct ll_fid *fid)
1012 {
1013         struct dentry *parent, *child;
1014         
1015         parent = list_entry(dir->i_dentry.next, struct dentry, d_alias);
1016         child = d_lookup(parent, name);
1017         if (child) {
1018                 if (child->d_inode)
1019                         ll_inode2fid(fid, child->d_inode);
1020                 dput(child);
1021         }
1022 }
1023
1024 static int ll_rmdir_generic(struct inode *dir, struct dentry *dparent,
1025                             struct qstr *name)
1026 {
1027         struct ptlrpc_request *request = NULL;
1028         struct mdc_op_data op_data = {{0}};
1029         struct dentry *dentry;
1030         int rc;
1031         ENTRY;
1032         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
1033                name->len, name->name, dir->i_ino, dir->i_generation, dir);
1034
1035         /* Check if we have something mounted at the dir we are going to delete
1036          * In such a case there would always be dentry present. */
1037         if (dparent) {
1038                 dentry = d_lookup(dparent, name);
1039                 if (dentry) {
1040                         int mounted = d_mountpoint(dentry);
1041                         dput(dentry);
1042                         if (mounted)
1043                                 GOTO(out, rc = -EBUSY);
1044                 }
1045         }
1046
1047         rc = ll_prepare_mdc_op_data(&op_data, dir, NULL, name->name,
1048                                     name->len, S_IFDIR, NULL);
1049         if (rc)
1050                 GOTO(out, rc);
1051         
1052         ll_get_child_fid(dir, name, &op_data.fid3);
1053         rc = mdc_unlink(ll_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1054         if (rc)
1055                 GOTO(out, rc);
1056         ll_update_times(request, REPLY_REC_OFF, dir);
1057
1058         EXIT;
1059 out:
1060         ptlrpc_req_finished(request);
1061         return(rc);
1062 }
1063
1064 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
1065 {
1066         struct mds_body *body;
1067         struct lov_mds_md *eadata;
1068         struct lov_stripe_md *lsm = NULL;
1069         struct obd_trans_info oti = { 0 };
1070         struct obdo *oa;
1071         int rc;
1072         ENTRY;
1073
1074         /* req is swabbed so this is safe */
1075         body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, sizeof(*body));
1076
1077         if (!(body->valid & OBD_MD_FLEASIZE))
1078                 RETURN(0);
1079
1080         if (body->eadatasize == 0) {
1081                 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
1082                 GOTO(out, rc = -EPROTO);
1083         }
1084
1085         /* The MDS sent back the EA because we unlinked the last reference
1086          * to this file. Use this EA to unlink the objects on the OST.
1087          * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
1088          * check it is complete and sensible. */
1089         eadata = lustre_swab_repbuf(request, REPLY_REC_OFF + 1,
1090                                     body->eadatasize, NULL);
1091         LASSERT(eadata != NULL);
1092         if (eadata == NULL) {
1093                 CERROR("Can't unpack MDS EA data\n");
1094                 GOTO(out, rc = -EPROTO);
1095         }
1096
1097         rc = obd_unpackmd(ll_i2obdexp(dir), &lsm, eadata, body->eadatasize);
1098         if (rc < 0) {
1099                 CERROR("obd_unpackmd: %d\n", rc);
1100                 GOTO(out, rc);
1101         }
1102         LASSERT(rc >= sizeof(*lsm));
1103
1104         rc = obd_checkmd(ll_i2obdexp(dir), ll_i2mdcexp(dir), lsm);
1105         if (rc)
1106                 GOTO(out_free_memmd, rc);
1107
1108         OBDO_ALLOC(oa);
1109         if (oa == NULL)
1110                 GOTO(out_free_memmd, rc = -ENOMEM);
1111
1112         oa->o_id = lsm->lsm_object_id;
1113         oa->o_mode = body->mode & S_IFMT;
1114         oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
1115
1116         if (body->valid & OBD_MD_FLCOOKIE) {
1117                 oa->o_valid |= OBD_MD_FLCOOKIE;
1118                 oti.oti_logcookies =
1119                         lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF + 2,
1120                                        sizeof(struct llog_cookie) *
1121                                        lsm->lsm_stripe_count);
1122                 if (oti.oti_logcookies == NULL) {
1123                         oa->o_valid &= ~OBD_MD_FLCOOKIE;
1124                         body->valid &= ~OBD_MD_FLCOOKIE;
1125                 }
1126         }
1127
1128         rc = obd_destroy(ll_i2obdexp(dir), oa, lsm, &oti, ll_i2mdcexp(dir));
1129         OBDO_FREE(oa);
1130         if (rc)
1131                 CERROR("obd destroy objid "LPX64" error %d\n",
1132                        lsm->lsm_object_id, rc);
1133  out_free_memmd:
1134         obd_free_memmd(ll_i2obdexp(dir), &lsm);
1135  out:
1136         return rc;
1137 }
1138
1139 static int ll_unlink_generic(struct inode * dir, struct qstr *name)
1140 {
1141         struct ptlrpc_request *request = NULL;
1142         struct mdc_op_data op_data = {{0}};
1143         int rc;
1144         ENTRY;
1145
1146         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
1147                name->len, name->name, dir->i_ino, dir->i_generation, dir);
1148
1149         rc = ll_prepare_mdc_op_data(&op_data, dir, NULL, name->name,
1150                                     name->len, 0, NULL);
1151         if (rc)
1152                 GOTO(out, rc);
1153
1154         ll_get_child_fid(dir, name, &op_data.fid3);
1155         rc = mdc_unlink(ll_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1156         if (rc)
1157                 GOTO(out, rc);
1158
1159         ll_update_times(request, REPLY_REC_OFF, dir);
1160
1161         rc = ll_objects_destroy(request, dir);
1162         if (rc)
1163                 GOTO(out, rc);
1164         EXIT;
1165  out:
1166         ptlrpc_req_finished(request);
1167         return(rc);
1168 }
1169
1170 static int ll_rename_generic(struct inode *src, struct qstr *src_name,
1171                              struct inode *tgt, struct qstr *tgt_name)
1172 {
1173         struct ptlrpc_request *request = NULL;
1174         struct ll_sb_info *sbi = ll_i2sbi(src);
1175         struct mdc_op_data op_data = {{0}};
1176         int err;
1177
1178         ENTRY;
1179         CDEBUG(D_VFSTRACE,"VFS Op:oldname=%.*s,src_dir=%lu/%u(%p),newname=%.*s,"
1180                "tgt_dir=%lu/%u(%p)\n", src_name->len, src_name->name,
1181                src->i_ino, src->i_generation, src, tgt_name->len,
1182                tgt_name->name, tgt->i_ino, tgt->i_generation, tgt);
1183
1184         err = ll_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0, NULL);
1185         if (err)
1186                 GOTO(out, err);
1187         
1188         ll_get_child_fid(src, src_name, &op_data.fid3);
1189         ll_get_child_fid(tgt, tgt_name, &op_data.fid4);
1190         err = mdc_rename(sbi->ll_mdc_exp, &op_data,
1191                          src_name->name, src_name->len,
1192                          tgt_name->name, tgt_name->len, &request);
1193         if (err)
1194                 GOTO(out, err);
1195         ll_update_times(request, REPLY_REC_OFF, src);
1196         ll_update_times(request, REPLY_REC_OFF, tgt);
1197         err = ll_objects_destroy(request, src);
1198         if (err)
1199                 GOTO(out, err);
1200
1201         EXIT;
1202 out:
1203         ptlrpc_req_finished(request);
1204
1205         return(err);
1206 }
1207
1208 #ifdef HAVE_VFS_INTENT_PATCHES
1209 static int ll_mknod_raw(struct nameidata *nd, int mode, dev_t rdev)
1210 {
1211         return ll_mknod_generic(nd->dentry->d_inode, &nd->last, mode,rdev,NULL);
1212 }
1213 static int ll_rename_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
1214 {
1215         return ll_rename_generic(srcnd->dentry->d_inode, &srcnd->last,
1216                                  tgtnd->dentry->d_inode, &tgtnd->last);
1217 }
1218 static int ll_link_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
1219 {
1220         return ll_link_generic(srcnd->dentry->d_inode, tgtnd->dentry->d_inode,
1221                                &tgtnd->last, NULL);
1222 }
1223 static int ll_symlink_raw(struct nameidata *nd, const char *tgt)
1224 {
1225         return ll_symlink_generic(nd->dentry->d_inode, &nd->last, tgt, NULL);
1226 }
1227 static int ll_rmdir_raw(struct nameidata *nd)
1228 {
1229         return ll_rmdir_generic(nd->dentry->d_inode, nd->dentry, &nd->last);
1230 }
1231 static int ll_mkdir_raw(struct nameidata *nd, int mode)
1232 {
1233         return ll_mkdir_generic(nd->dentry->d_inode, &nd->last, mode, NULL);
1234 }
1235 static int ll_unlink_raw(struct nameidata *nd)
1236 {
1237         return ll_unlink_generic(nd->dentry->d_inode, &nd->last);
1238 }
1239 #endif
1240
1241 static int ll_mknod(struct inode *dir, struct dentry *dchild, int mode,
1242                     ll_dev_t rdev)
1243 {
1244         return ll_mknod_generic(dir, &dchild->d_name, mode,
1245                                 old_encode_dev(rdev), dchild);
1246 }
1247
1248 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1249 static int ll_unlink(struct inode * dir, struct dentry *dentry)
1250 {
1251         return ll_unlink_generic(dir, &dentry->d_name);
1252 }
1253 static int ll_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1254 {
1255         return ll_mkdir_generic(dir, &dentry->d_name, mode, dentry);
1256 }
1257 static int ll_rmdir(struct inode *dir, struct dentry *dentry)
1258 {
1259         return ll_rmdir_generic(dir, NULL, &dentry->d_name);
1260 }
1261 static int ll_symlink(struct inode *dir, struct dentry *dentry,
1262                       const char *oldname)
1263 {
1264         return ll_symlink_generic(dir, &dentry->d_name, oldname, dentry);
1265 }
1266 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1267                    struct dentry *new_dentry)
1268 {
1269         return ll_link_generic(old_dentry->d_inode, dir,
1270                                &new_dentry->d_name, new_dentry);
1271 }
1272 static int ll_rename(struct inode *old_dir, struct dentry *old_dentry,
1273                      struct inode *new_dir, struct dentry *new_dentry)
1274 {
1275         return ll_rename_generic(old_dir, &old_dentry->d_name, new_dir,
1276                                  &new_dentry->d_name);
1277 }
1278 #endif
1279
1280 struct inode_operations ll_dir_inode_operations = {
1281 #ifdef HAVE_VFS_INTENT_PATCHES
1282         .link_raw           = ll_link_raw,
1283         .unlink_raw         = ll_unlink_raw,
1284         .symlink_raw        = ll_symlink_raw,
1285         .mkdir_raw          = ll_mkdir_raw,
1286         .rmdir_raw          = ll_rmdir_raw,
1287         .mknod_raw          = ll_mknod_raw,
1288         .rename_raw         = ll_rename_raw,
1289         .setattr            = ll_setattr,
1290         .setattr_raw        = ll_setattr_raw,
1291 #endif
1292         .mknod              = ll_mknod,
1293 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1294         .create_it          = ll_create_it,
1295         .lookup_it          = ll_lookup_it,
1296         .revalidate_it      = ll_inode_revalidate_it,
1297 #else
1298         .lookup             = ll_lookup_nd,
1299         .create             = ll_create_nd,
1300         /* We need all these non-raw things for NFSD, to not patch it. */
1301         .unlink             = ll_unlink,
1302         .mkdir              = ll_mkdir,
1303         .rmdir              = ll_rmdir,
1304         .symlink            = ll_symlink,
1305         .link               = ll_link,
1306         .rename             = ll_rename,
1307         .setattr            = ll_setattr,
1308         .getattr            = ll_getattr,
1309 #endif
1310         .permission         = ll_inode_permission,
1311         .setxattr           = ll_setxattr,
1312         .getxattr           = ll_getxattr,
1313         .listxattr          = ll_listxattr,
1314         .removexattr        = ll_removexattr,
1315 };
1316
1317 struct inode_operations ll_special_inode_operations = {
1318 #ifdef HAVE_VFS_INTENT_PATCHES
1319         .setattr_raw    = ll_setattr_raw,
1320 #endif
1321         .setattr        = ll_setattr,
1322 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1323         .getattr        = ll_getattr,
1324 #else
1325         .revalidate_it  = ll_inode_revalidate_it,
1326 #endif
1327         .permission     = ll_inode_permission,
1328         .setxattr       = ll_setxattr,
1329         .getxattr       = ll_getxattr,
1330         .listxattr      = ll_listxattr,
1331         .removexattr    = ll_removexattr,
1332 };