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