Whamcloud - gitweb
3c4d375d1401d495e70fa4078b55c2cd64e89314
[fs/lustre-release.git] / lustre / llite / namei.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #include <linux/fs.h>
34 #include <linux/sched.h>
35 #include <linux/mm.h>
36 #include <linux/quotaops.h>
37 #include <linux/highmem.h>
38 #include <linux/pagemap.h>
39 #include <linux/security.h>
40 #include <linux/user_namespace.h>
41 #ifdef HAVE_UIDGID_HEADER
42 # include <linux/uidgid.h>
43 #endif
44
45 #define DEBUG_SUBSYSTEM S_LLITE
46
47 #include <obd_support.h>
48 #include <lustre_fid.h>
49 #include <lustre_dlm.h>
50 #include "llite_internal.h"
51
52 static int ll_create_it(struct inode *dir, struct dentry *dentry,
53                         struct lookup_intent *it,
54                         void *secctx, __u32 secctxlen);
55
56 /* called from iget5_locked->find_inode() under inode_lock spinlock */
57 static int ll_test_inode(struct inode *inode, void *opaque)
58 {
59         struct ll_inode_info    *lli = ll_i2info(inode);
60         struct lustre_md        *md = opaque;
61
62         if (unlikely(!(md->body->mbo_valid & OBD_MD_FLID))) {
63                 CERROR("MDS body missing FID\n");
64                 return 0;
65         }
66
67         if (!lu_fid_eq(&lli->lli_fid, &md->body->mbo_fid1))
68                 return 0;
69
70         return 1;
71 }
72
73 static int ll_set_inode(struct inode *inode, void *opaque)
74 {
75         struct ll_inode_info *lli = ll_i2info(inode);
76         struct mdt_body *body = ((struct lustre_md *)opaque)->body;
77
78         if (unlikely(!(body->mbo_valid & OBD_MD_FLID))) {
79                 CERROR("MDS body missing FID\n");
80                 return -EINVAL;
81         }
82
83         lli->lli_fid = body->mbo_fid1;
84         if (unlikely(!(body->mbo_valid & OBD_MD_FLTYPE))) {
85                 CERROR("Can not initialize inode "DFID" without object type: "
86                        "valid = %#llx\n",
87                        PFID(&lli->lli_fid), body->mbo_valid);
88                 return -EINVAL;
89         }
90
91         inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mbo_mode & S_IFMT);
92         if (unlikely(inode->i_mode == 0)) {
93                 CERROR("Invalid inode "DFID" type\n", PFID(&lli->lli_fid));
94                 return -EINVAL;
95         }
96
97         ll_lli_init(lli);
98
99         return 0;
100 }
101
102
103 /**
104  * Get an inode by inode number(@hash), which is already instantiated by
105  * the intent lookup).
106  */
107 struct inode *ll_iget(struct super_block *sb, ino_t hash,
108                       struct lustre_md *md)
109 {
110         struct inode    *inode;
111         int             rc = 0;
112
113         ENTRY;
114
115         LASSERT(hash != 0);
116         inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md);
117         if (inode == NULL)
118                 RETURN(ERR_PTR(-ENOMEM));
119
120         if (inode->i_state & I_NEW) {
121                 rc = ll_read_inode2(inode, md);
122                 if (rc == 0 && S_ISREG(inode->i_mode) &&
123                     ll_i2info(inode)->lli_clob == NULL)
124                         rc = cl_file_inode_init(inode, md);
125
126                 if (rc != 0) {
127                         /* Let's clear directory lsm here, otherwise
128                          * make_bad_inode() will reset the inode mode
129                          * to regular, then ll_clear_inode will not
130                          * be able to clear lsm_md */
131                         if (S_ISDIR(inode->i_mode))
132                                 ll_dir_clear_lsm_md(inode);
133                         make_bad_inode(inode);
134                         unlock_new_inode(inode);
135                         iput(inode);
136                         inode = ERR_PTR(rc);
137                 } else {
138                         inode_has_no_xattr(inode);
139                         unlock_new_inode(inode);
140                 }
141         } else if (is_bad_inode(inode)) {
142                 iput(inode);
143                 inode = ERR_PTR(-ESTALE);
144         } else if (!(inode->i_state & (I_FREEING | I_CLEAR))) {
145                 rc = ll_update_inode(inode, md);
146                 CDEBUG(D_VFSTRACE, "got inode: "DFID"(%p): rc = %d\n",
147                        PFID(&md->body->mbo_fid1), inode, rc);
148                 if (rc != 0) {
149                         if (S_ISDIR(inode->i_mode))
150                                 ll_dir_clear_lsm_md(inode);
151                         iput(inode);
152                         inode = ERR_PTR(rc);
153                 }
154         }
155
156         RETURN(inode);
157 }
158
159 static void ll_invalidate_negative_children(struct inode *dir)
160 {
161         struct dentry *dentry, *tmp_subdir;
162         DECLARE_LL_D_HLIST_NODE_PTR(p);
163
164         spin_lock(&dir->i_lock);
165         ll_d_hlist_for_each_entry(dentry, p, &dir->i_dentry) {
166                 spin_lock(&dentry->d_lock);
167                 if (!list_empty(&dentry->d_subdirs)) {
168                         struct dentry *child;
169
170                         list_for_each_entry_safe(child, tmp_subdir,
171                                                  &dentry->d_subdirs,
172                                                  d_child) {
173                                 if (child->d_inode == NULL)
174                                         d_lustre_invalidate(child, 1);
175                         }
176                 }
177                 spin_unlock(&dentry->d_lock);
178         }
179         spin_unlock(&dir->i_lock);
180 }
181
182 int ll_test_inode_by_fid(struct inode *inode, void *opaque)
183 {
184         return lu_fid_eq(&ll_i2info(inode)->lli_fid, opaque);
185 }
186
187 static int ll_dom_lock_cancel(struct inode *inode, struct ldlm_lock *lock)
188 {
189         struct lu_env *env;
190         struct ll_inode_info *lli = ll_i2info(inode);
191         __u16 refcheck;
192         int rc;
193         ENTRY;
194
195         if (!lli->lli_clob) {
196                 /* due to DoM read on open, there may exist pages for Lustre
197                  * regular file even though cl_object is not set up yet. */
198                 truncate_inode_pages(inode->i_mapping, 0);
199                 RETURN(0);
200         }
201
202         env = cl_env_get(&refcheck);
203         if (IS_ERR(env))
204                 RETURN(PTR_ERR(env));
205
206         /* reach MDC layer to flush data under  the DoM ldlm lock */
207         rc = cl_object_flush(env, lli->lli_clob, lock);
208
209         cl_env_put(env, &refcheck);
210         RETURN(rc);
211 }
212
213 static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
214 {
215         struct inode *inode = ll_inode_from_resource_lock(lock);
216         struct ll_inode_info *lli;
217         __u64 bits = to_cancel;
218         int rc;
219
220         ENTRY;
221
222         if (!inode) {
223                 /* That means the inode is evicted most likely and may cause
224                  * the skipping of lock cleanups below, so print the message
225                  * about that in log.
226                  */
227                 if (lock->l_resource->lr_lvb_inode)
228                         LDLM_DEBUG(lock,
229                                    "can't take inode for the lock (%sevicted)\n",
230                                    lock->l_resource->lr_lvb_inode->i_state &
231                                    I_FREEING ? "" : "not ");
232                 RETURN_EXIT;
233         }
234
235         if (!fid_res_name_eq(ll_inode2fid(inode),
236                              &lock->l_resource->lr_name)) {
237                 LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
238                            PFID(ll_inode2fid(inode)), inode);
239                 LBUG();
240         }
241
242         if (bits & MDS_INODELOCK_XATTR) {
243                 ll_xattr_cache_destroy(inode);
244                 bits &= ~MDS_INODELOCK_XATTR;
245         }
246
247         /* For OPEN locks we differentiate between lock modes
248          * LCK_CR, LCK_CW, LCK_PR - bug 22891 */
249         if (bits & MDS_INODELOCK_OPEN)
250                 ll_have_md_lock(inode, &bits, lock->l_req_mode);
251
252         if (bits & MDS_INODELOCK_OPEN) {
253                 fmode_t fmode;
254
255                 switch (lock->l_req_mode) {
256                 case LCK_CW:
257                         fmode = FMODE_WRITE;
258                         break;
259                 case LCK_PR:
260                         fmode = FMODE_EXEC;
261                         break;
262                 case LCK_CR:
263                         fmode = FMODE_READ;
264                         break;
265                 default:
266                         LDLM_ERROR(lock, "bad lock mode for OPEN lock");
267                         LBUG();
268                 }
269
270                 ll_md_real_close(inode, fmode);
271
272                 bits &= ~MDS_INODELOCK_OPEN;
273         }
274
275         if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
276                     MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM |
277                     MDS_INODELOCK_DOM))
278                 ll_have_md_lock(inode, &bits, LCK_MINMODE);
279
280         if (bits & MDS_INODELOCK_DOM) {
281                 rc =  ll_dom_lock_cancel(inode, lock);
282                 if (rc < 0)
283                         CDEBUG(D_INODE, "cannot flush DoM data "
284                                DFID": rc = %d\n",
285                                PFID(ll_inode2fid(inode)), rc);
286         }
287
288         if (bits & MDS_INODELOCK_LAYOUT) {
289                 struct cl_object_conf conf = {
290                         .coc_opc = OBJECT_CONF_INVALIDATE,
291                         .coc_inode = inode,
292                 };
293
294                 rc = ll_layout_conf(inode, &conf);
295                 if (rc < 0)
296                         CDEBUG(D_INODE, "cannot invalidate layout of "
297                                DFID": rc = %d\n",
298                                PFID(ll_inode2fid(inode)), rc);
299         }
300
301         lli = ll_i2info(inode);
302
303         if (bits & MDS_INODELOCK_UPDATE)
304                 lli->lli_update_atime = 1;
305
306         if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
307                 CDEBUG(D_INODE, "invalidating inode "DFID" lli = %p, "
308                        "pfid  = "DFID"\n", PFID(ll_inode2fid(inode)),
309                        lli, PFID(&lli->lli_pfid));
310                 truncate_inode_pages(inode->i_mapping, 0);
311
312                 if (unlikely(!fid_is_zero(&lli->lli_pfid))) {
313                         struct inode *master_inode = NULL;
314                         unsigned long hash;
315
316                         /* This is slave inode, since all of the child dentry
317                          * is connected on the master inode, so we have to
318                          * invalidate the negative children on master inode */
319                         CDEBUG(D_INODE, "Invalidate s"DFID" m"DFID"\n",
320                                PFID(ll_inode2fid(inode)), PFID(&lli->lli_pfid));
321
322                         hash = cl_fid_build_ino(&lli->lli_pfid,
323                                         ll_need_32bit_api(ll_i2sbi(inode)));
324
325                         /* Do not lookup the inode with ilookup5, otherwise
326                          * it will cause dead lock,
327                          * 1. Client1 send chmod req to the MDT0, then on MDT0,
328                          * it enqueues master and all of its slaves lock,
329                          * (mdt_attr_set() -> mdt_lock_slaves()), after gets
330                          * master and stripe0 lock, it will send the enqueue
331                          * req (for stripe1) to MDT1, then MDT1 finds the lock
332                          * has been granted to client2. Then MDT1 sends blocking
333                          * ast to client2.
334                          * 2. At the same time, client2 tries to unlink
335                          * the striped dir (rm -rf striped_dir), and during
336                          * lookup, it will hold the master inode of the striped
337                          * directory, whose inode state is NEW, then tries to
338                          * revalidate all of its slaves, (ll_prep_inode()->
339                          * ll_iget()->ll_read_inode2()-> ll_update_inode().).
340                          * And it will be blocked on the server side because
341                          * of 1.
342                          * 3. Then the client get the blocking_ast req, cancel
343                          * the lock, but being blocked if using ->ilookup5()),
344                          * because master inode state is NEW. */
345                         master_inode = ilookup5_nowait(inode->i_sb, hash,
346                                                         ll_test_inode_by_fid,
347                                                         (void *)&lli->lli_pfid);
348                         if (master_inode) {
349                                 ll_invalidate_negative_children(master_inode);
350                                 iput(master_inode);
351                         }
352                 } else {
353                         ll_invalidate_negative_children(inode);
354                 }
355         }
356
357         if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
358             inode->i_sb->s_root != NULL &&
359             inode != inode->i_sb->s_root->d_inode)
360                 ll_invalidate_aliases(inode);
361
362         if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM))
363                 forget_all_cached_acls(inode);
364
365         iput(inode);
366         RETURN_EXIT;
367 }
368
369 /* Check if the given lock may be downgraded instead of canceling and
370  * that convert is really needed. */
371 int ll_md_need_convert(struct ldlm_lock *lock)
372 {
373         struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
374         struct inode *inode;
375         __u64 wanted = lock->l_policy_data.l_inodebits.cancel_bits;
376         __u64 bits = lock->l_policy_data.l_inodebits.bits & ~wanted;
377         enum ldlm_mode mode = LCK_MINMODE;
378
379         if (!lock->l_conn_export ||
380             !exp_connect_lock_convert(lock->l_conn_export))
381                 return 0;
382
383         if (!wanted || !bits || ldlm_is_cancel(lock))
384                 return 0;
385
386         /* do not convert locks other than DOM for now */
387         if (!((bits | wanted) & MDS_INODELOCK_DOM))
388                 return 0;
389
390         /* We may have already remaining bits in some other lock so
391          * lock convert will leave us just extra lock for the same bit.
392          * Check if client has other lock with the same bits and the same
393          * or lower mode and don't convert if any.
394          */
395         switch (lock->l_req_mode) {
396         case LCK_PR:
397                 mode = LCK_PR;
398                 /* fallthrough */
399         case LCK_PW:
400                 mode |= LCK_CR;
401                 break;
402         case LCK_CW:
403                 mode = LCK_CW;
404                 /* fallthrough */
405         case LCK_CR:
406                 mode |= LCK_CR;
407                 break;
408         default:
409                 /* do not convert other modes */
410                 return 0;
411         }
412
413         /* is lock is too old to be converted? */
414         lock_res_and_lock(lock);
415         if (ktime_after(ktime_get(),
416                         ktime_add(lock->l_last_used,
417                                   ktime_set(ns->ns_dirty_age_limit, 0)))) {
418                 unlock_res_and_lock(lock);
419                 return 0;
420         }
421         unlock_res_and_lock(lock);
422
423         inode = ll_inode_from_resource_lock(lock);
424         ll_have_md_lock(inode, &bits, mode);
425         iput(inode);
426         return !!(bits);
427 }
428
429 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
430                        void *data, int flag)
431 {
432         struct lustre_handle lockh;
433         __u64 bits = lock->l_policy_data.l_inodebits.bits;
434         int rc;
435
436         ENTRY;
437
438         switch (flag) {
439         case LDLM_CB_BLOCKING:
440         {
441                 __u64 cancel_flags = LCF_ASYNC;
442
443                 if (ll_md_need_convert(lock)) {
444                         cancel_flags |= LCF_CONVERT;
445                         /* For lock convert some cancel actions may require
446                          * this lock with non-dropped canceled bits, e.g. page
447                          * flush for DOM lock. So call ll_lock_cancel_bits()
448                          * here while canceled bits are still set.
449                          */
450                         bits = lock->l_policy_data.l_inodebits.cancel_bits;
451                         if (bits & MDS_INODELOCK_DOM)
452                                 ll_lock_cancel_bits(lock, MDS_INODELOCK_DOM);
453                 }
454                 ldlm_lock2handle(lock, &lockh);
455                 rc = ldlm_cli_cancel(&lockh, cancel_flags);
456                 if (rc < 0) {
457                         CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
458                         RETURN(rc);
459                 }
460                 break;
461         }
462         case LDLM_CB_CANCELING:
463                 /* Nothing to do for non-granted locks */
464                 if (!ldlm_is_granted(lock))
465                         break;
466
467                 if (ldlm_is_converting(lock)) {
468                         /* this is called on already converted lock, so
469                          * ibits has remained bits only and cancel_bits
470                          * are bits that were dropped.
471                          * Note that DOM lock is handled prior lock convert
472                          * and is excluded here.
473                          */
474                         bits = lock->l_policy_data.l_inodebits.cancel_bits &
475                                 ~MDS_INODELOCK_DOM;
476                 } else {
477                         LASSERT(ldlm_is_canceling(lock));
478                 }
479                 ll_lock_cancel_bits(lock, bits);
480                 break;
481         default:
482                 LBUG();
483         }
484
485         RETURN(0);
486 }
487
488 __u32 ll_i2suppgid(struct inode *i)
489 {
490         if (in_group_p(i->i_gid))
491                 return (__u32)from_kgid(&init_user_ns, i->i_gid);
492         else
493                 return (__u32) __kgid_val(INVALID_GID);
494 }
495
496 /* Pack the required supplementary groups into the supplied groups array.
497  * If we don't need to use the groups from the target inode(s) then we
498  * instead pack one or more groups from the user's supplementary group
499  * array in case it might be useful.  Not needed if doing an MDS-side upcall. */
500 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
501 {
502         LASSERT(i1 != NULL);
503         LASSERT(suppgids != NULL);
504
505         suppgids[0] = ll_i2suppgid(i1);
506
507         if (i2)
508                 suppgids[1] = ll_i2suppgid(i2);
509         else
510                 suppgids[1] = -1;
511 }
512
513 /*
514  * try to reuse three types of dentry:
515  * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
516  *    by concurrent .revalidate).
517  * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
518  *    be cleared by others calling d_lustre_revalidate).
519  * 3. DISCONNECTED alias.
520  */
521 static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
522 {
523         struct dentry *alias, *discon_alias, *invalid_alias;
524         DECLARE_LL_D_HLIST_NODE_PTR(p);
525
526         if (ll_d_hlist_empty(&inode->i_dentry))
527                 return NULL;
528
529         discon_alias = invalid_alias = NULL;
530
531         spin_lock(&inode->i_lock);
532         ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry) {
533                 LASSERT(alias != dentry);
534
535                 spin_lock(&alias->d_lock);
536                 if ((alias->d_flags & DCACHE_DISCONNECTED) &&
537                     S_ISDIR(inode->i_mode))
538                         /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
539                         discon_alias = alias;
540                 else if (alias->d_parent == dentry->d_parent             &&
541                          alias->d_name.hash == dentry->d_name.hash       &&
542                          alias->d_name.len == dentry->d_name.len         &&
543                          memcmp(alias->d_name.name, dentry->d_name.name,
544                                 dentry->d_name.len) == 0)
545                         invalid_alias = alias;
546                 spin_unlock(&alias->d_lock);
547
548                 if (invalid_alias)
549                         break;
550         }
551         alias = invalid_alias ?: discon_alias ?: NULL;
552         if (alias) {
553                 spin_lock(&alias->d_lock);
554                 dget_dlock(alias);
555                 spin_unlock(&alias->d_lock);
556         }
557         spin_unlock(&inode->i_lock);
558
559         return alias;
560 }
561
562 /*
563  * Similar to d_splice_alias(), but lustre treats invalid alias
564  * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
565  */
566 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
567 {
568         struct dentry *new;
569         int rc;
570
571         if (inode) {
572                 new = ll_find_alias(inode, de);
573                 if (new) {
574                         rc = ll_d_init(new);
575                         if (rc < 0) {
576                                 dput(new);
577                                 return ERR_PTR(rc);
578                         }
579                         d_move(new, de);
580                         iput(inode);
581                         CDEBUG(D_DENTRY,
582                                "Reuse dentry %p inode %p refc %d flags %#x\n",
583                               new, new->d_inode, ll_d_count(new), new->d_flags);
584                         return new;
585                 }
586         }
587         rc = ll_d_init(de);
588         if (rc < 0)
589                 return ERR_PTR(rc);
590         d_add(de, inode);
591         CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
592                de, de->d_inode, ll_d_count(de), de->d_flags);
593         return de;
594 }
595
596 static int ll_lookup_it_finish(struct ptlrpc_request *request,
597                                struct lookup_intent *it,
598                                struct inode *parent, struct dentry **de,
599                                void *secctx, __u32 secctxlen)
600 {
601         struct inode             *inode = NULL;
602         __u64                     bits = 0;
603         int                       rc;
604         struct dentry *alias;
605         ENTRY;
606
607         /* NB 1 request reference will be taken away by ll_intent_lock()
608          * when I return */
609         CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
610                it->it_disposition);
611         if (!it_disposition(it, DISP_LOOKUP_NEG)) {
612                 struct req_capsule *pill = &request->rq_pill;
613                 struct mdt_body *body = req_capsule_server_get(pill,
614                                                                &RMF_MDT_BODY);
615
616                 rc = ll_prep_inode(&inode, request, (*de)->d_sb, it);
617                 if (rc)
618                         RETURN(rc);
619
620                 if (it->it_op & IT_OPEN)
621                         ll_dom_finish_open(inode, request, it);
622
623                 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
624
625                 /* We used to query real size from OSTs here, but actually
626                  * this is not needed. For stat() calls size would be updated
627                  * from subsequent do_revalidate()->ll_inode_revalidate_it() in
628                  * 2.4 and
629                  * vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
630                  * Everybody else who needs correct file size would call
631                  * ll_glimpse_size or some equivalent themselves anyway.
632                  * Also see bug 7198.
633                  */
634
635                 /* If security context was returned by MDT, put it in
636                  * inode now to save an extra getxattr from security hooks,
637                  * and avoid deadlock.
638                  */
639                 if (body->mbo_valid & OBD_MD_SECCTX) {
640                         secctx = req_capsule_server_get(pill, &RMF_FILE_SECCTX);
641                         secctxlen = req_capsule_get_size(pill,
642                                                            &RMF_FILE_SECCTX,
643                                                            RCL_SERVER);
644
645                         if (secctxlen)
646                                 CDEBUG(D_SEC, "server returned security context"
647                                        " for "DFID"\n",
648                                        PFID(ll_inode2fid(inode)));
649                 }
650
651                 if (secctx != NULL && secctxlen != 0) {
652                         inode_lock(inode);
653                         rc = security_inode_notifysecctx(inode, secctx,
654                                                          secctxlen);
655                         inode_unlock(inode);
656                         if (rc)
657                                 CWARN("cannot set security context for "
658                                       DFID": rc = %d\n",
659                                       PFID(ll_inode2fid(inode)), rc);
660                 }
661         }
662
663         /* Only hash *de if it is unhashed (new dentry).
664          * Atoimc_open may passin hashed dentries for open.
665          */
666         alias = ll_splice_alias(inode, *de);
667         if (IS_ERR(alias))
668                 GOTO(out, rc = PTR_ERR(alias));
669
670         *de = alias;
671
672         if (!it_disposition(it, DISP_LOOKUP_NEG)) {
673                 /* we have lookup look - unhide dentry */
674                 if (bits & MDS_INODELOCK_LOOKUP)
675                         d_lustre_revalidate(*de);
676         } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
677                 /*
678                  * If file was created on the server, the dentry is revalidated
679                  * in ll_create_it if the lock allows for it.
680                  */
681                 /* Check that parent has UPDATE lock. */
682                 struct lookup_intent parent_it = {
683                                         .it_op = IT_GETATTR,
684                                         .it_lock_handle = 0 };
685                 struct lu_fid   fid = ll_i2info(parent)->lli_fid;
686
687                 /* If it is striped directory, get the real stripe parent */
688                 if (unlikely(ll_dir_striped(parent))) {
689                         rc = md_get_fid_from_lsm(ll_i2mdexp(parent),
690                                                  ll_i2info(parent)->lli_lsm_md,
691                                                  (*de)->d_name.name,
692                                                  (*de)->d_name.len, &fid);
693                         if (rc != 0)
694                                 GOTO(out, rc);
695                 }
696
697                 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it, &fid,
698                                        NULL)) {
699                         d_lustre_revalidate(*de);
700                         ll_intent_release(&parent_it);
701                 }
702         }
703
704         GOTO(out, rc = 0);
705
706 out:
707         if (rc != 0 && it->it_op & IT_OPEN)
708                 ll_open_cleanup((*de)->d_sb, request);
709
710         return rc;
711 }
712
713 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
714                                    struct lookup_intent *it,
715                                    void **secctx, __u32 *secctxlen,
716                                    struct pcc_create_attach *pca)
717 {
718         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
719         struct dentry *save = dentry, *retval;
720         struct ptlrpc_request *req = NULL;
721         struct md_op_data *op_data = NULL;
722         struct lov_user_md *lum = NULL;
723         __u32 opc;
724         int rc;
725         char secctx_name[XATTR_NAME_MAX + 1];
726
727         ENTRY;
728
729         if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
730                 RETURN(ERR_PTR(-ENAMETOOLONG));
731
732         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), intent=%s\n",
733                dentry->d_name.len, dentry->d_name.name,
734                PFID(ll_inode2fid(parent)), parent, LL_IT2STR(it));
735
736         if (d_mountpoint(dentry))
737                 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
738
739         if (it == NULL || it->it_op == IT_GETXATTR)
740                 it = &lookup_it;
741
742         if (it->it_op == IT_GETATTR && dentry_may_statahead(parent, dentry)) {
743                 rc = ll_statahead(parent, &dentry, 0);
744                 if (rc == 1)
745                         RETURN(dentry == save ? NULL : dentry);
746         }
747
748         if (it->it_op & IT_OPEN && it->it_flags & FMODE_WRITE &&
749             dentry->d_sb->s_flags & SB_RDONLY)
750                 RETURN(ERR_PTR(-EROFS));
751
752         if (it->it_op & IT_CREAT)
753                 opc = LUSTRE_OPC_CREATE;
754         else
755                 opc = LUSTRE_OPC_ANY;
756
757         op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
758                                      dentry->d_name.len, 0, opc, NULL);
759         if (IS_ERR(op_data))
760                 GOTO(out, retval = ERR_CAST(op_data));
761
762         /* enforce umask if acl disabled or MDS doesn't support umask */
763         if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
764                 it->it_create_mode &= ~current_umask();
765
766         if (it->it_op & IT_CREAT &&
767             ll_i2sbi(parent)->ll_flags & LL_SBI_FILE_SECCTX) {
768                 rc = ll_dentry_init_security(dentry, it->it_create_mode,
769                                              &dentry->d_name,
770                                              &op_data->op_file_secctx_name,
771                                              &op_data->op_file_secctx,
772                                              &op_data->op_file_secctx_size);
773                 if (rc < 0)
774                         GOTO(out, retval = ERR_PTR(rc));
775                 if (secctx != NULL)
776                         *secctx = op_data->op_file_secctx;
777                 if (secctxlen != NULL)
778                         *secctxlen = op_data->op_file_secctx_size;
779         } else {
780                 if (secctx != NULL)
781                         *secctx = NULL;
782                 if (secctxlen != NULL)
783                         *secctxlen = 0;
784         }
785
786         /* ask for security context upon intent */
787         if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_OPEN)) {
788                 /* get name of security xattr to request to server */
789                 rc = ll_listsecurity(parent, secctx_name,
790                                      sizeof(secctx_name));
791                 if (rc < 0) {
792                         CDEBUG(D_SEC, "cannot get security xattr name for "
793                                DFID": rc = %d\n",
794                                PFID(ll_inode2fid(parent)), rc);
795                 } else if (rc > 0) {
796                         op_data->op_file_secctx_name = secctx_name;
797                         op_data->op_file_secctx_name_size = rc;
798                         CDEBUG(D_SEC, "'%.*s' is security xattr for "DFID"\n",
799                                rc, secctx_name, PFID(ll_inode2fid(parent)));
800                 }
801         }
802
803         if (pca && pca->pca_dataset) {
804                 struct pcc_dataset *dataset = pca->pca_dataset;
805
806                 OBD_ALLOC_PTR(lum);
807                 if (lum == NULL)
808                         GOTO(out, retval = ERR_PTR(-ENOMEM));
809
810                 lum->lmm_magic = LOV_USER_MAGIC_V1;
811                 lum->lmm_pattern = LOV_PATTERN_F_RELEASED | LOV_PATTERN_RAID0;
812                 op_data->op_data = lum;
813                 op_data->op_data_size = sizeof(*lum);
814                 op_data->op_archive_id = dataset->pccd_rwid;
815
816                 rc = obd_fid_alloc(NULL, ll_i2mdexp(parent), &op_data->op_fid2,
817                                    op_data);
818                 if (rc)
819                         GOTO(out, retval = ERR_PTR(rc));
820
821                 rc = pcc_inode_create(parent->i_sb, dataset, &op_data->op_fid2,
822                                       &pca->pca_dentry);
823                 if (rc)
824                         GOTO(out, retval = ERR_PTR(rc));
825
826                 it->it_flags |= MDS_OPEN_PCC;
827         }
828
829         rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
830                             &ll_md_blocking_ast, 0);
831         /* If the MDS allows the client to chgrp (CFS_SETGRP_PERM), but the
832          * client does not know which suppgid should be sent to the MDS, or
833          * some other(s) changed the target file's GID after this RPC sent
834          * to the MDS with the suppgid as the original GID, then we should
835          * try again with right suppgid. */
836         if (rc == -EACCES && it->it_op & IT_OPEN &&
837             it_disposition(it, DISP_OPEN_DENY)) {
838                 struct mdt_body *body;
839
840                 LASSERT(req != NULL);
841
842                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
843                 if (op_data->op_suppgids[0] == body->mbo_gid ||
844                     op_data->op_suppgids[1] == body->mbo_gid ||
845                     !in_group_p(make_kgid(&init_user_ns, body->mbo_gid)))
846                         GOTO(out, retval = ERR_PTR(-EACCES));
847
848                 fid_zero(&op_data->op_fid2);
849                 op_data->op_suppgids[1] = body->mbo_gid;
850                 ptlrpc_req_finished(req);
851                 req = NULL;
852                 ll_intent_release(it);
853                 rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
854                                     &ll_md_blocking_ast, 0);
855         }
856
857         if (rc < 0)
858                 GOTO(out, retval = ERR_PTR(rc));
859
860         /* dir layout may change */
861         ll_unlock_md_op_lsm(op_data);
862         rc = ll_lookup_it_finish(req, it, parent, &dentry,
863                                  secctx != NULL ? *secctx : NULL,
864                                  secctxlen != NULL ? *secctxlen : 0);
865         if (rc != 0) {
866                 ll_intent_release(it);
867                 GOTO(out, retval = ERR_PTR(rc));
868         }
869
870         if ((it->it_op & IT_OPEN) && dentry->d_inode &&
871             !S_ISREG(dentry->d_inode->i_mode) &&
872             !S_ISDIR(dentry->d_inode->i_mode)) {
873                 ll_release_openhandle(dentry, it);
874         }
875         ll_lookup_finish_locks(it, dentry);
876
877         GOTO(out, retval = (dentry == save) ? NULL : dentry);
878
879 out:
880         if (op_data != NULL && !IS_ERR(op_data)) {
881                 if (secctx != NULL && secctxlen != NULL) {
882                         /* caller needs sec ctx info, so reset it in op_data to
883                          * prevent it from being freed */
884                         op_data->op_file_secctx = NULL;
885                         op_data->op_file_secctx_size = 0;
886                 }
887                 ll_finish_md_op_data(op_data);
888         }
889
890         if (lum != NULL)
891                 OBD_FREE_PTR(lum);
892
893         ptlrpc_req_finished(req);
894         return retval;
895 }
896
897 #ifdef HAVE_IOP_ATOMIC_OPEN
898 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
899                                    unsigned int flags)
900 {
901         struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
902         struct dentry *de;
903
904         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), flags=%u\n",
905                dentry->d_name.len, dentry->d_name.name,
906                PFID(ll_inode2fid(parent)), parent, flags);
907
908         /*
909          * Optimize away (CREATE && !OPEN). Let .create handle the race.
910          * but only if we have write permissions there, otherwise we need
911          * to proceed with lookup. LU-4185
912          */
913         if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN) &&
914             (inode_permission(parent, MAY_WRITE | MAY_EXEC) == 0))
915                 return NULL;
916
917         if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE))
918                 itp = NULL;
919         else
920                 itp = &it;
921         de = ll_lookup_it(parent, dentry, itp, NULL, NULL, NULL);
922
923         if (itp != NULL)
924                 ll_intent_release(itp);
925
926         return de;
927 }
928
929 #ifdef FMODE_CREATED /* added in Linux v4.18-rc1-20-g73a09dd */
930 # define ll_is_opened(o, f)             ((f)->f_mode & FMODE_OPENED)
931 # define ll_finish_open(f, d, o)        finish_open((f), (d), NULL)
932 # define ll_last_arg
933 # define ll_set_created(o, f)                                           \
934 do {                                                                    \
935         (f)->f_mode |= FMODE_CREATED;                                   \
936 } while (0)
937
938 #else
939 # define ll_is_opened(o, f)             (*(o))
940 # define ll_finish_open(f, d, o)        finish_open((f), (d), NULL, (o))
941 # define ll_last_arg                    , int *opened
942 # define ll_set_created(o, f)                                           \
943 do {                                                                    \
944         *(o) |= FILE_CREATED;                                           \
945 } while (0)
946
947 #endif
948
949 /*
950  * For cached negative dentry and new dentry, handle lookup/create/open
951  * together.
952  */
953 static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
954                           struct file *file, unsigned open_flags,
955                           umode_t mode ll_last_arg)
956 {
957         struct lookup_intent *it;
958         struct dentry *de;
959         long long lookup_flags = LOOKUP_OPEN;
960         void *secctx = NULL;
961         __u32 secctxlen = 0;
962         struct ll_sb_info *sbi;
963         struct pcc_create_attach pca = { NULL, NULL };
964         int rc = 0;
965         ENTRY;
966
967         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), file %p,"
968                            "open_flags %x, mode %x opened %d\n",
969                dentry->d_name.len, dentry->d_name.name,
970                PFID(ll_inode2fid(dir)), dir, file, open_flags, mode,
971                ll_is_opened(opened, file));
972
973         /* Only negative dentries enter here */
974         LASSERT(dentry->d_inode == NULL);
975
976         if (!d_unhashed(dentry)) {
977                 /* A valid negative dentry that just passed revalidation,
978                  * there's little point to try and open it server-side,
979                  * even though there's a minuscule chance it might succeed.
980                  * Either way it's a valid race to just return -ENOENT here.
981                  */
982                 if (!(open_flags & O_CREAT))
983                         return -ENOENT;
984
985                 /* Otherwise we just unhash it to be rehashed afresh via
986                  * lookup if necessary
987                  */
988                 d_drop(dentry);
989         }
990
991         OBD_ALLOC(it, sizeof(*it));
992         if (!it)
993                 RETURN(-ENOMEM);
994
995         it->it_op = IT_OPEN;
996         if (open_flags & O_CREAT) {
997                 it->it_op |= IT_CREAT;
998                 lookup_flags |= LOOKUP_CREATE;
999                 sbi = ll_i2sbi(dir);
1000                 /* Volatile file is used for HSM restore, so do not use PCC */
1001                 if (!filename_is_volatile(dentry->d_name.name,
1002                                           dentry->d_name.len, NULL)) {
1003                         struct pcc_matcher item;
1004                         struct pcc_dataset *dataset;
1005
1006                         item.pm_uid = from_kuid(&init_user_ns, current_uid());
1007                         item.pm_gid = from_kgid(&init_user_ns, current_gid());
1008                         item.pm_projid = ll_i2info(dir)->lli_projid;
1009                         item.pm_name = &dentry->d_name;
1010                         dataset = pcc_dataset_match_get(&sbi->ll_pcc_super,
1011                                                         &item);
1012                         pca.pca_dataset = dataset;
1013                 }
1014         }
1015         it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
1016         it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
1017         it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1018
1019         /* Dentry added to dcache tree in ll_lookup_it */
1020         de = ll_lookup_it(dir, dentry, it, &secctx, &secctxlen, &pca);
1021         if (IS_ERR(de))
1022                 rc = PTR_ERR(de);
1023         else if (de != NULL)
1024                 dentry = de;
1025
1026         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1027
1028         if (!rc) {
1029                 if (it_disposition(it, DISP_OPEN_CREATE)) {
1030                         /* Dentry instantiated in ll_create_it. */
1031                         rc = ll_create_it(dir, dentry, it, secctx, secctxlen);
1032                         security_release_secctx(secctx, secctxlen);
1033                         if (rc) {
1034                                 /* We dget in ll_splice_alias. */
1035                                 if (de != NULL)
1036                                         dput(de);
1037                                 goto out_release;
1038                         }
1039
1040                         rc = pcc_inode_create_fini(dentry->d_inode, &pca);
1041                         if (rc) {
1042                                 if (de != NULL)
1043                                         dput(de);
1044                                 GOTO(out_release, rc);
1045                         }
1046
1047                         ll_set_created(opened, file);
1048                 } else {
1049                         /* Open the file with O_CREAT, but the file already
1050                          * existed on MDT. This may happend in the case that
1051                          * the LOOKUP ibits lock is revoked and the
1052                          * corresponding dentry cache is deleted.
1053                          * i.e. In the current Lustre, the truncate operation
1054                          * will revoke the LOOKUP ibits lock, and the file
1055                          * dentry cache will be invalidated. The following open
1056                          * with O_CREAT flag will call into ->atomic_open, the
1057                          * file was wrongly though as newly created file and
1058                          * try to auto cache the file. So after client knows it
1059                          * is not a DISP_OPEN_CREATE, it should cleanup the
1060                          * already created PCC copy.
1061                          */
1062                         pcc_create_attach_cleanup(dir->i_sb, &pca);
1063                 }
1064
1065                 if (dentry->d_inode && it_disposition(it, DISP_OPEN_OPEN)) {
1066                         /* Open dentry. */
1067                         if (S_ISFIFO(dentry->d_inode->i_mode)) {
1068                                 /* We cannot call open here as it might
1069                                  * deadlock. This case is unreachable in
1070                                  * practice because of OBD_CONNECT_NODEVOH. */
1071                                 rc = finish_no_open(file, de);
1072                         } else {
1073                                 file->private_data = it;
1074                                 rc = ll_finish_open(file, dentry, opened);
1075                                 /* We dget in ll_splice_alias. finish_open takes
1076                                  * care of dget for fd open.
1077                                  */
1078                                 if (de != NULL)
1079                                         dput(de);
1080                         }
1081                 } else {
1082                         rc = finish_no_open(file, de);
1083                 }
1084         } else {
1085                 pcc_create_attach_cleanup(dir->i_sb, &pca);
1086         }
1087
1088 out_release:
1089         ll_intent_release(it);
1090         OBD_FREE(it, sizeof(*it));
1091
1092         RETURN(rc);
1093 }
1094
1095 #else /* !HAVE_IOP_ATOMIC_OPEN */
1096 static struct lookup_intent *
1097 ll_convert_intent(struct open_intent *oit, int lookup_flags, bool is_readonly)
1098 {
1099         struct lookup_intent *it;
1100
1101         OBD_ALLOC_PTR(it);
1102         if (!it)
1103                 return ERR_PTR(-ENOMEM);
1104
1105         if (lookup_flags & LOOKUP_OPEN) {
1106                 it->it_op = IT_OPEN;
1107                 /* Avoid file creation for ro bind mount point(is_readonly) */
1108                 if ((lookup_flags & LOOKUP_CREATE) && !is_readonly)
1109                         it->it_op |= IT_CREAT;
1110                 it->it_create_mode = (oit->create_mode & S_IALLUGO) | S_IFREG;
1111                 it->it_flags = ll_namei_to_lookup_intent_flag(oit->flags &
1112                                                 ~(is_readonly ? O_CREAT : 0));
1113                 it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1114         } else {
1115                 it->it_op = IT_GETATTR;
1116         }
1117
1118         return it;
1119 }
1120
1121 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
1122                                    struct nameidata *nd)
1123 {
1124         struct dentry *de;
1125         ENTRY;
1126
1127         if (nd && !(nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))) {
1128                 struct lookup_intent *it;
1129
1130                 if (ll_d2d(dentry) && ll_d2d(dentry)->lld_it) {
1131                         it = ll_d2d(dentry)->lld_it;
1132                         ll_d2d(dentry)->lld_it = NULL;
1133                 } else {
1134                         /*
1135                          * Optimize away (CREATE && !OPEN). Let .create handle
1136                          * the race. But only if we have write permissions
1137                          * there, otherwise we need to proceed with lookup.
1138                          * LU-4185
1139                          */
1140                         if ((nd->flags & LOOKUP_CREATE) &&
1141                             !(nd->flags & LOOKUP_OPEN) &&
1142                             (inode_permission(parent,
1143                                               MAY_WRITE | MAY_EXEC) == 0))
1144                                 RETURN(NULL);
1145
1146                         it = ll_convert_intent(&nd->intent.open, nd->flags,
1147                                 (nd->path.mnt->mnt_flags & MNT_READONLY) ||
1148                                 (nd->path.mnt->mnt_sb->s_flags & SB_RDONLY));
1149                         if (IS_ERR(it))
1150                                 RETURN((struct dentry *)it);
1151                 }
1152
1153                 de = ll_lookup_it(parent, dentry, it, NULL, NULL, NULL);
1154                 if (de)
1155                         dentry = de;
1156                 if ((nd->flags & LOOKUP_OPEN) && !IS_ERR(dentry)) { /* Open */
1157                         if (dentry->d_inode &&
1158                             it_disposition(it, DISP_OPEN_OPEN)) { /* nocreate */
1159                                 if (S_ISFIFO(dentry->d_inode->i_mode)) {
1160                                         /* We cannot call open here as it might
1161                                          * deadlock. This case is unreachable in
1162                                          * practice because of
1163                                          * OBD_CONNECT_NODEVOH. */
1164                                 } else {
1165                                         struct file *filp;
1166
1167                                         nd->intent.open.file->private_data = it;
1168                                         filp = lookup_instantiate_filp(nd,
1169                                                                        dentry,
1170                                                                        NULL);
1171                                         if (IS_ERR(filp)) {
1172                                                 if (de)
1173                                                         dput(de);
1174                                                 de = (struct dentry *)filp;
1175                                         }
1176                                 }
1177                         } else if (it_disposition(it, DISP_OPEN_CREATE)) {
1178                                 /* XXX This can only reliably work on assumption
1179                                  * that there are NO hashed negative dentries.*/
1180                                 ll_d2d(dentry)->lld_it = it;
1181                                 it = NULL; /* Will be freed in ll_create_nd */
1182                                 /* We absolutely depend on ll_create_nd to be
1183                                  * called to not leak this intent and possible
1184                                  * data attached to it */
1185                         }
1186                 }
1187
1188                 if (it) {
1189                         ll_intent_release(it);
1190                         OBD_FREE(it, sizeof(*it));
1191                 }
1192         } else {
1193                 de = ll_lookup_it(parent, dentry, NULL, NULL, NULL, NULL);
1194         }
1195
1196         RETURN(de);
1197 }
1198 #endif /* HAVE_IOP_ATOMIC_OPEN */
1199
1200 /* We depend on "mode" being set with the proper file type/umask by now */
1201 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
1202 {
1203         struct inode *inode = NULL;
1204         struct ptlrpc_request *request = NULL;
1205         struct ll_sb_info *sbi = ll_i2sbi(dir);
1206         int rc;
1207         ENTRY;
1208
1209         LASSERT(it && it->it_disposition);
1210
1211         LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
1212         request = it->it_request;
1213         it_clear_disposition(it, DISP_ENQ_CREATE_REF);
1214         rc = ll_prep_inode(&inode, request, dir->i_sb, it);
1215         if (rc)
1216                 GOTO(out, inode = ERR_PTR(rc));
1217
1218         /* Pause to allow for a race with concurrent access by fid */
1219         OBD_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_NODE_PAUSE, cfs_fail_val);
1220
1221         /* We asked for a lock on the directory, but were granted a
1222          * lock on the inode.  Since we finally have an inode pointer,
1223          * stuff it in the lock. */
1224         CDEBUG(D_DLMTRACE, "setting l_ast_data to inode "DFID"(%p)\n",
1225                PFID(ll_inode2fid(inode)), inode);
1226         ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
1227         EXIT;
1228  out:
1229         ptlrpc_req_finished(request);
1230         return inode;
1231 }
1232
1233 /*
1234  * By the time this is called, we already have created the directory cache
1235  * entry for the new file, but it is so far negative - it has no inode.
1236  *
1237  * We defer creating the OBD object(s) until open, to keep the intent and
1238  * non-intent code paths similar, and also because we do not have the MDS
1239  * inode number before calling ll_create_node() (which is needed for LOV),
1240  * so we would need to do yet another RPC to the MDS to store the LOV EA
1241  * data on the MDS.  If needed, we would pass the PACKED lmm as data and
1242  * lmm_size in datalen (the MDS still has code which will handle that).
1243  *
1244  * If the create succeeds, we fill in the inode information
1245  * with d_instantiate().
1246  */
1247 static int ll_create_it(struct inode *dir, struct dentry *dentry,
1248                         struct lookup_intent *it,
1249                         void *secctx, __u32 secctxlen)
1250 {
1251         struct inode *inode;
1252         __u64 bits = 0;
1253         int rc = 0;
1254         ENTRY;
1255
1256         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), intent=%s\n",
1257                dentry->d_name.len, dentry->d_name.name,
1258                PFID(ll_inode2fid(dir)), dir, LL_IT2STR(it));
1259
1260         rc = it_open_error(DISP_OPEN_CREATE, it);
1261         if (rc)
1262                 RETURN(rc);
1263
1264         inode = ll_create_node(dir, it);
1265         if (IS_ERR(inode))
1266                 RETURN(PTR_ERR(inode));
1267
1268         if ((ll_i2sbi(inode)->ll_flags & LL_SBI_FILE_SECCTX) &&
1269             secctx != NULL) {
1270                 inode_lock(inode);
1271                 /* must be done before d_instantiate, because it calls
1272                  * security_d_instantiate, which means a getxattr if security
1273                  * context is not set yet */
1274                 rc = security_inode_notifysecctx(inode, secctx, secctxlen);
1275                 inode_unlock(inode);
1276                 if (rc)
1277                         RETURN(rc);
1278         }
1279
1280         d_instantiate(dentry, inode);
1281
1282         if (!(ll_i2sbi(inode)->ll_flags & LL_SBI_FILE_SECCTX)) {
1283                 rc = ll_inode_init_security(dentry, inode, dir);
1284                 if (rc)
1285                         RETURN(rc);
1286         }
1287
1288         ll_set_lock_data(ll_i2sbi(dir)->ll_md_exp, inode, it, &bits);
1289         if (bits & MDS_INODELOCK_LOOKUP)
1290                 d_lustre_revalidate(dentry);
1291
1292         RETURN(0);
1293 }
1294
1295 void ll_update_times(struct ptlrpc_request *request, struct inode *inode)
1296 {
1297         struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
1298                                                        &RMF_MDT_BODY);
1299
1300         LASSERT(body);
1301         if (body->mbo_valid & OBD_MD_FLMTIME &&
1302             body->mbo_mtime > inode->i_mtime.tv_sec) {
1303                 CDEBUG(D_INODE,
1304                        "setting fid " DFID " mtime from %lld to %llu\n",
1305                        PFID(ll_inode2fid(inode)),
1306                        (s64)inode->i_mtime.tv_sec, body->mbo_mtime);
1307                 inode->i_mtime.tv_sec = body->mbo_mtime;
1308         }
1309
1310         if (body->mbo_valid & OBD_MD_FLCTIME &&
1311             body->mbo_ctime > inode->i_ctime.tv_sec)
1312                 inode->i_ctime.tv_sec = body->mbo_ctime;
1313 }
1314
1315 static int ll_new_node(struct inode *dir, struct dentry *dchild,
1316                        const char *tgt, umode_t mode, int rdev, __u32 opc)
1317 {
1318         struct qstr *name = &dchild->d_name;
1319         struct ptlrpc_request *request = NULL;
1320         struct md_op_data *op_data;
1321         struct inode *inode = NULL;
1322         struct ll_sb_info *sbi = ll_i2sbi(dir);
1323         int tgt_len = 0;
1324         int err;
1325
1326         ENTRY;
1327         if (unlikely(tgt != NULL))
1328                 tgt_len = strlen(tgt) + 1;
1329
1330 again:
1331         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name,
1332                                      name->len, 0, opc, NULL);
1333         if (IS_ERR(op_data))
1334                 GOTO(err_exit, err = PTR_ERR(op_data));
1335
1336         if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
1337                 err = ll_dentry_init_security(dchild, mode, &dchild->d_name,
1338                                               &op_data->op_file_secctx_name,
1339                                               &op_data->op_file_secctx,
1340                                               &op_data->op_file_secctx_size);
1341                 if (err < 0)
1342                         GOTO(err_exit, err);
1343         }
1344
1345         err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
1346                         from_kuid(&init_user_ns, current_fsuid()),
1347                         from_kgid(&init_user_ns, current_fsgid()),
1348                         cfs_curproc_cap_pack(), rdev, &request);
1349 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 58, 0)
1350         /*
1351          * server < 2.12.58 doesn't pack default LMV in intent_getattr reply,
1352          * fetch default LMV here.
1353          */
1354         if (unlikely(err == -EREMOTE)) {
1355                 struct ll_inode_info    *lli = ll_i2info(dir);
1356                 struct lmv_user_md      *lum;
1357                 int                     lumsize;
1358                 int                     err2;
1359
1360                 ptlrpc_req_finished(request);
1361                 request = NULL;
1362
1363                 err2 = ll_dir_getstripe(dir, (void **)&lum, &lumsize, &request,
1364                                         OBD_MD_DEFAULT_MEA);
1365                 ll_finish_md_op_data(op_data);
1366                 op_data = NULL;
1367                 if (err2 == 0) {
1368                         struct lustre_md md = { NULL };
1369
1370                         md.body = req_capsule_server_get(&request->rq_pill,
1371                                                          &RMF_MDT_BODY);
1372                         if (!md.body)
1373                                 GOTO(err_exit, err = -EPROTO);
1374
1375                         OBD_ALLOC_PTR(md.default_lmv);
1376                         if (!md.default_lmv)
1377                                 GOTO(err_exit, err = -ENOMEM);
1378
1379                         md.default_lmv->lsm_md_magic = lum->lum_magic;
1380                         md.default_lmv->lsm_md_stripe_count =
1381                                 lum->lum_stripe_count;
1382                         md.default_lmv->lsm_md_master_mdt_index =
1383                                 lum->lum_stripe_offset;
1384                         md.default_lmv->lsm_md_hash_type = lum->lum_hash_type;
1385
1386                         err = ll_update_inode(dir, &md);
1387                         md_free_lustre_md(sbi->ll_md_exp, &md);
1388                         if (err)
1389                                 GOTO(err_exit, err);
1390                 } else if (err2 == -ENODATA && lli->lli_default_lsm_md) {
1391                         /*
1392                          * If there are no default stripe EA on the MDT, but the
1393                          * client has default stripe, then it probably means
1394                          * default stripe EA has just been deleted.
1395                          */
1396                         down_write(&lli->lli_lsm_sem);
1397                         if (lli->lli_default_lsm_md)
1398                                 OBD_FREE_PTR(lli->lli_default_lsm_md);
1399                         lli->lli_default_lsm_md = NULL;
1400                         up_write(&lli->lli_lsm_sem);
1401                 } else {
1402                         GOTO(err_exit, err);
1403                 }
1404
1405                 ptlrpc_req_finished(request);
1406                 request = NULL;
1407                 goto again;
1408         }
1409 #endif
1410
1411         if (err < 0)
1412                 GOTO(err_exit, err);
1413
1414         ll_update_times(request, dir);
1415
1416         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_NEWNODE_PAUSE, cfs_fail_val);
1417
1418         err = ll_prep_inode(&inode, request, dchild->d_sb, NULL);
1419         if (err)
1420                 GOTO(err_exit, err);
1421
1422         if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
1423                 inode_lock(inode);
1424                 /* must be done before d_instantiate, because it calls
1425                  * security_d_instantiate, which means a getxattr if security
1426                  * context is not set yet */
1427                 err = security_inode_notifysecctx(inode,
1428                                                   op_data->op_file_secctx,
1429                                                   op_data->op_file_secctx_size);
1430                 inode_unlock(inode);
1431                 if (err)
1432                         GOTO(err_exit, err);
1433         }
1434
1435         d_instantiate(dchild, inode);
1436
1437         if (!(sbi->ll_flags & LL_SBI_FILE_SECCTX)) {
1438                 err = ll_inode_init_security(dchild, inode, dir);
1439                 if (err)
1440                         GOTO(err_exit, err);
1441         }
1442
1443         EXIT;
1444 err_exit:
1445         if (request != NULL)
1446                 ptlrpc_req_finished(request);
1447
1448         if (!IS_ERR_OR_NULL(op_data))
1449                 ll_finish_md_op_data(op_data);
1450
1451         return err;
1452 }
1453
1454 static int ll_mknod(struct inode *dir, struct dentry *dchild, ll_umode_t mode,
1455                     dev_t rdev)
1456 {
1457         struct qstr *name = &dchild->d_name;
1458         int err;
1459         ENTRY;
1460
1461         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p) mode %o dev %x\n",
1462                name->len, name->name, PFID(ll_inode2fid(dir)), dir,
1463                mode, rdev);
1464
1465         if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1466                 mode &= ~current_umask();
1467
1468         switch (mode & S_IFMT) {
1469         case 0:
1470                 mode |= S_IFREG;
1471                 /* fallthrough */
1472         case S_IFREG:
1473         case S_IFCHR:
1474         case S_IFBLK:
1475         case S_IFIFO:
1476         case S_IFSOCK:
1477                 err = ll_new_node(dir, dchild, NULL, mode, old_encode_dev(rdev),
1478                                   LUSTRE_OPC_MKNOD);
1479                 break;
1480         case S_IFDIR:
1481                 err = -EPERM;
1482                 break;
1483         default:
1484                 err = -EINVAL;
1485         }
1486
1487         if (!err)
1488                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
1489
1490         RETURN(err);
1491 }
1492
1493 #ifdef HAVE_IOP_ATOMIC_OPEN
1494 /*
1495  * Plain create. Intent create is handled in atomic_open.
1496  */
1497 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
1498                         umode_t mode, bool want_excl)
1499 {
1500         int rc;
1501
1502         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1503
1504         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), "
1505                            "flags=%u, excl=%d\n", dentry->d_name.len,
1506                dentry->d_name.name, PFID(ll_inode2fid(dir)),
1507                dir, mode, want_excl);
1508
1509         /* Using mknod(2) to create a regular file is designed to not recognize
1510          * volatile file name, so we use ll_mknod() here. */
1511         rc = ll_mknod(dir, dentry, mode, 0);
1512
1513         ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
1514
1515         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, unhashed %d\n",
1516                dentry->d_name.len, dentry->d_name.name, d_unhashed(dentry));
1517
1518         return rc;
1519 }
1520 #else /* !HAVE_IOP_ATOMIC_OPEN */
1521 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
1522                         ll_umode_t mode, struct nameidata *nd)
1523 {
1524         struct ll_dentry_data *lld = ll_d2d(dentry);
1525         struct lookup_intent *it = NULL;
1526         int rc;
1527
1528         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1529
1530         if (lld != NULL)
1531                 it = lld->lld_it;
1532
1533         if (!it) {
1534                 /* LU-8559: use LUSTRE_OPC_CREATE for non atomic open case
1535                  * so that volatile file name is recoginized.
1536                  * Mknod(2), however, is designed to not recognize volatile
1537                  * file name to avoid inode leak under orphan directory until
1538                  * MDT reboot */
1539                 return ll_new_node(dir, dentry, NULL, mode, 0,
1540                                    LUSTRE_OPC_CREATE);
1541         }
1542
1543         lld->lld_it = NULL;
1544
1545         /* Was there an error? Propagate it! */
1546         if (it->it_status) {
1547                 rc = it->it_status;
1548                 goto out;
1549         }
1550
1551         rc = ll_create_it(dir, dentry, it, NULL, 0);
1552         if (nd && (nd->flags & LOOKUP_OPEN) && dentry->d_inode) { /* Open */
1553                 struct file *filp;
1554
1555                 nd->intent.open.file->private_data = it;
1556                 filp = lookup_instantiate_filp(nd, dentry, NULL);
1557                 if (IS_ERR(filp))
1558                         rc = PTR_ERR(filp);
1559         }
1560
1561 out:
1562         ll_intent_release(it);
1563         OBD_FREE(it, sizeof(*it));
1564
1565         if (!rc)
1566                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
1567
1568         return rc;
1569 }
1570 #endif /* HAVE_IOP_ATOMIC_OPEN */
1571
1572 static int ll_symlink(struct inode *dir, struct dentry *dchild,
1573                       const char *oldpath)
1574 {
1575         struct qstr *name = &dchild->d_name;
1576         int err;
1577         ENTRY;
1578
1579         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), target=%.*s\n",
1580                name->len, name->name, PFID(ll_inode2fid(dir)),
1581                dir, 3000, oldpath);
1582
1583         err = ll_new_node(dir, dchild, oldpath, S_IFLNK | S_IRWXUGO, 0,
1584                           LUSTRE_OPC_SYMLINK);
1585
1586         if (!err)
1587                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1);
1588
1589         RETURN(err);
1590 }
1591
1592 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1593                    struct dentry *new_dentry)
1594 {
1595         struct inode *src = old_dentry->d_inode;
1596         struct qstr *name = &new_dentry->d_name;
1597         struct ll_sb_info *sbi = ll_i2sbi(dir);
1598         struct ptlrpc_request *request = NULL;
1599         struct md_op_data *op_data;
1600         int err;
1601
1602         ENTRY;
1603         CDEBUG(D_VFSTRACE, "VFS Op: inode="DFID"(%p), dir="DFID"(%p), "
1604                "target=%.*s\n", PFID(ll_inode2fid(src)), src,
1605                PFID(ll_inode2fid(dir)), dir, name->len, name->name);
1606
1607         op_data = ll_prep_md_op_data(NULL, src, dir, name->name, name->len,
1608                                      0, LUSTRE_OPC_ANY, NULL);
1609         if (IS_ERR(op_data))
1610                 RETURN(PTR_ERR(op_data));
1611
1612         err = md_link(sbi->ll_md_exp, op_data, &request);
1613         ll_finish_md_op_data(op_data);
1614         if (err)
1615                 GOTO(out, err);
1616
1617         ll_update_times(request, dir);
1618         ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
1619         EXIT;
1620 out:
1621         ptlrpc_req_finished(request);
1622         RETURN(err);
1623 }
1624
1625 static int ll_mkdir(struct inode *dir, struct dentry *dchild, ll_umode_t mode)
1626 {
1627         struct qstr *name = &dchild->d_name;
1628         int err;
1629         ENTRY;
1630
1631         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1632                name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1633
1634         if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1635                 mode &= ~current_umask();
1636
1637         mode = (mode & (S_IRWXUGO|S_ISVTX)) | S_IFDIR;
1638
1639         err = ll_new_node(dir, dchild, NULL, mode, 0, LUSTRE_OPC_MKDIR);
1640         if (err == 0)
1641                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1);
1642
1643         RETURN(err);
1644 }
1645
1646 static int ll_rmdir(struct inode *dir, struct dentry *dchild)
1647 {
1648         struct qstr *name = &dchild->d_name;
1649         struct ptlrpc_request *request = NULL;
1650         struct md_op_data *op_data;
1651         int rc;
1652         ENTRY;
1653
1654         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1655                name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1656
1657         if (unlikely(d_mountpoint(dchild)))
1658                 RETURN(-EBUSY);
1659
1660         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len,
1661                                      S_IFDIR, LUSTRE_OPC_ANY, NULL);
1662         if (IS_ERR(op_data))
1663                 RETURN(PTR_ERR(op_data));
1664
1665         if (dchild->d_inode != NULL)
1666                 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
1667
1668         op_data->op_fid2 = op_data->op_fid3;
1669         rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1670         ll_finish_md_op_data(op_data);
1671         if (rc == 0) {
1672                 ll_update_times(request, dir);
1673                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1674         }
1675
1676         ptlrpc_req_finished(request);
1677         RETURN(rc);
1678 }
1679
1680 /**
1681  * Remove dir entry
1682  **/
1683 int ll_rmdir_entry(struct inode *dir, char *name, int namelen)
1684 {
1685         struct ptlrpc_request *request = NULL;
1686         struct md_op_data *op_data;
1687         int rc;
1688         ENTRY;
1689
1690         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1691                namelen, name, PFID(ll_inode2fid(dir)), dir);
1692
1693         op_data = ll_prep_md_op_data(NULL, dir, NULL, name, strlen(name),
1694                                      S_IFDIR, LUSTRE_OPC_ANY, NULL);
1695         if (IS_ERR(op_data))
1696                 RETURN(PTR_ERR(op_data));
1697         op_data->op_cli_flags |= CLI_RM_ENTRY;
1698         rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1699         ll_finish_md_op_data(op_data);
1700         if (rc == 0) {
1701                 ll_update_times(request, dir);
1702                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1703         }
1704
1705         ptlrpc_req_finished(request);
1706         RETURN(rc);
1707 }
1708
1709 static int ll_unlink(struct inode *dir, struct dentry *dchild)
1710 {
1711         struct qstr *name = &dchild->d_name;
1712         struct ptlrpc_request *request = NULL;
1713         struct md_op_data *op_data;
1714         struct mdt_body *body;
1715         int rc;
1716         ENTRY;
1717         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1718                name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1719
1720         /*
1721          * XXX: unlink bind mountpoint maybe call to here,
1722          * just check it as vfs_unlink does.
1723          */
1724         if (unlikely(d_mountpoint(dchild)))
1725                 RETURN(-EBUSY);
1726
1727         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len, 0,
1728                                      LUSTRE_OPC_ANY, NULL);
1729         if (IS_ERR(op_data))
1730                 RETURN(PTR_ERR(op_data));
1731
1732         op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
1733
1734         op_data->op_fid2 = op_data->op_fid3;
1735         rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1736         ll_finish_md_op_data(op_data);
1737         if (rc)
1738                 GOTO(out, rc);
1739
1740         /*
1741          * The server puts attributes in on the last unlink, use them to update
1742          * the link count so the inode can be freed immediately.
1743          */
1744         body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
1745         if (body->mbo_valid & OBD_MD_FLNLINK)
1746                 set_nlink(dchild->d_inode, body->mbo_nlink);
1747
1748         ll_update_times(request, dir);
1749         ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
1750
1751 out:
1752         ptlrpc_req_finished(request);
1753         RETURN(rc);
1754 }
1755
1756 static int ll_rename(struct inode *src, struct dentry *src_dchild,
1757                      struct inode *tgt, struct dentry *tgt_dchild
1758 #ifdef HAVE_IOPS_RENAME_WITH_FLAGS
1759                      , unsigned int flags
1760 #endif
1761                      )
1762 {
1763         struct qstr *src_name = &src_dchild->d_name;
1764         struct qstr *tgt_name = &tgt_dchild->d_name;
1765         struct ptlrpc_request *request = NULL;
1766         struct ll_sb_info *sbi = ll_i2sbi(src);
1767         struct md_op_data *op_data;
1768         int err;
1769         ENTRY;
1770
1771 #ifdef HAVE_IOPS_RENAME_WITH_FLAGS
1772         if (flags)
1773                 return -EINVAL;
1774 #endif
1775
1776         CDEBUG(D_VFSTRACE, "VFS Op:oldname=%.*s, src_dir="DFID
1777                "(%p), newname=%.*s, tgt_dir="DFID"(%p)\n",
1778                src_name->len, src_name->name,
1779                PFID(ll_inode2fid(src)), src, tgt_name->len,
1780                tgt_name->name, PFID(ll_inode2fid(tgt)), tgt);
1781
1782         if (unlikely(d_mountpoint(src_dchild) || d_mountpoint(tgt_dchild)))
1783                 RETURN(-EBUSY);
1784
1785         op_data = ll_prep_md_op_data(NULL, src, tgt, NULL, 0, 0,
1786                                      LUSTRE_OPC_ANY, NULL);
1787         if (IS_ERR(op_data))
1788                 RETURN(PTR_ERR(op_data));
1789
1790         if (src_dchild->d_inode != NULL)
1791                 op_data->op_fid3 = *ll_inode2fid(src_dchild->d_inode);
1792
1793         if (tgt_dchild->d_inode != NULL)
1794                 op_data->op_fid4 = *ll_inode2fid(tgt_dchild->d_inode);
1795
1796         err = md_rename(sbi->ll_md_exp, op_data,
1797                         src_name->name, src_name->len,
1798                         tgt_name->name, tgt_name->len, &request);
1799         ll_finish_md_op_data(op_data);
1800         if (!err) {
1801                 ll_update_times(request, src);
1802                 ll_update_times(request, tgt);
1803                 ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
1804         }
1805
1806         ptlrpc_req_finished(request);
1807
1808         if (err == 0)
1809                 d_move(src_dchild, tgt_dchild);
1810
1811         RETURN(err);
1812 }
1813
1814 const struct inode_operations ll_dir_inode_operations = {
1815         .mknod          = ll_mknod,
1816 #ifdef HAVE_IOP_ATOMIC_OPEN
1817         .atomic_open    = ll_atomic_open,
1818 #endif
1819         .lookup         = ll_lookup_nd,
1820         .create         = ll_create_nd,
1821         /* We need all these non-raw things for NFSD, to not patch it. */
1822         .unlink         = ll_unlink,
1823         .mkdir          = ll_mkdir,
1824         .rmdir          = ll_rmdir,
1825         .symlink        = ll_symlink,
1826         .link           = ll_link,
1827         .rename         = ll_rename,
1828         .setattr        = ll_setattr,
1829         .getattr        = ll_getattr,
1830         .permission     = ll_inode_permission,
1831 #ifdef HAVE_IOP_XATTR
1832         .setxattr       = ll_setxattr,
1833         .getxattr       = ll_getxattr,
1834         .removexattr    = ll_removexattr,
1835 #endif
1836         .listxattr      = ll_listxattr,
1837 #ifdef HAVE_IOP_GET_ACL
1838         .get_acl        = ll_get_acl,
1839 #endif
1840 #ifdef HAVE_IOP_SET_ACL
1841         .set_acl        = ll_set_acl,
1842 #endif
1843 };
1844
1845 const struct inode_operations ll_special_inode_operations = {
1846         .setattr        = ll_setattr,
1847         .getattr        = ll_getattr,
1848         .permission     = ll_inode_permission,
1849 #ifdef HAVE_IOP_XATTR
1850         .setxattr       = ll_setxattr,
1851         .getxattr       = ll_getxattr,
1852         .removexattr    = ll_removexattr,
1853 #endif
1854         .listxattr      = ll_listxattr,
1855 #ifdef HAVE_IOP_GET_ACL
1856         .get_acl        = ll_get_acl,
1857 #endif
1858 #ifdef HAVE_IOP_SET_ACL
1859         .set_acl        = ll_set_acl,
1860 #endif
1861 };