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