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